diff --git a/Bio_Industries_2/common.lua b/Bio_Industries_2/common.lua index 209d09d..2e9d10e 100644 --- a/Bio_Industries_2/common.lua +++ b/Bio_Industries_2/common.lua @@ -119,7 +119,7 @@ return function(mod_name) --~ log("Entered function get_tree_ignore_list!") local ignore = {} local trees = game and - prototypes.get_entity_filtered({{filter = "type", type = "tree"}}) or + game.get_filtered_entity_prototypes({{filter = "type", type = "tree"}}) or data.raw.tree for tree_name, tree in pairs(trees) do --~ log("tree_name: " .. tree_name) @@ -281,7 +281,7 @@ return function(mod_name) local ret = false if game then - local AB = prototypes.item["fertilizer"].place_as_tile_result.result.name + local AB = game.item_prototypes["fertilizer"].place_as_tile_result.result.name -- In data stage, place_as_tile is only changed to Alien Biomes tiles if -- both "vegetation-green-grass-1" and "vegetation-green-grass-3" exist. Therefore, -- we only need to check for one tile in the control stage. @@ -316,7 +316,7 @@ return function(mod_name) common.show("base_name", c_name) common.show("data", c_data) -- Is the base entity in the game? - if c_data.base and c_data.base.name and prototypes.entity[c_data.base.name] then + if c_data.base and c_data.base.name and game.entity_prototypes[c_data.base.name] then -- Make a copy of the compound-entity data common.writeDebug("%s exists -- copying data", {c_name}) ret[c_name] = util.table.deepcopy(c_data) @@ -326,7 +326,7 @@ common.show("data", c_data) --~ h_type = common.HE_map[h_key] common.writeDebug("h_key: %s\th_data: %s", {h_key, h_data}) -- Remove hidden entity if it doesn't exist - if not prototypes.entity[h_data.name] then + if not game.entity_prototypes[h_data.name] then common.writeDebug("Removing %s (%s) from list of hidden entities!", {h_data.name, h_key}) ret[c_name].hidden[h_key] = nil end @@ -338,7 +338,7 @@ common.writeDebug("h_key: %s\th_data: %s", {h_key, h_data}) if tab then -- Remove main table from global common.writeDebug("Removing %s (%s obsolete entries)", {tab, #tab}) - storage[tab] = nil + global[tab] = nil end -- If this compound entity requires additional tables in global, initialize @@ -346,8 +346,8 @@ common.writeDebug("h_key: %s\th_data: %s", {h_key, h_data}) local related_tables = c_data.add_global_tables if related_tables then for t, tab in ipairs(related_tables or {}) do - common.writeDebug("Removing storage[%s] (%s values)", {tab, table_size(storage[tab])}) - storage[tab] = nil + common.writeDebug("Removing global[%s] (%s values)", {tab, table_size(global[tab])}) + global[tab] = nil end end @@ -355,9 +355,9 @@ common.writeDebug("h_key: %s\th_data: %s", {h_key, h_data}) local related_vars = c_data.add_global_values if related_vars then for var_name, value in pairs(related_vars or {}) do - common.writeDebug("Removing storage[%s] (was: %s)", - {var_name, var_name and storage[var_name] or "nil"}) - storage[var_name] = nil + common.writeDebug("Removing global[%s] (was: %s)", + {var_name, var_name and global[var_name] or "nil"}) + global[var_name] = nil end end end @@ -370,18 +370,18 @@ common.writeDebug("h_key: %s\th_data: %s", {h_key, h_data}) common.add_optional_data = function(base) local f_name = "add_optional_data" common.writeDebug("Entered function %s(%s)", {f_name, common.print_name_id(base)}) - if not (base and base.valid and storage.compound_entities[base.name]) then + if not (base and base.valid and global.compound_entities[base.name]) then common.arg_err(base, "base of a compound entity") end -- Add optional values to global table - local data = storage.compound_entities[base.name] + local data = global.compound_entities[base.name] common.show("data", data) local tab = data.tab common.show("tab", tab) -common.show("storage[tab]", storage[tab] or "nil") +common.show("global[tab]", global[tab] or "nil") - local entry = storage[tab][base.unit_number] + local entry = global[tab][base.unit_number] for k, v in pairs(data.optional or {}) do if entry[k] then @@ -399,15 +399,15 @@ common.show("storage[tab]", storage[tab] or "nil") common.clean_global_compounds_table = function(entity_name) local f_name = "clean_table" common.writeDebug("Entered function %s(%s)", {f_name, entity_name or "nil"}) -common.writeDebug("Entries in common.compound_entities[%s]: %s", {entity_name, table_size(storage.compound_entities[entity_name])}) +common.writeDebug("Entries in common.compound_entities[%s]: %s", {entity_name, table_size(global.compound_entities[entity_name])}) - --~ local entity_table = storage[common.compound_entities[entity_name].tab] + --~ local entity_table = global[common.compound_entities[entity_name].tab] --~ local hidden_entities = common.compound_entities[entity_name].hidden - local entity_table = storage.compound_entities[entity_name] + local entity_table = global.compound_entities[entity_name] common.show("entity_table", entity_table and entity_table.tab) - entity_table = entity_table and entity_table.tab and storage[entity_table.tab] + entity_table = entity_table and entity_table.tab and global[entity_table.tab] common.writeDebug("entity_table: %s", {entity_table}, "line") - local hidden_entities = storage.compound_entities[entity_name].hidden + local hidden_entities = global.compound_entities[entity_name].hidden common.show("hidden_entities", hidden_entities) local removed = 0 -- Scan the whole table @@ -438,11 +438,11 @@ common.show("Pruned list size", table_size(entity_table)) common.restore_missing_entities = function(entity_name) local f_name = "restore_missing_entities" common.writeDebug("Entered function %s(%s)", {f_name, entity_name or "nil"}) ---~ common.writeDebug("storage.compound_entities[%s]: %s", {entity_name, storage.compound_entities[entity_name]}) -common.writeDebug("storage.compound_entities[%s]: %s entries", {entity_name, table_size(storage.compound_entities[entity_name])}) +--~ common.writeDebug("global.compound_entities[%s]: %s", {entity_name, global.compound_entities[entity_name]}) +common.writeDebug("global.compound_entities[%s]: %s entries", {entity_name, table_size(global.compound_entities[entity_name])}) - local check = storage.compound_entities[entity_name] - local entity_table = check and storage[check.tab] or {} + local check = global.compound_entities[entity_name] + local entity_table = check and global[check.tab] or {} local hidden_entities = check and check.hidden or {} local checked = 0 @@ -485,12 +485,12 @@ common.writeDebug("Restored %s entities", {restored}) local cnt = 0 local h_cnt = 0 - local data = storage.compound_entities[compound_name] + local data = global.compound_entities[compound_name] if not data then common.arg_err(compound_name, "name of a compound entity") end - local g_tab = storage[data.tab] + local g_tab = global[data.tab] local found, h_found ,created -- Scan all surfaces @@ -553,7 +553,7 @@ common.writeDebug("Restored %s entities", {restored}) common.writeDebug("Entered function %s()", {f_name}) local cnt = 0 - for compound_entity, c in pairs(storage.compound_entities) do + for compound_entity, c in pairs(global.compound_entities) do cnt = cnt + common.register_in_compound_entity_tab(compound_entity) end --~ common.writeDebug("Registered %s compound entities", {cnt}) @@ -647,7 +647,7 @@ common.show("new", {x = base_pos.x + offset.x, y = base_pos.y + offset.y}) for key, tab in pairs(hidden_entities) do common.writeDebug("key: %s\tname: %s", {key, tab}) --~ data = common.compound_entities[base_entity.name].hidden[key] - data = storage.compound_entities[base_entity.name].hidden[key] + data = global.compound_entities[base_entity.name].hidden[key] --~ common.show("common.compound_entities[base_entity.name].hidden", --~ common.compound_entities[base_entity.name].hidden) common.show("data", data) @@ -671,7 +671,7 @@ common.show("data", data) end -- Add optional values to global table - --~ local optional = storage.compound_entities[base_entity.name].optional + --~ local optional = global.compound_entities[base_entity.name].optional --~ for k, v in pairs(optional or {}) do --~ g_table[base_entity.unit_number][k] = v --~ end @@ -688,7 +688,7 @@ common.show("data", data) if common.get_startup_setting("BI_Easy_Bio_Gardens") then common.writeDebug("\"Easy gardens\": Compiling list of poles they can connect to!" ) ret = {} - local poles = prototypes.get_entity_filtered({ + local poles = game.get_filtered_entity_prototypes({ {filter = "type", type = "electric-pole"}, {filter = "name", name = { -- Poles named here will be ignored! @@ -713,23 +713,23 @@ common.writeDebug("\"Easy gardens\": Not active -- nothing to do!" ) -- added to the table yet if the pole has just been built. In this -- case, we pass on the new pole explicitly!) common.connect_garden_pole = function(base, new_pole) - local compound_entity = storage.compound_entities["bi-bio-garden"] + local compound_entity = global.compound_entities["bi-bio-garden"] --~ local pole_type = "electric-pole" - --~ local pole = storage[compound_entity.tab][base.unit_number] and - --~ storage[compound_entity.tab][base.unit_number][pole_type] or + --~ local pole = global[compound_entity.tab][base.unit_number] and + --~ global[compound_entity.tab][base.unit_number][pole_type] or --~ new_pole - local pole = storage[compound_entity.tab][base.unit_number] and - storage[compound_entity.tab][base.unit_number].pole or + local pole = global[compound_entity.tab][base.unit_number] and + global[compound_entity.tab][base.unit_number].pole or new_pole --~ if pole and pole.valid then - --~ local wire_reach = prototypes.entity[compound_entity.hidden[pole_type]] and - --~ prototypes.entity[compound_entity.hidden[pole_type]].max_wire_distance + --~ local wire_reach = game.entity_prototypes[compound_entity.hidden[pole_type]] and + --~ game.entity_prototypes[compound_entity.hidden[pole_type]].max_wire_distance if pole and pole.valid and compound_entity.hidden and compound_entity.hidden.pole and compound_entity.hidden.pole.name then - local wire_reach = prototypes.entity[compound_entity.hidden.pole.name] and - prototypes.entity[compound_entity.hidden.pole.name].max_wire_distance + local wire_reach = game.entity_prototypes[compound_entity.hidden.pole.name] and + game.entity_prototypes[compound_entity.hidden.pole.name].max_wire_distance if not wire_reach then error("Prototype for hidden pole of Bio gardens doesn't exist!") end @@ -758,14 +758,14 @@ common.writeDebug("Connected pole %g to %s %g: %s", --~ -- Connect hidden poles to other poles that may be in reach. --~ common.garden_pole_connectors = common.garden_pole_connectors and next() or --~ common.get_garden_pole_connectors() ---~ common.show("Poles hidden bio-garden poles may connect to", storage.mod_settings.garden_pole_connectors) +--~ common.show("Poles hidden bio-garden poles may connect to", global.mod_settings.garden_pole_connectors) -- Look for other poles around this one neighbours = pole.surface.find_entities_filtered({ position = pole.position, radius = wire_reach, type = "electric-pole", - name = storage.mod_settings.garden_pole_connectors, + name = global.mod_settings.garden_pole_connectors, }) common.writeDebug("Pole %g has %s neighbours", {pole.unit_number, #neighbours}) for n, neighbour in pairs(neighbours or{}) do @@ -785,7 +785,7 @@ common.writeDebug("Connected pole %g to neighbour %s (%g): %s", common.connect_power_rail = function(base, new_pole) --~ local pole_type = "electric-pole" - local pole = storage.bi_power_rail_table[base.unit_number].pole or new_pole + local pole = global.bi_power_rail_table[base.unit_number].pole or new_pole if pole and pole.valid then -- Remove all copper wires from new pole pole.disconnect_neighbour() @@ -806,7 +806,7 @@ common.writeDebug("Rail %s of %s (%s): %s (%s)", {direction, base.name, base.uni -- Only make a connection if found rail is a powered rail -- (We'll know it's the right type if we find it in our table!) - neighbour = neighbour and neighbour.valid and storage.bi_power_rail_table[neighbour.unit_number] + neighbour = neighbour and neighbour.valid and global.bi_power_rail_table[neighbour.unit_number] if neighbour and neighbour.pole and neighbour.pole.valid then pole.connect_neighbour(neighbour.pole) common.writeDebug("Connected poles!") diff --git a/Bio_Industries_2/control.lua b/Bio_Industries_2/control.lua index 523c8f5..fe4a43c 100644 --- a/Bio_Industries_2/control.lua +++ b/Bio_Industries_2/control.lua @@ -14,8 +14,8 @@ end -- let's just declare the variable here and fill it later. local AlienBiomes ---~ local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(true) -local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(false) +--~ local Event = require('__stdlib__/stdlib/event/event').set_protected_mode(true) +local Event = require('__stdlib__/stdlib/event/event').set_protected_mode(false) require ("util") require ("libs/util_ext") require ("control_tree") @@ -48,7 +48,7 @@ end local function get_bi_trees() local list = {} - local trees = prototypes.get_entity_filtered({{filter = "type", type = "tree"}}) + local trees = game.get_filtered_entity_prototypes({{filter = "type", type = "tree"}}) for tree_name, tree in pairs(trees) do if tree_name:match("^bio%-tree%-.+%-%d$") then BioInd.show("Found matching tree", tree_name) @@ -70,7 +70,7 @@ local tile_patterns = { local function get_fixed_tiles() local list = {} - for tile_name, tile in pairs(prototypes.tile) do + for tile_name, tile in pairs(game.tile_prototypes) do for p, pattern in ipairs(tile_patterns) do if tile_name:match(pattern) then BioInd.show("Found matching tile", tile_name) @@ -89,7 +89,7 @@ end local function get_arboretum_recipes() local list = {} - local recipes = prototypes.recipe + local recipes = game.recipe_prototypes local name for i = 1, 5 do @@ -119,40 +119,40 @@ BioInd.writeDebug("Entered init!") game.check_prototype_translations() end - storage = storage or {} + global = global or {} -------------------------------------------------------------------- -- Settings -------------------------------------------------------------------- -- Global table for storing the last state of certain mod settings - storage.mod_settings = storage.mod_settings or {} + global.mod_settings = global.mod_settings or {} if BioInd.get_startup_setting("BI_Easy_Bio_Gardens") then - storage.mod_settings.garden_pole_connectors = BioInd.get_garden_pole_connectors() + global.mod_settings.garden_pole_connectors = BioInd.get_garden_pole_connectors() else - storage.mod_settings.garden_pole_connectors = nil + global.mod_settings.garden_pole_connectors = nil end -- Global table for storing the data of compound entities. They may change between -- saves (e.g. Bio gardens only need hidden poles when the "Easy gardens" setting -- is active). - --~ storage.compound_entities = storage.compound_entities or BioInd.compound_entities - storage.compound_entities = BioInd.rebuild_compound_entity_list() + --~ global.compound_entities = global.compound_entities or BioInd.compound_entities + global.compound_entities = BioInd.rebuild_compound_entity_list() -------------------------------------------------------------------- -- Tree stuff! -------------------------------------------------------------------- - storage.bi = storage.bi or {} - storage.bi.tree_growing = storage.bi.tree_growing or {} + global.bi = global.bi or {} + global.bi.tree_growing = global.bi.tree_growing or {} for i = 1, 4 do - storage.bi["tree_growing_stage_" .. i] = storage.bi["tree_growing_stage_" .. i] or {} + global.bi["tree_growing_stage_" .. i] = global.bi["tree_growing_stage_" .. i] or {} end -- List of tree prototypes created by BI - storage.bi.trees = get_bi_trees() + global.bi.trees = get_bi_trees() -- List of tile prototypes that can't be fertilized - storage.bi.barren_tiles = get_fixed_tiles() + global.bi.barren_tiles = get_fixed_tiles() -------------------------------------------------------------------- -- Compound entities @@ -160,7 +160,7 @@ BioInd.writeDebug("Entered init!") -- Check what global tables we need for compound entities local compound_entity_tables = {} --~ for compound, compound_data in pairs(BioInd.compound_entities) do - for compound, compound_data in pairs(storage.compound_entities) do + for compound, compound_data in pairs(global.compound_entities) do -- BioInd.compound_entities contains entries that point to the same table -- (e.g. straight/curved rails, or overlay entities), so we just overwrite -- them to remove duplicates @@ -172,37 +172,37 @@ BioInd.show("Need to check these tables in global", compound_entity_tables) local result for compound_tab, compound_name in pairs(compound_entity_tables) do -- Init table - storage[compound_tab] = storage[compound_tab] or {} - BioInd.writeDebug("Initialized storage[%s] (%s entities stored)", - {compound_name, table_size(storage[compound_tab])}) + global[compound_tab] = global[compound_tab] or {} + BioInd.writeDebug("Initialized global[%s] (%s entities stored)", + {compound_name, table_size(global[compound_tab])}) -- If this compound entity requires additional tables in global, initialize -- them now! - local related_tables = storage.compound_entities[compound_name].add_global_tables + local related_tables = global.compound_entities[compound_name].add_global_tables if related_tables then for t, tab in ipairs(related_tables or {}) do - storage[tab] = storage[tab] or {} - BioInd.writeDebug("Initialized storage[%s] (%s values)", {tab, table_size(storage[tab])}) + global[tab] = global[tab] or {} + BioInd.writeDebug("Initialized global[%s] (%s values)", {tab, table_size(global[tab])}) end end -- If this compound entity requires additional values in global, initialize -- them now! - local related_vars = storage.compound_entities[compound_name].add_global_values + local related_vars = global.compound_entities[compound_name].add_global_values if related_vars then for var_name, value in pairs(related_vars or {}) do - storage[var_name] = storage[var_name] or value - BioInd.writeDebug("Set storage[%s] to %s", {var_name, storage[var_name]}) + global[var_name] = global[var_name] or value + BioInd.writeDebug("Set global[%s] to %s", {var_name, global[var_name]}) end end -- Clean up global tables (We can skip this for empty tables!) - if next(storage[compound_tab]) then + if next(global[compound_tab]) then -- Remove invalid entities result = BioInd.clean_global_compounds_table(compound_name) - BioInd.writeDebug("Removed %s invalid entries from storage[%s]!", + BioInd.writeDebug("Removed %s invalid entries from global[%s]!", {result, compound_tab}) -- Restore missing hidden entities result = BioInd.restore_missing_entities(compound_name) - BioInd.writeDebug("Checked %s compound entities and restored %s missing hidden entries for storage[\"%s\"]!", + BioInd.writeDebug("Checked %s compound entities and restored %s missing hidden entries for global[\"%s\"]!", {result.checked, result.restored, compound_tab}) end end @@ -215,9 +215,9 @@ BioInd.show("Need to check these tables in global", compound_entity_tables) -------------------------------------------------------------------- -- Musk floor -------------------------------------------------------------------- - storage.bi_musk_floor_table = storage.bi_musk_floor_table or {} - storage.bi_musk_floor_table.tiles = storage.bi_musk_floor_table.tiles or {} - storage.bi_musk_floor_table.forces = storage.bi_musk_floor_table.forces or {} + global.bi_musk_floor_table = global.bi_musk_floor_table or {} + global.bi_musk_floor_table.tiles = global.bi_musk_floor_table.tiles or {} + global.bi_musk_floor_table.forces = global.bi_musk_floor_table.forces or {} @@ -225,17 +225,17 @@ BioInd.show("Need to check these tables in global", compound_entity_tables) -- Arboretum -------------------------------------------------------------------- -- Global table for arboretum radars - storage.bi_arboretum_radar_table = storage.bi_arboretum_radar_table or {} + global.bi_arboretum_radar_table = global.bi_arboretum_radar_table or {} -- Global table of ingredients for terraformer recipes - storage.bi_arboretum_recipe_table = get_arboretum_recipes() + global.bi_arboretum_recipe_table = get_arboretum_recipes() -------------------------------------------------------------------- -- Compatibility with other mods -------------------------------------------------------------------- - storage.compatible = storage.compatible or {} - storage.compatible.AlienBiomes = BioInd.AB_tiles() + global.compatible = global.compatible or {} + global.compatible.AlienBiomes = BioInd.AB_tiles() -- enable researched recipes @@ -279,11 +279,11 @@ BioInd.writeDebug("On Configuration changed: %s", {ConfigurationChangedData}) -- need to make sure that the lists of growing trees don't contain removed tree -- prototypes! (This fix is needed when "Alien Biomes" has been removed; it should -- work with all other mods that create trees as well.) - local trees = storage.bi.trees + local trees = global.bi.trees local tab -- Growing stages for i = 1, 4 do - tab = storage.bi["tree_growing_stage_" .. i] + tab = global.bi["tree_growing_stage_" .. i] BioInd.writeDebug("Number of trees in growing stage %s: %s", {i, table_size(tab)}) --~ for t, tree in pairs(tab) do --~ if not trees[tree.tree_name] then @@ -352,7 +352,7 @@ Event.register(defines.events.on_trigger_created_entity, function(event) --~ seed_planted_trigger(event) BioInd.writeDebug("Seed Bomb Activated - Standard") local currTile = surface.get_tile(position).name - if storage.bi.barren_tiles[currTile] then + if global.bi.barren_tiles[currTile] then BioInd.writeDebug("Can't fertilize %s!", {currTile}) else BioInd.writeDebug("Using fertilizer!") @@ -369,7 +369,7 @@ Event.register(defines.events.on_trigger_created_entity, function(event) --~ seed_planted_trigger(event) BioInd.writeDebug("Seed Bomb Activated - Advanced") local currTile = surface.get_tile(position).name - if storage.bi.barren_tiles[currTile] then + if global.bi.barren_tiles[currTile] then BioInd.writeDebug("Can't fertilize %s!", {currTile}) else BioInd.writeDebug("Using fertilizer!") @@ -406,7 +406,7 @@ local function On_Built(event) BioInd.show("Built entity", BioInd.print_name_id(entity)) - local base_entry = storage.compound_entities[entity.name] + local base_entry = global.compound_entities[entity.name] local base = base_entry and entity -- We've found a compound entity! @@ -448,7 +448,7 @@ BioInd.show("base_entry.optional", base_entry.optional) BioInd.writeDebug("Second pass -- creating hidden entities!") BioInd.show("base_entry", base_entry) -BioInd.writeDebug("storage[%s]: %s", {base_entry.tab, storage[base_entry.tab]}) +BioInd.writeDebug("global[%s]: %s", {base_entry.tab, global[base_entry.tab]}) BioInd.show("base.name", base.name) BioInd.show("base.unit_number", base.unit_number) BioInd.show("hidden_entities", hidden_entities) @@ -456,9 +456,9 @@ BioInd.show("hidden_entities", hidden_entities) -- We must call create_entities even if there are no hidden entities (e.g. if -- the "Easy Gardens" setting is disabled and no hidden poles are required) -- because the compound entity gets registered there! - BioInd.create_entities(storage[base_entry.tab], base, hidden_entities) + BioInd.create_entities(global[base_entry.tab], base, hidden_entities) BioInd.writeDebug("Stored %s in table: %s", - {BioInd.print_name_id(base), storage[base_entry.tab][base.unit_number]}) + {BioInd.print_name_id(base), global[base_entry.tab][base.unit_number]}) end -- The built entity isn't one of our compound entities. @@ -480,9 +480,9 @@ BioInd.show("Base entity", BioInd.print_name_id(base)) -- Arboretum radar -- we need to add it to the table! if entity.type == "radar" and entity.name == entities["bi-arboretum-area"].hidden[h_key].name and base then - storage.bi_arboretum_radar_table[entity.unit_number] = base.unit_number + global.bi_arboretum_radar_table[entity.unit_number] = base.unit_number entity.backer_name = "" - BioInd.writeDebug("Added %s to storage.bi_arboretum_radar_table", {BioInd.print_name_id(entity)}) + BioInd.writeDebug("Added %s to global.bi_arboretum_radar_table", {BioInd.print_name_id(entity)}) -- Electric poles -- we need to take care that they don't hook up to hidden poles! elseif entity.type == "electric-pole" then @@ -562,15 +562,15 @@ BioInd.writeDebug("Entered function On_Pre_Remove(%s)", {event}) end --~ local compound_entity = BioInd.compound_entities[entity.name] - local compound_entity = storage.compound_entities[entity.name] - local base_entry = compound_entity and storage[compound_entity.tab][entity.unit_number] + local compound_entity = global.compound_entities[entity.name] + local base_entry = compound_entity and global[compound_entity.tab][entity.unit_number] BioInd.show("entity.name", entity.name) BioInd.show("entity.unit_number", entity.unit_number) BioInd.show("compound_entity", compound_entity) BioInd.show("base_entry", base_entry) BioInd.show("compound_entity.tab", compound_entity and compound_entity.tab or "nil") -BioInd.writeDebug("storage[%s]: %s", {compound_entity and compound_entity.tab or "nil", compound_entity and storage[compound_entity.tab] or "nil"}) +BioInd.writeDebug("global[%s]: %s", {compound_entity and compound_entity.tab or "nil", compound_entity and global[compound_entity.tab] or "nil"}) -- Found a compound entity from our list! if base_entry then @@ -579,8 +579,8 @@ BioInd.writeDebug("Found compound entity %s", -- Arboretum: Need to separately remove the entry from the radar table if entity.name == "bi-arboretum" and base_entry.radar and base_entry.radar.valid then - storage.bi_arboretum_radar_table[base_entry.radar.unit_number] = nil -BioInd.show("Removed arboretum radar! Table", storage.bi_arboretum_radar_table) + global.bi_arboretum_radar_table[base_entry.radar.unit_number] = nil +BioInd.show("Removed arboretum radar! Table", global.bi_arboretum_radar_table) end -- Power rails: Connections must be explicitely removed, otherwise the poles @@ -603,7 +603,7 @@ BioInd.writeDebug("Removing hidden entity %s", {BioInd.print_name_id(base_entry[ BioInd.remove_entity(base_entry[hidden]) base_entry[hidden] = nil end - storage[compound_entity.tab][entity.unit_number] = nil + global[compound_entity.tab][entity.unit_number] = nil -- Rail-to-power: Connections must be explicitely removed, otherwise the poles -- from the different rail tracks hooked up to this connector will automatically @@ -616,16 +616,16 @@ BioInd.writeDebug("Removing hidden entity %s", {BioInd.print_name_id(base_entry[ -- Removed seedling elseif entity.name == "seedling" then BioInd.writeDebug("Seedling has been removed") - remove_plants(entity.position, storage.bi.tree_growing) + remove_plants(entity.position, global.bi.tree_growing) -- Removed tree - elseif entity.type == "tree" and storage.bi.trees[entity.name] then + elseif entity.type == "tree" and global.bi.trees[entity.name] then BioInd.show("Removed tree", entity.name) local tree_stage = entity.name:match('^.+%-(%d)$') BioInd.writeDebug("Removed tree %s (grow stage: %s)", {entity.name, tree_stage or nil}) if tree_stage then - remove_plants(entity.position, storage.bi["tree_growing_stage_" .. tree_stage]) + remove_plants(entity.position, global.bi["tree_growing_stage_" .. tree_stage]) else error(string.format("Tree %s does not have a valid tree_stage: %s", entity.name, tree_stage or "nil")) end @@ -649,11 +649,11 @@ local function On_Damage(event) -- Base was damaged: Find the radar associated with it! if entity.name == arb then - associated = storage.bi_arboretum_table[entity.unit_number].radar + associated = global.bi_arboretum_table[entity.unit_number].radar -- Radar was damaged: Find the base entity! - elseif entity.name == storage.compound_entities[arb].hidden.radar.name then - local base_id = storage.bi_arboretum_radar_table[entity.unit_number] - associated = storage.bi_arboretum_table[base_id].base + elseif entity.name == global.compound_entities[arb].hidden.radar.name then + local base_id = global.bi_arboretum_radar_table[entity.unit_number] + associated = global.bi_arboretum_table[base_id].base end if associated and associated.valid then @@ -679,10 +679,10 @@ BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) if -- Table checks - storage.compound_entities[entity.name] or - storage.bi.trees[entity.name] or + global.compound_entities[entity.name] or + global.bi.trees[entity.name] or -- Entity checks - entity.name == storage.compound_entities["bi-arboretum"].hidden.radar.name or + entity.name == global.compound_entities["bi-arboretum"].hidden.radar.name or entity.name == "bi-power-to-rail-pole" or entity.name == "seedling" then @@ -704,9 +704,9 @@ local function On_Sector_Scanned(event) BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) ---- Each time a Arboretum-Radar scans a sector ---- - local arboretum = storage.bi_arboretum_radar_table[event.radar.unit_number] + local arboretum = global.bi_arboretum_radar_table[event.radar.unit_number] if arboretum then - Get_Arboretum_Recipe(storage.bi_arboretum_table[arboretum], event) + Get_Arboretum_Recipe(global.bi_arboretum_table[arboretum], event) end end @@ -740,21 +740,21 @@ BioInd.show("Removing", o.name) end -- Remove tile from global tables - local force_name = storage.bi_musk_floor_table.tiles and - storage.bi_musk_floor_table.tiles[x] and - storage.bi_musk_floor_table.tiles[x][y] + local force_name = global.bi_musk_floor_table.tiles and + global.bi_musk_floor_table.tiles[x] and + global.bi_musk_floor_table.tiles[x][y] if force_name then BioInd.writeDebug("Removing Musk floor tile from tables!") - storage.bi_musk_floor_table.tiles[x][y] = nil - if not next(storage.bi_musk_floor_table.tiles[x]) then - storage.bi_musk_floor_table.tiles[x] = nil + global.bi_musk_floor_table.tiles[x][y] = nil + if not next(global.bi_musk_floor_table.tiles[x]) then + global.bi_musk_floor_table.tiles[x] = nil end - if storage.bi_musk_floor_table.forces[force_name] and - storage.bi_musk_floor_table.forces[force_name][x] then - storage.bi_musk_floor_table.forces[force_name][x][y] = nil - if not next(storage.bi_musk_floor_table.forces[force_name][x]) then - storage.bi_musk_floor_table.forces[force_name][x] = nil + if global.bi_musk_floor_table.forces[force_name] and + global.bi_musk_floor_table.forces[force_name][x] then + global.bi_musk_floor_table.forces[force_name][x][y] = nil + if not next(global.bi_musk_floor_table.forces[force_name][x]) then + global.bi_musk_floor_table.forces[force_name][x] = nil end end end @@ -783,12 +783,12 @@ local function place_musk_floor(force, position, surface) end -- Add to global tables! - storage.bi_musk_floor_table.tiles[x] = storage.bi_musk_floor_table.tiles[x] or {} - storage.bi_musk_floor_table.tiles[x][y] = force + global.bi_musk_floor_table.tiles[x] = global.bi_musk_floor_table.tiles[x] or {} + global.bi_musk_floor_table.tiles[x][y] = force - storage.bi_musk_floor_table.forces[force] = storage.bi_musk_floor_table.forces[force] or {} - storage.bi_musk_floor_table.forces[force][x] = storage.bi_musk_floor_table.forces[force][x] or {} - storage.bi_musk_floor_table.forces[force][x][y] = true + global.bi_musk_floor_table.forces[force] = global.bi_musk_floor_table.forces[force] or {} + global.bi_musk_floor_table.forces[force][x] = global.bi_musk_floor_table.forces[force][x] or {} + global.bi_musk_floor_table.forces[force][x][y] = true end -------------------------------------------------------------------- @@ -849,12 +849,12 @@ BioInd.show("index", index) BioInd.show("t.old_tile.name", t.old_tile.name) -- We want to restore removed tiles if nothing is supposed to grow on them! - if storage.bi.barren_tiles[t.old_tile.name] then + if global.bi.barren_tiles[t.old_tile.name] then BioInd.writeDebug("%s was used on forbidden ground (%s)!", {item.name, t.old_tile.name}) restore_tiles[#restore_tiles + 1] = {name = t.old_tile.name, position = t.position} -- Is that tile minable? - products = storage.bi.barren_tiles[t.old_tile.name] + products = global.bi.barren_tiles[t.old_tile.name] if type(products) == "table" then --~ for p, product in ipairs(products) do --~ if player then @@ -897,10 +897,10 @@ BioInd.show("restore_tiles", restore_tiles) local removed_tiles = {} for index, t in pairs(old_tiles or {tile}) do position = BioInd.normalize_position(t.position) - test = storage.bi_musk_floor_table and - storage.bi_musk_floor_table.tiles and - storage.bi_musk_floor_table.tiles[position.x] and - storage.bi_musk_floor_table.tiles[position.x][position.y] + test = global.bi_musk_floor_table and + global.bi_musk_floor_table.tiles and + global.bi_musk_floor_table.tiles[position.x] and + global.bi_musk_floor_table.tiles[position.x][position.y] if test then removed_tiles[#removed_tiles + 1] = { old_tile = {name = "bi-solar-mat"}, @@ -937,8 +937,8 @@ local function Tile_Changed(event) for t, tile in ipairs(event.tiles) do BioInd.show("t", t) pos = BioInd.normalize_position(tile.position) - tile_force = storage.bi_musk_floor_table.tiles[pos.x] and - storage.bi_musk_floor_table.tiles[pos.x][pos.y] + tile_force = global.bi_musk_floor_table.tiles[pos.x] and + global.bi_musk_floor_table.tiles[pos.x][pos.y] --~ -- Fall back to MuskForceName if it is available --~ UseMuskForce and MuskForceName or --~ -- Fall back to "neutral" @@ -1059,8 +1059,8 @@ Event.register(defines.events.on_entity_damaged, On_Damage, function(event) -- Ignore damage without effect (invulnerable/resistant entities) if event.final_damage_amount ~= 0 and -- Terraformer/Terraformer radar was damaged - (storage.bi_arboretum_table[entity.unit_number] or - storage.bi_arboretum_radar_table[entity.unit_number]) then + (global.bi_arboretum_table[entity.unit_number] or + global.bi_arboretum_radar_table[entity.unit_number]) then return true end end) @@ -1087,7 +1087,7 @@ setmetatable(_ENV, { .. serpent.line{key = key or '', value = value or ''} .. '\n') end, __index = function (self, key) --locked_global_read - if not (key == "game" or key == "mods" or key == "storage") then + if not (key == "game" or key == "mods") then error('\n\n[ER Global Lock] Forbidden global *read*:\n' .. serpent.line{key = key or ''} .. '\n') end diff --git a/Bio_Industries_2/control_arboretum.lua b/Bio_Industries_2/control_arboretum.lua index 490f851..d053309 100644 --- a/Bio_Industries_2/control_arboretum.lua +++ b/Bio_Industries_2/control_arboretum.lua @@ -4,8 +4,8 @@ BioInd.writeDebug("Entered control_arboretum.lua") ---Arboretum Stuff ---~ local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(true) -local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(false) +--~ local Event = require('__stdlib__/stdlib/event/event').set_protected_mode(true) +local Event = require('__stdlib__/stdlib/event/event').set_protected_mode(false) -- If a recipe with NORMAL FERTILIZER is used, don't fertilize tiles set have "true" -- set! (Fertile tiles set to true in this table can't be made more fertile with @@ -49,7 +49,7 @@ end -- Check that all ingredients are available! local function check_ingredients(arboretum) local recipe = arboretum.get_recipe() - local need = recipe and storage.bi_arboretum_recipe_table[recipe.name] + local need = recipe and global.bi_arboretum_recipe_table[recipe.name] local function check(need, have) for name, amount in pairs(need or {}) do @@ -111,7 +111,7 @@ function Get_Arboretum_Recipe(ArboretumTable, event) -- 'AlienBiomes' is a bool value -- we don't want to read it again if it's false, -- but only if it hasn't been set yet! - AB = storage.compatible.AlienBiomes + AB = global.compatible.AlienBiomes --~ terrain_name_g1 = terrain_name_g1 or (AB and "vegetation-green-grass-1" or "grass-1") --~ terrain_name_g3 = terrain_name_g3 or (AB and "vegetation-green-grass-3" or "grass-3") terrain_name_g1 = terrain_name_g1 or (AB and "vegetation-green-grass-1" or "grass-1") diff --git a/Bio_Industries_2/control_tree.lua b/Bio_Industries_2/control_tree.lua index 31660ff..eb09e13 100644 --- a/Bio_Industries_2/control_tree.lua +++ b/Bio_Industries_2/control_tree.lua @@ -1,7 +1,7 @@ --~ local BioInd = require("__"..script.mod_name.."__.common")(script.mod_name) -- All tree Growing stuff -local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(true) +local Event = require('__stdlib__/stdlib/event/event').set_protected_mode(true) local terrains = require("libs/trees-and-terrains") @@ -317,7 +317,7 @@ BioInd.show("seedbomb", seedbomb) surface = surface, seed_bomb = seedbomb } - plant_tree(storage.bi.tree_growing, tree_data, false) + plant_tree(global.bi.tree_growing, tree_data, false) end function seed_planted(event) @@ -449,8 +449,8 @@ BioInd.show(growth_chance.." <= ("..fertility.." + 5)", growth_chance <= (fertil BioInd.show("grow_time", grow_time) local stage_1_tree_name = "bio-tree-"..tree_name.."-1" - if not (prototypes.item[stage_1_tree_name] or - prototypes.entity[stage_1_tree_name]) then + if not (game.item_prototypes[stage_1_tree_name] or + game.entity_prototypes[stage_1_tree_name]) then stage_1_tree_name = tree_name end BioInd.writeDebug("stage_1_tree_name: %s", {stage_1_tree_name}) @@ -462,7 +462,7 @@ BioInd.writeDebug("stage_1_tree_name: %s", {stage_1_tree_name}) time = event.tick + grow_time, surface = surface } - plant_tree(storage.bi.tree_growing_stage_1, tree_data, true) + plant_tree(global.bi.tree_growing_stage_1, tree_data, true) end end end @@ -587,8 +587,8 @@ BioInd.writeDebug("Entered function Grow_tree_stage(%s, %s)", {stage_table, stag local fertility, key = f.fertility, f.key local next_stage_tree_name = "bio-tree-"..final_tree.."-"..next_stage - if not (prototypes.item[next_stage_tree_name] or - prototypes.entity[next_stage_tree_name]) then + if not (game.item_prototypes[next_stage_tree_name] or + game.entity_prototypes[next_stage_tree_name]) then next_stage_tree_name = final_tree BioInd.writeDebug("Next stage %g: Prototype did not exist", {next_stage}) else @@ -622,7 +622,7 @@ BioInd.writeDebug("Entered function Grow_tree_stage(%s, %s)", {stage_table, stag time = time_planted + grow_time, surface = surface } - plant_tree(storage.bi["tree_growing_stage_"..next_stage], tree_data, true) + plant_tree(global.bi["tree_growing_stage_"..next_stage], tree_data, true) end end @@ -636,32 +636,32 @@ end ---- Growing Tree --Event.register(-12, function(event) Event.register(defines.events.on_tick, function(event) - if storage.bi.tree_growing_stage_1 == nil then + if global.bi.tree_growing_stage_1 == nil then for i = 1, 4 do - storage.bi["tree_growing_stage_"..i] = storage.bi["tree_growing_stage_"..i] or {} + global.bi["tree_growing_stage_"..i] = global.bi["tree_growing_stage_"..i] or {} end end local tick = event.tick - if storage.bi.tree_growing[tick] then - for t, tree_data in pairs(storage.bi.tree_growing[tick]) do + if global.bi.tree_growing[tick] then + for t, tree_data in pairs(global.bi.tree_growing[tick]) do BioInd.writeDebug("Trying to move tree %s to first grow stage!", {t}) Grow_tree_first_stage(tree_data, event) end - BioInd.writeDebug("Removing storage.bi.tree_growing[%s]!", {tick}) - storage.bi.tree_growing[tick] = nil + BioInd.writeDebug("Removing global.bi.tree_growing[%s]!", {tick}) + global.bi.tree_growing[tick] = nil end local stage_table for stage = 1, 4 do - stage_table = storage.bi["tree_growing_stage_"..stage] + stage_table = global.bi["tree_growing_stage_"..stage] if stage_table[tick] then for t, tree_data in pairs(stage_table[tick]) do BioInd.writeDebug("Moving tree %s to next grow stage!", {t}) Grow_tree_stage(tree_data, stage) end - BioInd.writeDebug("Removing storage.bi.tree_growing_stage_%s[%s]!", + BioInd.writeDebug("Removing global.bi.tree_growing_stage_%s[%s]!", {stage, tick}) stage_table[tick] = nil end diff --git a/Bio_Industries_2/libs/util_ext.lua b/Bio_Industries_2/libs/util_ext.lua index be73d1a..d576fb6 100644 --- a/Bio_Industries_2/libs/util_ext.lua +++ b/Bio_Industries_2/libs/util_ext.lua @@ -73,15 +73,15 @@ function ungroup(index_id, group_id) end ------------------------------------------------------------------- function _init_group(index_id) - if not storage.group then - storage.group = {} + if not global.group then + global.group = {} end - if not storage.group.default then - storage.group.default = {} + if not global.group.default then + global.group.default = {} end - if index_id and not storage.group[index_id] then + if index_id and not global.group[index_id] then -- don't care if they name their group "default" - storage.group[index_id] = {} + global.group[index_id] = {} end end @@ -90,8 +90,8 @@ function _new_group(index_id) local group_id_r = nil while group_id_r == nil do - local group_id_x = "gid-" .. (group_id_n + #storage.group[index_id]) - if storage.group[index_id][group_id_x] then + local group_id_x = "gid-" .. (group_id_n + #global.group[index_id]) + if global.group[index_id][group_id_x] then -- collision group_id_n = group_id_n + 1 else @@ -103,22 +103,22 @@ function _new_group(index_id) end function _addto_group(index_id, group_id, member_id) - if storage.group[index_id] then - if not storage.group[index_id][group_id] then - storage.group[index_id][group_id] = {} + if global.group[index_id] then + if not global.group[index_id][group_id] then + global.group[index_id][group_id] = {} end end - table.insert(storage.group[index_id][group_id], member_id) + table.insert(global.group[index_id][group_id], member_id) end function _get_group(index_id, group_id) - return storage.group[index_id][group_id] + return global.group[index_id][group_id] end function _of_group(index_id, member_id) --full scan - for kx, vx in pairs(storage.group[index_id]) do + for kx, vx in pairs(global.group[index_id]) do for ky, vy in pairs(vx) do if member_id == vy then return vx @@ -129,7 +129,7 @@ function _of_group(index_id, member_id) end function _clear_group(index_id, group_id) - storage.group[index_id][group_id] = nil + global.group[index_id][group_id] = nil end ------------------------------------------------------------------- diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.02.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.02.lua new file mode 100644 index 0000000..e17a203 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.02.lua @@ -0,0 +1,20 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["steel-processing"] and + technologies["steel-processing"].researched and + recipes["bi-stone-crusher"] then + + recipes["bi-stone-crusher"].enabled = true + recipes["bi-stone-crusher"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.06.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.06.lua new file mode 100644 index 0000000..05ec2fd --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.06.lua @@ -0,0 +1,20 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["steel-processing"] and + technologies["steel-processing"].researched and + recipes["bi-crushed-stone-1"] then + + recipes["bi-crushed-stone-1"].enabled = true + recipes["bi-crushed-stone-1"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.11.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.11.lua new file mode 100644 index 0000000..182836f --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.11.lua @@ -0,0 +1,22 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + + + if game.technology_prototypes["bi-tech-bio-cannon"] and + technologies["bi-tech-bio-cannon"].researched and + recipes["bi-bio-cannon-proto-ammo"] then + + recipes["bi-bio-cannon-proto-ammo"].enabled = true + recipes["bi-bio-cannon-proto-ammo"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.13.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.13.lua new file mode 100644 index 0000000..fdef829 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.13.lua @@ -0,0 +1,20 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["electric-energy-accumulators"] and + technologies["electric-energy-accumulators"].researched then + if game.item_prototypes["bi-bio-accumulator"] then + recipes["bi-bio-accumulator"].enabled = true + recipes["bi-bio-accumulator"].reload() + end + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.19.json b/Bio_Industries_2/migrations/Bio_Industries_0.17.19.json new file mode 100644 index 0000000..788b532 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.19.json @@ -0,0 +1,7 @@ +{ + "item": + [ + ["bi-charcoal", "wood-charcoal"] + ] +} + diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.22.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.22.lua new file mode 100644 index 0000000..d7fa812 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.22.lua @@ -0,0 +1,38 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["bi-tech-coal-processing-1"] then + if game.item_prototypes["wood-bricks"] then + if recipes["bi-wood-fuel-brick"] then + recipes["bi-wood-fuel-brick"].enabled = true + recipes["bi-wood-fuel-brick"].reload() + end + if recipes["bi-solid-fuel"] then + recipes["bi-solid-fuel"].enabled = true + recipes["bi-solid-fuel"].reload() + end + end + end + + if game.technology_prototypes["bi-tech-coal-processing-2"] and + recipes["bi-pellet-coke"] then + + recipes["bi-pellet-coke"].enabled = true + recipes["bi-pellet-coke"].reload() + end + + if game.technology_prototypes["bi-tech-bio-farming"] and + recipes["bi-woodpulp"] then + + recipes["bi-woodpulp"].enabled = true + recipes["bi-woodpulp"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.26.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.26.lua new file mode 100644 index 0000000..f60a44e --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.26.lua @@ -0,0 +1,16 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["bi-tech-coal-processing-3"] and recipes["bi-coke-coal"] then + recipes["bi-coke-coal"].enabled = true + recipes["bi-coke-coal"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.17.31.lua b/Bio_Industries_2/migrations/Bio_Industries_0.17.31.lua new file mode 100644 index 0000000..bd5a28d --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.17.31.lua @@ -0,0 +1,16 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +--~ game.reload_script() + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + if game.technology_prototypes["bi-tech-bio-farming"] and recipes["bi-wood-from-pulp"] then + recipes["bi-wood-from-pulp"].enabled = true + recipes["bi-wood-from-pulp"].reload() + end + + force.reset_recipes() + force.reset_technologies() +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.01.json b/Bio_Industries_2/migrations/Bio_Industries_0.18.01.json new file mode 100644 index 0000000..114e4a1 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.01.json @@ -0,0 +1,143 @@ +{ + "entity": + [ + ["bi-bioreactor", "bi-bio-reactor"], + ["Bio_Cannon_r", "Bio-Cannon-r"], + ["bi-big-wooden-pole", "bi-wooden-pole-big"], + ["bi-huge-wooden-pole", "bi-wooden-pole-huge"], + ["bi-large-wooden-chest", "bi-wooden-chest-large"], + ["bi-huge-wooden-chest", "bi-wooden-chest-huge"], + ["bi-large-wooden-chest", "bi-wooden-chest-large"], + ["bi-giga-wooden-chest", "bi-wooden-chest-giga"], + ["bi-solar-boiler-panel-2", "bi-solar-boiler-panel"], + ["bi-solar-boiler-2", "bi-solar-boiler"] + ], + + "item": + [ + ["bi-bioreactor", "bi-bio-reactor"], + ["bi-basic-dart-magazine", "bi-dart-magazine-basic"], + ["bi-enhanced-dart-magazine", "bi-dart-magazine-enhanced"], + ["bi-standard-dart-magazine", "bi-dart-magazine-standard"], + ["bi-poison-dart-magazine", "bi-dart-magazine-poison"], + ["bi-solar-boiler-2", "bi-solar-boiler"] + ], + + "recipe": + [ + ["bi_recipe_rail_wood", "bi-rail-wood"], + ["bi_recipe_rail_wood_to_concrete", "bi-rail-wood-to-concrete"], + ["bi_recipe_rail_wood_bridge", "bi-rail-wood-bridge"], + ["bi_rail_power", "bi-rail-power"], + ["bi_recipe_power_to_rail_pole", "bi-power-to-rail-pole"], + ["bi_recipe_basic_dart_magazine", "bi-dart-magazine-basic"], + ["bi_recipe_enhanced_dart_magazine", "bi-dart-magazine-enhanced"], + ["bi_recipe_standard_dart_magazine", "bi-dart-magazine-standard"], + ["bi_recipe_poison_dart_magazine", "bi-dart-magazine-poison"], + ["bi_recipe_bi_dart_rifle", "bi-dart-rifle"], + ["bi_recipe_big_wooden_pole", "bi-wooden-pole-big"], + ["bi_recipe_huge_wooden_pole", "bi-wooden-pole-huge"], + ["bi_recipe_bio_cannon", "bi-bio-cannon"], + ["bi_recipe_bio_cannon_basic_ammo", "bi-bio-cannon-basic-ammo"], + ["bi_recipe_bio_cannon_poison_ammo", "bi-bio-cannon-poison-ammo"], + ["bi_recipe_bio_cannon_proto_ammo", "bi-bio-cannon-proto-ammo"], + ["bi_recipe_boiler", "bi-bio-boiler"], + ["bi_recipe_dart_turret", "bi-dart-turret"], + ["bi_recipe_large_wooden_chest", "bi-wooden-chest-large"], + ["bi_recipe_huge_wooden_chest", "bi-wooden-chest-huge"], + ["bi_recipe_giga_wooden_chest", "bi-wooden-chest-giga"], + ["bi_recipe_production_science_pack", "bi-production-science-pack"], + ["bi_recipe_seed_bomb_advanced", "bi-seed-bomb-advanced"], + ["bi_recipe_seed_bomb_basic", "bi-seed-bomb-basic"], + ["bi_recipe_seed_bomb_standard", "bi-seed-bomb-standard"], + ["bi_recipe_wooden_fence", "bi-wooden-fence"], + ["bi_recipe_arboretum_r1", "bi-arboretum-r1"], + ["bi_recipe_arboretum_r2", "bi-arboretum-r2"], + ["bi_recipe_arboretum_r3", "bi-arboretum-r3"], + ["bi_recipe_arboretum_r4", "bi-arboretum-r4"], + ["bi_recipe_arboretum_r5", "bi-arboretum-r5"], + ["bi_recipe_arboretum", "bi-arboretum"], + ["bi_recipe_cellulose_1", "bi-cellulose-1"], + ["bi_recipe_cellulose_2", "bi-cellulose-2"], + ["bi_recipe_acid", "bi-acid"], + ["bi_recipe_accumulator", "bi-bio-accumulator"], + ["bi_recipe_adv_fertiliser_1", "bi-adv-fertiliser-1"], + ["bi_recipe_adv_fertiliser_2", "bi-adv-fertiliser-2"], + ["bi_recipe_ash_1", "bi-ash-1"], + ["bi_recipe_ash_2", "bi-ash-2"], + ["bi_recipe_battery", "bi-battery"], + ["bi_recipe_bio_farm", "bi-bio-farm"], + ["bi_recipe_bio_garden", "bi-bio-garden"], + ["bi_recipe_bio_solar_farm", "bi-bio-solar-farm"], + ["bi_recipe_biomass_1", "bi-biomass-1"], + ["bi_recipe_biomass_2", "bi-biomass-2"], + ["bi_recipe_biomass_3", "bi-biomass-3"], + ["bi_recipe_biomass_conversion_1", "bi-biomass-conversion-1"], + ["bi_recipe_biomass_conversion_2", "bi-biomass-conversion-2"], + ["bi_recipe_biomass_conversion_3", "bi-biomass-conversion-3"], + ["bi_recipe_biomass_conversion_4", "bi-biomass-conversion-4"], + ["bi_recipe_burner_inserter_disassemble", "bi-burner-inserter-disassemble"], + ["bi_recipe_burner_mining_drill_disassemble", "bi-burner-mining-drill-disassemble"], + ["bi_recipe_long_handed_inserter_disassemble", "bi-long-handed-inserter-disassemble"], + ["bi_recipe_steel_furnace_disassemble", "bi-steel-furnace-disassemble"], + ["bi_recipe_stone_furnace_disassemble", "bi-stone-furnace-disassemble"], + ["bi_recipe_charcoal_2", "bi-charcoal-2"], + ["bi_recipe_charcoal", "bi-charcoal-1"], + ["bi_recipe_clean_air_1", "bi-purified-air-1"], + ["bi_recipe_clean_air_2", "bi-purified-air-2"], + ["bi_recipe_coal_2", "bi-coal-2"], + ["bi_recipe_coal", "bi-coal-1"], + ["bi_recipe_coke_coal", "bi-coke-coal"], + ["bi_recipe_crushed_stone", "bi-crushed-stone-1"], + ["bi_recipe_fertiliser_1", "bi-fertiliser-1"], + ["bi_recipe_fertiliser_2", "bi-fertiliser-2"], + ["bi_recipe_greenhouse", "bi-bio-greenhouse"], + ["bi_recipe_huge_substation", "bi-large-substation"], + ["bi_recipe_liquid_air", "bi-liquid-air"], + ["bi_recipe_logs_mk1", "bi-logs-1"], + ["bi_recipe_logs_mk2", "bi-logs-2"], + ["bi_recipe_logs_mk3", "bi-logs-3"], + ["bi_recipe_logs_mk4", "bi-logs-4"], + ["bi_recipe_nitrogen", "bi-nitrogen"], + ["bi_recipe_plastic_1", "bi-plastic-1"], + ["bi_recipe_plastic_2", "bi-plastic-2"], + ["bi_recipe_seed_1", "bi-seed-1"], + ["bi_recipe_seed_2", "bi-seed-2"], + ["bi_recipe_seed_3", "bi-seed-3"], + ["bi_recipe_seed_4", "bi-seed-4"], + ["bi_recipe_seedling_mk1", "bi-seedling-1"], + ["bi_recipe_seedling_mk2", "bi-seedling-2"], + ["bi_recipe_seedling_mk3", "bi-seedling-3"], + ["bi_recipe_seedling_mk4", "bi-seedling-4"], + ["bi_recipe_solar_boiler_panel", "bi-solar-boiler-panel"], + ["bi_recipe_solar_mat", "bi-solar-mat"], + ["bi_recipe_sulfur_angels", "bi-sulfur-angels"], + ["bi_recipe_sulfur", "bi-sulfur"], + ["bi_recipe_woodpulp", "bi-woodpulp"], + ["bi_recipe_wood_from_pulp", "bi-wood-from-pulp"], + ["bi_recipe_pellete_coal_2", "bi-pellete-coal-2"], + ["bi_recipe_bioreactor", "bi-bio-reactor"], + ["bi_recipe_mineralized_sulfuric_waste", "bi-mineralized-sulfuric-waste"], + ["bi_recipe_slag_slurry", "bi-slag-slurry"], + ["bi_recipe_resin_wood", "bi-resin-wood"], + ["bi_recipe_resin_pulp", "bi-resin-pulp"], + ["bi_recipe_press_wood", "bi-press-wood"], + ["bi_recipe_stone_brick", "bi-stone-brick"], + ["bi_recipe_wood_fuel_brick", "bi-wood-fuel-brick"], + ["bi_recipe_solid_fuel", "bi-solid-fuel"], + ["bi_recipe_pellet_coke", "bi-pellet-coke"], + ["bi_recipe_wood_pipe", "bi-wood-pipe"], + ["bi_recipe_pipe_to_ground_wood", "bi-wood-pipe-to-ground"], + ["bi_recipe_cokery", "bi-cokery"], + ["bi_recipe_stone_crusher", "bi-stone-crusher"] + ], + + "technology": + [ + ["bi_tech_advanced_biotechnology", "bi-tech-advanced-biotechnology"], + ["bi_tech_bio_cannon", "bi-tech-bio-cannon"], + ["bi_tech_bio_farming", "bi-tech-bio-farming"], + ["bi_tech_fertiliser", "bi-tech-fertiliser"], + ["bi_tech_organic_plastic", "bi-tech-organic-plastic"] + ] +} diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.01.lua b/Bio_Industries_2/migrations/Bio_Industries_0.18.01.lua new file mode 100644 index 0000000..2dc639b --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.01.lua @@ -0,0 +1,43 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') +--~ game.reload_script() + + +for index, force in pairs(game.forces) do + local technologies = force.technologies + local recipes = force.recipes + + for _, tech in ipairs({"bi-tech-coal-processing-2", "bi-tech-coal-processing-3"}) do + -- Technology exists and has already been researched +BioInd.writeDebug("Checking tech: %s for force %s (Researched: %s)", {tech, force and force.name or "nil", technologies[tech] and technologies[tech].researched or "nil"}) + + if game.technology_prototypes[tech] and technologies[tech].researched then + -- Check if all prerequisite technologies have been researched + local all_prereqs = true + for pname, ptech in pairs(technologies[tech].prerequisites) do + BioInd.writeDebug("pname: %s", {pname}) + BioInd.writeDebug("ptech: %s", {ptech}) + if not ptech.researched then + all_prereqs = false + break + end + end + + -- If not all prerequisite technologies have been researched, ... + if not all_prereqs then + game.print({"", "Not all prerequisite technologies for ", {"technology-name." .. tech}, " have been researched!"}) + -- reset all unlocked recipes and + for _, effect in pairs(technologies[tech].effects) do + if effect.type == "unlock-recipe" then + game.print({"", "Disabling recipe \"", {"recipe-name." .. effect.recipe}, "\""}) + recipes[effect.recipe].enabled = false + recipes[effect.recipe].reload() + end + end + -- unresearch the technology + game.print({"", "Disabling technology \"", {"technology-name." .. tech}, "\"" }) + technologies[tech].researched = false + technologies[tech].reload() + end + end + end +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.10.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.10.lua.bak new file mode 100644 index 0000000..54f5d6b --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.10.lua.bak @@ -0,0 +1,82 @@ +local BioInd = require('__Bio_Industries__/common')('Bio_Industries') +------------------------------------------------------------------------------------ +-- Remove left over radars and hidden entities left after terraformer (arboretum) +-- has been moved. +------------------------------------------------------------------------------------ + +-- Function to remove entities +local function remove_entity(surface, data) + local name = data[1] + local type = data[2] + local desc = data[3] + local name_in_table = data[4] or type -- Needed for "electric-pole", which is stored as "pole" in the table + + local count = 0 + + -- Look for entity on surface + local surface_entities = surface.find_entities_filtered{ + name = name, + type = type, + } + --~ BioInd.writeDebug("Found " .. tostring(#surface_entities) .. " " .. desc .. "s.") + + -- Check against entities in list + for index, entity in pairs(surface_entities) do + BioInd.writeDebug("%g: Looking for %s: %s.", {index, desc, entity.unit_number}) + + local match = false + for _a, arboretum in pairs(global.bi_arboretum_table or {}) do + --~ BioInd.writeDebug("arboretum: %s", {arboretum}) + if entity == arboretum[name_in_table] then + BioInd.writeDebug("The %s (%g) belongs to arboretum/terraformer %g!", {desc, entity.unit_number, _a}) + match = trueentity.unit_number + break + end + end + + -- Remove entity from surface if it has no match in arboretum/terraformer list + if not match then + log("Removing " .. desc .. " " .. entity.unit_number .. ".") + count = count + 1 + entity.destroy() + end + end + log("Removed " .. tostring(count) .. " " .. desc .. "s (terraformer remnants) from " .. surface.name .. ".") + game.print("[Bio Industries] Removed " .. tostring(count) .. " " .. desc .. "s (terraformer remnants) from " .. surface.name .. ".") +end + +-- Clean up global list of arboretums +if global.bi_arboretum_table then + + BioInd.writeDebug("Remove invalid arboretums/terraformers from list:") + local count = 0 + for index, arboretum in pairs(global.bi_arboretum_table) do + local entity = arboretum.inventory + + BioInd.writeDebug("Arboretum %g is valid: %s", {index, entity and entity.valid}) + if not entity.valid then + global.bi_arboretum_table[index] = nil + count = count + 1 + log("Removed arboretum/terraformer " .. tostring(index) .. " from global list.") + end + end + log("Removed " .. tostring(count) .. " non-existing terraformers from global list.") + game.print("[Bio Industries] Removed " .. tostring(count) .. " non-existing terraformers from global list.") + + ------------------------------------------------------------------------------------ + -- Check for left-over entities from moved/removed arboretums/terraformers + for index, surface in pairs(game.surfaces) do + BioInd.writeDebug("Looking for left-over hidden entities from moved/removed terraformers on %s.", {surface.name}) + + for _, entity in pairs({ + {"bi-arboretum-hidden-radar", "radar", "radar"}, + {"bi-hidden-power-pole", "electric-pole", "hidden power pole", "pole"}, + {"bi-bio-farm-light", "lamp", "hidden lamp"} + }) do + + remove_entity(surface, entity) + end + + end + BioInd.writeDebug("Done.") +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.11.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.11.lua.bak new file mode 100644 index 0000000..9b4b710 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.11.lua.bak @@ -0,0 +1,121 @@ +local BioInd = require('common')('Bio_Industries') +------------------------------------------------------------------------------------ +-- Restore hidden power poles and hidden lamps accidentally removed in the +-- previous version. +------------------------------------------------------------------------------------ + +local pole_name = "bi-hidden-power-pole" +local lamp_name = "bi-bio-farm-light" + +local pole_count = 0 +local lamp_count = 0 + +-- Restoring hidden power pole for solar boilers +for index, solar_boiler in pairs(global.bi_solar_boiler_table) do + -- Remove invalid solar boilers from list + if not solar_boiler.base.valid then + BioInd.writeDebug("Removing invalid solar boiler " .. tostring(index) .. " from global list.") + if solar_boiler.boiler.valid then + solar_boiler.boiler.destroy() + end + if solar_boiler.pole.valid then + solar_boiler.pole.destroy() + end + global.bi_solar_boiler_table = nil + + -- Restore hidden power pole if necessary + elseif not solar_boiler.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar boiler " .. tostring(index) .. ".") + local new_pole = solar_boiler.base.surface.create_entity({ + name = pole_name, + position = solar_boiler.base.position, + direction = solar_boiler.base.direction, + force = solar_boiler.base.force + }) + global.bi_solar_boiler_table[index].pole = new_pole + pole_count = pole_count + 1 + end +end +log("Restored " .. tostring(pole_count) .. " hidden power poles for solar boilers.") +game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles for solar boilers.") + + +-- Restoring hidden power pole for solar farms +pole_count = 0 + +for index, solar_farm in pairs(global.bi_solar_farm_table) do + -- Remove invalid solar boilers from list + if not solar_farm.base.valid then + BioInd.writeDebug("Removing invalid solar farm " .. tostring(index) .. " from global list.") + if solar_farm.pole.valid then + solar_farm.pole.destroy() + end + global.bi_solar_farm_table = nil + + -- Restore hidden power pole if necessary + elseif not solar_farm.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar farm " .. tostring(index) .. ".") + local new_pole = solar_farm.base.surface.create_entity({ + name = pole_name, + position = solar_farm.base.position, + direction = solar_farm.base.direction, + force = solar_farm.base.force + }) + global.bi_solar_farm_table[index].pole = new_pole + pole_count = pole_count + 1 + end +end +log("Restored " .. tostring(pole_count) .. " hidden power poles for solar farms.") +game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles for solar farms.") + + +-- Restoring hidden power pole and hidden lamps for bio farms +pole_count = 0 + +for index, bio_farm in pairs(global.bi_bio_farm_table) do + -- Remove invalid solar boilers from list + if not bio_farm.base.valid then + BioInd.writeDebug("Removing invalid solar farm " .. tostring(index) .. " from global list.") + if bio_farm.pole.valid then + bio_farm.pole.destroy() + end + if bio_farm.panel.valid then + bio_farm.panel.destroy() + end + if bio_farm.lamp.valid then + bio_farm.lamp.destroy() + end + global.bi_bio_farm_table = nil + + -- Restore hidden entities if necessary + else + -- Restore hidden power pole + if not bio_farm.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar farm " .. tostring(index) .. ".") + local new_pole = bio_farm.base.surface.create_entity({ + name = pole_name, + position = bio_farm.base.position, + direction = bio_farm.base.direction, + force = bio_farm.base.force + }) + global.bi_bio_farm_table[index].pole = new_pole + pole_count = pole_count + 1 + end + -- Restore hidden lamp + if not bio_farm.lamp.valid then + BioInd.writeDebug("Creating new hidden lamp for solar farm " .. tostring(index) .. ".") + local new_lamp = bio_farm.base.surface.create_entity({ + name = lamp_name, + position = bio_farm.base.position, + force = bio_farm.base.force + }) + + global.bi_bio_farm_table[index].lamp = new_lamp + lamp_count = lamp_count + 1 + end + end +end +log("Restored " .. tostring(pole_count) .. " hidden power poles and " .. tostring(lamp_count) .. + " hidden lamps for bio farms.") +game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles and " .. tostring(lamp_count) .. + " hidden lamps for bio farms.") diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.13.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.13.lua.bak new file mode 100644 index 0000000..4c97bfa --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.13.lua.bak @@ -0,0 +1,135 @@ +local BioInd = require('__Bio_Industries__/common')('Bio_Industries') +log("Entered fixed migration script!") +------------------------------------------------------------------------------------ +-- In 0.18.11, loading a saved game could have resulted in a crash because a +-- complete table (instead of individual entries) was removed. However, if +-- the complete table *was* deleted, the game *must* have crashed and the original +-- tables couldn't have been overwritten in a new saved game. So, we can presume +-- all tables still exist in the state of pre 0.18.11 and just run the (fixed) +-- migration script from 0.18.11 again. +------------------------------------------------------------------------------------ + +local pole_name = "bi-hidden-power-pole" +local lamp_name = "bi-bio-farm-light" + +local pole_count = 0 +local lamp_count = 0 + +-- Restoring hidden power pole for solar boilers +if global.bi_solar_boiler_table then + for index, solar_boiler in pairs(global.bi_solar_boiler_table) do + -- Remove invalid solar boilers from list + if not solar_boiler.base.valid then + BioInd.writeDebug("Removing invalid solar boiler %g from global list.", {index}) + if solar_boiler.boiler.valid then + solar_boiler.boiler.destroy() + end + if solar_boiler.pole.valid then + solar_boiler.pole.destroy() + end + global.bi_solar_boiler_table[index] = nil + + -- Restore hidden power pole if necessary + elseif not solar_boiler.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar boiler %g.", {index}) + global.bi_solar_boiler_table[index].pole = solar_boiler.base.surface.create_entity({ + name = pole_name, + position = solar_boiler.base.position, + direction = solar_boiler.base.direction, + force = solar_boiler.base.force + }) + pole_count = pole_count + 1 + end + end + if pole_count > 0 then + log("Restored " .. tostring(pole_count) .. " hidden power poles for solar boilers.") + game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles for solar boilers.") + end +end + +-- Restoring hidden power pole for solar farms +if global.bi_solar_farm_table then + pole_count = 0 + + for index, solar_farm in pairs(global.bi_solar_farm_table) do + -- Remove invalid solar boilers from list + if not solar_farm.base.valid then + BioInd.writeDebug("Removing invalid solar farm %g from global list.", {index}) + if solar_farm.pole.valid then + solar_farm.pole.destroy() + end + global.bi_solar_farm_table[index] = nil + + -- Restore hidden power pole if necessary + elseif not solar_farm.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar farm %g.", {index}) + --~ local new_pole = solar_farm.base.surface.create_entity({ + global.bi_solar_farm_table[index].pole = solar_farm.base.surface.create_entity({ + name = pole_name, + position = solar_farm.base.position, + direction = solar_farm.base.direction, + force = solar_farm.base.force + }) + pole_count = pole_count + 1 + end + end + if pole_count > 0 then + log("Restored " .. tostring(pole_count) .. " hidden power poles for solar farms.") + game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles for solar farms.") + end +end + + +-- Restoring hidden power pole and hidden lamps for bio farms +if global.bi_bio_farm_table then + pole_count = 0 + + for index, bio_farm in pairs(global.bi_bio_farm_table) do + -- Remove invalid solar boilers from list + if not bio_farm.base.valid then + BioInd.writeDebug("Removing invalid solar farm %g from global list.", {index}) + if bio_farm.pole.valid then + bio_farm.pole.destroy() + end + if bio_farm.panel.valid then + bio_farm.panel.destroy() + end + if bio_farm.lamp.valid then + bio_farm.lamp.destroy() + end + global.bi_bio_farm_table[index] = nil + + -- Restore hidden entities if necessary + else + -- Restore hidden power pole + if not bio_farm.pole.valid then + BioInd.writeDebug("Creating new hidden power pole for solar farm %g.", {index}) + --~ local new_pole = bio_farm.base.surface.create_entity({ + global.bi_bio_farm_table[index].pole = bio_farm.base.surface.create_entity({ + name = pole_name, + position = bio_farm.base.position, + direction = bio_farm.base.direction, + force = bio_farm.base.force + }) + pole_count = pole_count + 1 + end + -- Restore hidden lamp + if not bio_farm.lamp.valid then + BioInd.writeDebug("Creating new hidden lamp for solar farm %g.", {index}) + --~ local new_lamp = bio_farm.base.surface.create_entity({ + global.bi_bio_farm_table[index].lamp = bio_farm.base.surface.create_entity({ + name = lamp_name, + position = bio_farm.base.position, + force = bio_farm.base.force + }) + lamp_count = lamp_count + 1 + end + end + end + if pole_count > 0 or lamp_count > 0 then + log("Restored " .. tostring(pole_count) .. " hidden power poles and " .. tostring(lamp_count) .. + " hidden lamps for bio farms.") + game.print("[Bio Industries] Restored " .. tostring(pole_count) .. " hidden power poles and " .. + tostring(lamp_count) .. " hidden lamps for bio farms.") + end +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.20_+_0.17.51.json b/Bio_Industries_2/migrations/Bio_Industries_0.18.20_+_0.17.51.json new file mode 100644 index 0000000..2b67b38 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.20_+_0.17.51.json @@ -0,0 +1,6 @@ +{ + "recipe": + [ + ["bi-basic-petroleum-gas-processing", "bi-basic-gas-processing"] + ] +} diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.24_+_0.17.55.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.24_+_0.17.55.lua.bak new file mode 100644 index 0000000..faa4fdb --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.24_+_0.17.55.lua.bak @@ -0,0 +1,122 @@ +local BioInd = require('__Bio_Industries__/common')('Bio_Industries') +------------------------------------------------------------------------------------ +-- This version uses a different algorithm to wiring the powered rails. Only +-- Rail-to-power connectors and poles on rails connected to (not crossing!) a newly +-- placed track will be connected with each other. +------------------------------------------------------------------------------------ + +BioInd.writeDebug("Entered migration script 0.18.24+0.17.55") + +-- Look for Rail-to-power connectors on all surfaces +for s, surface in pairs(game.surfaces) do + local connectors = surface.find_entities_filtered{name = "bi-power-to-rail-pole"} +--log("Looking for rail-to-power connectors on surface " .. s) + for _, connector in ipairs(connectors) do + -- Find connections to powered rails + local neighbours = connector.neighbours["copper"] +--log("neighbours of connector " .. connector.unit_number .. ": " .. serpent.block(neighbours)) + for p, pole in pairs(neighbours) do + -- Disconnect hidden power-rail poles from connector + if pole.name == "bi-power-rail-hidden-pole" then + connector.disconnect_neighbour(pole) +--log("Disconnected " .. pole.name .. " " .. pole.unit_number) + end + end + end +end + + +log("Done -- looking for hidden poles now!") +-- Disconnect all hidden rail poles +for r, rail in pairs(global.bi_power_rail_table) do + -- Rail is still valid + if rail.base and rail.base.valid then +--log(tostring(r) .. ": rail.base.valid: " .. tostring(rail.base.valid)) + -- Disconnect pole if it's valid! + if rail.pole and rail.pole.valid then + rail.pole.disconnect_neighbour() + BioInd.writeDebug("Disconnected pole number %g", {rail.pole.unit_number}) +--log("Disconnected pole number " .. rail.pole.unit_number) + -- Place a new pole if we don't have one yet. + else + -- Create Hidden Power Pole + local track = rail.base + local new_pole = track.surface.create_entity({ + name = "bi-power-rail-hidden-pole", + position = track.position, + force = track.force + }) + new_pole.minable = false + new_pole.destructible = false + new_pole.disconnect_neighbour() + + global.bi_power_rail_table[r].pole = new_pole + BioInd.writeDebug("Created new pole %g on %s.", {new_pole.unit_number, track.name, track.unit_number}) + end + -- Rail doesn't exist anymore + elseif not rail.base.valid then +--log(tostring(r) .. ": rail.base.valid: " .. tostring(rail.base.valid)) + -- Check the pole! + if rail.pole and rail.pole.valid then + BioInd.writeDebug("Rail %g doesn't exist anymore: Removing pole %g from surface %s.", {r, rail.pole.unit_number, rail.pole.surface.name, rail.pole.surface.name}) + rail.pole.destroy() + end + + -- Remove track from table! + global.bi_power_rail_table[r] = nil + BioInd.writeDebug("Removed powered rail %g from table.", {r}) + end +end + +-- Rewire hidden rail poles +for r, rail in pairs(global.bi_power_rail_table) do +BioInd.writeDebug("Disconnected pole number %g", {rail.pole.unit_number}) +--log("Disconnected pole number " .. rail.pole.unit_number) + local rail_track = rail.base + local rail_pole = rail.pole + -- Look for connecting rails at front and back of the new rail + for s, side in ipairs( {"front", "back"} ) do +BioInd.writeDebug("Looking for rails at %s", {side}) +--log("Looking for rails at " .. side) + local neighbour + -- Look in all three directions + for d, direction in ipairs( {"left", "straight", "right"} ) do +BioInd.writeDebug("Looking for rails in %s direction", {direction}) +--log("Looking for rails in " .. direction .. " direction") + neighbour = rail_track.get_connected_rail{ + rail_direction = defines.rail_direction[side], + rail_connection_direction = defines.rail_connection_direction[direction] + } +BioInd.writeDebug("Rail %s of %s (%s): (%s)", {direction, rail_track.name, rail_track.unit_number,neighbour and neighbour.name or "nil", neighbour and neighbour.unit_number or "nil"}) +--log("Rail " .. direction .. " of " .. + --~ rail_track.name .. " (" .. rail_track.unit_number .. "): " .. + --~ serpent.line(neighbour and neighbour.name) .. + --~ " (" .. serpent.line(neighbour and neighbour.unit_number) ..")") + + -- Only make a connection if found rail is a powered rail + -- (We'll know it's the right type if we find it in our table!) + neighbour = neighbour and neighbour.valid and global.bi_power_rail_table[neighbour.unit_number] + if neighbour then + rail_pole.connect_neighbour(neighbour.pole) +BioInd.writeDebug("Connected poles!") +--log("Connected poles!") + end + end + + -- Look for Power-rail connectors + local connector = rail_track.surface.find_entities_filtered{ + position = rail_track.position, + radius = BioInd.POWER_TO_RAIL_WIRE_DISTANCE, -- maximum_wire_distance of Power-to-rail-connectors + name = "bi-power-to-rail-pole" + } + + -- Connect to first Power-rail connector we've found + if connector and table_size(connector) > 0 then + rail_pole.connect_neighbour(connector[1]) +BioInd.writeDebug("Connected %s (%g) to %s (%g)", {rail_pole.name, rail_pole.unit_number, connector[1].name, connector[1].unit_number}) + end + end +end + +BioInd.writeDebug("End of migration script 0.18.24+0.17.55") +--log("End of migration script 0.18.24+0.17.55") diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.27_+_0.17.58.lua b/Bio_Industries_2/migrations/Bio_Industries_0.18.27_+_0.17.58.lua new file mode 100644 index 0000000..4142e24 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.27_+_0.17.58.lua @@ -0,0 +1,45 @@ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') +------------------------------------------------------------------------------------ +-- For some reason, the recipe for bi-biomass-2 was more advanced than the recipe +-- for bi-biomass-3. This worked because we changed their order whereever they've +-- been used, but it wasn't intuitive and caused confusion. +-- The recipes have been renamed in 0.17.58/0.18.27, now we need to make sure that +-- the recipes in bio-reactors making bio-mass are exchanged as well! +------------------------------------------------------------------------------------ + +BioInd.writeDebug("Entered migration script 0.18.27+0.17.58") + + +-- Look for bio-reactors on all surfaces +local reactors, recipe + +for s, surface in pairs(game.surfaces) do + reactors = surface.find_entities_filtered{ + type = "assembling-machine", + name = "bi-bio-reactor" + } + BioInd.writeDebug("Found %g bio-reactors on surface \"%s\".", + {#reactors, surface.name}) + + -- Get recipe of reactors + for r, reactor in ipairs(reactors) do + recipe = reactor.get_recipe() + recipe = recipe and recipe.name or "" + BioInd.writeDebug("Reactor %g has recipe \"%s\".", + {reactor.unit_number, recipe}) + + -- Exchange "bi-biomass-2" against "bi-biomass-3" + if recipe == "bi-biomass-2" then + reactor.set_recipe("bi-biomass-3") + BioInd.writeDebug("Set recipe to %s.", {reactor.get_recipe().name}) + + -- Exchange "bi-biomass-3" against "bi-biomass-2" + elseif recipe == "bi-biomass-3" then + reactor.set_recipe("bi-biomass-2") + BioInd.writeDebug("Set recipe to %s.", {reactor.get_recipe().name}) + end + end + +end + +BioInd.writeDebug("End of migration script 0.18.27+0.17.58") diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.29.json b/Bio_Industries_2/migrations/Bio_Industries_0.18.29.json new file mode 100644 index 0000000..f49ba27 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.29.json @@ -0,0 +1,6 @@ +{ + "recipe": + [ + ["bi-pellete-coal-2", "bi-pellet-coke-2"] + ] +} diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.29.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.29.lua.bak new file mode 100644 index 0000000..b5c5f7a --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.29.lua.bak @@ -0,0 +1,720 @@ +------------------------------------------------------------------------------------ +-- We didn't react to script_raised_revive before, so mods like Construction Drones +-- that filled in ghosts would just place the base entities, and not add the hidden +-- entities. Even worse: the base entities wouldn't be added to our lists! So, let's +-- rebuild everything once again! +------------------------------------------------------------------------------------ + +local BioInd = require('__Bio_Industries__/common')('Bio_Industries') +local cnt = 0 + + +game.print("Warning: The migration may run for a long time, depending on how many entities there are to migrate! Please be patient and wait until it's finished!") + +-- Removes the hidden entities at the position of a base entity +local created_entities = {} +local function remove_entities(base, names) + local entities = base and base.surface.find_entities_filtered{ + position = base.position, + name = names, + } +if entities and next(entities) then +BioInd.show("base.unit_number", base.unit_number) +BioInd.show("Found entities", table_size(entities)) +end + + for e, entity in ipairs(entities or {}) do +--~ BioInd.show("entity.unit_number", entity.unit_number) + if not created_entities[entity.unit_number] then + entity.destroy() + end + end +end + + +-- Removes the hidden entities stored with a base entity +local function remove_stored_entities(base, names) + for e, entity in ipairs(names or {}) do + if base[entity] and base[entity].valid then + base[entity].destroy() + end + end +end + + +-- Make hidden entities unminable and indestructible +local function make_unminable(entities) + for e, entity in ipairs(entities or {}) do + if entity.valid then + entity.minable = false + entity.destructible = false + end + end +end + + +-- Recreate hidden entities +local function recreate_entities(g_table, base_entity, hidden_entity_names, ...) +BioInd.show("#g_table", table_size(g_table)) +BioInd.show("hidden_entity_names", hidden_entity_names) + + if not (g_table and type(g_table) == "table") then + error(string.format("%s is not a valid table!", g_table)) + elseif not (base_entity and type(base_entity) == "table" and base_entity.valid) then + error(string.format("%s is not a valid base entity!", base_entity)) + elseif not ( + hidden_entity_names and type(hidden_entity_names) == "table" and next(hidden_entity_names) + ) then + error(string.format("%s is not a valid array of hidden-entity names!", hidden_entity_names)) + end + + local entity + + -- Initialize entry in global table + g_table[base_entity.unit_number] = {} + g_table[base_entity.unit_number].base = base_entity + + -- Create hidden entities + for key, name in pairs(hidden_entity_names) do + entity = base_entity.surface.create_entity({ + name = name, + position = base_entity.position, + force = base_entity.force + }) + + -- Make hidden entity unminable/undestructible + make_unminable({entity}) + + -- Add hidden entity to global table + g_table[base_entity.unit_number][key] = entity + + -- Add to temporary table of recreated hidden entities + created_entities[entity.unit_number] = true + end + + -- Add optional values to global table + for k, v in pairs(... or {}) do + g_table[base_entity.unit_number][k] = v + end +BioInd.show("g_table[base.unit_number]", g_table[base_entity.unit_number]) +end + + +-- Remove all common hidden power poles and hidden power rail poles +do + local entities + for s, surface in pairs(game.surfaces) do + entities = surface.find_entities_filtered({ + name = {"bi-hidden-power-pole", "bi-power-rail-hidden-pole"} + }) + for e, entity in pairs(entities) do + entity.destroy() + cnt = cnt + 1 + end + end + BioInd.writeDebug("Removed %s hidden poles (bi-hidden-power-pole, bi-power-rail-hidden-pole)", cnt) +end + +local base, boiler, lamp, pole, panel, radar, connectors +local base_name, boiler_name, lamp_name, pole_name, radar_name, panel_name, overlay_name + + + +------------------------------------------------------------------------------------ +-- Bio Farm -- +------------------------------------------------------------------------------------ + +-- Empty old list +for b, bio_farm in pairs(global.bi_bio_farm_table or {}) do + -- Remove hidden entities from bio_farms in our table + --~ for e, entity in ipairs({"pole", "panel", "lamp"}) do + --~ if bio_farm[entity] and bio_farm[entity].valid then + --~ bio_farm[entity].destroy() + --~ end + --~ end + remove_stored_entities(bio_farm, {"pole", "panel", "lamp"}) + -- Remove entry from table + global.bi_bio_farm_table[b] = nil + + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Bio-farms.", {cnt}) + +-- Generate new list +--~ local bio_farms, pole, panel, lamp +local bio_farms +pole_name = "bi-bio-farm-hidden-pole" +panel_name = "bi-bio-farm-hidden-panel" +lamp_name = "bi-bio-farm-light" + +cnt = 0 + +for s, surface in pairs(game.surfaces or {}) do + -- Find all bio_farms on surface! + bio_farms = surface.find_entities_filtered({name = "bi-bio-farm"}) + for b, bio_farm in ipairs(bio_farms or {}) do + -- Make a clean slate! + remove_entities(bio_farm, {pole_name, panel_name, lamp_name}) + + recreate_entities(global.bi_bio_farm_table, bio_farm, { + pole = pole_name, + panel = panel_name, + lamp = lamp_name + }) + + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Bio-farms.", {cnt}) + + +------------------------------------------------------------------------------------ +-- Bio Solar Boiler/Solar Plant -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Empty old list +for s, solar_boiler in pairs(global.bi_solar_boiler_table or {}) do + -- Remove hidden entities from solar_boilers in our table + remove_stored_entities(solar_boiler, {"pole", "boiler"}) + -- Remove entry from table + global.bi_solar_boiler_table[s] = nil + + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Solar boilers/power plants.", {cnt}) + + +-- Generate new list +--~ local solar_boilers, pole, boiler +local solar_boilers +pole_name = "bi-hidden-power-pole" +boiler_name = "bi-solar-boiler-hidden-panel" + +cnt = 0 + +for s, surface in pairs(game.surfaces or {}) do + -- Find all solar_boilers on surface! + solar_boilers = surface.find_entities_filtered({name = "bi-solar-boiler"}) + for b, boiler_solar in ipairs(solar_boilers or {}) do + -- Make a clean slate! + --~ remove_entities(boiler_solar, {pole_name, panel_name}) + remove_entities(boiler_solar, {boiler_name}) + + -- Recreate hidden entities + recreate_entities(global.bi_solar_boiler_table, boiler_solar, { + boiler = boiler_name, + pole = pole_name + }) + + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Solar boilers/power plants.", {cnt}) + + + +------------------------------------------------------------------------------------ +-- Solar Farm -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Empty old list +for s, solar_farm in pairs(global.bi_solar_farm_table or {}) do + --~ remove_stored_entities(solar_farm, {"pole"}) + -- Remove entry from table + global.bi_solar_farm_table[s] = nil + + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Solar farms.", {cnt}) + + +-- Generate new list +local solar_farms +pole_name = "bi-hidden-power-pole" + +cnt = 0 + +for s, surface in pairs(game.surfaces or {}) do + -- Find all solar_boilers on surface! + solar_farms = surface.find_entities_filtered({name = "bi-bio-solar-farm"}) + for sf, solar_farm in ipairs(solar_farms or {}) do + --~ -- Make a clean slate! + --~ remove_entities(solar_farm, {pole_name}) + -- Recreate hidden entities + recreate_entities(global.bi_solar_farm_table, solar_farm, {pole = pole_name}) + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Solar farms.", {cnt}) + + + +------------------------------------------------------------------------------------ +-- Bio Cannon -- +-- Bio Cannons have a different table format -- make that the same as the others -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Empty old list +for b, bio_cannon in pairs(global.bi_bio_cannon_table or {}) do + -- Remove hidden entities from Bio cannons in our table + + if bio_cannon[2] and bio_cannon[2].valid then + bio_cannon[2].destroy() + end + -- Remove entry from table + global.bi_bio_cannon_table[b] = nil + + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Bio-Cannons.", {cnt}) + + +-- Generate new list +--~ local bio_cannons, base, radar +local bio_cannons +base_name = "bi-bio-cannon" +overlay_name = "bi-bio-cannon-area" +radar_name = "bi-bio-cannon-hidden-radar" + +cnt = 0 + +for s, surface in pairs(game.surfaces or {}) do + -- Find all cannons on surface! + bio_cannons = surface.find_entities_filtered({name = {base_name, overlay_name}}) + for b, bio_cannon in ipairs(bio_cannons or {}) do + -- Make a clean slate! + remove_entities(bio_cannon, {radar_name}) + -- Recreate hidden entities + radar = surface.create_entity({ + name = radar_name, + position = bio_cannon.position, + force = bio_cannon.force + }) + make_unminable({radar}) + -- Make sure we don't use the overlay cannon! + if bio_cannon.name == overlay_name then + -- Create final cannon + base = surface.create_entity({ + name = base_name, + position = bio_cannon.position, + force = bio_cannon.force + }) + -- Set its health to that of overlay + base.health = bio_cannon.health + -- Remove overlay + bio_cannon.destroy() + BioInd.writeDebug("Replaced Bio-cannon overlay with Bio-cannon %s.", {base.unit_number}) + else + base = bio_cannon + end + -- Add to table + global.bi_bio_cannon_table[base.unit_number] = { + base = base, + radar = radar, + -- Bio-cannons will be checked once per second. Delay is based on the ammo the + -- cannon is loaded with. Let's use 20s (delay for best ammo) initially! + delay = (base.unit_number * base.unit_number) % 20 + } + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Bio-cannons.", {cnt}) + + + +------------------------------------------------------------------------------------ +-- Arboretum -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Empty old list +for a, arboretum in pairs(global.bi_arboretum_table or {}) do + -- Remove hidden entities from solar_boilers in our table (Don't call removal + -- function because radar position has been shifted, so the radar won't be found!) + for e, entity in ipairs({"radar", "pole", "lamp"}) do + if arboretum[entity] and arboretum[entity].valid then + arboretum[entity].destroy() + end + end + --~ remove_stored_entities(arboretum, {"radar", "pole", "lamp"}) + -- Remove entry from table + global.bi_arboretum_table[a] = nil + + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Arboretums.", {cnt}) + + +-- Generate new list +--~ local arboretums, pole, radar, lamp +local arboretums +base_name = "bi-arboretum" +overlay_name = "bi-arboretum-area" +pole_name = "bi-hidden-power-pole" +radar_name = "bi-arboretum-hidden-radar" +lamp_name = "bi-bio-farm-light" + +cnt = 0 + +-- We need to keep track of radars separately! +global.bi_arboretum_radar_table = {} + +for s, surface in pairs(game.surfaces or {}) do + -- Find all arboretums on surface! + arboretums = surface.find_entities_filtered({name = {base_name, overlay_name}}) + for a, arboretum in ipairs(arboretums or {}) do + -- Make a clean slate! + remove_entities(arboretum, {pole_name, radar_name, lamp_name}) + -- Recreate hidden entities + radar = surface.create_entity({ + name = radar_name, + position = {arboretum.position.x - 3.5, arboretum.position.y + 3.5}, + force = arboretum.force + }) + pole = surface.create_entity({ + name = pole_name, + position = arboretum.position, + force = arboretum.force + }) + lamp = surface.create_entity({ + name = lamp_name, + position = arboretum.position, + force = arboretum.force + }) + make_unminable({pole, radar, lamp}) + + -- Make sure we don't use the overlay! + if arboretum.name == overlay_name then + -- Create final arboretum + base = surface.create_entity({ + name = base_name, + position = arboretum.position, + force = arboretum.force + }) + -- Set its health to that of overlay + base.health = arboretum.health + -- Remove overlay + arboretum.destroy() + BioInd.writeDebug("Replaced Arboretum overlay with Arboretum %s.", {base.unit_number}) + else + base = arboretum + end +BioInd.writeDebug("Arboretum base: %g", {base.unit_number}) + -- Add to table + global.bi_arboretum_table[base.unit_number] = { + base = base, + pole = pole, + radar = radar, + lamp = lamp + } + -- Link radar to arboretum + global.bi_arboretum_radar_table[radar.unit_number] = base.unit_number + +--~ BioInd.writeDebug("Added new arboretum: %s", {global.bi_arboretum_table}) + + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Arboretums.", {cnt}) + + + +------------------------------------------------------------------------------------ +-- Power Rail -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Empty old list +for p, power_rail in pairs(global.bi_power_rail_table or {}) do + -- We can't remove all hidden poles at once because they are used in other compound + -- entities as well! + --~ remove_stored_entities(power_rail, {"pole"}) + -- Remove entry from table + global.bi_power_rail_table[p] = nil + cnt = cnt + 1 +end +BioInd.writeDebug("Removed hidden entities from %s Powered rails.", {cnt}) +BioInd.show("global.bi_power_rail_table", serpent.block(global.bi_power_rail_table)) + +-- Generate new list +local power_rails, neighbour +pole_name = "bi-power-rail-hidden-pole" +cnt = 0 + +for s, surface in pairs(game.surfaces or {}) do + -- Find all power rails on surface (there may be some that haven't been in our table)! + power_rails = surface.find_entities_filtered({ + name = {"bi-straight-rail-power","bi-curved-rail-power"} + }) +BioInd.show("table_size(power_rails) after finding power_rails on surface", table_size(power_rails)) + -- Unlike the other entities, power rails interact with each other. So lets's + -- recreate all hidden poles and update our tables before trying to connect + -- the poles! + for p, power_rail in ipairs(power_rails or {}) do +BioInd.show("p", p) +--~ BioInd.show("power_rail.unit_number", power_rail.unit_number) + + --~ -- In case our tables haven't been properly updated, there may still be power + --~ -- rails with hidden entities around -- remove them! + --~ remove_entities(power_rail, {pole_name}) + + -- Recreate hidden entities + recreate_entities(global.bi_power_rail_table, power_rail, {pole = pole_name}) + + -- Disconnect pole + global.bi_power_rail_table[power_rail.unit_number].pole.disconnect_neighbour() + + end +BioInd.show("table_size(global.bi_power_rail_table)", table_size(global.bi_power_rail_table)) + + + -- Rewire the power rails! + for p, power_rail in pairs(global.bi_power_rail_table or {}) do +BioInd.show("p", p) +--~ BioInd.writeDebug("power_rail", {power_rail}, "line") + + base = power_rail.base + pole = power_rail.pole +--~ BioInd.show("base.valid", base.valid) +--~ BioInd.show("pole.valid", pole.valid) + + -- Look for connecting rails at front and back of the new rail + for s, side in ipairs( {"front", "back"} ) do +BioInd.writeDebug("Looking for rails at %s.\tbase.valid: %s\tpole.valid: %s", {side, base.valid, pole.valid}) + -- Look in all three directions + for d, direction in ipairs( {"left", "straight", "right"} ) do + neighbour = base.get_connected_rail{ + rail_direction = defines.rail_direction[side], + rail_connection_direction = defines.rail_connection_direction[direction] + } + +BioInd.writeDebug("Rail %s of %s (%g):\t%s (%s)", {direction, base.name, base.unit_number, (neighbour and neighbour.name or "nil"), (neighbour and neighbour.unit_number or "nil")}) + + -- Only make a connection if found rail is a powered rail + -- (We'll know it's the right type if we find it in our table!) + neighbour = neighbour and neighbour.valid and global.bi_power_rail_table[neighbour.unit_number] + if neighbour then +--~ BioInd.show("neighbour", neighbour) +--~ BioInd.show("neighbour.base", neighbour and neighbour.base and neighbour.base.valid and neighbour.base.unit_number) +--~ BioInd.show("neighbour.pole", neighbour and neighbour.pole and neighbour.pole.valid and neighbour.pole.unit_number) + pole.connect_neighbour(neighbour.pole) + BioInd.writeDebug("Connected poles!") + end + end + end + + -- Look for Power-rail connectors +--~ BioInd.show("base", base) +--~ BioInd.show("base.position", base.position) +--~ BioInd.show("pole", pole and pole.unit_number) +--~ BioInd.show("pole.valid", pole and pole.valid) + + connectors = surface.find_entities_filtered{ + position = base.position, + radius = BioInd.POWER_TO_RAIL_WIRE_DISTANCE, -- maximum_wire_distance of Power-to-rail-connectors + name = "bi-power-to-rail-pole" + } +BioInd.show("table_size(connectors)", table_size(connectors)) + + -- Connect to just one Power-rail connector! + for c, connector in ipairs(connectors or {}) do +--~ BioInd.writeDebug("Network ID pole %s: %s\tNetwork ID connector %s: %s", + --~ {pole.unit_number, pole.electric_network_id, connector.unit_number, connector.electric_network_id}) + if pole.electric_network_id ~= connector.electric_network_id then + pole.connect_neighbour(connector) +BioInd.writeDebug("Connected %s (%s) to connector %s (%s)", {pole.name, pole.unit_number, connector.name, connector.unit_number}) +--~ BioInd.writeDebug("Network ID pole %s: %s\tNetwork ID connector %s: %s", + --~ {pole.unit_number, pole.electric_network_id, connector.unit_number, connector.electric_network_id}) + break + end + end +BioInd.writeDebug("Finished search for connectors") + cnt = cnt + 1 + end +end +BioInd.writeDebug("Recreated hidden entities for %s Powered rails.", {cnt}) + + + +--~ ------------------------------------------------------------------------------------ +--~ -- Solar Farm -- +--~ ------------------------------------------------------------------------------------ +--~ cnt = 0 + +--~ -- Empty old list +--~ for s, solar_farm in pairs(global.bi_solar_farm_table or {}) do + --~ -- Remove hidden entities from solar_boilers in our table + + --~ -- Remove entry from table + --~ global.bi_solar_farm_table[s] = nil + + --~ cnt = cnt + 1 +--~ end +--~ BioInd.writeDebug("Removed hidden entities from %s Solar farms.", {cnt}) + + +--~ -- Generate new list +--~ pole_name = "bi-hidden-power-pole" + +--~ cnt = 0 + +--~ for s, surface in pairs(game.surfaces or {}) do + --~ -- Find all solar farms on surface! + --~ solar_farms = surface.find_entities_filtered({name = "bi-bio-solar-farm"}) + --~ for sf, solar_farm in ipairs(solar_farms or {}) do + -- Make a clean slate! + --~ -- Recreate hidden entities + --~ pole = surface.create_entity({ + --~ name = pole_name, + --~ position = solar_farm.position, + --~ force = solar_farm.force + --~ }) + --~ make_unminable({pole}) + --~ -- Add to table + --~ global.bi_solar_farm_table[solar_farm.unit_number] = { + --~ base = solar_farm, + --~ pole = pole + --~ } + --~ -- Recreate hidden entities + --~ recreate_entities(global.bi_solar_farm_table, solar_farm, {pole = pole_name}) + + --~ cnt = cnt + 1 + --~ end +--~ end +--~ BioInd.writeDebug("Recreated hidden entities for %s Solar farms.", {cnt}) + + +------------------------------------------------------------------------------------ +-- Musk floor -- +------------------------------------------------------------------------------------ +cnt = 0 + +-- Create tables for storing force information on tiles +global.bi_musk_floor_table = global.bi_musk_floor_table or {} +-- Lookup table for force at tile position +global.bi_musk_floor_table.tiles = global.bi_musk_floor_table.tiles or {} +-- Lookup table for tiles placed by force +global.bi_musk_floor_table.forces = global.bi_musk_floor_table.forces or {} + + +local musk_floor_tiles +local tile_name = "bi-solar-mat" +pole_name = "bi-musk-mat-hidden-pole" +panel_name = "bi-musk-mat-hidden-panel" +local pole_type = "electric-pole" +local panel_type = "solar-panel" + +-- Remove panels and poles without tile from surfaces +local cnt_panel = 0 +local cnt_pole = 0 +for s, surface in pairs(game.surfaces or {}) do + local panels = surface.find_entities_filtered({name = panel_name, type = panel_type}) + for p, panel in ipairs(panels or {}) do + local x = surface.count_tiles_filtered({ + position = panel.position, + name = tile_name, + limit = 1 + }) + if x == 0 then + BioInd.writeDebug("Removing %s at position %s because there is no %s.", {panel.name, panel.position, tile_name}) + panel.destroy() + cnt_panel = cnt_panel + 1 + end + end + + local poles = surface.find_entities_filtered({name = pole_name, type = pole_type}) + for p, pole in ipairs(poles or {}) do + local x = surface.count_tiles_filtered({ + position = pole.position, + name = tile_name, + radius = 0.5, + limit = 1 + }) + if x == 0 then + BioInd.writeDebug("Removing %s at position %s because there is no %s.", {pole.name, pole.position, tile_name}) + pole.destroy() + cnt_pole = cnt_pole + 1 + end + end +end +BioInd.writeDebug("Removed %g hidden solar panels and %g hidden poles because they were not on %s.", {cnt_panel, cnt_pole, tile_name}) + +cnt_panel = 0 +cnt_pole = 0 +-- Generate new list +local x, y, poles, pole, panels, panel, force_name +for s, surface in pairs(game.surfaces or {}) do + local tiles = surface.find_tiles_filtered{name = tile_name} + for t, tile in ipairs(tiles or {}) do + x = tile.position.x or tile.position[1] + y = tile.position.y or tile.position[2] + + -- Check that there's a solar panel + panels = surface.find_entities_filtered({ + position = {x + 0.5, y + 0.5}, + name = panel_name, + type = panel_type, + limit = 1 + }) + panel = panels and panels[1] + if panel then + force_name = panel.force and panel.force.name + end + + -- Check that there's a pole + panels = surface.find_entities_filtered({ + position = {x + 0.5, y + 0.5}, + name = pole_name, + type = pole_type, + limit = 1 + }) + pole = poles and poles[1] + if pole and not force then + force_name = pole.force and pole.force.name + end + + force_name = force_name or "BI-Musk_floor_general_owner" + + -- Create/set force for panel + if panel then + panel.force = force_name + else + panel = surface.create_entity({ + name = panel_name, + type = panel_type, + force = force_name, + position = {x + 0.5, y + 0.5}, + }) + cnt_panel = cnt_panel + 1 + end + -- Create/set force for pole + if pole then + pole.force = force_name + else + pole = surface.create_entity({ + name = pole_name, + type = pole_type, + force = force_name, + position = {x + 0.5, y + 0.5}, + }) + cnt_pole = cnt_pole + 1 + end + + make_unminable({panel, pole}) + + -- Add to global tables + global.bi_musk_floor_table.tiles[x] = global.bi_musk_floor_table.tiles[x] or {} + global.bi_musk_floor_table.tiles[x][y] = force_name + + global.bi_musk_floor_table.forces[force_name] = global.bi_musk_floor_table.forces[force_name] or {} + global.bi_musk_floor_table.forces[force_name][x] = global.bi_musk_floor_table.forces[force_name][x] or {} + global.bi_musk_floor_table.forces[force_name][x][y] = true + end +end +BioInd.writeDebug("Created %g hidden solar panels and %g hidden poles.\nglobal.bi_musk_floor_table.tiles: %s\nglobal.bi_musk_floor_table.forces: %s", {cnt_panel, cnt_pole, global.bi_musk_floor_table.tiles, global.bi_musk_floor_table.forces}) + +BioInd.show("table_size(created_entities)", table_size(created_entities)) +created_entities = nil diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.json b/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.json new file mode 100644 index 0000000..ce97ae4 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.json @@ -0,0 +1,20 @@ +{ + "item": + [ + ["fertiliser", "fertilizer"], + ["bi-adv-fertiliser", "bi-adv-fertilizer"] + ], + + "recipe": + [ + ["bi-adv-fertiliser-1", "bi-adv-fertilizer-1"], + ["bi-adv-fertiliser-2", "bi-adv-fertilizer-2"], + ["bi-fertiliser-1", "bi-fertilizer-1"], + ["bi-fertiliser-2", "bi-fertilizer-2"] + ], + + "technology": + [ + ["bi-tech-fertiliser", "bi-tech-fertilizer"] + ] +} diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.lua b/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.lua new file mode 100644 index 0000000..36f76b2 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.31_+_1.01.01.lua @@ -0,0 +1,12 @@ +------------------------------------------------------------------------------------ +-- Just remove some obsolete global tables! +------------------------------------------------------------------------------------ +--~ local BioInd = require('__Bio_Industries_2__/common')('Bio_Industries_2') + +if global and global.bi then + global.bi.terrains = nil + global.bi.seed_bomb = nil + BioInd.writeDebug("Removed obsolete tables from global!") +end + +table.sort(global, function(a, b) return a < b end) diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.32_+_1.01.02.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.32_+_1.01.02.lua.bak new file mode 100644 index 0000000..ad7c999 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.32_+_1.01.02.lua.bak @@ -0,0 +1,29 @@ +------------------------------------------------------------------------------------ +-- BioGardens will now have a hidden pole. It can't be hooked up unless Fluid +-- fertilizer is active (maximum_wire_distance = 0), but it still needs to be there. +------------------------------------------------------------------------------------ +local BioInd = require('__Bio_Industries__/common')('Bio_Industries') + +-- Make sure the global table exists! +global.bi_bio_garden_table = {} + +local bio_gardens = {} +local hidden_entities = {pole = "bi-bio-garden-hidden-pole"} + +for s, surface in pairs(game.surfaces) do + bio_gardens = surface.find_entities_filtered{ + name = "bi-bio-garden", + type = "assembling-machine", + } + + for g, garden in ipairs(bio_gardens or {}) do + --~ BioInd.create_entities(global.bi_bio_garden_table, garden, hidden_entities, garden.position) + BioInd.create_entities(global.bi_bio_garden_table, garden, hidden_entities) + BioInd.writeDebug("Stored Bio garden %g in table: %s", {garden.unit_number, global.bi_bio_garden_table[garden.unit_number]}) + end +end + + +-- Create a table where we can store the last state of certain mod settings. +global.mod_settings = global.mod_settings or {} +global.mod_settings.BI_Easy_Bio_Gardens = BioInd.get_startup_setting("BI_Easy_Bio_Gardens") diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.34_+_1.01.04.lua.bak b/Bio_Industries_2/migrations/Bio_Industries_0.18.34_+_1.01.04.lua.bak new file mode 100644 index 0000000..0eab507 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.34_+_1.01.04.lua.bak @@ -0,0 +1,122 @@ +log("Entered migration script 1_00_04.lua of \"" .. script.mod_name .. "\".") + +-- Add functions that are also used in other files (debugging output etc.) +local BioInd = require("__" .. script.mod_name .. "__.common")(script.mod_name) + +------------------------------------------------------------------------------------ +-- Make sure that all compound entities have all the hidden entities they need! +------------------------------------------------------------------------------------ + +-- Compile a list of the entities we need to consider (we can ignore overlay entities) +local check_entities = {} +for name, data in pairs(BioInd.compound_entities) do + if not name:match("^.+%-area$") then + check_entities[name] = data + end +end + + +local function add_hidden_entity(tab, base, hidden_entity) + local optional, pos + + local entity_name = check_entities[base.name].hidden[hidden_entity] + + ------------------------------------------------------------------------------------ + -- Pre-processing + ------------------------------------------------------------------------------------ + pos = BioInd.normalize_position(base.position) + + -- Bio cannon + if tab == "bi_bio_cannon_table" then + optional = {delay = 0} + + -- Arboretum + elseif tab == "bi_arboretum_table" and hidden_entity == "radar" then + -- Radar position is off! + pos = {pos.x - 3.5, pos.y + 3.5} + end +BioInd.show("base.unit_number", base.unit_number) +BioInd.show("size of global[tab]", table_size(global[tab])) + + + ------------------------------------------------------------------------------------ + -- Create hidden entity + ------------------------------------------------------------------------------------ + --~ BioInd.create_entities(global[tab], base, {[hidden_entity] = entity_name}, pos, optional) + BioInd.create_entities(global[tab], base, {[hidden_entity] = entity_name}, optional) + + ------------------------------------------------------------------------------------ + -- Post-processing + ------------------------------------------------------------------------------------ + -- Arboretum + if tab == "bi_arboretum_table" and hidden_entity == "radar" then + local radar = global[tab][base.unit_number].radar + global.bi_arboretum_radar_table[radar.unit_number] = base.unit_number + + -- Power Rail + elseif tab == "bi_power_rail_table" then + BioInd.connect_power_rail(base) + end + +end + + +local entity, entities + +-- Find all compound entities +for s_name, surface in pairs(game.surfaces) do +BioInd.show("Looking for compound entities on surface", s_name) + + for entity_name, entity_data in pairs(check_entities) do +BioInd.show("Looking for", entity_name) + -- Get list of all base entities + entities = surface.find_entities_filtered({name = entity_name}) +BioInd.show("Number of found entities", #entities) + + -- Check the base entity is in the global table + global[entity_data.tab] = global[entity_data.tab] or {} + + for b, base in ipairs(entities) do + -- The base entity has been registered + if global[entity_data.tab][base.unit_number] then + entity = global[entity_data.tab][base.unit_number] +BioInd.writeDebug("%s is a registered entity. Checking hidden entities: %s", {BioInd.print_name_id(base), entity}) + -- Check hidden entities + for h_key, h_name in pairs(entity_data.hidden) do + -- Must add hidden entity + if not (entity[h_key] and entity[h_key].valid) then +BioInd.writeDebug("Adding hidden %s to %s", {h_key, BioInd.print_name_id(base)}) + add_hidden_entity(entity_data.tab, base, h_key) + -- Nothing to do + else +BioInd.writeDebug("%s is OK!", {BioInd.print_name_id(entity[h_key])}) + end + end + + -- Found unregistered entity! + else +BioInd.writeDebug("%s has not been registered. Adding hidden entities: %s", {BioInd.print_name_id(base), entity}) + -- Register base entity + global[entity_data.tab][base.unit_number] = {base = base} +BioInd.writeDebug("Added %s to global[%s]", {BioInd.print_name_id(base), entity_data.tab}) + -- Add hidden entities + for h_key, h_name in pairs(entity_data.hidden) do +BioInd.writeDebug("Adding hidden %s for %s", {h_key, BioInd.print_name_id(base)}) + add_hidden_entity(entity_data.tab, base, h_key) + end + end + + end + end +end + + +------------------------------------------------------------------------------------ +-- Reset effects of researched technologies! +------------------------------------------------------------------------------------ +for force_name, force in pairs(game.forces) do + force.reset_technology_effects() + BioInd.show("Reset technology effects for force", force_name) +end + +log("End of migration script 1_00_04.lua of \"" .. script.mod_name .. "\".") diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.json b/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.json new file mode 100644 index 0000000..89dd722 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.json @@ -0,0 +1,17 @@ +{ + "entity": + [ + ["bi-bio-farm-electric-pole", "bi-bio-farm-hidden-pole"], + ["bi-rail-hidden-power-pole", "bi-rail-power-hidden-pole"], + ["bi-musk-mat-pole", "bi-musk-mat-hidden-pole"], + + ["bi-bio-farm-solar-panel", "bi-bio-farm-hidden-panel"], + ["bi-musk-mat-solar-panel", "bi-musk-mat-hidden-panel"], + ["bi-solar-boiler-panel", "bi-solar-boiler-hidden-panel"], + + ["bi-arboretum-radar", "bi-arboretum-hidden-radar"], + ["Bio-Cannon-r", "bi-bio-cannon-hidden-radar"] + ] + +} + --~ ["bi-bio-farm-light", "bi-arboretum-hidden-lamp"], diff --git a/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.lua b/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.lua new file mode 100644 index 0000000..2078143 --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_0.18.35_+_1.01.05.lua @@ -0,0 +1,39 @@ +-- Add functions that are also used in other files (debugging output etc.) +--~ local BioInd = require("__" .. script.mod_name .. "__.common")(script.mod_name) +BioInd.writeDebug("Entered migration script 0.18.35+1.01.05") + +--~ require("util") + + +-- Migrating global tables to new names +for new, old in pairs({ + bi_arboretum_table = "Arboretum_Table", + bi_arboretum_radar_table = "Arboretum_Radar_Table", + bi_arboretum_recipe_table = "Arboretum_Recipes", + bi_bio_cannon_table = "Bio_Cannon_Table", +}) do + + global[new] = util.table.deepcopy(global[old]) + global[old] = nil + BioInd.writeDebug("Migrated global[\"%s\"] to global[\"%s\"].", {old, new}) +end + +-- Migrate renamed hidden entities! +local boilers = global["bi_solar_boiler_table"] + +-- Check the entries of all solar boilers +for b, boiler in pairs(boilers or {}) do + if boiler.boiler then + -- Only "boiler" exists (default) + if not boiler.panel then + boiler.panel = boiler.boiler + boiler.boiler = nil + BioInd.writeDebug("Moved \"boiler\" to \"panel\" in global[\"bi_solar_boiler_table\"][%s]: %s", + {b, boilers[b]}) + -- This should never be needed! + else + boiler.boiler = nil + BioInd.writeDebug("\"Panel\" already exists! Removed \"boiler\" from global[\"bi_solar_boiler_table\"][%s]: %s", {b, boilers[b]}) + end + end +end diff --git a/Bio_Industries_2/migrations/Bio_Industries_1.01.19.lua b/Bio_Industries_2/migrations/Bio_Industries_1.01.19.lua new file mode 100644 index 0000000..791df3a --- /dev/null +++ b/Bio_Industries_2/migrations/Bio_Industries_1.01.19.lua @@ -0,0 +1,46 @@ +--~ -- If a tutorial from Tips and Tricks is started, the migration will be applied to a +--~ -- mod named "level" and none of our global variables will be defined.) +--~ if script.mod_name ~= "autodrive" then + --~ AD.entered_file("leave", "Nothing to do for mod \""..script.mod_name.."\"!") + --~ return +--~ end +--~ AD.entered_file() + + +-- Add functions that are also used in other files (debugging output etc.) +--~ local BioInd = require("__" .. script.mod_name .. "__.common")(script.mod_name) +BioInd.writeDebug("Entered migration script 1.01.19") + +--~ require("util") + + +-- Restructure tables for growing trees. They used to be arrays of treedata that had +-- to be resorted by treedata.time whenever a new tree was added, so we could stop +-- the on_tick event when the treedata.time of the first array was in the future. +-- Now we index these tables directly by tick, so we can skip sorting the tables. +local function convert_tab(tab) + local ret = {} + local tick + + for t, tree_data in pairs(tab) do + tick = tree_data.time + --~ tree_data.time = nil + + ret[tick] = ret[tick] or {} + table.insert(ret[tick], tree_data) + end + + return ret +end + +local tab = "tree_growing" +BioInd.writeDebug("Converting table global.bi[%s]", {tab}) +global.bi[tab] = convert_tab(global.bi[tab]) +BioInd.show("global.bi["..tab.."]", global.bi[tab]) + +for s = 1, 4 do + tab = "tree_growing_stage_"..s + BioInd.writeDebug("Converting table global.bi[%s]", {tab}) + global.bi[tab] = convert_tab(global.bi[tab]) +BioInd.show("global.bi["..tab.."]", global.bi[tab]) +end diff --git a/Bio_Industries_2/settings.lua b/Bio_Industries_2/settings.lua index 2d442bb..0dc8865 100644 --- a/Bio_Industries_2/settings.lua +++ b/Bio_Industries_2/settings.lua @@ -169,20 +169,20 @@ end --~ data:extend({list}) --[[ Types of settings: - � startup - game must be restarted if changed (such a setting may affect prototypes' changes) - � runtime-global - per-world setting - � runtime-per-user - per-user setting + • startup - game must be restarted if changed (such a setting may affect prototypes' changes) + • runtime-global - per-world setting + • runtime-per-user - per-user setting Types of values: - � bool-setting - � double-setting - � int-setting - � string-setting + • bool-setting + • double-setting + • int-setting + • string-setting Files being processed by the game: - � settings.lua - � settings-updates.lua - � settings-final-fixes.lua + • settings.lua + • settings-updates.lua + • settings-final-fixes.lua Using in DATA.lua: data:extend({ @@ -230,7 +230,7 @@ Using in CONTROL.lua and in other code for reading: event.player_index event.setting GET: settings.startup["setting-name"].value - current value of startup setting; can be used in DATA.lua - GET: settings.storage["setting-name"].value - current value of per-world setting + GET: settings.global["setting-name"].value - current value of per-world setting GET: set = settings.get_player_settings(LuaPlayer) - current values for per-player settings; then use set["setting-name"].value GET: settings.player - default values ]] diff --git a/Bio_Industries_2/settings_changed.lua b/Bio_Industries_2/settings_changed.lua index 342948a..9126db9 100644 --- a/Bio_Industries_2/settings_changed.lua +++ b/Bio_Industries_2/settings_changed.lua @@ -99,10 +99,10 @@ settings_changed.bio_garden = function() -- Has this setting been changed since the last time the game was run? local current = BioInd.get_startup_setting("BI_Easy_Bio_Gardens") -BioInd.show("Last state of BI_Easy_Bio_Gardens", storage.mod_settings.BI_Easy_Bio_Gardens) +BioInd.show("Last state of BI_Easy_Bio_Gardens", global.mod_settings.BI_Easy_Bio_Gardens) BioInd.show("Current state of BI_Easy_Bio_Gardens", current) - if storage.mod_settings.BI_Easy_Bio_Gardens ~= current then + if global.mod_settings.BI_Easy_Bio_Gardens ~= current then BioInd.writeDebug("Setting has been changed!") local pole, neighbours -- This is the unmodified table! @@ -110,7 +110,7 @@ BioInd.writeDebug("Setting has been changed!") local hidden_entities = compound_entity.hidden -- Check that all gardens are still valid - for g, garden in pairs(storage[compound_entity.tab]) do + for g, garden in pairs(global[compound_entity.tab]) do -- Base entity doesn't exist -- remove hidden entities!'' if not (garden.base and garden.base.valid) then -- Remove all hidden entities! @@ -122,7 +122,7 @@ BioInd.writeDebug("Removing hidden entity %s %s", { BioInd.remove_entity(garden[hidden]) garden[hidden] = nil end - storage[compound_entity.tab][garden.entity.unit_number] = nil + global[compound_entity.tab][garden.entity.unit_number] = nil end end @@ -148,12 +148,12 @@ BioInd.writeDebug("Removing hidden entity %s %s", { -- Setting is on, so we need to create the hidden poles if current then BioInd.writeDebug("Need to create hidden poles for %s Bio Gardens!", - {table_size(storage.bi_bio_garden_table) }) + {table_size(global.bi_bio_garden_table) }) -- Restore the list of hidden entities - storage.compound_entities["bi-bio-garden"] = BioInd.compound_entities["bi-bio-garden"] + global.compound_entities["bi-bio-garden"] = BioInd.compound_entities["bi-bio-garden"] local base - for g, garden in pairs(storage.bi_bio_garden_table or {}) do + for g, garden in pairs(global.bi_bio_garden_table or {}) do -- Make sure the base entity exists! base = garden.base pole = base and garden[pole_type] @@ -168,7 +168,7 @@ BioInd.show("pole", pole) elseif base then -- Create hidden poles pole = BioInd.create_entities( - storage[compound_entity.tab], + global[compound_entity.tab], base, {pole = hidden_entities[pole_type].name} --~ base.position @@ -176,11 +176,11 @@ BioInd.show("pole", pole) -- Add the new pole to the table if pole then - storage[compound_entity.tab][base.unit_number][pole_type] = pole + global[compound_entity.tab][base.unit_number][pole_type] = pole BioInd.writeDebug("Stored %s %g in table: %s", { base.name, base.unit_number, - storage[compound_entity.tab][base.unit_number] + global[compound_entity.tab][base.unit_number] }) end end @@ -189,10 +189,10 @@ BioInd.show("pole", pole) -- Setting is off -- disconnect and remove hidden poles! else BioInd.writeDebug("%s Bio Gardens found -- try to disconnect hidden poles!", - {table_size(storage.bi_bio_garden_table) }) + {table_size(global.bi_bio_garden_table) }) -- Find hidden poles of registered gardens -BioInd.show("storage.bi_bio_garden_table", storage.bi_bio_garden_table) - for g, garden in pairs(storage.bi_bio_garden_table or {}) do +BioInd.show("global.bi_bio_garden_table", global.bi_bio_garden_table) + for g, garden in pairs(global.bi_bio_garden_table or {}) do if garden[pole_type] then -- Pole really exists: destroy the entity if garden[pole_type].valid then @@ -212,8 +212,8 @@ BioInd.show("storage.bi_bio_garden_table", storage.bi_bio_garden_table) -- We don't want to create hidden poles if the setting is off, -- so remove the pole from hidden entities! - storage.compound_entities["bi-bio-garden"].hidden[pole_type] = nil -BioInd.show("storage.compound_entities", storage.compound_entities) + global.compound_entities["bi-bio-garden"].hidden[pole_type] = nil +BioInd.show("global.compound_entities", global.compound_entities) end -- Remove any hidden poles that are not associated with a garden @@ -224,8 +224,8 @@ BioInd.show("storage.compound_entities", storage.compound_entities) end -- Update setting! - storage.mod_settings.BI_Easy_Bio_Gardens = current - BioInd.show("Updated setting to", storage.mod_settings.BI_Easy_Bio_Gardens) + global.mod_settings.BI_Easy_Bio_Gardens = current + BioInd.show("Updated setting to", global.mod_settings.BI_Easy_Bio_Gardens) else BioInd.writeDebug("Nothing to do!") end