Skip to content

Commit a2c6333

Browse files
author
notnotmelon
committed
fix: Removed "Factory floor 0". Resolves #256
1 parent 3a076c8 commit a2c6333

5 files changed

Lines changed: 81 additions & 96 deletions

File tree

locale/en/locale.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ factorissimo-2-notnotmelon=Factorissimo adds factory buildings to Factorio. Plac
1212
factory-connection-indicator-settings=Connection settings
1313
factory-packed=__1__ (Packed)
1414

15+
[item-description]
16+
bound-to=[font=default-semibold][color=255,230,192]Bound to: [/color][/font]__1__
17+
1518
[entity-name]
1619
borehole-pump=Borehole pump
1720
factory-1=Factory building 1
@@ -90,10 +93,9 @@ update-slower=Decreased update rate (delay: __1__)
9093
invalid-placement-recursion-1=[img=utility/warning_icon] This won't work yet! Research Recursion 1 first.
9194
invalid-placement-recursion-2=[img=utility/warning_icon] This won't work yet! Research Recursion 2 first.
9295
invalid-factory-data=[img=utility/warning_icon] Invalid factory data!
93-
invalid-placement-planet=[img=utility/warning_icon] This won't work here! This factory building is designed for [img=space-location/__1__] __2__.
96+
invalid-placement-surface=[img=utility/warning_icon] This won't work here! This factory building is designed for __1__. Was instead __2__.
9497
borehole-pump-no-fluid=[img=utility/warning_icon] There is no fluid available on this planet.
9598
se-cannot-build-in-spaceship-factory-building=[img=utility/warning_icon] Cannot build containers inside spaceship factory buildings.
96-
se-must-not-build-factory-building-on-a-spaceship=[img=utility/warning_icon] Already-constructed factory buildings cannot be built on spaceships. Try instead with a fresh factory.
9799
98100
[controls]
99101
factory-rotate=Change connection direction
@@ -163,6 +165,7 @@ Factorissimo2-factory-preview-mode-off=The factory preview will not render at al
163165
[space-location-name]
164166
factory-floor=[img=technology.factory-architecture-t1] Factory floor __1__
165167
space-factory-floor=[img=factory-floor-space] Space factory floor
168+
se-spaceship-factory-floor=[img=technology.se-spaceship] Spaceship factory floor
166169
167170
[space-location-description]
168171
factory-floor=Interior building area of your factory buildings on [planet=__2__].

migrations/2.0.0.lua

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ for _, factory in pairs(storage.factories) do
1818
factorissimo.update_power_connection(factory)
1919
end
2020

21-
local new_surface_factories = {}
22-
for surface_name, factory_list in pairs(storage.surface_factories or {}) do
23-
if type(surface_name) == "string" then
24-
local surface = game.get_surface(surface_name)
25-
new_surface_factories[surface.index] = factory_list
26-
else
27-
new_surface_factories[surface_name] = factory_list
28-
end
29-
end
30-
3121
storage.surface_factory_counters = nil
3222
storage.middleman_circuit_connectors = nil
3323
storage.spidertrons = nil
34-
35-
local old_factory_surface = game.surfaces["factory-floor-1"]
36-
local planet = game.planets["nauvis-factory-floor"]
37-
if old_factory_surface and planet and not planet.surface then
38-
planet.associate_surface(old_factory_surface)
39-
end

prototypes/space-location.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data:extend {{
2323
gravity = -1,
2424
pressure = 10000,
2525
["solar-power"] = 0,
26-
}
26+
},
2727
}}
2828

2929
data:extend{{
@@ -126,7 +126,7 @@ end
126126
-- we need to copy all existing planets in order to create factory floors for them
127127
local factory_floors = {}
128128
for _, planet in pairs(data.raw.planet) do
129-
if planet.hidden and not planet.name == "neo-nauvis" then goto continue end
129+
if planet.hidden and planet.name ~= "neo-nauvis" then goto continue end
130130
if planet.ignored_for_factorissimo then goto continue end
131131

132132
local factory_floor = table.deepcopy(planet)

script/factory-buildings.lua

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ factorissimo.on_event(factorissimo.events.on_init(), function()
1414
storage.factories_by_entity = storage.factories_by_entity or {}
1515
-- Map: Surface index -> list of factories on it
1616
storage.surface_factories = storage.surface_factories or {}
17-
-- Scalar
18-
storage.next_factory_surface = storage.next_factory_surface or 0
1917
end)
2018

2119
-- RECURSION TECHNOLOGY --
@@ -45,17 +43,32 @@ local function was_this_placed_on_a_space_exploration_spaceship(layout, building
4543
}
4644
end
4745

48-
--- @param surface LuaSurface|LuaPlanet
46+
local function surface_localised_name(surface)
47+
if surface.localised_name then
48+
return surface.localised_name
49+
elseif surface.planet and surface.planet.prototype.localised_name then
50+
return {"", "[img=space-location.", surface.planet.name, "] ", surface.planet.prototype.localised_name}
51+
else
52+
return {"?", {"space-location-name." .. surface.name}, surface.name}
53+
end
54+
end
55+
4956
--- @return string
50-
local function true_name(surface)
51-
if surface.name:find("%-factory%-floor$") then
52-
return surface.name:gsub("%-factory%-floor$", "")
53-
elseif (surface.object_name or type(surface)) == "LuaSurface" then
54-
if surface.planet or surface.platform then
55-
return surface.planet.name
56-
end
57+
local function which_surface_should_this_new_factory_be_placed_on(layout, building)
58+
if was_this_placed_on_a_space_exploration_spaceship(layout, building) then
59+
return "se-spaceship-factory-floor"
60+
end
61+
62+
local surface = building.surface
63+
if layout.surface_override then
64+
return layout.surface_override
65+
elseif surface.platform then
66+
return "space-factory-floor"
67+
elseif surface.planet then
68+
return surface.planet.name:gsub("%-factory%-floor", "") .. "-factory-floor"
69+
else
70+
return surface.name:gsub("%-factory%-floor", "") .. "-factory-floor"
5771
end
58-
return surface.name:gsub("%-%d+$", "")
5972
end
6073

6174
local function set_factory_active_or_inactive(factory)
@@ -68,30 +81,10 @@ local function set_factory_active_or_inactive(factory)
6881
local position = building.position
6982

7083
local function can_place_factory_here()
71-
-- Check if a player is trying to cheat by moving factories to diffrent planets.
72-
local original_planet = factory.original_planet
73-
local inside_surface = factory.inside_surface
74-
75-
if original_planet and original_planet.valid then
76-
if inside_surface and inside_surface.valid and inside_surface.name ~= "se-spaceship-factory-floor" then
77-
local original_planet_name = true_name(original_planet)
78-
local surface_name = true_name(surface)
79-
if original_planet_name ~= surface_name then
80-
local original_planet_prototype = (game.planets[original_planet_name] or original_planet).prototype
81-
local flying_text = {"factory-connection-text.invalid-placement-planet", original_planet_name, original_planet_prototype.localised_name}
82-
return false, flying_text, true
83-
end
84-
end
85-
end
86-
87-
-- In space exploration, we differentiate between space factories and spaceship factories.
88-
if script.active_mods["space-exploration"] then
89-
if inside_surface and inside_surface.valid then
90-
local spaceship = was_this_placed_on_a_space_exploration_spaceship(factory.layout, building)
91-
if inside_surface.name == "space-factory-floor" and spaceship then
92-
return false, {"factory-connection-text.se-must-not-build-factory-building-on-a-spaceship"}, true
93-
end
94-
end
84+
-- Check if a player is trying to cheat by moving factories between surfaces.
85+
if factory.inside_surface.name ~= which_surface_should_this_new_factory_be_placed_on(factory.layout, building) then
86+
flying_text = {"factory-connection-text.invalid-placement-surface", surface_localised_name(factory.inside_surface), surface_localised_name(surface)}
87+
return false, flying_text, true
9588
end
9689

9790
if settings.global["Factorissimo2-free-recursion"].value then
@@ -211,21 +204,6 @@ end)
211204

212205
-- FACTORY GENERATION --
213206

214-
local function which_void_surface_should_this_new_factory_be_placed_on(layout, building)
215-
if was_this_placed_on_a_space_exploration_spaceship(layout, building) then
216-
return "se-spaceship-factory-floor"
217-
end
218-
if layout.surface_override then return layout.surface_override end
219-
220-
local surface = building.surface
221-
if surface.planet then
222-
return (surface.planet.name .. "-factory-floor"):gsub("%-factory%-floor%-factory%-floor", "-factory-floor")
223-
end
224-
225-
storage.next_factory_surface = storage.next_factory_surface + 1
226-
return storage.next_factory_surface .. "-factory-floor"
227-
end
228-
229207
factorissimo.on_event(defines.events.on_surface_created, function(event)
230208
local surface = game.get_surface(event.surface_index)
231209
if not surface.name:find("%-factory%-floor$") then return end
@@ -254,12 +232,23 @@ local function find_first_unused_position(surface)
254232
return #used_indexes + 1
255233
end
256234

257-
local function surface_sanity_checks(surface)
235+
local function surface_sanity_checks(surface, building)
236+
if remote.interfaces["RSO"] then -- RSO compatibility
237+
pcall(remote.call, "RSO", "ignoreSurface", surface.name)
238+
end
239+
258240
if surface.name == "space-factory-floor" then
259241
surface.localised_name = {"space-location-name.space-factory-floor"}
260242
surface.set_property("gravity", 0)
261243
surface.set_property("pressure", 0)
262244
surface.set_property("magnetic-field", 0)
245+
elseif surface.name == "se-spaceship-factory-floor" then
246+
surface.localised_name = {"space-location-name.se-spaceship-factory-floor"}
247+
surface.set_property("gravity", 0)
248+
surface.set_property("pressure", 0)
249+
surface.set_property("magnetic-field", 0)
250+
else
251+
surface.localised_name = surface_localised_name(surface)
263252
end
264253

265254
surface.daytime = 0.5
@@ -269,30 +258,35 @@ local function surface_sanity_checks(surface)
269258
surface.map_gen_settings = {width = 2, height = 2}
270259
end
271260

272-
local function create_factory_position(layout, building)
273-
local surface_name = which_void_surface_should_this_new_factory_be_placed_on(layout, building)
261+
local function create_factory_surface(surface_name)
262+
assert(_G.surface == nil)
263+
264+
if remote.interfaces["RSO"] then -- RSO compatibility
265+
pcall(remote.call, "RSO", "ignoreSurface", surface_name)
266+
end
267+
274268
local surface = game.get_surface(surface_name)
269+
if surface then
270+
return surface
271+
end
275272

276-
if not surface then
277-
if remote.interfaces["RSO"] then -- RSO compatibility
278-
pcall(remote.call, "RSO", "ignoreSurface", surface_name)
279-
end
273+
local planet = game.planets[surface_name]
274+
if planet then
275+
return planet.create_surface()
276+
end
280277

281-
local planet = game.planets[surface_name]
282-
if planet then
283-
surface = planet.surface or planet.create_surface()
284-
end
278+
return game.create_surface(surface_name, {width = 2, height = 2})
279+
end
285280

286-
if not surface then
287-
surface = game.create_surface(surface_name, {width = 2, height = 2})
288-
surface.localised_name = {"space-location-name.factory-floor", storage.next_factory_surface}
289-
end
281+
local function create_factory_position(layout, building)
282+
local surface_name = which_surface_should_this_new_factory_be_placed_on(layout, building)
283+
local surface = game.get_surface(surface_name)
290284

291-
assert(surface)
292-
assert(surface.name == surface_name)
285+
if not surface then
286+
surface = create_factory_surface(surface_name)
293287
end
294288

295-
surface_sanity_checks(surface)
289+
surface_sanity_checks(surface, building)
296290

297291
local n = find_first_unused_position(surface) - 1
298292
local FACTORISSIMO_CHUNK_SPACING = 16
@@ -345,7 +339,6 @@ end
345339

346340
local function add_hidden_tile_rect(factory)
347341
local surface = factory.inside_surface
348-
local layout = factory.layout
349342
local xmin = factory.inside_x - 64
350343
local ymin = factory.inside_y - 64
351344
local xmax = factory.inside_x + 64
@@ -487,6 +480,8 @@ local sprite_path_translation = {
487480
virtual = "virtual-signal",
488481
}
489482
local function generate_factory_item_description(factory)
483+
local bound_to = {"item-description.bound-to", surface_localised_name(factory.inside_surface)}
484+
490485
local overlay = factory.inside_overlay_controller
491486
local params = {}
492487
if overlay and overlay.valid then
@@ -500,7 +495,11 @@ local function generate_factory_item_description(factory)
500495
end
501496
end
502497
local params = table.concat(params, "\n")
503-
if params ~= "" then return "[font=heading-2]" .. params .. "[/font]" end
498+
if params == "" then
499+
return bound_to
500+
else
501+
return {"", bound_to, "\n[font=heading-2]" .. params .. "[/font]"}
502+
end
504503
end
505504

506505
local function is_completely_empty(factory)
@@ -547,7 +546,7 @@ local function cleanup_factory_interior(factory)
547546
factory.inside_surface.set_tiles(out_of_map_tiles)
548547

549548
local factory_lists = {storage.factories, storage.saved_factories, storage.factories_by_entity}
550-
for surface_index, factory_list in pairs(storage.surface_factories) do
549+
for _, factory_list in pairs(storage.surface_factories) do
551550
factory_lists[#factory_lists + 1] = factory_list
552551
end
553552

@@ -734,7 +733,6 @@ local function create_fresh_factory(entity)
734733
local layout = remote_api.create_layout(entity.name, entity.quality)
735734
local factory = create_factory_interior(layout, entity)
736735
create_factory_exterior(factory, entity)
737-
factory.original_planet = entity.surface.planet
738736
set_factory_active_or_inactive(factory)
739737
return factory
740738
end

script/migration.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ factorissimo.on_event(factorissimo.events.on_init(), function()
66
if not factory.force or not factory.force.valid then
77
factory.force = game.forces.player
88
end
9+
910
-- Fix issues when quality prototypes are removed.
1011
if not factory.quality or not factory.quality.valid then
1112
if factory.building and factory.building.valid then
@@ -14,9 +15,8 @@ factorissimo.on_event(factorissimo.events.on_init(), function()
1415
factory.quality = prototypes.quality.normal
1516
end
1617
end
17-
-- Ensure that original planet is set.
18-
if not factory.original_planet and factory.outside_surface and factory.outside_surface.valid then
19-
factory.original_planet = factory.outside_surface.planet
20-
end
18+
19+
-- Clean deprecated data.
20+
factory.original_planet = nil
2121
end
2222
end)

0 commit comments

Comments
 (0)