diff --git a/Bio_Industries_2/Test_Spawn.lua b/Bio_Industries_2/Test_Spawn.lua index b344a51..8c50d88 100644 --- a/Bio_Industries_2/Test_Spawn.lua +++ b/Bio_Industries_2/Test_Spawn.lua @@ -2,84 +2,84 @@ function Test_Spawn() - local surface = game.surfaces['nauvis'] + local surface = game.surfaces['nauvis'] - surface.create_entity({name = "tree-01", position = {2, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-02", position = {4, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-02-red", position = {6, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-03", position = {8, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-04", position = {10, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-05", position = {12, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-06", position = {14, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-06-brown", position = {16, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-07", position = {18, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-08", position = {20, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-08-brown", position = {22, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-09", position = {24, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-09-brown", position = {26, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-09-red", position = {28, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-a", position = {30, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-b", position = {32, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-c", position = {34, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-d", position = {36, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-e", position = {38, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-f", position = {40, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-g", position = {42, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-h", position = {44, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-i", position = {46, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-j", position = {48, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-k", position = {50, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-l", position = {52, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-m", position = {54, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-desert-n", position = {56, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-a", position = {58, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-b", position = {60, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-c", position = {62, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-d", position = {64, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-e", position = {66, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-f", position = {68, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-g", position = {70, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-h", position = {72, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-i", position = {74, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-j", position = {76, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-k", position = {78, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-l", position = {80, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-m", position = {82, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-n", position = {84, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-dryland-o", position = {86, 10}, force = game.forces.player}) - --surface.create_entity({name = "tree-grassland-0", position = {88, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-a", position = {90, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-b", position = {92, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-c", position = {94, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-d", position = {96, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-e", position = {98, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-f", position = {100, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-g", position = {102, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-h", position = {104, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-h2", position = {106, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-h3", position = {108, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-i", position = {110, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-k", position = {112, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-l", position = {114, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-m", position = {116, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-n", position = {118, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-p", position = {120, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-grassland-q", position = {122, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-snow-a", position = {124, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-volcanic-a", position = {126, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-a", position = {128, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-b", position = {130, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-c", position = {132, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-d", position = {134, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-e", position = {136, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-f", position = {138, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-g", position = {140, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-h", position = {142, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-i", position = {144, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-j", position = {146, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-k", position = {148, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-l", position = {150, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-m", position = {152, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-n", position = {154, 10}, force = game.forces.player}) - surface.create_entity({name = "tree-wetland-o", position = {156, 10}, force = game.forces.player}) + surface.create_entity({ name = "tree-01", position = { 2, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-02", position = { 4, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-02-red", position = { 6, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-03", position = { 8, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-04", position = { 10, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-05", position = { 12, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-06", position = { 14, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-06-brown", position = { 16, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-07", position = { 18, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-08", position = { 20, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-08-brown", position = { 22, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-09", position = { 24, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-09-brown", position = { 26, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-09-red", position = { 28, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-a", position = { 30, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-b", position = { 32, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-c", position = { 34, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-d", position = { 36, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-e", position = { 38, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-f", position = { 40, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-g", position = { 42, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-h", position = { 44, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-i", position = { 46, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-j", position = { 48, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-k", position = { 50, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-l", position = { 52, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-m", position = { 54, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-desert-n", position = { 56, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-a", position = { 58, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-b", position = { 60, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-c", position = { 62, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-d", position = { 64, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-e", position = { 66, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-f", position = { 68, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-g", position = { 70, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-h", position = { 72, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-i", position = { 74, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-j", position = { 76, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-k", position = { 78, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-l", position = { 80, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-m", position = { 82, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-n", position = { 84, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-dryland-o", position = { 86, 10 }, force = game.forces.player }) + --surface.create_entity({name = "tree-grassland-0", position = {88, 10}, force = game.forces.player}) + surface.create_entity({ name = "tree-grassland-a", position = { 90, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-b", position = { 92, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-c", position = { 94, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-d", position = { 96, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-e", position = { 98, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-f", position = { 100, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-g", position = { 102, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-h", position = { 104, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-h2", position = { 106, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-h3", position = { 108, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-i", position = { 110, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-k", position = { 112, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-l", position = { 114, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-m", position = { 116, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-n", position = { 118, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-p", position = { 120, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-grassland-q", position = { 122, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-snow-a", position = { 124, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-volcanic-a", position = { 126, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-a", position = { 128, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-b", position = { 130, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-c", position = { 132, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-d", position = { 134, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-e", position = { 136, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-f", position = { 138, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-g", position = { 140, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-h", position = { 142, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-i", position = { 144, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-j", position = { 146, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-k", position = { 148, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-l", position = { 150, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-m", position = { 152, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-n", position = { 154, 10 }, force = game.forces.player }) + surface.create_entity({ name = "tree-wetland-o", position = { 156, 10 }, force = game.forces.player }) end diff --git a/Bio_Industries_2/control.lua b/Bio_Industries_2/control.lua index cee4a70..5c967f0 100644 --- a/Bio_Industries_2/control.lua +++ b/Bio_Industries_2/control.lua @@ -2,8 +2,8 @@ BioInd = require("__" .. script.mod_name .. "__.common")(script.mod_name) local settings_changed = require("settings_changed") if BioInd.get_startup_setting("BI_Enable_gvv_support") then - BioInd.writeDebug("Activating support for gvv!") - require("__gvv__/gvv")() + BioInd.writeDebug("Activating support for gvv!") + require("__gvv__/gvv")() end @@ -14,10 +14,10 @@ end local AlienBiomes local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(false) -require ("util") -require ("libs/util_ext") -require ("control_tree") -require ("control_arboretum") +require("util") +require("libs/util_ext") +require("control_tree") +require("control_arboretum") ---************** Used for Testing ----- @@ -26,619 +26,618 @@ require ("control_arboretum") local function Create_dummy_force() - -- Create dummy force for musk floor if electric grid overlay should NOT be shown in map view + -- Create dummy force for musk floor if electric grid overlay should NOT be shown in map view local f = game.create_force(BioInd.MuskForceName) -- Set new force as neutral to every other force for name, force in pairs(game.forces) do - if name ~= BioInd.MuskForceName then - f.set_friend(force, false) - f.set_cease_fire(force, true) - end + if name ~= BioInd.MuskForceName then + f.set_friend(force, false) + f.set_cease_fire(force, true) + end end -- New force won't share chart data with any other force f.share_chart = false - BioInd.writeDebug("Created force: %s", {game.forces[BioInd.MuskForceName].name}) + BioInd.writeDebug("Created force: %s", { game.forces[BioInd.MuskForceName].name }) end -- Generate a look-up table with the names of our trees local function get_bi_trees() - local list = {} + local list = {} - local trees = prototypes.get_entity_filtered({{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) - list[tree_name] = true + local trees = prototypes.get_entity_filtered({ { 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) + list[tree_name] = true + end end - end - return list + return list end -- Generate a look-up table with the names of tiles that can't be changed by fertilizer local tile_patterns = { - ".*concrete.*", - ".*stone%-path.*", - "^bi%-solar%-mat$", - "^bi%-wood%-floor$", + ".*concrete.*", + ".*stone%-path.*", + "^bi%-solar%-mat$", + "^bi%-wood%-floor$", } local function get_fixed_tiles() - local list = {} + local list = {} - for tile_name, tile in pairs(prototypes.tile) do - for p, pattern in ipairs(tile_patterns) do - if tile_name:match(pattern) then -BioInd.show("Found matching tile", tile_name) - -- If a tile is minable and fertilizer is used on it, we must deduct the mined - -- tiles from the player/robot again! - list[tile_name] = tile.mineable_properties.products or true - end + for tile_name, tile in pairs(prototypes.tile) do + for p, pattern in ipairs(tile_patterns) do + if tile_name:match(pattern) then + BioInd.show("Found matching tile", tile_name) + -- If a tile is minable and fertilizer is used on it, we must deduct the mined + -- tiles from the player/robot again! + list[tile_name] = tile.mineable_properties.products or true + end + end end - end -BioInd.show("Forbidden tiles", list) - return list + BioInd.show("Forbidden tiles", list) + return list end -- Generate a look-up table with recipe ingredients, as other mods may have changed them local function get_arboretum_recipes() - local list = {} + local list = {} - local recipes = prototypes.recipe - local name + local recipes = prototypes.recipe + local name - for i = 1, 5 do - name = "bi-arboretum-r" .. i - list[name] = {} - list[name].items = {} - list[name].fluids = {} + for i = 1, 5 do + name = "bi-arboretum-r" .. i + list[name] = {} + list[name].items = {} + list[name].fluids = {} - for i, ingredient in pairs(recipes[name].ingredients) do - if ingredient.type == "item" then - list[name].items[ingredient.name] = ingredient.amount - else - list[name].fluids[ingredient.name] = ingredient.amount - end + for i, ingredient in pairs(recipes[name].ingredients) do + if ingredient.type == "item" then + list[name].items[ingredient.name] = ingredient.amount + else + list[name].fluids[ingredient.name] = ingredient.amount + end + end end - end - BioInd.show("Terraformer recipes", list) - return list + BioInd.show("Terraformer recipes", list) + return list end -------------------------------------------------------------------- local function init() -BioInd.writeDebug("Entered init!") - if BioInd.is_debug then - game.check_prototype_translations() - end + BioInd.writeDebug("Entered init!") + if BioInd.is_debug then + game.check_prototype_translations() + end - storage = storage or {} + storage = storage or {} - -------------------------------------------------------------------- - -- Settings - -------------------------------------------------------------------- - -- Global table for storing the last state of certain mod settings - storage.mod_settings = storage.mod_settings or {} - if BioInd.get_startup_setting("BI_Easy_Bio_Gardens") then - storage.mod_settings.garden_pole_connectors = BioInd.get_garden_pole_connectors() - else - storage.mod_settings.garden_pole_connectors = nil - end + -------------------------------------------------------------------- + -- Settings + -------------------------------------------------------------------- + -- Global table for storing the last state of certain mod settings + storage.mod_settings = storage.mod_settings or {} + if BioInd.get_startup_setting("BI_Easy_Bio_Gardens") then + storage.mod_settings.garden_pole_connectors = BioInd.get_garden_pole_connectors() + else + storage.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). + -- 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 = BioInd.rebuild_compound_entity_list() - -------------------------------------------------------------------- - -- Tree stuff! - -------------------------------------------------------------------- - storage.bi = storage.bi or {} - storage.bi.tree_growing = storage.bi.tree_growing or {} - for i = 1, 4 do - storage.bi["tree_growing_stage_" .. i] = storage.bi["tree_growing_stage_" .. i] or {} - end + -------------------------------------------------------------------- + -- Tree stuff! + -------------------------------------------------------------------- + storage.bi = storage.bi or {} + storage.bi.tree_growing = storage.bi.tree_growing or {} + for i = 1, 4 do + storage.bi["tree_growing_stage_" .. i] = storage.bi["tree_growing_stage_" .. i] or {} + end - -- List of tree prototypes created by BI - storage.bi.trees = get_bi_trees() + -- List of tree prototypes created by BI + storage.bi.trees = get_bi_trees() - -- List of tile prototypes that can't be fertilized - storage.bi.barren_tiles = get_fixed_tiles() + -- List of tile prototypes that can't be fertilized + storage.bi.barren_tiles = get_fixed_tiles() - -------------------------------------------------------------------- - -- Compound entities - -------------------------------------------------------------------- - -- Check what global tables we need for compound entities - local compound_entity_tables = {} + -------------------------------------------------------------------- + -- Compound entities + -------------------------------------------------------------------- + -- Check what global tables we need for compound entities + local compound_entity_tables = {} for compound, compound_data in pairs(storage.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 - compound_entity_tables[compound_data.tab] = compound - end -BioInd.show("Need to check these tables in global", compound_entity_tables) - - -- Prepare global tables storing data of compound entities - 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])}) - -- If this compound entity requires additional tables in global, initialize - -- them now! - local related_tables = storage.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])}) - end + -- 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 + compound_entity_tables[compound_data.tab] = compound end - -- If this compound entity requires additional values in global, initialize - -- them now! - local related_vars = storage.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]}) - end + BioInd.show("Need to check these tables in global", compound_entity_tables) + + -- Prepare global tables storing data of compound entities + 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]) }) + -- If this compound entity requires additional tables in global, initialize + -- them now! + local related_tables = storage.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]) }) + 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 + 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] }) + end + end + + -- Clean up global tables (We can skip this for empty tables!) + if next(storage[compound_tab]) then + -- Remove invalid entities + result = BioInd.clean_global_compounds_table(compound_name) + BioInd.writeDebug("Removed %s invalid entries from storage[%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\"]!", + { result.checked, result.restored, compound_tab }) + end + end + -- Search all surfaces for unregistered compound entities + result = BioInd.find_unregistered_entities() + BioInd.writeDebug("Registered %s forgotten entities!", { result }) + + + + -------------------------------------------------------------------- + -- 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 {} + + + + -------------------------------------------------------------------- + -- Arboretum + -------------------------------------------------------------------- + -- Global table for arboretum radars + storage.bi_arboretum_radar_table = storage.bi_arboretum_radar_table or {} + + -- Global table of ingredients for terraformer recipes + storage.bi_arboretum_recipe_table = get_arboretum_recipes() + + + -------------------------------------------------------------------- + -- Compatibility with other mods + -------------------------------------------------------------------- + storage.compatible = storage.compatible or {} + storage.compatible.AlienBiomes = BioInd.AB_tiles() + + + -- enable researched recipes + for i, force in pairs(game.forces) do + BioInd.writeDebug("Reset technology effects for force %s.", { force.name }) + force.reset_technology_effects() end - -- Clean up global tables (We can skip this for empty tables!) - if next(storage[compound_tab]) then - -- Remove invalid entities - result = BioInd.clean_global_compounds_table(compound_name) - BioInd.writeDebug("Removed %s invalid entries from storage[%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\"]!", - {result.checked, result.restored, compound_tab}) - end - end - -- Search all surfaces for unregistered compound entities - result = BioInd.find_unregistered_entities() - BioInd.writeDebug("Registered %s forgotten entities!", {result}) - - - - -------------------------------------------------------------------- - -- 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 {} - - - - -------------------------------------------------------------------- - -- Arboretum - -------------------------------------------------------------------- - -- Global table for arboretum radars - storage.bi_arboretum_radar_table = storage.bi_arboretum_radar_table or {} - - -- Global table of ingredients for terraformer recipes - storage.bi_arboretum_recipe_table = get_arboretum_recipes() - - - -------------------------------------------------------------------- - -- Compatibility with other mods - -------------------------------------------------------------------- - storage.compatible = storage.compatible or {} - storage.compatible.AlienBiomes = BioInd.AB_tiles() - - - -- enable researched recipes - for i, force in pairs(game.forces) do - BioInd.writeDebug("Reset technology effects for force %s.", {force.name}) - force.reset_technology_effects() - end - - -- Create dummy force for musk floor if electric grid overlay should NOT be shown in map view - if BioInd.UseMuskForce and not game.forces[BioInd.MuskForceName] then + -- Create dummy force for musk floor if electric grid overlay should NOT be shown in map view + if BioInd.UseMuskForce and not game.forces[BioInd.MuskForceName] then Create_dummy_force() - end - + end end -------------------------------------------------------------------- local function On_Load() - log("Entered On_Load!") - + log("Entered On_Load!") end -------------------------------------------------------------------- local function On_Config_Change(ConfigurationChangedData) -BioInd.writeDebug("On Configuration changed: %s", {ConfigurationChangedData}) + BioInd.writeDebug("On Configuration changed: %s", { ConfigurationChangedData }) - -- Re-initialize global tables etc. - init() + -- Re-initialize global tables etc. + init() - -- Has setting BI_Show_musk_floor_in_mapview changed? - if ConfigurationChangedData.mod_startup_settings_changed then - settings_changed.musk_floor() - -- Has this been obsoleted by the new init process? Turn it off for now! - end - - -- We've made a list of the tree prototypes that are currently available. Now we - -- 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 tab - -- Growing stages - for i = 1, 4 do - tab = storage.bi["tree_growing_stage_" .. i] -BioInd.writeDebug("Number of trees in growing stage %s: %s", {i, table_size(tab)}) - for t = #tab, 1, -1 do - if not trees[tab[t].tree_name] then - BioInd.writeDebug("Removing invalid tree %s (%s)", {t, tab[t].tree_name}) - table.remove(tab, t) - end + -- Has setting BI_Show_musk_floor_in_mapview changed? + if ConfigurationChangedData.mod_startup_settings_changed then + settings_changed.musk_floor() + -- Has this been obsoleted by the new init process? Turn it off for now! end - -- Removing trees will create gaps in the table, but we need it as a continuous - -- list. (Trees need to be sorted by growing time, and we always look at the - -- tree with index 1 when checking if a tree has completed the growing stage, so - -- lets sort the table after all invalid trees have been removed!) - table.sort(tab, function(a, b) return a.time < b.time end) -BioInd.show("Number of trees in final list", #tab) - end + -- We've made a list of the tree prototypes that are currently available. Now we + -- 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 tab + -- Growing stages + for i = 1, 4 do + tab = storage.bi["tree_growing_stage_" .. i] + BioInd.writeDebug("Number of trees in growing stage %s: %s", { i, table_size(tab) }) + for t = #tab, 1, -1 do + if not trees[tab[t].tree_name] then + BioInd.writeDebug("Removing invalid tree %s (%s)", { t, tab[t].tree_name }) + table.remove(tab, t) + end + end + + -- Removing trees will create gaps in the table, but we need it as a continuous + -- list. (Trees need to be sorted by growing time, and we always look at the + -- tree with index 1 when checking if a tree has completed the growing stage, so + -- lets sort the table after all invalid trees have been removed!) + table.sort(tab, function(a, b) return a.time < b.time end) + BioInd.show("Number of trees in final list", #tab) + end end -------------------------------------------------------------------- --- Used for some compatibility with Angels Mods Event.register(defines.events.on_player_joined_game, function(event) - local player = game.players[event.player_index] - local force = player.force - local techs = force.technologies + local player = game.players[event.player_index] + local force = player.force + local techs = force.technologies - if BioInd.get_startup_setting("angels-use-angels-barreling") then - techs['fluid-handling'].researched = false - techs['bi-tech-fertilizer'].reload() - local _t = techs['angels-fluid-barreling'].researched - techs['angels-fluid-barreling'].researched = false - techs['angels-fluid-barreling'].researched = _t - end + if BioInd.get_startup_setting("angels-use-angels-barreling") then + techs['fluid-handling'].researched = false + techs['bi-tech-fertilizer'].reload() + local _t = techs['angels-fluid-barreling'].researched + techs['angels-fluid-barreling'].researched = false + techs['angels-fluid-barreling'].researched = _t + end end) --------------------------------------------- Event.register(defines.events.on_trigger_created_entity, function(event) - --- Used for Seed-bomb - local ent = event.entity - local surface = ent.surface - local position = ent.position + --- Used for Seed-bomb + local ent = event.entity + local surface = ent.surface + local position = ent.position - -- '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! - AlienBiomes = AlienBiomes ~= nil and AlienBiomes or BioInd.AB_tiles() + -- '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! + AlienBiomes = AlienBiomes ~= nil and AlienBiomes or BioInd.AB_tiles() - -- Basic - if ent.name == "seedling" then - BioInd.writeDebug("Seed Bomb Activated - Basic") - seed_planted_trigger(event) + -- Basic + if ent.name == "seedling" then + BioInd.writeDebug("Seed Bomb Activated - Basic") + seed_planted_trigger(event) - -- Standard - elseif ent.name == "seedling-2" then - BioInd.writeDebug("Seed Bomb Activated - Standard") - local currTile = surface.get_tile(position).name - if storage.bi.barren_tiles[currTile] then - BioInd.writeDebug("Can't fertilize %s!", {currTile}) - else - BioInd.writeDebug("Using fertilizer!") - local terrain_name_s = AlienBiomes and "vegetation-green-grass-3" or "grass-3" - surface.set_tiles{{name = terrain_name_s, position = position}} + -- Standard + elseif ent.name == "seedling-2" then + BioInd.writeDebug("Seed Bomb Activated - Standard") + local currTile = surface.get_tile(position).name + if storage.bi.barren_tiles[currTile] then + BioInd.writeDebug("Can't fertilize %s!", { currTile }) + else + BioInd.writeDebug("Using fertilizer!") + local terrain_name_s = AlienBiomes and "vegetation-green-grass-3" or "grass-3" + surface.set_tiles { { name = terrain_name_s, position = position } } + end + seed_planted_trigger(event) + + -- Advanced + elseif ent.name == "seedling-3" then + BioInd.writeDebug("Seed Bomb Activated - Advanced") + local currTile = surface.get_tile(position).name + if storage.bi.barren_tiles[currTile] then + BioInd.writeDebug("Can't fertilize %s!", { currTile }) + else + BioInd.writeDebug("Using fertilizer!") + local terrain_name_a = AlienBiomes and "vegetation-green-grass-1" or "grass-1" + surface.set_tiles { { name = terrain_name_a, position = position } } + end + seed_planted_trigger(event) end - seed_planted_trigger(event) - - -- Advanced - elseif ent.name == "seedling-3" then - BioInd.writeDebug("Seed Bomb Activated - Advanced") - local currTile = surface.get_tile(position).name - if storage.bi.barren_tiles[currTile] then - BioInd.writeDebug("Can't fertilize %s!", {currTile}) - else - BioInd.writeDebug("Using fertilizer!") - local terrain_name_a = AlienBiomes and "vegetation-green-grass-1" or "grass-1" - surface.set_tiles{{name = terrain_name_a, position = position}} - end - seed_planted_trigger(event) - end end) -------------------------------------------------------------------- local function On_Built(event) - BioInd.writeDebug("Entered function On_Built with these data: " .. serpent.block(event)) - local entity = event.created_entity or event.entity - if not (entity and entity.valid) then - BioInd.arg_err(entity or "nil", "entity") - end + BioInd.writeDebug("Entered function On_Built with these data: " .. serpent.block(event)) + local entity = event.created_entity or event.entity + if not (entity and entity.valid) then + BioInd.arg_err(entity or "nil", "entity") + end - local surface = BioInd.is_surface(entity.surface) or - BioInd.arg_err(entity.surface or "nil", "surface") - local position = BioInd.normalize_position(entity.position) or - BioInd.arg_err(entity.position or "nil", "position") - local force = entity.force + local surface = BioInd.is_surface(entity.surface) or + BioInd.arg_err(entity.surface or "nil", "surface") + local position = BioInd.normalize_position(entity.position) or + BioInd.arg_err(entity.position or "nil", "position") + local force = entity.force - -- We can ignore ghosts -- if ghosts are revived, there will be - -- another event that triggers where actual entities are placed! - if entity.name == "entity-ghost" then - BioInd.writeDebug("Built ghost of %s -- return!", {entity.ghost_name}) - return - end + -- We can ignore ghosts -- if ghosts are revived, there will be + -- another event that triggers where actual entities are placed! + if entity.name == "entity-ghost" then + BioInd.writeDebug("Built ghost of %s -- return!", { entity.ghost_name }) + return + end - BioInd.show("Built entity", BioInd.print_name_id(entity)) + BioInd.show("Built entity", BioInd.print_name_id(entity)) - local base_entry = storage.compound_entities[entity.name] - local base = base_entry and entity + local base_entry = storage.compound_entities[entity.name] + local base = base_entry and entity - -- We've found a compound entity! - if base then - -- Make sure we work with a copy of the original table! We don't want to - -- remove anything from it for real. - local hidden_entities = util.table.deepcopy(base_entry.hidden) + -- We've found a compound entity! + if base then + -- Make sure we work with a copy of the original table! We don't want to + -- remove anything from it for real. + local hidden_entities = util.table.deepcopy(base_entry.hidden) - BioInd.writeDebug("%s (%s) is a compound entity. Need to create %s", {base.name, base.unit_number, hidden_entities}) -BioInd.show("hidden_entities", hidden_entities) + BioInd.writeDebug("%s (%s) is a compound entity. Need to create %s", + { base.name, base.unit_number, hidden_entities }) + BioInd.show("hidden_entities", hidden_entities) local new_base - local new_base_name = base_entry.new_base_name - -- If the base entity is only an overlay, we'll replace it with the real base - -- entity and raise an event. The hidden entities will be created in the second - -- pass (triggered by building the final entity). -BioInd.show("base_entry.new_base_name", base_entry.new_base_name) -BioInd.show("base_entry.new_base_name == base.name", base_entry.new_base_name == base.name) -BioInd.show("base_entry.optional", base_entry.optional) + local new_base_name = base_entry.new_base_name + -- If the base entity is only an overlay, we'll replace it with the real base + -- entity and raise an event. The hidden entities will be created in the second + -- pass (triggered by building the final entity). + BioInd.show("base_entry.new_base_name", base_entry.new_base_name) + BioInd.show("base_entry.new_base_name == base.name", base_entry.new_base_name == base.name) + BioInd.show("base_entry.optional", base_entry.optional) if new_base_name and new_base_name ~= base.name then - new_base = surface.create_entity({ - name = new_base_name, - position = base.position, - direction = base.direction, - force = base.force, - raise_built = true - }) - new_base.health = base.health - BioInd.show("Created final base entity", BioInd.print_name_id(new_base)) + new_base = surface.create_entity({ + name = new_base_name, + position = base.position, + direction = base.direction, + force = base.force, + raise_built = true + }) + new_base.health = base.health + BioInd.show("Created final base entity", BioInd.print_name_id(new_base)) - base.destroy({raise_destroy = true}) - base = new_base - BioInd.writeDebug("Destroyed old base entity!") + base.destroy({ raise_destroy = true }) + base = new_base + BioInd.writeDebug("Destroyed old base entity!") - -- Second pass: We've placed the final base entity now, so we can create the - -- the hidden entities! + -- Second pass: We've placed the final base entity now, so we can create the + -- the hidden entities! + else + 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.show("base.name", base.name) + BioInd.show("base.unit_number", base.unit_number) + 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.writeDebug("Stored %s in table: %s", + { BioInd.print_name_id(base), storage[base_entry.tab][base.unit_number] }) + end + + -- The built entity isn't one of our compound entities. else -BioInd.writeDebug("Second pass -- creating hidden entities!") -BioInd.show("base_entry", base_entry) + BioInd.writeDebug("%s is not a compound entity!", { BioInd.print_name_id(entity) }) -BioInd.writeDebug("storage[%s]: %s", {base_entry.tab, storage[base_entry.tab]}) -BioInd.show("base.name", base.name) -BioInd.show("base.unit_number", base.unit_number) -BioInd.show("hidden_entities", hidden_entities) + -- If one of our hidden entities has been built, we'll have raised this event + -- ourselves and have passed on the base entity. + base = event.base_entity - -- 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.writeDebug("Stored %s in table: %s", - {BioInd.print_name_id(base), storage[base_entry.tab][base.unit_number]}) + local entities = BioInd.compound_entities + BioInd.show("Base entity", BioInd.print_name_id(base)) + + -- The hidden entities are listed with a common handle ("pole", "panel" etc.). We + -- can get it from the reverse-lookup list via the entity type! + local h_key = BioInd.HE_map_reverse[entity.type] + BioInd.show("h_key", h_key or "nil") + + -- 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 + entity.backer_name = "" + BioInd.writeDebug("Added %s to storage.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 + local pole = entity + -- Make sure hidden poles of the Bio gardens are connected correctly! + if pole.name == entities["bi-bio-garden"].hidden[h_key].name and base then + BioInd.writeDebug("Bio garden!") + BioInd.connect_garden_pole(base, pole) + BioInd.writeDebug("Connected %s (%s)", { pole.name, pole.unit_number or "nil" }) + end + + -- A seedling has been planted + elseif entity.name == "seedling" then + seed_planted(event) + BioInd.writeDebug("Planted seedling!") + + -- Something else has been built + else + BioInd.writeDebug("Nothing to do for %s!", { entity.name }) + end end - - -- The built entity isn't one of our compound entities. - else -BioInd.writeDebug("%s is not a compound entity!", {BioInd.print_name_id(entity)}) - - -- If one of our hidden entities has been built, we'll have raised this event - -- ourselves and have passed on the base entity. - base = event.base_entity - - local entities = BioInd.compound_entities -BioInd.show("Base entity", BioInd.print_name_id(base)) - - -- The hidden entities are listed with a common handle ("pole", "panel" etc.). We - -- can get it from the reverse-lookup list via the entity type! - local h_key = BioInd.HE_map_reverse[entity.type] - BioInd.show("h_key", h_key or "nil") - - -- 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 - entity.backer_name = "" - BioInd.writeDebug("Added %s to storage.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 - local pole = entity - -- Make sure hidden poles of the Bio gardens are connected correctly! - if pole.name == entities["bi-bio-garden"].hidden[h_key].name and base then -BioInd.writeDebug("Bio garden!") - BioInd.connect_garden_pole(base, pole) - BioInd.writeDebug("Connected %s (%s)", {pole.name, pole.unit_number or "nil"}) - end - - -- A seedling has been planted - elseif entity.name == "seedling" then - seed_planted(event) - BioInd.writeDebug("Planted seedling!") - - -- Something else has been built - else - BioInd.writeDebug("Nothing to do for %s!", {entity.name}) - end - end - BioInd.writeDebug("End of function On_Built") + BioInd.writeDebug("End of function On_Built") end local function remove_plants(entity_position, tabl) -BioInd.writeDebug("Entered function remove_plants(%s, %s)", {entity_position or "nil", tabl or "nil"}) + BioInd.writeDebug("Entered function remove_plants(%s, %s)", { entity_position or "nil", tabl or "nil" }) local e = BioInd.normalize_position(entity_position) if not e then - BioInd.arg_err(entity_position or "nil", "position") + BioInd.arg_err(entity_position or "nil", "position") end BioInd.check_args(tabl, "table") local pos for k, v in pairs(tabl or {}) do - pos = BioInd.normalize_position(v.position) - if pos and pos.x == e.x and pos.y == e.y then -BioInd.writeDebug("Removing entry %s from table: %s", {k, v}) - table.remove(tabl, k) - break - end + pos = BioInd.normalize_position(v.position) + if pos and pos.x == e.x and pos.y == e.y then + BioInd.writeDebug("Removing entry %s from table: %s", { k, v }) + table.remove(tabl, k) + break + end end end -------------------------------------------------------------------- local function On_Pre_Remove(event) -BioInd.writeDebug("Entered function On_Pre_Remove(%s)", {event}) - local entity = event.entity + BioInd.writeDebug("Entered function On_Pre_Remove(%s)", { event }) + local entity = event.entity - if not (entity and entity.valid) then - BioInd.writeDebug("No valid entity -- nothing to do!") - return - end + if not (entity and entity.valid) then + BioInd.writeDebug("No valid entity -- nothing to do!") + return + end local compound_entity = storage.compound_entities[entity.name] - local base_entry = compound_entity and storage[compound_entity.tab][entity.unit_number] -BioInd.show("entity.name", entity.name) -BioInd.show("entity.unit_number", entity.unit_number) + local base_entry = compound_entity and storage[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.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" }) - -- Found a compound entity from our list! - if base_entry then -BioInd.writeDebug("Found compound entity %s", - {base_entry.base and BioInd.print_name_id(base_entry.base)}) + -- Found a compound entity from our list! + if base_entry then + BioInd.writeDebug("Found compound entity %s", + { base_entry.base and BioInd.print_name_id(base_entry.base) }) - -- 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) - end + -- 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) + end - -- Power rails: Connections must be explicitely removed, otherwise the poles - -- from the remaining rails will automatically connect and bridge the gap in - -- the power supply! + -- Power rails: Connections must be explicitely removed, otherwise the poles + -- from the remaining rails will automatically connect and bridge the gap in + -- the power supply! if entity.name:match("bi%-%a+%-rail%-power") and base_entry.pole and base_entry.pole.valid then -BioInd.writeDebug("Before") - BioInd.writeDebug("Disconnecting %s!", {BioInd.print_name_id(base_entry.pole)}) - base_entry.pole.disconnect_neighbour() -BioInd.writeDebug("After") - end + BioInd.writeDebug("Before") + BioInd.writeDebug("Disconnecting %s!", { BioInd.print_name_id(base_entry.pole) }) + base_entry.pole.disconnect_neighbour() + BioInd.writeDebug("After") + end - -- Default: Remove all hidden entities! - for hidden, h_name in pairs(compound_entity.hidden or {}) do -BioInd.show("hidden", hidden) + -- Default: Remove all hidden entities! + for hidden, h_name in pairs(compound_entity.hidden or {}) do + BioInd.show("hidden", hidden) -BioInd.writeDebug("Removing hidden entity %s", {BioInd.print_name_id(base_entry[hidden])}) - BioInd.remove_entity(base_entry[hidden]) - base_entry[hidden] = nil - end - storage[compound_entity.tab][entity.unit_number] = nil + BioInd.writeDebug("Removing hidden entity %s", { BioInd.print_name_id(base_entry[hidden]) }) + BioInd.remove_entity(base_entry[hidden]) + base_entry[hidden] = nil + end + storage[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 - -- keep the separate power networks connected! - elseif entity.name == "bi-power-to-rail-pole" then - BioInd.writeDebug("Rail-to-power connector has been removed") - entity.disconnect_neighbour() - BioInd.writeDebug("Removed copper wires from %s (%g)", {entity.name, entity.unit_number}) + -- Rail-to-power: Connections must be explicitely removed, otherwise the poles + -- from the different rail tracks hooked up to this connector will automatically + -- keep the separate power networks connected! + elseif entity.name == "bi-power-to-rail-pole" then + BioInd.writeDebug("Rail-to-power connector has been removed") + entity.disconnect_neighbour() + BioInd.writeDebug("Removed copper wires from %s (%g)", { entity.name, entity.unit_number }) - -- Removed seedling - elseif entity.name == "seedling" then - BioInd.writeDebug("Seedling has been removed") - remove_plants(entity.position, storage.bi.tree_growing) + -- Removed seedling + elseif entity.name == "seedling" then + BioInd.writeDebug("Seedling has been removed") + remove_plants(entity.position, storage.bi.tree_growing) - -- Removed tree - elseif entity.type == "tree" and storage.bi.trees[entity.name] then - BioInd.show("Removed tree", entity.name) + -- Removed tree + elseif entity.type == "tree" and storage.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]) + 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]) + else + error(string.format("Tree %s does not have a valid tree_stage: %s", entity.name, tree_stage or "nil")) + end + + -- Removed something else else - error(string.format("Tree %s does not have a valid tree_stage: %s", entity.name, tree_stage or "nil")) + BioInd.writeDebug("%s has been removed -- nothing to do!", { entity.name }) end - - -- Removed something else - else - BioInd.writeDebug("%s has been removed -- nothing to do!", {entity.name}) - end end -------------------------------------------------------------------- local function On_Damage(event) - local f_name = "On_Damage" - BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) - local entity = event.entity - local final_health = event.final_health + local f_name = "On_Damage" + BioInd.writeDebug("Entered function %s(%s)", { f_name, event }) + local entity = event.entity + local final_health = event.final_health - local arb = "bi-arboretum" - local associated + local arb = "bi-arboretum" + local associated - -- Base was damaged: Find the radar associated with it! - if entity.name == arb then - associated = storage.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 - end + -- Base was damaged: Find the radar associated with it! + if entity.name == arb then + associated = storage.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 + end - if associated and associated.valid then - associated.health = final_health - BioInd.writeDebug("%s was damaged (%s). Reducing health of %s to %s!", { - BioInd.print_name_id(entity), - event.final_damage_amount, - entity.name == arb and "associated radar" or "base", - associated.health - }) - end + if associated and associated.valid then + associated.health = final_health + BioInd.writeDebug("%s was damaged (%s). Reducing health of %s to %s!", { + BioInd.print_name_id(entity), + event.final_damage_amount, + entity.name == arb and "associated radar" or "base", + associated.health + }) + end end -------------------------------------------------------------------- local function On_Death(event) - local f_name = "On_Death" -BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) + local f_name = "On_Death" + BioInd.writeDebug("Entered function %s(%s)", { f_name, event }) - local entity = event.entity - if not entity then - error("Something went wrong -- no entity data!") - end + local entity = event.entity + if not entity then + error("Something went wrong -- no entity data!") + end - if - -- Table checks - storage.compound_entities[entity.name] or - storage.bi.trees[entity.name] or - -- Entity checks - entity.name == storage.compound_entities["bi-arboretum"].hidden.radar.name or - entity.name == "bi-power-to-rail-pole" or - entity.name == "seedling" then - - BioInd.writeDebug("Divert to On_Pre_Remove!") - On_Pre_Remove(event) - else - BioInd.writeDebug("Nothing to do!") - end + if + -- Table checks + storage.compound_entities[entity.name] or + storage.bi.trees[entity.name] or + -- Entity checks + entity.name == storage.compound_entities["bi-arboretum"].hidden.radar.name or + entity.name == "bi-power-to-rail-pole" or + entity.name == "seedling" then + BioInd.writeDebug("Divert to On_Pre_Remove!") + On_Pre_Remove(event) + else + BioInd.writeDebug("Nothing to do!") + end end @@ -648,14 +647,14 @@ end -- Radar completed a sector scan local function On_Sector_Scanned(event) - local f_name = "On_Sector_Scanned" - BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) + local f_name = "On_Sector_Scanned" + 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] - if arboretum then - Get_Arboretum_Recipe(storage.bi_arboretum_table[arboretum], event) - end + ---- Each time a Arboretum-Radar scans a sector ---- + local arboretum = storage.bi_arboretum_radar_table[event.radar.unit_number] + if arboretum then + Get_Arboretum_Recipe(storage.bi_arboretum_table[arboretum], event) + end end @@ -666,273 +665,270 @@ end -------------------------------------------------------------------- -- Solar mat was removed local function solar_mat_removed(event) - BioInd.writeDebug("Entered solar_mat_removed (\"%s\")", {event}) + BioInd.writeDebug("Entered solar_mat_removed (\"%s\")", { event }) - local surface = game.surfaces[event.surface_index] - local tiles = event.tiles + local surface = game.surfaces[event.surface_index] + local tiles = event.tiles - local pos, x, y - -- tiles contains an array of the old tiles and their position - for t, tile in pairs(tiles) do - if tile.old_tile and tile.old_tile.name == "bi-solar-mat" then - pos = BioInd.normalize_position(tile.position) - x, y = pos.x, pos.y + local pos, x, y + -- tiles contains an array of the old tiles and their position + for t, tile in pairs(tiles) do + if tile.old_tile and tile.old_tile.name == "bi-solar-mat" then + pos = BioInd.normalize_position(tile.position) + x, y = pos.x, pos.y -BioInd.writeDebug("Looking for hidden entities to remove") - for _, o in pairs(surface.find_entities_filtered{ - name = {'bi-musk-mat-hidden-pole', 'bi-musk-mat-hidden-panel'}, - position = {x + 0.5, y + 0.5} - } or {}) do -BioInd.show("Removing", o.name) - o.destroy() - end + BioInd.writeDebug("Looking for hidden entities to remove") + for _, o in pairs(surface.find_entities_filtered { + name = { 'bi-musk-mat-hidden-pole', 'bi-musk-mat-hidden-panel' }, + position = { x + 0.5, y + 0.5 } + } or {}) do + BioInd.show("Removing", o.name) + o.destroy() + 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] - 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 + -- 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] + 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 + 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 + end + end + end 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 - end - end - end - end - end - BioInd.writeDebug("bi-solar-mat: removed %g tiles", {table_size(tiles)}) + BioInd.writeDebug("bi-solar-mat: removed %g tiles", { table_size(tiles) }) end -------------------------------------------------------------------- -- A solar mat must be placed local function place_musk_floor(force, position, surface) - BioInd.check_args(force, "string") - position = BioInd.normalize_position(position) or BioInd.arg_err(position, "position") - surface = BioInd.is_surface(surface) or BioInd.arg_err(surface, "surface") + BioInd.check_args(force, "string") + position = BioInd.normalize_position(position) or BioInd.arg_err(position, "position") + surface = BioInd.is_surface(surface) or BioInd.arg_err(surface, "surface") - local x, y = position.x, position.y - local created - for n, name in ipairs({"bi-musk-mat-hidden-pole", "bi-musk-mat-hidden-panel"}) do - created = surface.create_entity({name = name, position = {x + 0.5, y + 0.5}, force = force}) - created.minable = false - created.destructible = false - BioInd.writeDebug("Created %s: %s", {name, created.unit_number}) - end + local x, y = position.x, position.y + local created + for n, name in ipairs({ "bi-musk-mat-hidden-pole", "bi-musk-mat-hidden-panel" }) do + created = surface.create_entity({ name = name, position = { x + 0.5, y + 0.5 }, force = force }) + created.minable = false + created.destructible = false + BioInd.writeDebug("Created %s: %s", { name, created.unit_number }) + 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 + -- 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 - 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 + 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 end -------------------------------------------------------------------- -- Solar mat was built local function solar_mat_built(event) -BioInd.show("Entered function \"solar_mat_built\"", event) - -- Called from player, bot and script-raised events, so event may - -- contain "robot" or "player_index" + BioInd.show("Entered function \"solar_mat_built\"", event) + -- Called from player, bot and script-raised events, so event may + -- contain "robot" or "player_index" - local tile = event.tile - local surface = game.surfaces[event.surface_index] - local player = event.player_index and game.players[event.player_index] - local robot = event.robot - local force = (BioInd.UseMuskForce and BioInd.MuskForceName) or - (event.player_index and game.players[event.player_index].force.name) or - (event.robot and event.robot.force.name) or - event.force.name -BioInd.show("Force.name", force) + local tile = event.tile + local surface = game.surfaces[event.surface_index] + local player = event.player_index and game.players[event.player_index] + local robot = event.robot + local force = (BioInd.UseMuskForce and BioInd.MuskForceName) or + (event.player_index and game.players[event.player_index].force.name) or + (event.robot and event.robot.force.name) or + event.force.name + BioInd.show("Force.name", force) - -- Item that was used to place the tile - local item = event.item - local old_tiles = event.tiles + -- Item that was used to place the tile + local item = event.item + local old_tiles = event.tiles - local position --, x, y + local position --, x, y - -- Musk floor has been built -- create hidden entities! - if tile.name == "bi-solar-mat" then - BioInd.writeDebug("Solar Mat has been built -- must create hidden entities!") -BioInd.show("Tile data", tile ) + -- Musk floor has been built -- create hidden entities! + if tile.name == "bi-solar-mat" then + BioInd.writeDebug("Solar Mat has been built -- must create hidden entities!") + BioInd.show("Tile data", tile) - for index, t in pairs(old_tiles or {tile}) do -BioInd.show("Read old_tile inside loop", t) - -- event.tiles will also contain landscape tiles like "grass-1", and it will always - -- contain at least one tile - position = BioInd.normalize_position(t.position) - -- If we got here by a call from script_raised_built, force may be stored - -- with the tile - force = force or t.force -BioInd.show("Got force from tile data", t.force or "false") - BioInd.writeDebug("Building solar mat for force %s at position %s", - {tostring(type(force) == "table" and force.name or force), position}) + for index, t in pairs(old_tiles or { tile }) do + BioInd.show("Read old_tile inside loop", t) + -- event.tiles will also contain landscape tiles like "grass-1", and it will always + -- contain at least one tile + position = BioInd.normalize_position(t.position) + -- If we got here by a call from script_raised_built, force may be stored + -- with the tile + force = force or t.force + BioInd.show("Got force from tile data", t.force or "false") + BioInd.writeDebug("Building solar mat for force %s at position %s", + { tostring(type(force) == "table" and force.name or force), position }) - place_musk_floor(force, position, surface) - end - - -- Fertilizer/Advanced fertilizer has been used. Check if the tile was valid - -- (no Musk floor, no wooden floor, no concrete etc.) - elseif item and (item.name == "fertilizer" or item.name == "bi-adv-fertilizer") then - - local restore_tiles = {} - local products, remove_this - - for index, t in pairs(old_tiles or {tile}) do -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 -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] - if type(products) == "table" then - for p, product in ipairs(products) do - remove_this = {name = product.name, count = product.amount} - if player then - BioInd.writeDebug("Removing %s (%s) from player %s", - {product.name, product.amount, player.name}) - player.remove_item(remove_this) - elseif robot then - BioInd.writeDebug("Removing %s (%s) from robot %s", - {product.name, product.amount, robot.unit_number}) - robot.remove_item(remove_this) - end - end + place_musk_floor(force, position, surface) end - end - end -BioInd.show("restore_tiles", restore_tiles) - if restore_tiles then - surface.set_tiles( - restore_tiles, - true, -- correct_tiles - true, -- remove_colliding_entities - true, -- remove_colliding_decoratives - true -- raise_event - ) - end - -- Some other tile has been built -- check if it replaced musk floor! - else - local test - 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] - if test then - removed_tiles[#removed_tiles + 1] = { - old_tile = {name = "bi-solar-mat"}, - position = position - } - end - end - if next(removed_tiles) then - solar_mat_removed({surface_index = event.surface_index, tiles = removed_tiles}) + -- Fertilizer/Advanced fertilizer has been used. Check if the tile was valid + -- (no Musk floor, no wooden floor, no concrete etc.) + elseif item and (item.name == "fertilizer" or item.name == "bi-adv-fertilizer") then + local restore_tiles = {} + local products, remove_this + + for index, t in pairs(old_tiles or { tile }) do + 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 + 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] + if type(products) == "table" then + for p, product in ipairs(products) do + remove_this = { name = product.name, count = product.amount } + if player then + BioInd.writeDebug("Removing %s (%s) from player %s", + { product.name, product.amount, player.name }) + player.remove_item(remove_this) + elseif robot then + BioInd.writeDebug("Removing %s (%s) from robot %s", + { product.name, product.amount, robot.unit_number }) + robot.remove_item(remove_this) + end + end + end + end + end + BioInd.show("restore_tiles", restore_tiles) + if restore_tiles then + surface.set_tiles( + restore_tiles, + true, -- correct_tiles + true, -- remove_colliding_entities + true, -- remove_colliding_decoratives + true -- raise_event + ) + end + + -- Some other tile has been built -- check if it replaced musk floor! else - BioInd.writeDebug("%s has been built -- nothing to do!", {tile.name}) + local test + 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] + if test then + removed_tiles[#removed_tiles + 1] = { + old_tile = { name = "bi-solar-mat" }, + position = position + } + end + end + if next(removed_tiles) then + solar_mat_removed({ surface_index = event.surface_index, tiles = removed_tiles }) + else + BioInd.writeDebug("%s has been built -- nothing to do!", { tile.name }) + end end - end - end -------------------------------------------------------------------- -- A tille has been changed local function Tile_Changed(event) - local f_name = "Tile_Changed" - BioInd.writeDebug("Entered function %s(%s)", {f_name, event}) + local f_name = "Tile_Changed" + BioInd.writeDebug("Entered function %s(%s)", { f_name, event }) - -- The event gives us only a list of the new tiles that have been placed. - -- So let's check if any Musk floor has been built! - local new_musk_floor_tiles = {} - local old_musk_floor_tiles = {} - local remove_musk_floor_tiles = {} - local pos, old_tile, force + -- The event gives us only a list of the new tiles that have been placed. + -- So let's check if any Musk floor has been built! + local new_musk_floor_tiles = {} + local old_musk_floor_tiles = {} + local remove_musk_floor_tiles = {} + local pos, old_tile, force - local tile_force + local tile_force - 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] - BioInd.show("Placed tile", tile.name) + 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] + BioInd.show("Placed tile", tile.name) - -- Musk floor was placed - if tile.name == "bi-solar-mat" then - BioInd.writeDebug("Musk floor tile was placed!") - new_musk_floor_tiles[#new_musk_floor_tiles + 1] = { - old_tile = { name = tile.name }, - position = pos, - force = tile_force or - BioInd.UseMuskForce and BioInd.MuskForceName or - "neutral" - } - -- Other tile was placed -- by one of our fertilizers? - elseif tile.name:match("^vegetation%-green%-grass%-[13]$") or - tile.name:match("^green%-grass%-[13]$") then - BioInd.writeDebug("Fertilizer was used!") + -- Musk floor was placed + if tile.name == "bi-solar-mat" then + BioInd.writeDebug("Musk floor tile was placed!") + new_musk_floor_tiles[#new_musk_floor_tiles + 1] = { + old_tile = { name = tile.name }, + position = pos, + force = tile_force or + BioInd.UseMuskForce and BioInd.MuskForceName or + "neutral" + } + -- Other tile was placed -- by one of our fertilizers? + elseif tile.name:match("^vegetation%-green%-grass%-[13]$") or + tile.name:match("^green%-grass%-[13]$") then + BioInd.writeDebug("Fertilizer was used!") - -- Fertilizer was used on a Musk floor tile -- restore the tile! -BioInd.show("Musk floor tile in position", tile_force) - if tile_force then - old_musk_floor_tiles[#old_musk_floor_tiles + 1] = { - old_tile = { name = "bi-solar-mat" }, - position = pos, - force = tile_force - } - end - -- Other tile was placed on a Musk floor tile -- remove Musk floor from lists! - elseif tile_force then - remove_musk_floor_tiles[#remove_musk_floor_tiles + 1] = { - old_tile = { name = "bi-solar-mat" }, - position = pos, - } + -- Fertilizer was used on a Musk floor tile -- restore the tile! + BioInd.show("Musk floor tile in position", tile_force) + if tile_force then + old_musk_floor_tiles[#old_musk_floor_tiles + 1] = { + old_tile = { name = "bi-solar-mat" }, + position = pos, + force = tile_force + } + end + -- Other tile was placed on a Musk floor tile -- remove Musk floor from lists! + elseif tile_force then + remove_musk_floor_tiles[#remove_musk_floor_tiles + 1] = { + old_tile = { name = "bi-solar-mat" }, + position = pos, + } + end end - end -BioInd.show("new_musk_floor_tiles", new_musk_floor_tiles) -BioInd.show("old_musk_floor_tiles", old_musk_floor_tiles) -BioInd.show("remove_musk_floor_tiles", remove_musk_floor_tiles) + BioInd.show("new_musk_floor_tiles", new_musk_floor_tiles) + BioInd.show("old_musk_floor_tiles", old_musk_floor_tiles) + BioInd.show("remove_musk_floor_tiles", remove_musk_floor_tiles) - if next(new_musk_floor_tiles) then - solar_mat_built({ - surface_index = event.surface_index, - tile = {name = "bi-solar-mat"}, - force = BioInd.MuskForceName, - tiles = new_musk_floor_tiles - }) - end - if next(old_musk_floor_tiles) then - solar_mat_built({ - surface_index = event.surface_index, - tile = {name = "bi-solar-mat"}, - tiles = old_musk_floor_tiles - }) - end - if next(remove_musk_floor_tiles) then - solar_mat_removed({surface_index = event.surface_index, tiles = remove_musk_floor_tiles}) - end - BioInd.show("End of function", f_name) + if next(new_musk_floor_tiles) then + solar_mat_built({ + surface_index = event.surface_index, + tile = { name = "bi-solar-mat" }, + force = BioInd.MuskForceName, + tiles = new_musk_floor_tiles + }) + end + if next(old_musk_floor_tiles) then + solar_mat_built({ + surface_index = event.surface_index, + tile = { name = "bi-solar-mat" }, + tiles = old_musk_floor_tiles + }) + end + if next(remove_musk_floor_tiles) then + solar_mat_removed({ surface_index = event.surface_index, tiles = remove_musk_floor_tiles }) + end + BioInd.show("End of function", f_name) end @@ -945,31 +941,31 @@ Event.register(Event.core_events.load, On_Load) Event.build_events = { - defines.events.on_built_entity, - defines.events.on_robot_built_entity, - defines.events.script_raised_built, - defines.events.script_raised_revive + defines.events.on_built_entity, + defines.events.on_robot_built_entity, + defines.events.script_raised_built, + defines.events.script_raised_revive } Event.pre_remove_events = { - defines.events.on_pre_player_mined_item, - defines.events.on_robot_pre_mined, - defines.events.on_player_mined_entity, - defines.events.on_robot_mined_entity, + defines.events.on_pre_player_mined_item, + defines.events.on_robot_pre_mined, + defines.events.on_player_mined_entity, + defines.events.on_robot_mined_entity, } - Event.death_events = { - defines.events.on_entity_died, - defines.events.script_raised_destroy +Event.death_events = { + defines.events.on_entity_died, + defines.events.script_raised_destroy } Event.tile_build_events = { - defines.events.on_player_built_tile, - defines.events.on_robot_built_tile + defines.events.on_player_built_tile, + defines.events.on_robot_built_tile } Event.tile_remove_events = { - defines.events.on_player_mined_tile, - defines.events.on_robot_mined_tile + defines.events.on_player_mined_tile, + defines.events.on_robot_mined_tile } Event.tile_script_action = { - defines.events.script_raised_set_tiles + defines.events.script_raised_set_tiles } Event.register(Event.build_events, On_Built) @@ -980,24 +976,24 @@ Event.register(Event.tile_remove_events, solar_mat_removed) Event.register(defines.events.on_entity_damaged, On_Damage, function(event) - -- A function is needed for event filtering with stdlib! - local entity = event.entity + -- A function is needed for event filtering with stdlib! + local entity = event.entity - -- 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 - return true - end + -- 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 + return true + end end) -- Radar scan Event.register(defines.events.on_sector_scanned, On_Sector_Scanned, function(event) - -- A function is needed for event filtering with stdlib! - if event.radar.name == BioInd.compound_entities["bi-arboretum"].hidden.radar.name then - return true - end + -- A function is needed for event filtering with stdlib! + if event.radar.name == BioInd.compound_entities["bi-arboretum"].hidden.radar.name then + return true + end end) -- Tile changed @@ -1009,14 +1005,14 @@ Event.register(Event.tile_script_action, Tile_Changed) -- (Thanks to eradicator!) -- ------------------------------------------------------------------------------------ setmetatable(_ENV, { - __newindex = function (self, key, value) --locked_global_write - error('\n\n[ER Global Lock] Forbidden global *write*:\n' - .. serpent.line{key = key or '', value = value or ''} .. '\n') + __newindex = function(self, key, value) --locked_global_write + error('\n\n[ER Global Lock] Forbidden global *write*:\n' + .. 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 - error('\n\n[ER Global Lock] Forbidden global *read*:\n' - .. serpent.line{key = key or ''} .. '\n') + __index = function(self, key) --locked_global_read + if not (key == "game" or key == "mods" or key == "storage") then + error('\n\n[ER Global Lock] Forbidden global *read*:\n' + .. serpent.line { key = key or '' } .. '\n') + end end - end }) diff --git a/Bio_Industries_2/control_arboretum.lua b/Bio_Industries_2/control_arboretum.lua index c541451..db79727 100644 --- a/Bio_Industries_2/control_arboretum.lua +++ b/Bio_Industries_2/control_arboretum.lua @@ -1,4 +1,3 @@ - BioInd.writeDebug("Entered control_arboretum.lua") ---Arboretum Stuff @@ -9,18 +8,18 @@ local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(fa -- set! (Fertile tiles set to true in this table can't be made more fertile with -- normal fertilizer, and nothing should grow on the other tiles.) local Terrain_Check_1 = { - ["grass-1"] = true, -- Fertility: 100% - ["grass-3"] = true, -- Fertility: 85% - ["vegetation-green-grass-1"] = true, -- Fertility: 100% - ["vegetation-green-grass-3"] = true, -- Fertility: 85% + ["grass-1"] = true, -- Fertility: 100% + ["grass-3"] = true, -- Fertility: 85% + ["vegetation-green-grass-1"] = true, -- Fertility: 100% + ["vegetation-green-grass-3"] = true, -- Fertility: 85% } -- If a recipe with ADVANCED FERTILIZER is used, don't fertilize tiles set have "true" set! -- (Fertile tiles in this table can't be made more fertile, and nothing should grow on the -- the others tiles!) local Terrain_Check_2 = { - ["grass-1"] = true, -- Fertility: 100% - ["vegetation-green-grass-1"] = true, -- Fertility: 100% + ["grass-1"] = true, -- Fertility: 100% + ["vegetation-green-grass-1"] = true, -- Fertility: 100% } local plant_radius = 75 @@ -32,230 +31,230 @@ local AB, terrain_name_g1, terrain_name_g3 local function get_new_position(pos) - pos = BioInd.normalize_position(pos) or BioInd.arg_err("nil", position) - local xxx = math.random(-plant_radius, plant_radius) - local yyy = math.random(-plant_radius, plant_radius) + pos = BioInd.normalize_position(pos) or BioInd.arg_err("nil", position) + local xxx = math.random(-plant_radius, plant_radius) + local yyy = math.random(-plant_radius, plant_radius) - return {x = pos.x + xxx, y = pos.y + yyy} + return { x = pos.x + xxx, y = pos.y + yyy } 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 recipe = arboretum.get_recipe() + local need = recipe and storage.bi_arboretum_recipe_table[recipe.name] - local function check(need, have) - for name, amount in pairs(need or {}) do - if not (have and have[name]) or (have[name] < amount) then - BioInd.writeDebug("Missing ingredient %s (have %s of %s)", {name, have[name] or 0, amount}) - return false - end + local function check(need, have) + for name, amount in pairs(need or {}) do + if not (have and have[name]) or (have[name] < amount) then + BioInd.writeDebug("Missing ingredient %s (have %s of %s)", { name, have[name] or 0, amount }) + return false + end + end + return true end - return true - end - local inventory = arboretum.get_inventory(defines.inventory.assembling_machine_input) - return need and - check(need.items, inventory and inventory.get_contents()) and - check(need.fluids, arboretum.get_fluid_contents()) and - {ingredients = need, name = recipe.name} or nil + local inventory = arboretum.get_inventory(defines.inventory.assembling_machine_input) + return need and + check(need.items, inventory and inventory.get_contents()) and + check(need.fluids, arboretum.get_fluid_contents()) and + { ingredients = need, name = recipe.name } or nil end local function consume_ingredients(arboretum, need) - local inventory = arboretum.get_inventory(defines.inventory.assembling_machine_input) - for item, i in pairs(need.items or {}) do - inventory.remove({name = item, count = i}) -BioInd.writeDebug("Removed %s (%s)", {item, i}) - end -BioInd.show("Inventory", inventory.get_contents() or "nil") + local inventory = arboretum.get_inventory(defines.inventory.assembling_machine_input) + for item, i in pairs(need.items or {}) do + inventory.remove({ name = item, count = i }) + BioInd.writeDebug("Removed %s (%s)", { item, i }) + end + BioInd.show("Inventory", inventory.get_contents() or "nil") - for fluid, f in pairs(need.fluids or {}) do - arboretum.remove_fluid({name = fluid, amount = f}) -BioInd.writeDebug("Removed %s (%s)", {fluid, f}) - end -BioInd.show("Fluid contents", arboretum.get_fluid_contents() or "nil") + for fluid, f in pairs(need.fluids or {}) do + arboretum.remove_fluid({ name = fluid, amount = f }) + BioInd.writeDebug("Removed %s (%s)", { fluid, f }) + end + BioInd.show("Fluid contents", arboretum.get_fluid_contents() or "nil") end local function set_tile(current, target, surface, position) - if current ~= target then - surface.set_tiles( - {{name = target, position = position}}, - true, -- correct_tiles - true, -- remove_colliding_entities - true, -- remove_colliding_decoratives - true -- raise_event - ) - end + if current ~= target then + surface.set_tiles( + { { name = target, position = position } }, + true, -- correct_tiles + true, -- remove_colliding_entities + true, -- remove_colliding_decoratives + true -- raise_event + ) + end end function Get_Arboretum_Recipe(ArboretumTable, event) - BioInd.writeDebug("Entered function Get_Arboretum_Recipe(%s, %s)", {ArboretumTable, event}) - if not ArboretumTable then - BioInd.writeDebug("%s is not a valid ArboretumTable. Leaving immediately!") - return - end - - local arboretum = ArboretumTable.base - local new_position, currentTilename - local pos, surface, Inventory, stack - - -- '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 - 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") - - - local check = check_ingredients(arboretum) - local ingredients, recipe_name - if check then - ingredients, recipe_name = check.ingredients, check.name - end - - if ingredients then - local create_seedling, new_plant - pos = BioInd.normalize_position(arboretum.position) or - BioInd.arg_err("nil", "position") - surface = arboretum.surface - - -- Just plant a tree and hope the ground is fertile! - if recipe_name == "bi-arboretum-r1" then - BioInd.writeDebug(tostring(recipe_name) .. ": Just plant a tree") - - --- 10 attempts to find a random spot to plant a tree and/or change terrain - for k = 1, 10 do - new_position = get_new_position(pos) - new_plant = { - name= "seedling", - position = new_position, - force = "neutral" - } - - if surface.can_place_entity(new_plant) then - consume_ingredients(arboretum, ingredients) - create_seedling = surface.create_entity(new_plant) - seed_planted_arboretum(event, create_seedling) - --- After sucessfully planting a tree, break out of the loop. - break - else - BioInd.writeDebug("Can't plant here (attempt %s)", k) - end - end - -- Fertilize the ground with normal fertilizer. Ignore tiles listed in Terrain_Check_1! - elseif recipe_name == "bi-arboretum-r2" then - BioInd.writeDebug(tostring(recipe_name) .. ": Just change terrain to grass-3 (basic)") - - for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain - new_position = get_new_position(pos) - currentTilename = surface.get_tile(new_position.x, new_position.y).name - - -- We need to fertilize the ground! - if Bi_Industries.fertility[currentTilename] and not Terrain_Check_1[currentTilename] then - consume_ingredients(arboretum, ingredients) - BioInd.writeDebug("%s: Changing terrain from %s to %s (%s)", - {k, currentTilename or "unknown tile", - terrain_name_g3, serpent.line(new_position)}) - set_tile(currentTilename, terrain_name_g3, surface, new_position) - --- After sucessfully changing the terrain, break out of the loop. - break - else - BioInd.writeDebug("%s: Can't change terrain (%s)", - {k, currentTilename or "unknown tile"}) - end - end - -- Fertilize the ground with advanced fertilizer. Ignore tiles listed in Terrain_Check_2! - elseif recipe_name == "bi-arboretum-r3" then - BioInd.writeDebug(tostring(recipe_name) .. ": Just change terrain to grass-1 (advanced)") - - for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain - new_position = get_new_position(pos) - currentTilename = surface.get_tile(new_position.x, new_position.y).name - - if Bi_Industries.fertility[currentTilename] and currentTilename ~= terrain_name_g1 then - consume_ingredients(arboretum, ingredients) - BioInd.writeDebug("%s: Changing terrain from %s to %s (%s)", - {k, currentTilename or "unknown tile", - terrain_name_g1, serpent.line(new_position)}) - set_tile(currentTilename, terrain_name_g1, surface, new_position) - --- After sucessfully changing the terrain, break out of the loop. - break - else - BioInd.writeDebug("%s: Can't change terrain (%s)", - {k, currentTilename or "unknown tile"}) - end - end - -- Fertilize the ground with normal fertilizer. Ignore tiles listed in Terrain_Check_1! - -- Also plant a tree. - elseif recipe_name == "bi-arboretum-r4" then - BioInd.writeDebug(tostring(recipe_name) .. ": Plant Tree AND change the terrain to grass-3 (basic)") - - for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain - new_position = get_new_position(pos) - currentTilename = surface.get_tile(new_position.x, new_position.y).name - new_plant = { - name= "seedling", - position = new_position, - force = "neutral" - } - - -- Test to see if we can plant - if surface.can_place_entity(new_plant) and Bi_Industries.fertility[currentTilename] then - consume_ingredients(arboretum, ingredients) - -- Refund fertilizer -- no need to waste it on fertile ground! - if Terrain_Check_1[currentTilename] then - arboretum.insert({name = "fertilizer", count = ingredients.items.fertilizer}) - BioInd.writeDebug("Refunded fertilizer!") - end - - set_tile(currentTilename, terrain_name_g3, surface, new_position) - create_seedling = surface.create_entity(new_plant) - seed_planted_arboretum(event, create_seedling) - --- After sucessfully planting a tree or changing the terrain, break out of the loop. - break - else - BioInd.writeDebug("%s: Can't change terrain and plant a tree (%s)", - {k, currentTilename or "unknown tile"}) - end - end - -- Fertilize the ground with advanced fertilizer. Ignore tiles listed in Terrain_Check_2! - -- Also plant a tree. - elseif recipe_name == "bi-arboretum-r5" then - BioInd.writeDebug(tostring(recipe_name) .. ": Plant Tree and change the terrain to grass-1 (advanced)") - - for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain - new_position = get_new_position(pos) - currentTilename = surface.get_tile(new_position.x, new_position.y).name - new_plant = { - name= "seedling", - position = new_position, - force = "neutral" - } - - if surface.can_place_entity(new_plant) and Bi_Industries.fertility[currentTilename] then - consume_ingredients(arboretum, ingredients) - -- Refund fertilizer -- no need to waste it on fertile ground! - if Terrain_Check_2[currentTilename] then - arboretum.insert({ - name = "bi-adv-fertilizer", count = ingredients.items["bi-adv-fertilizer"] - }) - BioInd.writeDebug("Refunded advanced fertilizer!") - end - - set_tile(currentTilename, terrain_name_g1, surface, new_position) - create_seedling = surface.create_entity(new_plant) - seed_planted_arboretum (event, create_seedling) - --- After sucessfully planting a tree or changing the terrain, break out of the loop. - break - else - BioInd.writeDebug("%s: Can't change terrain and plant a tree (%s)", - {k, currentTilename or "unknown tile"}) - end - end - else - BioInd.writeDebug("Terraformer has no recipe!") + BioInd.writeDebug("Entered function Get_Arboretum_Recipe(%s, %s)", { ArboretumTable, event }) + if not ArboretumTable then + BioInd.writeDebug("%s is not a valid ArboretumTable. Leaving immediately!") + return + end + + local arboretum = ArboretumTable.base + local new_position, currentTilename + local pos, surface, Inventory, stack + + -- '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 + 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") + + + local check = check_ingredients(arboretum) + local ingredients, recipe_name + if check then + ingredients, recipe_name = check.ingredients, check.name + end + + if ingredients then + local create_seedling, new_plant + pos = BioInd.normalize_position(arboretum.position) or + BioInd.arg_err("nil", "position") + surface = arboretum.surface + + -- Just plant a tree and hope the ground is fertile! + if recipe_name == "bi-arboretum-r1" then + BioInd.writeDebug(tostring(recipe_name) .. ": Just plant a tree") + + --- 10 attempts to find a random spot to plant a tree and/or change terrain + for k = 1, 10 do + new_position = get_new_position(pos) + new_plant = { + name = "seedling", + position = new_position, + force = "neutral" + } + + if surface.can_place_entity(new_plant) then + consume_ingredients(arboretum, ingredients) + create_seedling = surface.create_entity(new_plant) + seed_planted_arboretum(event, create_seedling) + --- After sucessfully planting a tree, break out of the loop. + break + else + BioInd.writeDebug("Can't plant here (attempt %s)", k) + end + end + -- Fertilize the ground with normal fertilizer. Ignore tiles listed in Terrain_Check_1! + elseif recipe_name == "bi-arboretum-r2" then + BioInd.writeDebug(tostring(recipe_name) .. ": Just change terrain to grass-3 (basic)") + + for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain + new_position = get_new_position(pos) + currentTilename = surface.get_tile(new_position.x, new_position.y).name + + -- We need to fertilize the ground! + if Bi_Industries.fertility[currentTilename] and not Terrain_Check_1[currentTilename] then + consume_ingredients(arboretum, ingredients) + BioInd.writeDebug("%s: Changing terrain from %s to %s (%s)", + { k, currentTilename or "unknown tile", + terrain_name_g3, serpent.line(new_position) }) + set_tile(currentTilename, terrain_name_g3, surface, new_position) + --- After sucessfully changing the terrain, break out of the loop. + break + else + BioInd.writeDebug("%s: Can't change terrain (%s)", + { k, currentTilename or "unknown tile" }) + end + end + -- Fertilize the ground with advanced fertilizer. Ignore tiles listed in Terrain_Check_2! + elseif recipe_name == "bi-arboretum-r3" then + BioInd.writeDebug(tostring(recipe_name) .. ": Just change terrain to grass-1 (advanced)") + + for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain + new_position = get_new_position(pos) + currentTilename = surface.get_tile(new_position.x, new_position.y).name + + if Bi_Industries.fertility[currentTilename] and currentTilename ~= terrain_name_g1 then + consume_ingredients(arboretum, ingredients) + BioInd.writeDebug("%s: Changing terrain from %s to %s (%s)", + { k, currentTilename or "unknown tile", + terrain_name_g1, serpent.line(new_position) }) + set_tile(currentTilename, terrain_name_g1, surface, new_position) + --- After sucessfully changing the terrain, break out of the loop. + break + else + BioInd.writeDebug("%s: Can't change terrain (%s)", + { k, currentTilename or "unknown tile" }) + end + end + -- Fertilize the ground with normal fertilizer. Ignore tiles listed in Terrain_Check_1! + -- Also plant a tree. + elseif recipe_name == "bi-arboretum-r4" then + BioInd.writeDebug(tostring(recipe_name) .. ": Plant Tree AND change the terrain to grass-3 (basic)") + + for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain + new_position = get_new_position(pos) + currentTilename = surface.get_tile(new_position.x, new_position.y).name + new_plant = { + name = "seedling", + position = new_position, + force = "neutral" + } + + -- Test to see if we can plant + if surface.can_place_entity(new_plant) and Bi_Industries.fertility[currentTilename] then + consume_ingredients(arboretum, ingredients) + -- Refund fertilizer -- no need to waste it on fertile ground! + if Terrain_Check_1[currentTilename] then + arboretum.insert({ name = "fertilizer", count = ingredients.items.fertilizer }) + BioInd.writeDebug("Refunded fertilizer!") + end + + set_tile(currentTilename, terrain_name_g3, surface, new_position) + create_seedling = surface.create_entity(new_plant) + seed_planted_arboretum(event, create_seedling) + --- After sucessfully planting a tree or changing the terrain, break out of the loop. + break + else + BioInd.writeDebug("%s: Can't change terrain and plant a tree (%s)", + { k, currentTilename or "unknown tile" }) + end + end + -- Fertilize the ground with advanced fertilizer. Ignore tiles listed in Terrain_Check_2! + -- Also plant a tree. + elseif recipe_name == "bi-arboretum-r5" then + BioInd.writeDebug(tostring(recipe_name) .. ": Plant Tree and change the terrain to grass-1 (advanced)") + + for k = 1, 10 do --- 10 attempts to find a random spot to plant a tree and / or change terrain + new_position = get_new_position(pos) + currentTilename = surface.get_tile(new_position.x, new_position.y).name + new_plant = { + name = "seedling", + position = new_position, + force = "neutral" + } + + if surface.can_place_entity(new_plant) and Bi_Industries.fertility[currentTilename] then + consume_ingredients(arboretum, ingredients) + -- Refund fertilizer -- no need to waste it on fertile ground! + if Terrain_Check_2[currentTilename] then + arboretum.insert({ + name = "bi-adv-fertilizer", count = ingredients.items["bi-adv-fertilizer"] + }) + BioInd.writeDebug("Refunded advanced fertilizer!") + end + + set_tile(currentTilename, terrain_name_g1, surface, new_position) + create_seedling = surface.create_entity(new_plant) + seed_planted_arboretum(event, create_seedling) + --- After sucessfully planting a tree or changing the terrain, break out of the loop. + break + else + BioInd.writeDebug("%s: Can't change terrain and plant a tree (%s)", + { k, currentTilename or "unknown tile" }) + end + end + else + BioInd.writeDebug("Terraformer has no recipe!") + end end - end end diff --git a/Bio_Industries_2/control_tree.lua b/Bio_Industries_2/control_tree.lua index bbbca44..9b7a045 100644 --- a/Bio_Industries_2/control_tree.lua +++ b/Bio_Industries_2/control_tree.lua @@ -1,4 +1,3 @@ - -- All tree Growing stuff local Event = require('__kry_stdlib__/stdlib/event/event').set_protected_mode(true) @@ -8,25 +7,25 @@ Bi_Industries = {} Bi_Industries.fertility = { ["vegetation-green-grass-1"] = 100, - ["grass-1"] = 100, - ["grass-3"] = 85, - ["grass-2"] = 70, - ["grass-4"] = 60, - ["red-desert-0"] = 50, - ["dirt-3"] = 40, - ["dirt-5"] = 37, - ["dirt-6"] = 34, - ["dirt-7"] = 31, - ["dirt-4"] = 28, - ["dry-dirt"] = 25, - ["dirt-2"] = 22, - ["dirt-1"] = 19, - ["red-desert-2"] = 16, - ["red-desert-3"] = 13, - ["sand-3"] = 10, - ["sand-2"] = 7, - ["sand-1"] = 4, - ["red-desert-1"] = 1, + ["grass-1"] = 100, + ["grass-3"] = 85, + ["grass-2"] = 70, + ["grass-4"] = 60, + ["red-desert-0"] = 50, + ["dirt-3"] = 40, + ["dirt-5"] = 37, + ["dirt-6"] = 34, + ["dirt-7"] = 31, + ["dirt-4"] = 28, + ["dry-dirt"] = 25, + ["dirt-2"] = 22, + ["dirt-1"] = 19, + ["red-desert-2"] = 16, + ["red-desert-3"] = 13, + ["sand-3"] = 10, + ["sand-2"] = 7, + ["sand-1"] = 4, + ["red-desert-1"] = 1, ["frozen-snow-0"] = 1, ["frozen-snow-1"] = 1, ["frozen-snow-2"] = 1, @@ -226,432 +225,428 @@ Bi_Industries.fertility = { -- If we get passed on a tile_name, we can skip getting the tile at position! local function get_tile_fertility(surface, position, tile_name) - surface = BioInd.is_surface(surface) or BioInd.arg_err(surface or "nil", "surface") - position = BioInd.normalize_position(position) or BioInd.arg_err(position or "nil", "position") + surface = BioInd.is_surface(surface) or BioInd.arg_err(surface or "nil", "surface") + position = BioInd.normalize_position(position) or BioInd.arg_err(position or "nil", "position") - tile_name = tile_name or surface.get_tile(position.x, position.y).name + tile_name = tile_name or surface.get_tile(position.x, position.y).name - local fertility = Bi_Industries.fertility[tile_name] + local fertility = Bi_Industries.fertility[tile_name] - return fertility and {fertility = fertility, key = "fertilizer"} or - {fertility = 1, key = "default"} + return fertility and { fertility = fertility, key = "fertilizer" } or + { fertility = 1, key = "default" } end local function plant_tree(tabl, tree, create_entity) - BioInd.check_args(tabl, "table") - BioInd.check_args(tree, "table") - BioInd.check_args(tree.time, "number", "time") - -- tree.tree_name is only required if we really want to create a tree, - -- not if we just want to add a table entry! - if create_entity then - BioInd.check_args(tree.tree_name, "string", "tree_name") - end + BioInd.check_args(tabl, "table") + BioInd.check_args(tree, "table") + BioInd.check_args(tree.time, "number", "time") + -- tree.tree_name is only required if we really want to create a tree, + -- not if we just want to add a table entry! + if create_entity then + BioInd.check_args(tree.tree_name, "string", "tree_name") + end - if not (tree.position and BioInd.normalize_position(tree.position)) then - BioInd.arg_err(tree.position or "nil", "position") - elseif not (tree.surface and BioInd.is_surface(tree.surface)) then - BioInd.arg_err(tree.surface or "nil", "surface") - end + if not (tree.position and BioInd.normalize_position(tree.position)) then + BioInd.arg_err(tree.position or "nil", "position") + elseif not (tree.surface and BioInd.is_surface(tree.surface)) then + BioInd.arg_err(tree.surface or "nil", "surface") + end - local grow_until_tick = tree.time -BioInd.show("grow_until_tick", grow_until_tick) - tabl[grow_until_tick] = tabl[grow_until_tick] or {} + local grow_until_tick = tree.time + BioInd.show("grow_until_tick", grow_until_tick) + tabl[grow_until_tick] = tabl[grow_until_tick] or {} - -- Update table - table.insert(tabl[grow_until_tick], tree) -BioInd.writeDebug("Added tree to table!") + -- Update table + table.insert(tabl[grow_until_tick], tree) + BioInd.writeDebug("Added tree to table!") - -- Plant the new tree - if create_entity then - tree.surface.create_entity({ - name = tree.tree_name, - position = tree.position, - force = "neutral" - }) - end + -- Plant the new tree + if create_entity then + tree.surface.create_entity({ + name = tree.tree_name, + position = tree.position, + force = "neutral" + }) + end end -- t_base, t_penalty: numbers; seedbomb: Boolean local function plant_seed(event, t_base, t_penalty, seedbomb) - for a, arg in pairs({ - {arg = event, type = "table"}, - {arg = t_base, type = "number"}, - {arg = t_penalty, type = "number"} - }) do - BioInd.check_args(arg.arg, arg.type, arg.desc) - end + for a, arg in pairs({ + { arg = event, type = "table" }, + { arg = t_base, type = "number" }, + { arg = t_penalty, type = "number" } + }) do + BioInd.check_args(arg.arg, arg.type, arg.desc) + end -BioInd.show("event", event) -BioInd.show("t_base", t_base) -BioInd.show("t_penalty", t_penalty) -BioInd.show("seedbomb", seedbomb) - -- Seed Planted (Put the seedling in the table) - local entity = event.entity or event.created_entity or - BioInd.arg_err("nil", "entity") - local surface = BioInd.is_surface(entity.surface) or - BioInd.arg_err(entity.surface or "nil", "surface") - local pos = BioInd.normalize_position(entity.position) or - BioInd.arg_err(entity.position or "nil", "position") + BioInd.show("event", event) + BioInd.show("t_base", t_base) + BioInd.show("t_penalty", t_penalty) + BioInd.show("seedbomb", seedbomb) + -- Seed Planted (Put the seedling in the table) + local entity = event.entity or event.created_entity or + BioInd.arg_err("nil", "entity") + local surface = BioInd.is_surface(entity.surface) or + BioInd.arg_err(entity.surface or "nil", "surface") + local pos = BioInd.normalize_position(entity.position) or + BioInd.arg_err(entity.position or "nil", "position") - -- Minimum will always be 1 - local fertility = get_tile_fertility(surface, pos).fertility + -- Minimum will always be 1 + local fertility = get_tile_fertility(surface, pos).fertility - -- Things will grow faster on fertile than on barren tiles - -- (No penalty for tiles with maximum fertility) - local grow_time = math.max(1, math.random(t_base) + t_penalty - (40 * fertility)) - local tree_data = { - position = pos, - time = event.tick + grow_time, - surface = surface, - seed_bomb = seedbomb - } - plant_tree(storage.bi.tree_growing, tree_data, false) + -- Things will grow faster on fertile than on barren tiles + -- (No penalty for tiles with maximum fertility) + local grow_time = math.max(1, math.random(t_base) + t_penalty - (40 * fertility)) + local tree_data = { + position = pos, + time = event.tick + grow_time, + surface = surface, + seed_bomb = seedbomb + } + plant_tree(storage.bi.tree_growing, tree_data, false) end function seed_planted(event) - plant_seed(event, 1000, 4000, false) + plant_seed(event, 1000, 4000, false) end function seed_planted_trigger(event) - plant_seed(event, 2000, 6000, true) + plant_seed(event, 2000, 6000, true) end function seed_planted_arboretum(event, entity) - event.created_entity = entity - plant_seed(event, 2000, 6000, false) + event.created_entity = entity + plant_seed(event, 2000, 6000, false) end - function summ_weight(tabl) - local summ = 0 - for i, tree_weights in pairs(tabl or {}) do - if (type(tree_weights) == "table") and tree_weights.weight then - summ = summ + tree_weights.weight + local summ = 0 + for i, tree_weights in pairs(tabl or {}) do + if (type(tree_weights) == "table") and tree_weights.weight then + summ = summ + tree_weights.weight + end end - end - return summ + return summ end function tree_from_max_index_tabl(max_index, tabl) - BioInd.check_args(max_index, "number") + BioInd.check_args(max_index, "number") - local rnd_index = math.random(max_index) - for tree_name, tree_weights in pairs(tabl or {}) do - if (type(tree_weights) == "table") and tree_weights.weight then - rnd_index = rnd_index - tree_weights.weight - if rnd_index <= 0 then - return tree_name - end + local rnd_index = math.random(max_index) + for tree_name, tree_weights in pairs(tabl or {}) do + if (type(tree_weights) == "table") and tree_weights.weight then + rnd_index = rnd_index - tree_weights.weight + if rnd_index <= 0 then + return tree_name + end + end end - end - return nil + return nil end local function random_tree(tile_name) -BioInd.show("[random_tree] tile_name", tile_name) - if terrains[tile_name] then - local trees_table = terrains[tile_name] - local max_index = summ_weight(trees_table) - BioInd.writeDebug("Found %s in table terrains.\tmax_index: %s", - {tile_name, max_index}) - return tree_from_max_index_tabl(max_index, trees_table) - end + BioInd.show("[random_tree] tile_name", tile_name) + if terrains[tile_name] then + local trees_table = terrains[tile_name] + local max_index = summ_weight(trees_table) + BioInd.writeDebug("Found %s in table terrains.\tmax_index: %s", + { tile_name, max_index }) + return tree_from_max_index_tabl(max_index, trees_table) + end end -- Settings used for the different grow stages local stage_settings = { - [1] = { - fertilizer = {max = 1500, penalty = 3000, factor = 30}, - default = {max = 1500, penalty = 6000, factor = 30}, - }, - [2] = { - fertilizer = {max = 1000, penalty = 2000, factor = 20}, - default = {max = 1500, penalty = 6000, factor = 30}, - }, - [3] = { - fertilizer = {max = 1000, penalty = 2000, factor = 20}, - default = {max = 1500, penalty = 6000, factor = 30}, - }, + [1] = { + fertilizer = { max = 1500, penalty = 3000, factor = 30 }, + default = { max = 1500, penalty = 6000, factor = 30 }, + }, + [2] = { + fertilizer = { max = 1000, penalty = 2000, factor = 20 }, + default = { max = 1500, penalty = 6000, factor = 30 }, + }, + [3] = { + fertilizer = { max = 1000, penalty = 2000, factor = 20 }, + default = { max = 1500, penalty = 6000, factor = 30 }, + }, } local function Grow_tree_first_stage(first_stage_table, event) - BioInd.check_args(first_stage_table, "table") - BioInd.check_args(event, "table") - local surface = BioInd.is_surface(first_stage_table.surface) or - BioInd.arg_err(first_stage_table.surface or "nil", "surface") - local position = BioInd.normalize_position(first_stage_table.position) or - BioInd.arg_err(first_stage_table.position or "nil", "position") - local seed_bomb = first_stage_table.seed_bomb + BioInd.check_args(first_stage_table, "table") + BioInd.check_args(event, "table") + local surface = BioInd.is_surface(first_stage_table.surface) or + BioInd.arg_err(first_stage_table.surface or "nil", "surface") + local position = BioInd.normalize_position(first_stage_table.position) or + BioInd.arg_err(first_stage_table.position or "nil", "position") + local seed_bomb = first_stage_table.seed_bomb - local tree = surface.find_entity("seedling", position) - local tree2 = surface.find_entity("seedling-2", position) - local tree3 = surface.find_entity("seedling-3", position) - BioInd.writeDebug("tree: %s\ttree2: %s\ttree3: %s", - {tree and tree.valid and tree.name or "nil", - tree2 and tree2.valid and tree2.name or "nil", - tree3 and tree3.valid and tree3.name or "nil"}) + local tree = surface.find_entity("seedling", position) + local tree2 = surface.find_entity("seedling-2", position) + local tree3 = surface.find_entity("seedling-3", position) + BioInd.writeDebug("tree: %s\ttree2: %s\ttree3: %s", + { tree and tree.valid and tree.name or "nil", + tree2 and tree2.valid and tree2.name or "nil", + tree3 and tree3.valid and tree3.name or "nil" }) - local tile_name = surface.get_tile(position).name + local tile_name = surface.get_tile(position).name - -- fertility will be 1 if terrain type is not listed above, so very small chance to grow. - local f = get_tile_fertility(surface, position, tile_name) - local fertility, key = f.fertility, f.key -BioInd.show("fertility", fertility) -BioInd.show("key", key) - -- Random value. Tree will grow if this value is smaller than the 'Fertility' value - local growth_chance = math.random(100) - - local tree_name, can_be_placed - if tree or tree2 or tree3 then -BioInd.writeDebug("Found a seedling!") - tree_name = random_tree(tile_name) - end -BioInd.show("tree_name", tree_name) - - - if tree then - BioInd.writeDebug("Have tree") - if tree.valid then - tree.destroy() - BioInd.writeDebug("Destroyed tree!") - end - - if tree_name and key == "fertilizer" and not seed_bomb then - -- Depending on Terrain, choose tree type & Convert seedling into a tree - BioInd.writeDebug("Fertilizer and no seed bomb: New tree can grow!") - -- Grow the new tree - can_be_placed = surface.can_place_entity({ - name = tree_name, position = position, force = "neutral" - }) -BioInd.show("can_be_placed", can_be_placed) -BioInd.show("growth_chance", growth_chance) -BioInd.show("fertility", fertility) -BioInd.show(growth_chance.." <= ("..fertility.." + 5)", growth_chance <= (fertility + 5)) - - if can_be_placed and growth_chance <= (fertility + 5) then - BioInd.writeDebug("Can be placed etc!") - -- Trees will grow faster on Fertile than on barren tiles - local grow_time = math.max(1, math.random(2000) + 4000 - (40 * fertility)) -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 - stage_1_tree_name = tree_name - end -BioInd.writeDebug("stage_1_tree_name: %s", {stage_1_tree_name}) - - local tree_data = { - tree_name = stage_1_tree_name, - final_tree = tree_name, - position = position, - time = event.tick + grow_time, - surface = surface - } - plant_tree(storage.bi.tree_growing_stage_1, tree_data, true) - end - end - end - - --- Seed Bomb Code -BioInd.show("tree_name", tree_name) -BioInd.show("tree2", tree2) -BioInd.show("tree3", tree3) - - if seed_bomb then - BioInd.writeDebug("Seed bomb was used!") - if tree2 and tree2.valid then - tree2.destroy() - BioInd.writeDebug("Removed tree2!") - end - if tree3 and tree3.valid then - tree3.destroy() - BioInd.writeDebug("Removed tree3!") - end - - --- Depending on Terrain, choose tree type & Convert seedling into a tree -BioInd.show("key", key) - if key == "fertilizer" then - BioInd.writeDebug("Got Tile") - if tree_name then - BioInd.writeDebug("Found Tree: %s", {tree_name}) - local new_tree = {name = tree_name, position = position, force = "neutral"} - can_be_placed = surface.can_place_entity(new_tree) -BioInd.show("can_be_placed", can_be_placed) -BioInd.show("growth_chance", growth_chance) -BioInd.show("fertility", fertility) -BioInd.show("growth_chance <= fertility", growth_chance <= fertility) - if can_be_placed and growth_chance <= fertility then - surface.create_entity(new_tree) - BioInd.writeDebug("Created new tree!") - end - else - BioInd.writeDebug("Tree not Found") - end - else - BioInd.writeDebug("Tile not Found") - end - end -end - -local function Grow_tree_last_stage(last_stage_table) - BioInd.check_args(last_stage_table, "table") - BioInd.check_args(last_stage_table.tree_name, "string", "tree_name") - BioInd.check_args(last_stage_table.final_tree, "string", "final_tree") - - local surface = BioInd.is_surface(last_stage_table.surface) or - BioInd.arg_err(last_stage_table.surface or "nil", "surface") - local position = BioInd.normalize_position(last_stage_table.position) or - BioInd.arg_err(last_stage_table.position or "nil", "position") - - local tree_name = last_stage_table.tree_name - local final_tree = last_stage_table.final_tree - - local tree = tree_name and surface.find_entity(tree_name, position) - - - if tree then - tree.destroy() - - -- fertility will be 1 if terrain type not listed above, so very small change to grow. - local f = get_tile_fertility(surface, position) + -- fertility will be 1 if terrain type is not listed above, so very small chance to grow. + local f = get_tile_fertility(surface, position, tile_name) local fertility, key = f.fertility, f.key - + BioInd.show("fertility", fertility) + BioInd.show("key", key) -- Random value. Tree will grow if this value is smaller than the 'Fertility' value local growth_chance = math.random(100) - --- Convert growing tree to fully grown tree - if (key == "fertilizer" or growth_chance <= fertility) then - - -- Grow the new tree - BioInd.writeDebug("Final Tree Name: %s", {final_tree}) - surface.create_entity({ - name = final_tree, - position = position, - force = "neutral" - }) + local tree_name, can_be_placed + if tree or tree2 or tree3 then + BioInd.writeDebug("Found a seedling!") + tree_name = random_tree(tile_name) + end + BioInd.show("tree_name", tree_name) + + + if tree then + BioInd.writeDebug("Have tree") + if tree.valid then + tree.destroy() + BioInd.writeDebug("Destroyed tree!") + end + + if tree_name and key == "fertilizer" and not seed_bomb then + -- Depending on Terrain, choose tree type & Convert seedling into a tree + BioInd.writeDebug("Fertilizer and no seed bomb: New tree can grow!") + -- Grow the new tree + can_be_placed = surface.can_place_entity({ + name = tree_name, position = position, force = "neutral" + }) + BioInd.show("can_be_placed", can_be_placed) + BioInd.show("growth_chance", growth_chance) + BioInd.show("fertility", fertility) + BioInd.show(growth_chance .. " <= (" .. fertility .. " + 5)", growth_chance <= (fertility + 5)) + + if can_be_placed and growth_chance <= (fertility + 5) then + BioInd.writeDebug("Can be placed etc!") + -- Trees will grow faster on Fertile than on barren tiles + local grow_time = math.max(1, math.random(2000) + 4000 - (40 * fertility)) + 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 + stage_1_tree_name = tree_name + end + BioInd.writeDebug("stage_1_tree_name: %s", { stage_1_tree_name }) + + local tree_data = { + tree_name = stage_1_tree_name, + final_tree = tree_name, + position = position, + time = event.tick + grow_time, + surface = surface + } + plant_tree(storage.bi.tree_growing_stage_1, tree_data, true) + end + end + end + + --- Seed Bomb Code + BioInd.show("tree_name", tree_name) + BioInd.show("tree2", tree2) + BioInd.show("tree3", tree3) + + if seed_bomb then + BioInd.writeDebug("Seed bomb was used!") + if tree2 and tree2.valid then + tree2.destroy() + BioInd.writeDebug("Removed tree2!") + end + if tree3 and tree3.valid then + tree3.destroy() + BioInd.writeDebug("Removed tree3!") + end + + --- Depending on Terrain, choose tree type & Convert seedling into a tree + BioInd.show("key", key) + if key == "fertilizer" then + BioInd.writeDebug("Got Tile") + if tree_name then + BioInd.writeDebug("Found Tree: %s", { tree_name }) + local new_tree = { name = tree_name, position = position, force = "neutral" } + can_be_placed = surface.can_place_entity(new_tree) + BioInd.show("can_be_placed", can_be_placed) + BioInd.show("growth_chance", growth_chance) + BioInd.show("fertility", fertility) + BioInd.show("growth_chance <= fertility", growth_chance <= fertility) + if can_be_placed and growth_chance <= fertility then + surface.create_entity(new_tree) + BioInd.writeDebug("Created new tree!") + end + else + BioInd.writeDebug("Tree not Found") + end + else + BioInd.writeDebug("Tile not Found") + end + end +end + +local function Grow_tree_last_stage(last_stage_table) + BioInd.check_args(last_stage_table, "table") + BioInd.check_args(last_stage_table.tree_name, "string", "tree_name") + BioInd.check_args(last_stage_table.final_tree, "string", "final_tree") + + local surface = BioInd.is_surface(last_stage_table.surface) or + BioInd.arg_err(last_stage_table.surface or "nil", "surface") + local position = BioInd.normalize_position(last_stage_table.position) or + BioInd.arg_err(last_stage_table.position or "nil", "position") + + local tree_name = last_stage_table.tree_name + local final_tree = last_stage_table.final_tree + + local tree = tree_name and surface.find_entity(tree_name, position) + + + if tree then + tree.destroy() + + -- fertility will be 1 if terrain type not listed above, so very small change to grow. + local f = get_tile_fertility(surface, position) + local fertility, key = f.fertility, f.key + + -- Random value. Tree will grow if this value is smaller than the 'Fertility' value + local growth_chance = math.random(100) + + --- Convert growing tree to fully grown tree + if (key == "fertilizer" or growth_chance <= fertility) then + -- Grow the new tree + BioInd.writeDebug("Final Tree Name: %s", { final_tree }) + surface.create_entity({ + name = final_tree, + position = position, + force = "neutral" + }) + end end - end end local function Grow_tree_stage(stage_table, stage) -BioInd.writeDebug("Entered function Grow_tree_stage(%s, %s)", {stage_table, stage}) - BioInd.check_args(stage_table, "table") - BioInd.check_args(stage, "number") - - if stage == 4 then - Grow_tree_last_stage(stage_table) - else - for a, arg in pairs({ - {arg = stage_table.tree_name, type = "string", desc = "tree_name"}, - {arg = stage_table.final_tree, type = "string", desc = "final_tree"}, - {arg = stage_table.time, type = "number", desc = "time"}, - }) do - BioInd.check_args(arg.arg, arg.type, arg.desc) - end - - local tree_name = stage_table.tree_name - local final_tree = stage_table.final_tree - local time_planted = stage_table.time - - local surface = BioInd.is_surface(stage_table.surface) or - BioInd.arg_err(stage_table.surface or "nil", "surface") - local position = BioInd.normalize_position(stage_table.position) or - BioInd.arg_err(stage_table.position or "nil", "position") - - - - local tree = tree_name and surface.find_entity(tree_name, position) - - if tree then - tree.destroy() - - local next_stage = stage + 1 - --- Depending on Terrain, choose tree type & Convert seedling into a tree - local f = get_tile_fertility(surface, position) - 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 - next_stage_tree_name = final_tree - BioInd.writeDebug("Next stage %g: Prototype did not exist", {next_stage}) - else - BioInd.writeDebug("Next stage %g: %s", {next_stage, next_stage_tree_name}) - end - - local can_be_placed = surface.can_place_entity{ - name = next_stage_tree_name, - position = position, - force = "neutral" - } - - if can_be_placed then - - if next_stage_tree_name == final_tree then - BioInd.writeDebug("Tree reached final stage, don't insert") - surface.create_entity({ - name = final_tree, - position = position, - force = "neutral" - }) - else - -- Trees will grow faster on fertile than on barren tiles! - local s = stage_settings[stage][key] - local grow_time = math.max(1, math.random(s.max) + s.penalty - (s.factor * fertility)) - - local tree_data = { - tree_name = next_stage_tree_name, - final_tree = final_tree, - position = position, - time = time_planted + grow_time, - surface = surface - } - plant_tree(storage.bi["tree_growing_stage_"..next_stage], tree_data, true) - end - end + BioInd.writeDebug("Entered function Grow_tree_stage(%s, %s)", { stage_table, stage }) + BioInd.check_args(stage_table, "table") + BioInd.check_args(stage, "number") + if stage == 4 then + Grow_tree_last_stage(stage_table) else - BioInd.writeDebug("Did not find that tree I was looking for...") + for a, arg in pairs({ + { arg = stage_table.tree_name, type = "string", desc = "tree_name" }, + { arg = stage_table.final_tree, type = "string", desc = "final_tree" }, + { arg = stage_table.time, type = "number", desc = "time" }, + }) do + BioInd.check_args(arg.arg, arg.type, arg.desc) + end + + local tree_name = stage_table.tree_name + local final_tree = stage_table.final_tree + local time_planted = stage_table.time + + local surface = BioInd.is_surface(stage_table.surface) or + BioInd.arg_err(stage_table.surface or "nil", "surface") + local position = BioInd.normalize_position(stage_table.position) or + BioInd.arg_err(stage_table.position or "nil", "position") + + + + local tree = tree_name and surface.find_entity(tree_name, position) + + if tree then + tree.destroy() + + local next_stage = stage + 1 + --- Depending on Terrain, choose tree type & Convert seedling into a tree + local f = get_tile_fertility(surface, position) + 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 + next_stage_tree_name = final_tree + BioInd.writeDebug("Next stage %g: Prototype did not exist", { next_stage }) + else + BioInd.writeDebug("Next stage %g: %s", { next_stage, next_stage_tree_name }) + end + + local can_be_placed = surface.can_place_entity { + name = next_stage_tree_name, + position = position, + force = "neutral" + } + + if can_be_placed then + if next_stage_tree_name == final_tree then + BioInd.writeDebug("Tree reached final stage, don't insert") + surface.create_entity({ + name = final_tree, + position = position, + force = "neutral" + }) + else + -- Trees will grow faster on fertile than on barren tiles! + local s = stage_settings[stage][key] + local grow_time = math.max(1, math.random(s.max) + s.penalty - (s.factor * fertility)) + + local tree_data = { + tree_name = next_stage_tree_name, + final_tree = final_tree, + position = position, + time = time_planted + grow_time, + surface = surface + } + plant_tree(storage.bi["tree_growing_stage_" .. next_stage], tree_data, true) + end + end + else + BioInd.writeDebug("Did not find that tree I was looking for...") + end end - end 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 - for i = 1, 4 do - storage.bi["tree_growing_stage_"..i] = storage.bi["tree_growing_stage_"..i] or {} + if storage.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 {} + end end - end - local tick = event.tick + local tick = event.tick - if storage.bi.tree_growing[tick] then - for t, tree_data in pairs(storage.bi.tree_growing[tick]) do - BioInd.writeDebug("Trying to move tree %s to first grow stage!", {t}) - Grow_tree_first_stage(tree_data, event) + if storage.bi.tree_growing[tick] then + for t, tree_data in pairs(storage.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 end - BioInd.writeDebug("Removing storage.bi.tree_growing[%s]!", {tick}) - storage.bi.tree_growing[tick] = nil - end - local stage_table - for stage = 1, 4 do - stage_table = storage.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]!", - {stage, tick}) - stage_table[tick] = nil + local stage_table + for stage = 1, 4 do + stage_table = storage.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]!", + { stage, tick }) + stage_table[tick] = nil + end end - end end) diff --git a/Bio_Industries_2/data-final-fixes.lua b/Bio_Industries_2/data-final-fixes.lua index 18abf61..5d14fe3 100644 --- a/Bio_Industries_2/data-final-fixes.lua +++ b/Bio_Industries_2/data-final-fixes.lua @@ -7,165 +7,166 @@ local ignore_trees = BioInd.get_tree_ignore_list() local removed = 0 for name, _ in pairs(ignore_trees or {}) do - if name:match("rtf%-bio%-tree%-.+%-%d-%d+") then - data.raw.tree[name] = nil - ignore_trees[name] = nil - removed = removed + 1 - BioInd.show("Removed tree prototype", name) - end + if name:match("rtf%-bio%-tree%-.+%-%d-%d+") then + data.raw.tree[name] = nil + ignore_trees[name] = nil + removed = removed + 1 + BioInd.show("Removed tree prototype", name) + end end -BioInd.writeDebug("Removed %g tree prototypes. Number of trees to ignore now: %g", {removed, table_size(ignore_trees)}) +BioInd.writeDebug("Removed %g tree prototypes. Number of trees to ignore now: %g", { removed, table_size(ignore_trees) }) BI.Settings.BI_Game_Tweaks_Emissions_Multiplier = settings.startup["BI_Game_Tweaks_Emissions_Multiplier"].value ---- Game Tweaks ---- Tree if BI.Settings.BI_Game_Tweaks_Tree then - - local new_results = { - { - type = "item", - name = "wood", - amount_min = 1, - amount_max = 6 + local new_results = { + { + type = "item", + name = "wood", + amount_min = 1, + amount_max = 6 + } } - } - for tree_name, tree in pairs(data.raw["tree"] or {}) do - if tree.minable and not ignore_trees[tree_name] then -BioInd.writeDebug("Tree name: %s\tminable.result: %s\tminable.count: %s", {tree.name, (tree.minable and tree.minable.result or "nil"), (tree.minable and tree.minable.count or "nil")}, "line") -BioInd.writeDebug("Tree name: %s\tminable.results: %s", {tree.name, (tree.minable and tree.minable.results or "nil")}, "line") - --CHECK FOR SINGLE RESULTS - -- mining.result may be set although mining.results exists (mining.result - -- will be ignored in that case; happens, for example with IR2's rubber - -- trees). In this case, overwriting mining.results with the data from - -- mining.result could break other mods (e.g. IR2's rubber trees should - -- yield "rubber-wood" instead of "wood"). - if tree.minable.result and not tree.minable.results then - BioInd.writeDebug("Tree has minable.result") - --CHECK FOR VANILLA TREES WOOD x 4 - if tree.minable.result == "wood" and tree.minable.count == 4 then - BioInd.writeDebug("Changing wood yield of %s to random value.", {tree.name}) - tree.minable.mining_particle = "wooden-particle" - tree.minable.mining_time = 1.5 - tree.minable.results = new_results - -- CONVERT RESULT TO RESULTS + for tree_name, tree in pairs(data.raw["tree"] or {}) do + if tree.minable and not ignore_trees[tree_name] then + BioInd.writeDebug("Tree name: %s\tminable.result: %s\tminable.count: %s", + { tree.name, (tree.minable and tree.minable.result or "nil"), (tree.minable and tree.minable.count or "nil") }, + "line") + BioInd.writeDebug("Tree name: %s\tminable.results: %s", + { tree.name, (tree.minable and tree.minable.results or "nil") }, "line") + --CHECK FOR SINGLE RESULTS + -- mining.result may be set although mining.results exists (mining.result + -- will be ignored in that case; happens, for example with IR2's rubber + -- trees). In this case, overwriting mining.results with the data from + -- mining.result could break other mods (e.g. IR2's rubber trees should + -- yield "rubber-wood" instead of "wood"). + if tree.minable.result and not tree.minable.results then + BioInd.writeDebug("Tree has minable.result") + --CHECK FOR VANILLA TREES WOOD x 4 + if tree.minable.result == "wood" and tree.minable.count == 4 then + BioInd.writeDebug("Changing wood yield of %s to random value.", { tree.name }) + tree.minable.mining_particle = "wooden-particle" + tree.minable.mining_time = 1.5 + tree.minable.results = new_results + -- CONVERT RESULT TO RESULTS + else + BioInd.writeDebug("Converting tree.minable.result to tree.minable.results!") + tree.minable.mining_particle = "wooden-particle" + tree.minable.results = { + { + type = "item", + name = tree.minable.result, + amount = tree.minable.count, + } + } + end + --CHECK FOR RESULTS TABLE + elseif tree.minable.results then + BioInd.writeDebug("Checking minable.results!") + for r, result in pairs(tree.minable.results) do + --CHECK FOR RESULT WOOD x 4 + if result.name == "wood" and result.amount == 4 then + BioInd.writeDebug("Changing result %s: %s", { r, result }, "line") + result.amount = nil + result.amount_min = 1 + result.amount_max = 6 + end + end + tree.minable.result = nil + tree.minable.count = nil + -- NEITHER RESULT NOR RESULTS EXIST -- CREATE RESULTS! + else + BioInd.writeDebug("Creating minable.results!") + tree.minable.results = new_results + end + BioInd.writeDebug("New minable.results: %s", + { tree.minable and tree.minable.results or "nil" }, "line") else - BioInd.writeDebug("Converting tree.minable.result to tree.minable.results!") - tree.minable.mining_particle = "wooden-particle" - tree.minable.results = { - { - type = "item", - name = tree.minable.result, - amount = tree.minable.count, - } - } + BioInd.writeDebug("Won't change results of %s!", { tree.name }) end - --CHECK FOR RESULTS TABLE - elseif tree.minable.results then - BioInd.writeDebug("Checking minable.results!") - for r, result in pairs(tree.minable.results) do - --CHECK FOR RESULT WOOD x 4 - if result.name == "wood" and result.amount == 4 then - BioInd.writeDebug("Changing result %s: %s", {r, result}, "line") - result.amount = nil - result.amount_min = 1 - result.amount_max = 6 - end - end - tree.minable.result = nil - tree.minable.count = nil - -- NEITHER RESULT NOR RESULTS EXIST -- CREATE RESULTS! - else - BioInd.writeDebug("Creating minable.results!") - tree.minable.results = new_results - end - BioInd.writeDebug("New minable.results: %s", - {tree.minable and tree.minable.results or "nil"}, "line") - else - BioInd.writeDebug("Won't change results of %s!", {tree.name}) end - end end ---- Game Tweaks ---- Player (Changed for 0.18.34/1.1.4!) if BI.Settings.BI_Game_Tweaks_Player then - -- There may be more than one character in the game! Here's a list of - -- the character prototype names or patterns matching character prototype - -- names we want to ignore. - local blacklist = { - ------------------------------------------------------------------------------------ - -- Known dummies -- - ------------------------------------------------------------------------------------ - -- Autodrive - "autodrive-passenger", - -- AAI Programmable Vehicles - "^.+%-_%-driver$", - -- Minime - "minime_character_dummy", - -- Water Turret (currently the dummies are not characters -- but things may change!) - "^WT%-.+%-dummy$", - ------------------------------------------------------------------------------------ - -- Other characters -- - ------------------------------------------------------------------------------------ - -- Bob's Classes and Multiple characters mod - "^.*bob%-character%-.+$", - } + -- There may be more than one character in the game! Here's a list of + -- the character prototype names or patterns matching character prototype + -- names we want to ignore. + local blacklist = { + ------------------------------------------------------------------------------------ + -- Known dummies -- + ------------------------------------------------------------------------------------ + -- Autodrive + "autodrive-passenger", + -- AAI Programmable Vehicles + "^.+%-_%-driver$", + -- Minime + "minime_character_dummy", + -- Water Turret (currently the dummies are not characters -- but things may change!) + "^WT%-.+%-dummy$", + ------------------------------------------------------------------------------------ + -- Other characters -- + ------------------------------------------------------------------------------------ + -- Bob's Classes and Multiple characters mod + "^.*bob%-character%-.+$", + } - local whitelist = { - -- Default character - "^character$", - -- Characters compatible with Minime - "^.*skin.*$", - } + local whitelist = { + -- Default character + "^character$", + -- Characters compatible with Minime + "^.*skin.*$", + } - local tweaks = { - loot_pickup_distance = 5, -- default 2 - build_distance = 20, -- Vanilla 6 - drop_item_distance = 20, -- Vanilla 6 - reach_distance = 20, -- Vanilla 6 - item_pickup_distance = 6, -- Vanilla 1 - reach_resource_distance = 6, -- Vanilla 2.7 - } + local tweaks = { + loot_pickup_distance = 5, -- default 2 + build_distance = 20, -- Vanilla 6 + drop_item_distance = 20, -- Vanilla 6 + reach_distance = 20, -- Vanilla 6 + item_pickup_distance = 6, -- Vanilla 1 + reach_resource_distance = 6, -- Vanilla 2.7 + } - local found, ignore - for char_name, character in pairs(data.raw.character) do -BioInd.show("Checking character", char_name) - found = false + local found, ignore + for char_name, character in pairs(data.raw.character) do + BioInd.show("Checking character", char_name) + found = false - for w, w_pattern in ipairs(whitelist) do - if char_name == w_pattern or char_name:match(w_pattern) then - ignore = false -BioInd.show("Found whitelisted character name", char_name) - for b, b_pattern in ipairs(blacklist) do - - if char_name == b_pattern or char_name:match(b_pattern) then -BioInd.writeDebug("%s is on the ignore list!", char_name) - -- Mark character as found - ignore = true - break - end + for w, w_pattern in ipairs(whitelist) do + if char_name == w_pattern or char_name:match(w_pattern) then + ignore = false + BioInd.show("Found whitelisted character name", char_name) + for b, b_pattern in ipairs(blacklist) do + if char_name == b_pattern or char_name:match(b_pattern) then + BioInd.writeDebug("%s is on the ignore list!", char_name) + -- Mark character as found + ignore = true + break + end + end + if not ignore then + found = true + break + end + end + if found then + break + end end - if not ignore then - found = true - break + + -- Apply tweaks + if found then + for tweak_name, tweak in pairs(tweaks) do + if character[tweak_name] < tweak then + BioInd.writeDebug("Changing %s from %s to %s", { tweak_name, character[tweak_name], tweak }) + character[tweak_name] = tweak + end + end end - end - if found then - break - end end - - -- Apply tweaks - if found then - for tweak_name, tweak in pairs(tweaks) do - if character[tweak_name] < tweak then -BioInd.writeDebug("Changing %s from %s to %s", {tweak_name, character[tweak_name], tweak}) - character[tweak_name] = tweak - end - end - end - end end @@ -174,124 +175,125 @@ end ---- Game Tweaks ---- Production science pack recipe if data.raw.recipe["bi-production-science-pack"] then - BI_Functions.lib.allow_productivity("bi-production-science-pack") - thxbob.lib.tech.add_recipe_unlock("production-science-pack", "bi-production-science-pack") - BioInd.writeDebug("Unlock for recipe \"bi-production-science-pack\" added.") + BI_Functions.lib.allow_productivity("bi-production-science-pack") + thxbob.lib.tech.add_recipe_unlock("production-science-pack", "bi-production-science-pack") + BioInd.writeDebug("Unlock for recipe \"bi-production-science-pack\" added.") end ---- Game Tweaks ---- Bots if BI.Settings.BI_Game_Tweaks_Bot then - -- Logistic & Construction bots can't catch fire or be mined - local function immunify(bot) - -- Changed for 0.18.34/1.1.4! - local can_insert = true - bot.flags = bot.flags or {} - bot.resistances = bot.resistances or {} - for f, flag in pairs(bot.flags) do - if flag == "not-flammable" then - can_insert = false - break - end - end - if can_insert then - table.insert(bot.flags, "not-flammable") - BioInd.writeDebug("Added flag \"not-flammable\" to %s", {bot.name}) + -- Logistic & Construction bots can't catch fire or be mined + local function immunify(bot) + -- Changed for 0.18.34/1.1.4! + local can_insert = true + bot.flags = bot.flags or {} + bot.resistances = bot.resistances or {} + for f, flag in pairs(bot.flags) do + if flag == "not-flammable" then + can_insert = false + break + end + end + if can_insert then + table.insert(bot.flags, "not-flammable") + BioInd.writeDebug("Added flag \"not-flammable\" to %s", { bot.name }) + end + + can_insert = true + for r, resistance in pairs(bot.resistances) do + if resistance.type == "fire" and resistance.percent ~= 100 then + BioInd.writeDebug("Change resistance against \"fire\" from %s to 100 %% for %s", + { resistance.percent or "nil", bot.name }) + bot.resistances[r] = { type = "fire", percent = 100 } + can_insert = false + break + end + end + if can_insert then + table.insert(bot.resistances, { type = "fire", percent = 100 }) + BioInd.writeDebug("Added resistance against \"fire\" to %s", { bot.name }) + end + + bot.minable = nil + BioInd.writeDebug("Made %s unminable", { bot.name }) end - can_insert = true - for r, resistance in pairs(bot.resistances) do - if resistance.type == "fire" and resistance.percent ~= 100 then - BioInd.writeDebug("Change resistance against \"fire\" from %s to 100 %% for %s", {resistance.percent or "nil", bot.name}) - bot.resistances[r] = {type = "fire", percent = 100} - can_insert = false - break - end - end - if can_insert then - table.insert(bot.resistances, {type = "fire", percent = 100}) - BioInd.writeDebug("Added resistance against \"fire\" to %s", {bot.name}) + --catches modded bots too + for _, bot in pairs(data.raw['construction-robot']) do + immunify(bot) end - bot.minable = nil - BioInd.writeDebug("Made %s unminable", {bot.name}) - end - - --catches modded bots too - for _, bot in pairs(data.raw['construction-robot']) do - immunify(bot) - end - - for _, bot in pairs(data.raw['logistic-robot']) do - immunify(bot) - end + for _, bot in pairs(data.raw['logistic-robot']) do + immunify(bot) + end end ---- Game Tweaks stack size ---- if BI.Settings.BI_Game_Tweaks_Stack_Size then - -- Changed for 0.18.34/1.1.4 - local tweaks = { - ["wood"] = {value = 400, se_limit = 200}, - ["stone"] = {value = 400, se_limit = 50}, - ["stone-crushed"] = {value = 800, se_limit = 200}, - ["concrete"] = {value = 400, se_limit = 200}, - ["slag"] = {value = 800, se_limit = 200}, - } - local item - local five_dim = BioInd.get_startup_setting("5d-change-stack") + -- Changed for 0.18.34/1.1.4 + local tweaks = { + ["wood"] = { value = 400, se_limit = 200 }, + ["stone"] = { value = 400, se_limit = 50 }, + ["stone-crushed"] = { value = 800, se_limit = 200 }, + ["concrete"] = { value = 400, se_limit = 200 }, + ["slag"] = { value = 800, se_limit = 200 }, + } + local item + local five_dim = BioInd.get_startup_setting("5d-change-stack") - for tweak_name, tweak in pairs(tweaks) do - item = data.raw.item[tweak_name] - if item then - -- Only adjust stack_size if 5Dim sets multiplier of 1 or is not active! - if item.stack_size < tweak.value and (five_dim == 1 or not five_dim) then - BioInd.writeDebug("Changing stacksize of %s from %s to %s", - {item.name, item.stack_size, tweak.value}) - item.stack_size = tweak.value - end - if mods["space-exploration"] then - item.stack_size = math.min(tweak.se_limit, item.stack_size) -BioInd.show("Adjusted stack_size on account of SE", item.stack_size ) - end + for tweak_name, tweak in pairs(tweaks) do + item = data.raw.item[tweak_name] + if item then + -- Only adjust stack_size if 5Dim sets multiplier of 1 or is not active! + if item.stack_size < tweak.value and (five_dim == 1 or not five_dim) then + BioInd.writeDebug("Changing stacksize of %s from %s to %s", + { item.name, item.stack_size, tweak.value }) + item.stack_size = tweak.value + end + if mods["space-exploration"] then + item.stack_size = math.min(tweak.se_limit, item.stack_size) + BioInd.show("Adjusted stack_size on account of SE", item.stack_size) + end + end end - end end --- Update fuel_emissions_multiplier values if BI.Settings.BI_Game_Tweaks_Emissions_Multiplier then - for item, factor in pairs({ - ["pellet-coke"] = 0.80, - ["enriched-fuel"] = 0.90, - ["solid-fuel"] = 1.00, - ["solid-carbon"] = 1.05, - ["carbon"] = 1.05, - ["wood-bricks"] = 1.20, - ["rocket-fuel"] = 1.20, - ["bi-seed"] = 1.30, - ["seedling"] = 1.30, - ["bi-wooden-pole-big"] = 1.30, - ["bi-wooden-pole-huge"] = 1.30, - ["bi-wooden-fence"] = 1.30, - ["bi-wood-pipe"] = 1.30, - ["bi-wood-pipe-to-ground"] = 1.30, - ["bi-wooden-chest-large"] = 1.30, - ["bi-wooden-chest-huge"] = 1.30, - ["bi-wooden-chest-giga"] = 1.30, - ["bi-ash"] = 1.30, - ["ash"] = 1.30, - ["wood-charcoal"] = 1.25, - ["cellulose-fiber"] = 1.40, - ["bi-woodpulp"] = 1.40, - ["solid-coke"] = 1.40, - ["wood-pellets"] = 1.40, - ["coal-crushed"] = 1.50, - ["wood"] = 1.60, - ["coal"] = 2.00, - -- Removed in 0.17.48/0.18.16 - }) do - BI_Functions.lib.fuel_emissions_multiplier_update(item, factor) - end + for item, factor in pairs({ + ["pellet-coke"] = 0.80, + ["enriched-fuel"] = 0.90, + ["solid-fuel"] = 1.00, + ["solid-carbon"] = 1.05, + ["carbon"] = 1.05, + ["wood-bricks"] = 1.20, + ["rocket-fuel"] = 1.20, + ["bi-seed"] = 1.30, + ["seedling"] = 1.30, + ["bi-wooden-pole-big"] = 1.30, + ["bi-wooden-pole-huge"] = 1.30, + ["bi-wooden-fence"] = 1.30, + ["bi-wood-pipe"] = 1.30, + ["bi-wood-pipe-to-ground"] = 1.30, + ["bi-wooden-chest-large"] = 1.30, + ["bi-wooden-chest-huge"] = 1.30, + ["bi-wooden-chest-giga"] = 1.30, + ["bi-ash"] = 1.30, + ["ash"] = 1.30, + ["wood-charcoal"] = 1.25, + ["cellulose-fiber"] = 1.40, + ["bi-woodpulp"] = 1.40, + ["solid-coke"] = 1.40, + ["wood-pellets"] = 1.40, + ["coal-crushed"] = 1.50, + ["wood"] = 1.60, + ["coal"] = 2.00, + -- Removed in 0.17.48/0.18.16 + }) do + BI_Functions.lib.fuel_emissions_multiplier_update(item, factor) + end end @@ -299,36 +301,38 @@ end -- Make vanilla and Bio boilers exchangeable if BI.Settings.BI_Bio_Fuel then - local boiler = data.raw["boiler"]["boiler"] - local boiler_group = boiler.fast_replaceable_group or "boiler" + local boiler = data.raw["boiler"]["boiler"] + local boiler_group = boiler.fast_replaceable_group or "boiler" - boiler.fast_replaceable_group = boiler_group - data.raw["boiler"]["bi-bio-boiler"].fast_replaceable_group = boiler_group + boiler.fast_replaceable_group = boiler_group + data.raw["boiler"]["bi-bio-boiler"].fast_replaceable_group = boiler_group end if mods["Krastorio2"] then - -- Krastorio² needs much more wood than usually provided by Bio Industries. If Krastorio² is - -- active, BI should produce much more wood/wood pulp. For better baĺancing, our recipes should - -- also be changed to require more wood/wood pulp as ingredients. - -- Recipes for making wood should also use/produce more seeds, seedlings, and water. It shouldn't - -- be necessary to increase the input of ash and fertilizer in these recipes as they already - -- require more wood/wood pulp. - local update = { - "wood", "bi-woodpulp", - "bi-seed", "seedling", "water", - } - for _, recipe in pairs(data.raw.recipe) do - BioInd.writeDebug("Recipe has \"mod\" property: %s", {recipe.mod and true or false}) - if recipe.mod == "Bio_Industries_2" then - krastorio.recipes.multiplyIngredients(recipe.name, update, 4) - krastorio.recipes.multiplyProducts(recipe.name, update, 4) - BioInd.writeDebug("Changed ingredients for %s: %s", {recipe and recipe.name or "nil", recipe and recipe.ingredients or "nil"}) - BioInd.writeDebug("Changed results for %s: %s", {recipe and recipe.name or "nil", recipe and recipe.results or "nil"}) + -- Krastorio² needs much more wood than usually provided by Bio Industries. If Krastorio² is + -- active, BI should produce much more wood/wood pulp. For better baĺancing, our recipes should + -- also be changed to require more wood/wood pulp as ingredients. + -- Recipes for making wood should also use/produce more seeds, seedlings, and water. It shouldn't + -- be necessary to increase the input of ash and fertilizer in these recipes as they already + -- require more wood/wood pulp. + local update = { + "wood", "bi-woodpulp", + "bi-seed", "seedling", "water", + } + for _, recipe in pairs(data.raw.recipe) do + BioInd.writeDebug("Recipe has \"mod\" property: %s", { recipe.mod and true or false }) + if recipe.mod == "Bio_Industries_2" then + krastorio.recipes.multiplyIngredients(recipe.name, update, 4) + krastorio.recipes.multiplyProducts(recipe.name, update, 4) + BioInd.writeDebug("Changed ingredients for %s: %s", + { recipe and recipe.name or "nil", recipe and recipe.ingredients or "nil" }) + BioInd.writeDebug("Changed results for %s: %s", + { recipe and recipe.name or "nil", recipe and recipe.results or "nil" }) + end end - end end @@ -336,43 +340,43 @@ end -- Make sure fertilizers have the "place_as_tile" property! local AlienBiomes = data.raw.tile["vegetation-green-grass-3"] and - data.raw.tile["vegetation-green-grass-1"] and true or false + data.raw.tile["vegetation-green-grass-1"] and true or false -- We've already set place_as_tile. If it doesn't exist, our fertilizer definition has -- been overwritten by some other mod, so we restore icons and localization and add -- place_as_tile again! local fertilizer = data.raw.item["fertilizer"] if not fertilizer.place_as_tile then - fertilizer.place_as_tile = { - result = AlienBiomes and "vegetation-green-grass-3" or "grass-3", - condition_size = 1, - condition = { layers = { water_tile = true }} - } - fertilizer.icon = ICONPATH .. "fertilizer_64.png" - fertilizer.icon_size = 64 - fertilizer.icons = { - { - icon = ICONPATH .. "fertilizer_64.png", - icon_size = 64, + fertilizer.place_as_tile = { + result = AlienBiomes and "vegetation-green-grass-3" or "grass-3", + condition_size = 1, + condition = { layers = { water_tile = true } } } - } - fertilizer.localised_name = {"BI-item-name.fertilizer"} - fertilizer.localised_description = {"BI-item-description.fertilizer"} + fertilizer.icon = ICONPATH .. "fertilizer_64.png" + fertilizer.icon_size = 64 + fertilizer.icons = { + { + icon = ICONPATH .. "fertilizer_64.png", + icon_size = 64, + } + } + fertilizer.localised_name = { "BI-item-name.fertilizer" } + fertilizer.localised_description = { "BI-item-description.fertilizer" } end data.raw.item["bi-adv-fertilizer"].place_as_tile = { - result = AlienBiomes and "vegetation-green-grass-1" or "grass-1", - condition_size = 1, - condition = { layers = { water_tile = true }} + result = AlienBiomes and "vegetation-green-grass-1" or "grass-1", + condition_size = 1, + condition = { layers = { water_tile = true } } } if mods["pycoalprocessing"] and BI.Settings.BI_Bio_Fuel then -- Bio_Fuel/recipe.lua:30: {type = "item", name = "bi-ash", amount = 15} - thxbob.lib.recipe.remove_result ("bi-basic-gas-processing", "bi-ash") + thxbob.lib.recipe.remove_result("bi-basic-gas-processing", "bi-ash") thxbob.lib.recipe.add_result("bi-basic-gas-processing", { - type = "item", - name = "ash", - amount = 15 + type = "item", + name = "ash", + amount = 15 }) end @@ -382,53 +386,53 @@ end --- If Space Exploration Mod is installed. if mods["space-exploration"] then - -- Space Exploration Mod likes Stack Sizes to be 200 max. - -- Changed in 1.1.11 - local tweaks = { - ["bi-solar-mat"] = 400, - ["bi-seed"] = 800, - ["seedling"] = 400, - ["bi-woodpulp"] = 800, - ["bi-ash"] = 400, - ["wood-charcoal"] = 400, - ["pellet-coke"] = 400, - ["stone-crushed"] = 400, - } - local item - - for tweak_name, tweak in pairs(tweaks) do - item = data.raw.item[tweak_name] - if item and item.stack_size then - item.stack_size = 200 - end - end - - if not mods["Natural_Evolution_Buildings"] then - - local ammo_tweaks = { - ["bi-dart-magazine-basic"] = 400, - ["bi-dart-magazine-standard"] = 400, - ["bi-dart-magazine-enhanced"] = 400, - ["bi-dart-magazine-poison"] = 400, + -- Space Exploration Mod likes Stack Sizes to be 200 max. + -- Changed in 1.1.11 + local tweaks = { + ["bi-solar-mat"] = 400, + ["bi-seed"] = 800, + ["seedling"] = 400, + ["bi-woodpulp"] = 800, + ["bi-ash"] = 400, + ["wood-charcoal"] = 400, + ["pellet-coke"] = 400, + ["stone-crushed"] = 400, } local item - for tweak_name, tweak in pairs(ammo_tweaks) do - item = data.raw.ammo[tweak_name] - item.stack_size = 200 + for tweak_name, tweak in pairs(tweaks) do + item = data.raw.item[tweak_name] + if item and item.stack_size then + item.stack_size = 200 + end + end + + if not mods["Natural_Evolution_Buildings"] then + local ammo_tweaks = { + ["bi-dart-magazine-basic"] = 400, + ["bi-dart-magazine-standard"] = 400, + ["bi-dart-magazine-enhanced"] = 400, + ["bi-dart-magazine-poison"] = 400, + } + local item + + for tweak_name, tweak in pairs(ammo_tweaks) do + item = data.raw.ammo[tweak_name] + item.stack_size = 200 + end end - end end if BI.Settings.Bio_Cannon then - local default_target_masks = data.raw["utility-constants"].default.default_trigger_target_mask_by_type - default_target_masks["unit-spawner"] = default_target_masks["unit-spawner"] or {"common"} -- everything should have "common", unless there is specific reason not to - table.insert(default_target_masks["unit-spawner"], "Bio_Cannon_Ammo") + local default_target_masks = data.raw["utility-constants"].default.default_trigger_target_mask_by_type + default_target_masks["unit-spawner"] = default_target_masks["unit-spawner"] or + { "common" } -- everything should have "common", unless there is specific reason not to + table.insert(default_target_masks["unit-spawner"], "Bio_Cannon_Ammo") - for w, worm in pairs(data.raw.turret) do - worm.trigger_target_mask = worm.trigger_target_mask or default_target_masks["turret"] or {"common"} - table.insert(worm.trigger_target_mask, "Bio_Cannon_Ammo") - end + for w, worm in pairs(data.raw.turret) do + worm.trigger_target_mask = worm.trigger_target_mask or default_target_masks["turret"] or { "common" } + table.insert(worm.trigger_target_mask, "Bio_Cannon_Ammo") + end end ------------------------------------------------------------------------------------ @@ -440,9 +444,9 @@ BioInd.BI_add_icons() for k, v in pairs(data.raw) do - for t, p in pairs(v) do - if p.se_allow_in_space then - BioInd.writeDebug("%s (%s) can be built in space!", {p.name, t}) + for t, p in pairs(v) do + if p.se_allow_in_space then + BioInd.writeDebug("%s (%s) can be built in space!", { p.name, t }) + end end - end end diff --git a/Bio_Industries_2/data-updates.lua b/Bio_Industries_2/data-updates.lua index bfd3557..171aa13 100644 --- a/Bio_Industries_2/data-updates.lua +++ b/Bio_Industries_2/data-updates.lua @@ -1,18 +1,18 @@ local BioInd = require('common')('Bio_Industries_2') for var, name in pairs({ - Bio_Cannon = "BI_Bio_Cannon", - BI_Bio_Fuel = "BI_Bio_Fuel", - BI_Easy_Bio_Gardens = "BI_Easy_Bio_Gardens", - BI_Game_Tweaks_Stack_Size = "BI_Game_Tweaks_Stack_Size", - BI_Game_Tweaks_Recipe = "BI_Game_Tweaks_Recipe", - BI_Game_Tweaks_Tree = "BI_Game_Tweaks_Tree", - BI_Game_Tweaks_Player = "BI_Game_Tweaks_Player", - BI_Game_Tweaks_Disassemble = "BI_Game_Tweaks_Disassemble", - BI_Game_Tweaks_Bot = "BI_Game_Tweaks_Bot", - BI_Solar_Additions = "BI_Solar_Additions", + Bio_Cannon = "BI_Bio_Cannon", + BI_Bio_Fuel = "BI_Bio_Fuel", + BI_Easy_Bio_Gardens = "BI_Easy_Bio_Gardens", + BI_Game_Tweaks_Stack_Size = "BI_Game_Tweaks_Stack_Size", + BI_Game_Tweaks_Recipe = "BI_Game_Tweaks_Recipe", + BI_Game_Tweaks_Tree = "BI_Game_Tweaks_Tree", + BI_Game_Tweaks_Player = "BI_Game_Tweaks_Player", + BI_Game_Tweaks_Disassemble = "BI_Game_Tweaks_Disassemble", + BI_Game_Tweaks_Bot = "BI_Game_Tweaks_Bot", + BI_Solar_Additions = "BI_Solar_Additions", }) do - BI.Settings[var] = BioInd.get_startup_setting(name) + BI.Settings[var] = BioInd.get_startup_setting(name) end @@ -25,17 +25,17 @@ require("prototypes.Wood_Products.pipes") -- Damage Bonus to Ammo -- Don't duplicate what NE does if not mods["Natural_Evolution_Buildings"] then - thxbob.lib.tech.add_recipe_unlock ("military", "bi-dart-magazine-standard") - thxbob.lib.tech.add_recipe_unlock ("military-2", "bi-dart-magazine-enhanced") - thxbob.lib.tech.add_recipe_unlock ("military-3", "bi-dart-magazine-poison") + thxbob.lib.tech.add_recipe_unlock("military", "bi-dart-magazine-standard") + thxbob.lib.tech.add_recipe_unlock("military-2", "bi-dart-magazine-enhanced") + thxbob.lib.tech.add_recipe_unlock("military-3", "bi-dart-magazine-poison") end require("prototypes.Bio_Turret.technology-updates") require("prototypes.Bio_Cannon.technology-updates") if not mods["Natural_Evolution_Buildings"] and BI.Settings.Bio_Cannon then - -- add Prototype Artillery as pre req for artillery - thxbob.lib.tech.add_prerequisite("artillery", "bi-tech-bio-cannon") + -- add Prototype Artillery as pre req for artillery + thxbob.lib.tech.add_prerequisite("artillery", "bi-tech-bio-cannon") end @@ -56,186 +56,195 @@ thxbob.lib.tech.add_recipe_unlock("logistics-3", "bi-wooden-chest-giga") -- Add Big and Huge electric poles to tech tree - thxbob.lib.tech.add_recipe_unlock ("logistics", "bi-wooden-pole-big") - thxbob.lib.tech.add_recipe_unlock ("electric-energy-distribution-2", "bi-wooden-pole-huge") +thxbob.lib.tech.add_recipe_unlock("logistics", "bi-wooden-pole-big") +thxbob.lib.tech.add_recipe_unlock("electric-energy-distribution-2", "bi-wooden-pole-huge") --- Wood Floors -- Make wood placeable only if Dectorio isn't installed. Should leave existing flooring intact. if not mods["Dectorio"] then - data.raw.item["wood"].place_as_tile = { - result = "bi-wood-floor", - condition_size = 4, - condition = { layers = { water_tile = true }} - } + data.raw.item["wood"].place_as_tile = { + result = "bi-wood-floor", + condition_size = 4, + condition = { layers = { water_tile = true } } + } end --- Make it so that the Base game tile "grass" can't be placed in blueprints --- New as of 0.16 -for _, tile in ipairs{"grass-1", "grass-2", "grass-3", "grass-4"} do - BI_Functions.lib.remove_from_blueprint(tile) +for _, tile in ipairs { "grass-1", "grass-2", "grass-3", "grass-4" } do + BI_Functions.lib.remove_from_blueprint(tile) end if mods["alien-biomes"] then - BioInd.writeDebug("Removing AB tiles from blueprints") - local patterns = { - "frozen%-snow%-%d", - "mineral%-aubergine%-dirt%-%d", - "mineral%-aubergine%-sand%-%d", - "mineral%-beige%-dirt%-%d", - "mineral%-beige%-sand%-%d", - "mineral%-black%-dirt%-%d", - "mineral%-black%-sand%-%d", - "mineral%-brown%-dirt%-%d", - "mineral%-brown%-sand%-%d", - "mineral%-cream%-dirt%-%d", - "mineral%-cream%-sand%-%d", - "mineral%-dustyrose%-dirt%-%d", - "mineral%-dustyrose%-sand%-%d", - "mineral%-grey%-dirt%-%d", - "mineral%-grey%-sand%-%d", - "mineral%-purple%-dirt%-%d", - "mineral%-purple%-sand%-%d", - "mineral%-red%-dirt%-%d", - "mineral%-red%-sand%-%d", - "mineral%-tan%-dirt%-%d", - "mineral%-tan%-sand%-%d", - "mineral%-violet%-dirt%-%d", - "mineral%-violet%-sand%-%d", - "mineral%-white%-dirt%-%d", - "mineral%-white%-sand%-%d", - "vegetation%-blue%-grass%-%d", - "vegetation%-green%-grass%-%d", - "vegetation%-mauve%-grass%-%d", - "vegetation%-olive%-grass%-%d", - "vegetation%-orange%-grass%-%d", - "vegetation%-purple%-grass%-%d", - "vegetation%-red%-grass%-%d", - "vegetation%-turquoise%-grass%-%d", - "vegetation%-violet%-grass%-%d", - "vegetation%-yellow%-grass%-%d", - "volcanic%-blue%-heat%-%d", - "volcanic%-green%-heat%-%d", - "volcanic%-orange%-heat%-%d", - "volcanic%-purple%-heat%-%d", - } - for tile_name, tile in pairs(data.raw.tile) do - for p, pattern in ipairs(patterns) do - if tile_name:match(pattern) then - BI_Functions.lib.remove_from_blueprint(tile) - break - end + BioInd.writeDebug("Removing AB tiles from blueprints") + local patterns = { + "frozen%-snow%-%d", + "mineral%-aubergine%-dirt%-%d", + "mineral%-aubergine%-sand%-%d", + "mineral%-beige%-dirt%-%d", + "mineral%-beige%-sand%-%d", + "mineral%-black%-dirt%-%d", + "mineral%-black%-sand%-%d", + "mineral%-brown%-dirt%-%d", + "mineral%-brown%-sand%-%d", + "mineral%-cream%-dirt%-%d", + "mineral%-cream%-sand%-%d", + "mineral%-dustyrose%-dirt%-%d", + "mineral%-dustyrose%-sand%-%d", + "mineral%-grey%-dirt%-%d", + "mineral%-grey%-sand%-%d", + "mineral%-purple%-dirt%-%d", + "mineral%-purple%-sand%-%d", + "mineral%-red%-dirt%-%d", + "mineral%-red%-sand%-%d", + "mineral%-tan%-dirt%-%d", + "mineral%-tan%-sand%-%d", + "mineral%-violet%-dirt%-%d", + "mineral%-violet%-sand%-%d", + "mineral%-white%-dirt%-%d", + "mineral%-white%-sand%-%d", + "vegetation%-blue%-grass%-%d", + "vegetation%-green%-grass%-%d", + "vegetation%-mauve%-grass%-%d", + "vegetation%-olive%-grass%-%d", + "vegetation%-orange%-grass%-%d", + "vegetation%-purple%-grass%-%d", + "vegetation%-red%-grass%-%d", + "vegetation%-turquoise%-grass%-%d", + "vegetation%-violet%-grass%-%d", + "vegetation%-yellow%-grass%-%d", + "volcanic%-blue%-heat%-%d", + "volcanic%-green%-heat%-%d", + "volcanic%-orange%-heat%-%d", + "volcanic%-purple%-heat%-%d", + } + for tile_name, tile in pairs(data.raw.tile) do + for p, pattern in ipairs(patterns) do + if tile_name:match(pattern) then + BI_Functions.lib.remove_from_blueprint(tile) + break + end + end end - end end --- Adds Solar Farm, Solar Plant, Musk Floor, Bio Accumulator and Substation to Tech tree if BI.Settings.BI_Solar_Additions then - if data.raw.technology["bob-solar-energy-2"] then - thxbob.lib.tech.add_recipe_unlock("bob-electric-energy-accumulators-3", "bi-bio-accumulator") - thxbob.lib.tech.add_recipe_unlock("electric-energy-distribution-2", "bi-large-substation") - thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-2", "bi-bio-solar-farm") - thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-2", "bi-solar-boiler-hidden-panel") - else - thxbob.lib.tech.add_recipe_unlock("electric-energy-accumulators", "bi-bio-accumulator") - thxbob.lib.tech.add_recipe_unlock("electric-energy-distribution-2", "bi-large-substation") - thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-bio-solar-farm") - thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-solar-boiler-hidden-panel") - end + if data.raw.technology["bob-solar-energy-2"] then + thxbob.lib.tech.add_recipe_unlock("bob-electric-energy-accumulators-3", "bi-bio-accumulator") + thxbob.lib.tech.add_recipe_unlock("electric-energy-distribution-2", "bi-large-substation") + thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-2", "bi-bio-solar-farm") + thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-2", "bi-solar-boiler-hidden-panel") + else + thxbob.lib.tech.add_recipe_unlock("electric-energy-accumulators", "bi-bio-accumulator") + thxbob.lib.tech.add_recipe_unlock("electric-energy-distribution-2", "bi-large-substation") + thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-bio-solar-farm") + thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-solar-boiler-hidden-panel") + end - if data.raw.technology["bob-solar-energy-3"] then - thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-3", "bi-solar-mat") - else - thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-solar-mat") - end + if data.raw.technology["bob-solar-energy-3"] then + thxbob.lib.tech.add_recipe_unlock("bob-solar-energy-3", "bi-solar-mat") + else + thxbob.lib.tech.add_recipe_unlock("solar-energy", "bi-solar-mat") + end - --- Electric redo if Bob' Electric - -- Huge Electric Pole - if data.raw.item["tinned-copper-cable"] then - thxbob.lib.recipe.remove_ingredient("bi-wooden-pole-huge", "wood") - thxbob.lib.recipe.add_new_ingredient("bi-wooden-pole-huge", { - type = "item", - name = "tinned-copper-cable", - amount = 15} - ) - end + --- Electric redo if Bob' Electric + -- Huge Electric Pole + if data.raw.item["tinned-copper-cable"] then + thxbob.lib.recipe.remove_ingredient("bi-wooden-pole-huge", "wood") + thxbob.lib.recipe.add_new_ingredient("bi-wooden-pole-huge", { + type = "item", + name = "tinned-copper-cable", + amount = 15 + } + ) + end - -- Solar Farm - if data.raw.item["solar-panel-large"] then - thxbob.lib.recipe.remove_ingredient("bi-bio-solar-farm", "solar-panel") - thxbob.lib.recipe.add_new_ingredient("bi-bio-solar-farm", { - type = "item", - name = "solar-panel-large", - amount = 30} - ) - end + -- Solar Farm + if data.raw.item["solar-panel-large"] then + thxbob.lib.recipe.remove_ingredient("bi-bio-solar-farm", "solar-panel") + thxbob.lib.recipe.add_new_ingredient("bi-bio-solar-farm", { + type = "item", + name = "solar-panel-large", + amount = 30 + } + ) + end - -- Huge Sub Station - if data.raw.item["substation-3"] then - thxbob.lib.recipe.remove_ingredient("bi-large-substation", "substation") - thxbob.lib.recipe.add_new_ingredient("bi-large-substation", { - type = "item", - name = "substation-3", - amount = 6} - ) - end + -- Huge Sub Station + if data.raw.item["substation-3"] then + thxbob.lib.recipe.remove_ingredient("bi-large-substation", "substation") + thxbob.lib.recipe.add_new_ingredient("bi-large-substation", { + type = "item", + name = "substation-3", + amount = 6 + } + ) + end - if data.raw.item["electrum-alloy"] then - thxbob.lib.recipe.remove_ingredient("bi-large-substation", "steel-plate") - thxbob.lib.recipe.add_new_ingredient("bi-large-substation", { - type = "item", - name = "electrum-alloy", - amount = 10} - ) - end + if data.raw.item["electrum-alloy"] then + thxbob.lib.recipe.remove_ingredient("bi-large-substation", "steel-plate") + thxbob.lib.recipe.add_new_ingredient("bi-large-substation", { + type = "item", + name = "electrum-alloy", + amount = 10 + } + ) + end - -- Huge Accumulator - if data.raw.item["large-accumulator-2"] then - thxbob.lib.recipe.remove_ingredient("bi-bio-accumulator", "accumulator") - thxbob.lib.recipe.add_new_ingredient("bi-bio-accumulator", { - type = "item", - name = "large-accumulator", - amount = 30} - ) - end + -- Huge Accumulator + if data.raw.item["large-accumulator-2"] then + thxbob.lib.recipe.remove_ingredient("bi-bio-accumulator", "accumulator") + thxbob.lib.recipe.add_new_ingredient("bi-bio-accumulator", { + type = "item", + name = "large-accumulator", + amount = 30 + } + ) + end - if data.raw.item["aluminium-plate"] then - thxbob.lib.recipe.remove_ingredient("bi-bio-accumulator", "copper-cable") - thxbob.lib.recipe.add_new_ingredient("bi-bio-accumulator", { - type = "item", - name = "aluminium-plate", - amount = 50} - ) - end + if data.raw.item["aluminium-plate"] then + thxbob.lib.recipe.remove_ingredient("bi-bio-accumulator", "copper-cable") + thxbob.lib.recipe.add_new_ingredient("bi-bio-accumulator", { + type = "item", + name = "aluminium-plate", + amount = 50 + } + ) + end - -- Solar Mat - if data.raw.item["aluminium-plate"] then - thxbob.lib.recipe.remove_ingredient("bi-solar-mat", "steel-plate") - thxbob.lib.recipe.add_new_ingredient("bi-solar-mat", { - type = "item", - name = "aluminium-plate", - amount = 1} - ) - end + -- Solar Mat + if data.raw.item["aluminium-plate"] then + thxbob.lib.recipe.remove_ingredient("bi-solar-mat", "steel-plate") + thxbob.lib.recipe.add_new_ingredient("bi-solar-mat", { + type = "item", + name = "aluminium-plate", + amount = 1 + } + ) + end - if data.raw.item["silicon-wafer"] then - thxbob.lib.recipe.remove_ingredient("bi-solar-mat", "copper-cable") - thxbob.lib.recipe.add_new_ingredient("bi-solar-mat", { - type = "item", - name = "silicon-wafer", - amount = 4} - ) - end + if data.raw.item["silicon-wafer"] then + thxbob.lib.recipe.remove_ingredient("bi-solar-mat", "copper-cable") + thxbob.lib.recipe.add_new_ingredient("bi-solar-mat", { + type = "item", + name = "silicon-wafer", + amount = 4 + } + ) + end - -- Solar Boiler / Plant - if data.raw.item["angels-electric-boiler"] then - thxbob.lib.recipe.remove_ingredient("bi-solar-boiler-hidden-panel", "boiler") - thxbob.lib.recipe.add_new_ingredient("bi-solar-boiler-hidden-panel", { - type = "item", - name = "angels-electric-boiler", - amount = 1} - ) - end + -- Solar Boiler / Plant + if data.raw.item["angels-electric-boiler"] then + thxbob.lib.recipe.remove_ingredient("bi-solar-boiler-hidden-panel", "boiler") + thxbob.lib.recipe.add_new_ingredient("bi-solar-boiler-hidden-panel", { + type = "item", + name = "angels-electric-boiler", + amount = 1 + } + ) + end end require("prototypes.Bio_Farm.compatible_recipes") -- Bob and Angels mesh @@ -244,99 +253,101 @@ require("prototypes.Bio_Farm.technology2") -- Replace fertilizer/advanced fertilizer + water with fluid fertilizers in Bio garden recipes! BioInd.show("data-updates.lua -- BI.Settings.BI_Easy_Bio_Gardens", BI.Settings.BI_Easy_Bio_Gardens) if BI.Settings.BI_Easy_Bio_Gardens then - BioInd.writeDebug("Must create fluid fertilizers!") - require("prototypes.Bio_Garden.fluid_fertilizer") + BioInd.writeDebug("Must create fluid fertilizers!") + require("prototypes.Bio_Garden.fluid_fertilizer") end -- Blacklist bioreactor in Assembler Pipe Passthrough if mods["assembler-pipe-passthrough"] then - appmod.blacklist['bi-bio-reactor'] = true + appmod.blacklist['bi-bio-reactor'] = true end -- Adds Bio recipes if BI.Settings.BI_Bio_Fuel then thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-cellulose-1") - thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-cellulose-2") + thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-cellulose-2") - -- Remove unlock for biomass-1 and add it again so all biomass recipes are next to each - -- other in the preview of technology unlocks! - thxbob.lib.tech.remove_recipe_unlock("bi-tech-advanced-biotechnology", "bi-biomass-1") - for u, unlock in ipairs({ - "bi-biomass-1", "bi-biomass-2", "bi-biomass-3", - "bi-battery", - "bi-biomass-conversion-1", "bi-biomass-conversion-2", "bi-biomass-conversion-3", "bi-biomass-conversion-4", - "bi-acid", "bi-bio-boiler" - }) do - thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", unlock) - end + -- Remove unlock for biomass-1 and add it again so all biomass recipes are next to each + -- other in the preview of technology unlocks! + thxbob.lib.tech.remove_recipe_unlock("bi-tech-advanced-biotechnology", "bi-biomass-1") + for u, unlock in ipairs({ + "bi-biomass-1", "bi-biomass-2", "bi-biomass-3", + "bi-battery", + "bi-biomass-conversion-1", "bi-biomass-conversion-2", "bi-biomass-conversion-3", "bi-biomass-conversion-4", + "bi-acid", "bi-bio-boiler" + }) do + thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", unlock) + end - -- Added for 0.17.49/0.18.17 (changed for 0.18.29) + -- Added for 0.17.49/0.18.17 (changed for 0.18.29) thxbob.lib.tech.add_recipe_unlock("bi-tech-coal-processing-2", "bi-basic-gas-processing") - if mods["angelspetrochem"] then - thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-sulfur-angels") - else - thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-sulfur") - end + if mods["angelspetrochem"] then + thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-sulfur-angels") else - thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", {type = "item", name = "fertilizer", amount = 50}) - thxbob.lib.recipe.remove_ingredient ("bi-adv-fertilizer-2", "fertilizer") - thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-2", {type = "item", name = "fertilizer", amount = 30}) + thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-sulfur") + end +else + thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", { type = "item", name = "fertilizer", amount = 50 }) + thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-2", "fertilizer") + thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-2", { type = "item", name = "fertilizer", amount = 30 }) end --- if the Alien Artifact is in the game, use it for some recipes if data.raw.item["alien-artifact"] then - --- Advanced fertilizer will use Alien Artifact - thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "bi-biomass") - thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", { - type = "item", - name = "alien-artifact", - amount = 5} - ) - thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-adv-fertilizer-1") + --- Advanced fertilizer will use Alien Artifact + thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "bi-biomass") + thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", { + type = "item", + name = "alien-artifact", + amount = 5 + } + ) + thxbob.lib.tech.add_recipe_unlock("bi-tech-advanced-biotechnology", "bi-adv-fertilizer-1") end ------- Adds a Mk3 recipe for wood if you're playing with Natural Evolution Buildings if mods["Natural_Evolution_Buildings"] then - thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "bi-biomass") - thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "alien-artifact") - thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", { - type = "fluid", - name = "NE_enhanced-nutrient-solution", - amount = 50} - ) + thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "bi-biomass") + thxbob.lib.recipe.remove_ingredient("bi-adv-fertilizer-1", "alien-artifact") + thxbob.lib.recipe.add_new_ingredient("bi-adv-fertilizer-1", { + type = "fluid", + name = "NE_enhanced-nutrient-solution", + amount = 50 + } + ) end ------------ Support for Bob's Greenhouse if data.raw["item"]["bob-greenhouse"] then - data.raw["item"]["seedling"].place_result = "seedling" - data.raw["item"]["seedling"].icon = ICONPATH .. "Seedling.png" - data.raw["item"]["seedling"].icon_size = 64 - data.raw["item"]["fertilizer"].icon = ICONPATH .. "fertilizer.png" - data.raw["item"]["fertilizer"].icon_size = 64 + data.raw["item"]["seedling"].place_result = "seedling" + data.raw["item"]["seedling"].icon = ICONPATH .. "Seedling.png" + data.raw["item"]["seedling"].icon_size = 64 + data.raw["item"]["fertilizer"].icon = ICONPATH .. "fertilizer.png" + data.raw["item"]["fertilizer"].icon_size = 64 - data.raw["item"]["fertilizer"].place_as_tile = { - result = BioInd.AB_tiles() and "vegetation-green-grass-3" or "grass-3", - condition_size = 1, - condition = { layers = { water_tile = true }} - } + data.raw["item"]["fertilizer"].place_as_tile = { + result = BioInd.AB_tiles() and "vegetation-green-grass-3" or "grass-3", + condition_size = 1, + condition = { layers = { water_tile = true } } + } end if settings.startup["angels-use-angels-barreling"] and settings.startup["angels-use-angels-barreling"].value then - data.raw.technology["bi-tech-fertilizer"].prerequisites = { - "bi-tech-bio-farming", - -- AND ( - "water-treatment", -- sulfur - -- OR - "angels-fluid-barreling", -- barreling (needed 'water-treatment' as prerequisites) - -- ) - } + data.raw.technology["bi-tech-fertilizer"].prerequisites = { + "bi-tech-bio-farming", + -- AND ( + "water-treatment", -- sulfur + -- OR + "angels-fluid-barreling", -- barreling (needed 'water-treatment' as prerequisites) + -- ) + } end @@ -348,138 +359,138 @@ if mods["angelspetrochem"] then data.raw.item["pellet-coke"].fuel_top_speed_multiplier = 1.2 data.raw.recipe["pellet-coke"].category = "biofarm-mod-smelting" - thxbob.lib.tech.remove_recipe_unlock ("angels-coal-processing-2", "pellet-coke") + thxbob.lib.tech.remove_recipe_unlock("angels-coal-processing-2", "pellet-coke") thxbob.lib.tech.add_recipe_unlock("angels-coal-cracking", "pellet-coke") end if data.raw.item["ash"] and mods["pycoalprocessing"] then - thxbob.lib.recipe.replace_ingredient ("bi-fertilizer-2", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-fertilizer-2", "bi-ash", "ash") - if mods["angelsrefining"] then - thxbob.lib.recipe.replace_ingredient ("bi-slag-slurry", "bi-ash", "ash") - end - - thxbob.lib.recipe.replace_ingredient ("bi-seed-2", "bi-ash", "ash") - thxbob.lib.recipe.replace_ingredient ("bi-seedling-2", "bi-ash", "ash") - thxbob.lib.recipe.replace_ingredient ("bi-logs-2", "bi-ash", "ash") - - data.raw.recipe["bi-ash-1"].result = "ash" - data.raw.recipe["bi-ash-2"].result = "ash" - - thxbob.lib.recipe.replace_ingredient ("bi-stone-brick", "bi-ash", "ash") - thxbob.lib.recipe.replace_ingredient ("bi-fertilizer-1", "bi-ash", "ash") - - if BI.Settings.BI_Bio_Fuel then - thxbob.lib.recipe.replace_ingredient ("bi-biomass-3", "bi-ash", "ash") - thxbob.lib.recipe.replace_ingredient ("bi-sulfur", "bi-ash", "ash") - thxbob.lib.recipe.replace_ingredient ("bi-sulfur-angels", "bi-ash", "ash") - - data.raw.recipe["bi-sulfur"].icon = ICONPATH .. "py_bio_sulfur.png" - data.raw.recipe["bi-sulfur"].icon_size = 64 - end - - data.raw.item["bi-ash"] = nil - data.raw.recipe["bi-ash-1"].icon = "__pycoalprocessinggraphics__/graphics/icons/ash.png" - data.raw.recipe["bi-ash-1"].icon_size = 32 - data.raw.recipe["bi-ash-2"].icon = "__pycoalprocessinggraphics__/graphics/icons/ash.png" - data.raw.recipe["bi-ash-2"].icon_size = 32 - - -- Use ash icon from pycoalprocessing in icons of recipes using ash - data.raw.recipe["bi-seed-2"].icon = ICONPATH .. "py_bio_seed2.png" - data.raw.recipe["bi-seed-2"].icon_size = 64 - data.raw.recipe["bi-seedling-2"].icon = ICONPATH .. "py_Seedling2.png" - data.raw.recipe["bi-seedling-2"].icon_size = 64 - data.raw.recipe["bi-logs-2"].icon = ICONPATH .. "py_raw-wood-mk2.png" - data.raw.recipe["bi-logs-2"].icon_size = 64 - data.raw.recipe["bi-ash-1"].icon = ICONPATH .. "py_ash_raw-wood.png" - data.raw.recipe["bi-ash-1"].icon_size = 64 - data.raw.recipe["bi-ash-2"].icon = ICONPATH .. "py_ash_woodpulp.png" - data.raw.recipe["bi-ash-2"].icon_size = 64 - data.raw.recipe["bi-stone-brick"].icon = ICONPATH .. "py_bi_stone_brick.png" - data.raw.recipe["bi-stone-brick"].icon_size = 64 + if mods["angelsrefining"] then + thxbob.lib.recipe.replace_ingredient("bi-slag-slurry", "bi-ash", "ash") end + thxbob.lib.recipe.replace_ingredient("bi-seed-2", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-seedling-2", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-logs-2", "bi-ash", "ash") + + data.raw.recipe["bi-ash-1"].result = "ash" + data.raw.recipe["bi-ash-2"].result = "ash" + + thxbob.lib.recipe.replace_ingredient("bi-stone-brick", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-fertilizer-1", "bi-ash", "ash") + + if BI.Settings.BI_Bio_Fuel then + thxbob.lib.recipe.replace_ingredient("bi-biomass-3", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-sulfur", "bi-ash", "ash") + thxbob.lib.recipe.replace_ingredient("bi-sulfur-angels", "bi-ash", "ash") + + data.raw.recipe["bi-sulfur"].icon = ICONPATH .. "py_bio_sulfur.png" + data.raw.recipe["bi-sulfur"].icon_size = 64 + end + + data.raw.item["bi-ash"] = nil + data.raw.recipe["bi-ash-1"].icon = "__pycoalprocessinggraphics__/graphics/icons/ash.png" + data.raw.recipe["bi-ash-1"].icon_size = 32 + data.raw.recipe["bi-ash-2"].icon = "__pycoalprocessinggraphics__/graphics/icons/ash.png" + data.raw.recipe["bi-ash-2"].icon_size = 32 + + -- Use ash icon from pycoalprocessing in icons of recipes using ash + data.raw.recipe["bi-seed-2"].icon = ICONPATH .. "py_bio_seed2.png" + data.raw.recipe["bi-seed-2"].icon_size = 64 + data.raw.recipe["bi-seedling-2"].icon = ICONPATH .. "py_Seedling2.png" + data.raw.recipe["bi-seedling-2"].icon_size = 64 + data.raw.recipe["bi-logs-2"].icon = ICONPATH .. "py_raw-wood-mk2.png" + data.raw.recipe["bi-logs-2"].icon_size = 64 + data.raw.recipe["bi-ash-1"].icon = ICONPATH .. "py_ash_raw-wood.png" + data.raw.recipe["bi-ash-1"].icon_size = 64 + data.raw.recipe["bi-ash-2"].icon = ICONPATH .. "py_ash_woodpulp.png" + data.raw.recipe["bi-ash-2"].icon_size = 64 + data.raw.recipe["bi-stone-brick"].icon = ICONPATH .. "py_bi_stone_brick.png" + data.raw.recipe["bi-stone-brick"].icon_size = 64 +end + ----- If Bob's bobrevamp, then ---- if mods["bobrevamp"] then - thxbob.lib.tech.remove_recipe_unlock ("bi-tech-coal-processing-1", "bi-solid-fuel") - thxbob.lib.tech.add_recipe_unlock("solid-fuel", "bi-solid-fuel") + thxbob.lib.tech.remove_recipe_unlock("bi-tech-coal-processing-1", "bi-solid-fuel") + thxbob.lib.tech.add_recipe_unlock("solid-fuel", "bi-solid-fuel") end ----- If Simple Silicon is active, add solar cell to Musk floor (solar mat) recipe if mods["SimpleSilicon"] then thxbob.lib.recipe.add_new_ingredient("bi-solar-mat", { - type = "item", - name = "SiSi-solar-cell", - amount = 1 - }) + type = "item", + name = "SiSi-solar-cell", + amount = 1 + }) end -- We may need liquid air and nitrogen -- but not if any of the following mods is active! - local ICONPATH = BioInd.modRoot .. "/graphics/icons/" +local ICONPATH = BioInd.modRoot .. "/graphics/icons/" - -- We only want to create nitrogen if it doesn't exist yet. We then also need to create - -- liquid air. - if not data.raw.fluid["nitrogen"] then +-- We only want to create nitrogen if it doesn't exist yet. We then also need to create +-- liquid air. +if not data.raw.fluid["nitrogen"] then data:extend({ - { - type = "fluid", - name = "nitrogen", - icon = ICONPATH .. "nitrogen.png", - icon_size = 64, - icons = { - { + { + type = "fluid", + name = "nitrogen", icon = ICONPATH .. "nitrogen.png", icon_size = 64, - icon_mipmaps = 1, - } + icons = { + { + icon = ICONPATH .. "nitrogen.png", + icon_size = 64, + icon_mipmaps = 1, + } + }, + default_temperature = 25, + gas_temperature = -210, + max_temperature = 100, + heat_capacity = "1kJ", + base_color = { r = 0.0, g = 0.0, b = 1.0 }, + flow_color = { r = 0.0, g = 0.0, b = 1.0 }, + pressure_to_speed_ratio = 0.4, + flow_to_energy_ratio = 0.59, + order = "a[fluid]-b[nitrogen]" }, - default_temperature = 25, - gas_temperature = -210, - max_temperature = 100, - heat_capacity = "1kJ", - base_color = {r = 0.0, g = 0.0, b = 1.0}, - flow_color = {r = 0.0, g = 0.0, b = 1.0}, - pressure_to_speed_ratio = 0.4, - flow_to_energy_ratio = 0.59, - order = "a[fluid]-b[nitrogen]" - }, }) - BioInd.writeDebug("Made recipe for \"nitrogen\".") + BioInd.writeDebug("Made recipe for \"nitrogen\".") if not data.raw.fluid["liquid-air"] then - data:extend({ - { - type = "fluid", - name = "liquid-air", - icon = ICONPATH .. "liquid-air.png", - icon_size = 64, - icons = { + data:extend({ { - icon = ICONPATH .. "liquid-air.png", - icon_size = 64, - icon_mipmaps = 1, - } - }, - default_temperature = 25, - gas_temperature = -100, - max_temperature = 100, - heat_capacity = "1kJ", - base_color = {r = 0, g = 0, b = 0}, - flow_color = {r = 0.5, g = 1.0, b = 1.0}, - pressure_to_speed_ratio = 0.4, - flow_to_energy_ratio = 0.59, - order = "a[fluid]-b[liquid-air]" - }, - }) - BioInd.writeDebug("Made recipe for \"liquid-air\".") + type = "fluid", + name = "liquid-air", + icon = ICONPATH .. "liquid-air.png", + icon_size = 64, + icons = { + { + icon = ICONPATH .. "liquid-air.png", + icon_size = 64, + icon_mipmaps = 1, + } + }, + default_temperature = 25, + gas_temperature = -100, + max_temperature = 100, + heat_capacity = "1kJ", + base_color = { r = 0, g = 0, b = 0 }, + flow_color = { r = 0.5, g = 1.0, b = 1.0 }, + pressure_to_speed_ratio = 0.4, + flow_to_energy_ratio = 0.59, + order = "a[fluid]-b[liquid-air]" + }, + }) + BioInd.writeDebug("Made recipe for \"liquid-air\".") end - -- Recipes for "bi-liquid-air" and "bi-nitrogen" aren't needed! - else + -- Recipes for "bi-liquid-air" and "bi-nitrogen" aren't needed! +else -- Remove recipe unlocks thxbob.lib.tech.remove_recipe_unlock("bi-tech-fertilizer", "bi-liquid-air") thxbob.lib.tech.remove_recipe_unlock("bi-tech-fertilizer", "bi-nitrogen") @@ -487,42 +498,42 @@ end -- Replace liquid air with oxygen (from Krastorio/K2) in recipes for Algae Biomass 2 and 3 if data.raw.fluid.oxygen then - thxbob.lib.recipe.replace_ingredient("bi-biomass-2", "liquid-air", "oxygen") - thxbob.lib.recipe.replace_ingredient("bi-biomass-3", "liquid-air", "oxygen") - BioInd.writeDebug("Replaced \"liquid-air\" with \"oxygen\" in recipes \"bi-biomass-2\" and \"bi-biomass-3\"") - -- Perhaps there is no oxygen? But there's nitrogen for sure, so we fall back to that! + thxbob.lib.recipe.replace_ingredient("bi-biomass-2", "liquid-air", "oxygen") + thxbob.lib.recipe.replace_ingredient("bi-biomass-3", "liquid-air", "oxygen") + BioInd.writeDebug("Replaced \"liquid-air\" with \"oxygen\" in recipes \"bi-biomass-2\" and \"bi-biomass-3\"") + -- Perhaps there is no oxygen? But there's nitrogen for sure, so we fall back to that! elseif data.raw.fluid.nitrogen then - thxbob.lib.recipe.replace_ingredient("bi-biomass-2", "liquid-air", "nitrogen") - thxbob.lib.recipe.replace_ingredient("bi-biomass-3", "liquid-air", "nitrogen") - BioInd.writeDebug("Replaced \"liquid-air\" with \"nitrogen\" in recipes \"bi-biomass-2\" and \"bi-biomass-3\"") + thxbob.lib.recipe.replace_ingredient("bi-biomass-2", "liquid-air", "nitrogen") + thxbob.lib.recipe.replace_ingredient("bi-biomass-3", "liquid-air", "nitrogen") + BioInd.writeDebug("Replaced \"liquid-air\" with \"nitrogen\" in recipes \"bi-biomass-2\" and \"bi-biomass-3\"") end -- Remove recipes for these fluids data.raw.recipe["bi-liquid-air"] = nil data.raw.recipe["bi-nitrogen"] = nil BioInd.writeDebug("Removed recipes for \"nitrogen\" and \"liquid air\".") - end +end -- Moved here from data-final-fixes.lua for 0.18.34/1.1.4! (Fixes https://mods.factorio.com/mod/Bio_Industries/discussion/5ff570bd916993002371332a) ---- Game Tweaks ---- Recipes if BI.Settings.BI_Game_Tweaks_Recipe then - --- Concrete Recipe Tweak - thxbob.lib.recipe.remove_ingredient("concrete", "iron-ore") - thxbob.lib.recipe.add_new_ingredient("concrete", {type = "item", name = "iron-stick", amount = 2}) + --- Concrete Recipe Tweak + thxbob.lib.recipe.remove_ingredient("concrete", "iron-ore") + thxbob.lib.recipe.add_new_ingredient("concrete", { type = "item", name = "iron-stick", amount = 2 }) - --- Stone Wall - thxbob.lib.recipe.add_new_ingredient("stone-wall", {type = "item", name = "iron-stick", amount = 1}) + --- Stone Wall + thxbob.lib.recipe.add_new_ingredient("stone-wall", { type = "item", name = "iron-stick", amount = 1 }) - --- Rail (Remove Stone and Add Crushed Stone) - if data.raw.item["stone-crushed"] then - thxbob.lib.recipe.remove_ingredient("rail", "stone") - thxbob.lib.recipe.add_new_ingredient("rail", {type = "item", name = "stone-crushed", amount = 6}) - thxbob.lib.recipe.remove_ingredient("bi-rail-wood", "stone") - thxbob.lib.recipe.add_new_ingredient("bi-rail-wood", {type = "item", name = "stone-crushed", amount = 6}) - end + --- Rail (Remove Stone and Add Crushed Stone) + if data.raw.item["stone-crushed"] then + thxbob.lib.recipe.remove_ingredient("rail", "stone") + thxbob.lib.recipe.add_new_ingredient("rail", { type = "item", name = "stone-crushed", amount = 6 }) + thxbob.lib.recipe.remove_ingredient("bi-rail-wood", "stone") + thxbob.lib.recipe.add_new_ingredient("bi-rail-wood", { type = "item", name = "stone-crushed", amount = 6 }) + end - -- vanilla rail recipe update - thxbob.lib.recipe.add_new_ingredient("rail", {type = "item", name = "concrete", amount = 6}) + -- vanilla rail recipe update + thxbob.lib.recipe.add_new_ingredient("rail", { type = "item", name = "concrete", amount = 6 }) end @@ -531,49 +542,48 @@ end ---- Game Tweaks ---- Disassemble Recipes require("prototypes.Bio_Tweaks.recipe") if BI.Settings.BI_Game_Tweaks_Disassemble then - for recipe, tech in pairs({ - ["bi-burner-mining-drill-disassemble"] = "automation-2", - ["bi-burner-inserter-disassemble"] = "automation-2", - ["bi-long-handed-inserter-disassemble"] = "automation-2", - ["bi-stone-furnace-disassemble"] = "automation-2", - ["bi-steel-furnace-disassemble"] = "advanced-material-processing", - }) do - thxbob.lib.tech.add_recipe_unlock(tech, recipe) - end - + for recipe, tech in pairs({ + ["bi-burner-mining-drill-disassemble"] = "automation-2", + ["bi-burner-inserter-disassemble"] = "automation-2", + ["bi-long-handed-inserter-disassemble"] = "automation-2", + ["bi-stone-furnace-disassemble"] = "automation-2", + ["bi-steel-furnace-disassemble"] = "advanced-material-processing", + }) do + thxbob.lib.tech.add_recipe_unlock(tech, recipe) + end end --- Enable Productivity in Recipes for recipe, r in pairs(data.raw.recipe) do - for p, pattern in ipairs({ - "bi%-acid", - "bi%-battery", - "bi%-biomass%-%d", - "bi%-biomass%-conversion%-%d", - "bi%-cellulose%-%d", - "bi%-crushed%-stone%-%d", - "bi%-liquid%-air", - "bi%-logs%-%d", - "bi%-nitrogen", - "bi%-plastic%-%d", - "bi%-press%-wood", - "bi%-resin%-pulp", - "bi%-resin%-wood", - "bi%-seed%-%d", - "bi%-seedling%-%d", - "bi%-stone%-brick", - "bi%-sulfur", - "bi%-sulfur%-angels", - "bi%-wood%-from%-pulp", - "bi%-woodpulp", - -- Added for 0.17.49/0.18.17 - "bi%-basic%-gas%-processing", - }) do - if recipe:match(pattern) then - BI_Functions.lib.allow_productivity(recipe) - break + for p, pattern in ipairs({ + "bi%-acid", + "bi%-battery", + "bi%-biomass%-%d", + "bi%-biomass%-conversion%-%d", + "bi%-cellulose%-%d", + "bi%-crushed%-stone%-%d", + "bi%-liquid%-air", + "bi%-logs%-%d", + "bi%-nitrogen", + "bi%-plastic%-%d", + "bi%-press%-wood", + "bi%-resin%-pulp", + "bi%-resin%-wood", + "bi%-seed%-%d", + "bi%-seedling%-%d", + "bi%-stone%-brick", + "bi%-sulfur", + "bi%-sulfur%-angels", + "bi%-wood%-from%-pulp", + "bi%-woodpulp", + -- Added for 0.17.49/0.18.17 + "bi%-basic%-gas%-processing", + }) do + if recipe:match(pattern) then + BI_Functions.lib.allow_productivity(recipe) + break + end end - end end @@ -583,10 +593,10 @@ end -- Make resistances for each damage type local resistances = {} for damage, d in pairs(data.raw["damage-type"]) do - resistances[#resistances + 1] = { - type = damage, - percent = 100 - } + resistances[#resistances + 1] = { + type = damage, + percent = 100 + } end -- Add resistances to prototypes @@ -594,12 +604,12 @@ end -- use compound_entities.hidden!) local h_type for h_key, h_names in pairs(BI.hidden_entities.types) do - h_type = BioInd.HE_map[h_key] - for h_name, h in pairs(h_names) do - data.raw[h_type][h_name].resistances = resistances - BioInd.writeDebug("Added resistances to %s (%s): %s", - {h_name, h_type, data.raw[h_type][h_name].resistances}) - end + h_type = BioInd.HE_map[h_key] + for h_name, h in pairs(h_names) do + data.raw[h_type][h_name].resistances = resistances + BioInd.writeDebug("Added resistances to %s (%s): %s", + { h_name, h_type, data.raw[h_type][h_name].resistances }) + end end -- Adjust resistances for radar of the terraformers. Unlike the other hidden parts @@ -609,11 +619,11 @@ local compound = BioInd.compound_entities["bi-arboretum"] local b = compound.base local r = compound.hidden.radar if b and r then - local resistances = data.raw[b.type][b.name].resistances - if resistances then - data.raw[r.type][r.name].resistances = util.table.deepcopy(resistances) - BioInd.writeDebug("Copied resistances from %s to %s!", {b.name, r.name}) - end + local resistances = data.raw[b.type][b.name].resistances + if resistances then + data.raw[r.type][r.name].resistances = util.table.deepcopy(resistances) + BioInd.writeDebug("Copied resistances from %s to %s!", { b.name, r.name }) + end end ------------------------------------------------------------------------------------ -- Omnifluid will be confused by our bi-solar-boiler (the compound boiler + solar @@ -621,64 +631,64 @@ end BioInd.show("Omnifluid is active", mods["omnimatter_fluid"] or "false") BioInd.show("forbidden_boilers", forbidden_boilers) -if mods["omnimatter_fluid"] then - forbidden_boilers = forbidden_boilers or {} - forbidden_boilers["bi-solar-boiler"] = true +if mods["omnimatter_fluid"] then + forbidden_boilers = forbidden_boilers or {} + forbidden_boilers["bi-solar-boiler"] = true end -BioInd.writeDebug("OMNIFLUID Test! forbidden_boilers = %s", {forbidden_boilers}) +BioInd.writeDebug("OMNIFLUID Test! forbidden_boilers = %s", { forbidden_boilers }) ------------------------------------------------------------------------------------ -- If the Py-Suite is installed, we move our coal-processing unlocks to their techs! local check, set if mods["pyrawores"] then - -- Are all techs there? - check = true - for i = 1, 3 do - if not data.raw.technology["coal-mk0" .. i] then - check = false - break - end - end - - if check then - set = true - local unlocks = require("prototypes.Bio_Farm.coal_processing") + -- Are all techs there? + check = true for i = 1, 3 do - for u, unlock in ipairs(unlocks[i]) do - thxbob.lib.tech.add_recipe_unlock("coal-mk0" .. i, unlock.recipe) -BioInd.writeDebug("Added recipe %s to unlocks of %s", {unlock.recipe, "coal-mk0" .. i}) - end + if not data.raw.technology["coal-mk0" .. i] then + check = false + break + end + end + + if check then + set = true + local unlocks = require("prototypes.Bio_Farm.coal_processing") + for i = 1, 3 do + for u, unlock in ipairs(unlocks[i]) do + thxbob.lib.tech.add_recipe_unlock("coal-mk0" .. i, unlock.recipe) + BioInd.writeDebug("Added recipe %s to unlocks of %s", { unlock.recipe, "coal-mk0" .. i }) + end + end end - end end -- PyRawOres has priority! if mods["pycoalprocessing"] and not set then - -- Are all techs there? - check = true - for i = 1, 3 do - if not data.raw.technology["coal-processing-" .. i] then - check = false - break - end - end - - if check then - set = true - local unlocks = require("prototypes.Bio_Farm.coal_processing") + -- Are all techs there? + check = true for i = 1, 3 do - for u, unlock in ipairs(unlocks[i]) do - thxbob.lib.tech.add_recipe_unlock("coal-processing-" .. i, unlock.recipe) -BioInd.writeDebug("Added recipe %s to unlocks of %s", {unlock.recipe, "coal-processing-" .. i}) - end + if not data.raw.technology["coal-processing-" .. i] then + check = false + break + end + end + + if check then + set = true + local unlocks = require("prototypes.Bio_Farm.coal_processing") + for i = 1, 3 do + for u, unlock in ipairs(unlocks[i]) do + thxbob.lib.tech.add_recipe_unlock("coal-processing-" .. i, unlock.recipe) + BioInd.writeDebug("Added recipe %s to unlocks of %s", { unlock.recipe, "coal-processing-" .. i }) + end + end end - end end if set then - for i = 1, 3 do - data.raw.technology["bi-tech-coal-processing-" .. i] = nil -BioInd.writeDebug("Removed technology " .. "bi-tech-coal-processing-" .. i) - end + for i = 1, 3 do + data.raw.technology["bi-tech-coal-processing-" .. i] = nil + BioInd.writeDebug("Removed technology " .. "bi-tech-coal-processing-" .. i) + end end -- Compatibility with Industrial Revolution diff --git a/Bio_Industries_2/data.lua b/Bio_Industries_2/data.lua index 7cf94b0..aab3060 100644 --- a/Bio_Industries_2/data.lua +++ b/Bio_Industries_2/data.lua @@ -10,93 +10,92 @@ if not thxbob then thxbob = {} end if not thxbob.lib then thxbob.lib = {} end for var, name in pairs({ - Bio_Cannon = "BI_Bio_Cannon", - BI_Bio_Fuel = "BI_Bio_Fuel", - BI_Easy_Bio_Gardens = "BI_Easy_Bio_Gardens", - BI_Bigger_Wooden_Chests = "BI_Bigger_Wooden_Chests", - BI_Game_Tweaks_Stack_Size = "BI_Game_Tweaks_Stack_Size", - BI_Game_Tweaks_Recipe = "BI_Game_Tweaks_Recipe", - BI_Game_Tweaks_Tree = "BI_Game_Tweaks_Tree", - BI_Game_Tweaks_Small_Tree_Collisionbox = "BI_Game_Tweaks_Small_Tree_Collisionbox", - BI_Game_Tweaks_Player = "BI_Game_Tweaks_Player", - BI_Game_Tweaks_Disassemble = "BI_Game_Tweaks_Disassemble", - BI_Game_Tweaks_Bot = "BI_Game_Tweaks_Bot", - BI_Solar_Additions = "BI_Solar_Additions" + Bio_Cannon = "BI_Bio_Cannon", + BI_Bio_Fuel = "BI_Bio_Fuel", + BI_Easy_Bio_Gardens = "BI_Easy_Bio_Gardens", + BI_Bigger_Wooden_Chests = "BI_Bigger_Wooden_Chests", + BI_Game_Tweaks_Stack_Size = "BI_Game_Tweaks_Stack_Size", + BI_Game_Tweaks_Recipe = "BI_Game_Tweaks_Recipe", + BI_Game_Tweaks_Tree = "BI_Game_Tweaks_Tree", + BI_Game_Tweaks_Small_Tree_Collisionbox = "BI_Game_Tweaks_Small_Tree_Collisionbox", + BI_Game_Tweaks_Player = "BI_Game_Tweaks_Player", + BI_Game_Tweaks_Disassemble = "BI_Game_Tweaks_Disassemble", + BI_Game_Tweaks_Bot = "BI_Game_Tweaks_Bot", + BI_Solar_Additions = "BI_Solar_Additions" }) do - BI.Settings[var] = BioInd.get_startup_setting(name) + BI.Settings[var] = BioInd.get_startup_setting(name) end --- Help Files -require ("libs.item-functions") -- From Bob's Libary -require ("libs.recipe-functions") -- From Bob's Libary -require ("libs.technology-functions") -- From Bob's Libary -require ("libs.functions") -- From Bob's Libary -require ("libs.category-functions") -- From Bob's Libary -require ("libs.bi_functions") -- Functions +require("libs.item-functions") -- From Bob's Libary +require("libs.recipe-functions") -- From Bob's Libary +require("libs.technology-functions") -- From Bob's Libary +require("libs.functions") -- From Bob's Libary +require("libs.category-functions") -- From Bob's Libary +require("libs.bi_functions") -- Functions -require ("prototypes.category") +require("prototypes.category") --- Bio Farm -require ("prototypes.Bio_Farm.entities") -require ("prototypes.Bio_Farm.item") -require ("prototypes.Bio_Farm.recipe") -require ("prototypes.Bio_Farm.liquids") -require ("prototypes.Bio_Farm.recipe-categories") -require ("prototypes.Bio_Farm.pipeConnectors") -require ("prototypes.Bio_Farm.technology") -require ("prototypes.Bio_Farm.tree_entities") +require("prototypes.Bio_Farm.entities") +require("prototypes.Bio_Farm.item") +require("prototypes.Bio_Farm.recipe") +require("prototypes.Bio_Farm.liquids") +require("prototypes.Bio_Farm.recipe-categories") +require("prototypes.Bio_Farm.pipeConnectors") +require("prototypes.Bio_Farm.technology") +require("prototypes.Bio_Farm.tree_entities") -- Bio Garden -require ("prototypes.Bio_Garden.entities") -require ("prototypes.Bio_Garden.item") -require ("prototypes.Bio_Garden.recipe") -require ("prototypes.Bio_Garden.recipe-categories") +require("prototypes.Bio_Garden.entities") +require("prototypes.Bio_Garden.item") +require("prototypes.Bio_Garden.recipe") +require("prototypes.Bio_Garden.recipe-categories") --- Bio Solar Farm -require ("prototypes.Bio_Solar_Farm.entities") -require ("prototypes.Bio_Solar_Farm.item") -require ("prototypes.Bio_Solar_Farm.recipe") +require("prototypes.Bio_Solar_Farm.entities") +require("prototypes.Bio_Solar_Farm.item") +require("prototypes.Bio_Solar_Farm.recipe") --- Wood Products -require ("prototypes.Wood_Products.entities") -require ("prototypes.Wood_Products.item") -require ("prototypes.Wood_Products.recipe") -require ("prototypes.Wood_Products.containers-entities") -require ("prototypes.Wood_Products.containers-item") -require ("prototypes.Wood_Products.containers-recipe") +require("prototypes.Wood_Products.entities") +require("prototypes.Wood_Products.item") +require("prototypes.Wood_Products.recipe") +require("prototypes.Wood_Products.containers-entities") +require("prototypes.Wood_Products.containers-item") +require("prototypes.Wood_Products.containers-recipe") if not mods["Natural_Evolution_Buildings"] then - --- Dart Turret (Bio turret) - require ("prototypes.Bio_Turret.item-group") - require ("prototypes.Bio_Turret.damage-type") - require ("prototypes.Bio_Turret.item") - require ("prototypes.Bio_Turret.recipe") - require ("prototypes.Bio_Turret.entity") + --- Dart Turret (Bio turret) + require("prototypes.Bio_Turret.item-group") + require("prototypes.Bio_Turret.damage-type") + require("prototypes.Bio_Turret.item") + require("prototypes.Bio_Turret.recipe") + require("prototypes.Bio_Turret.entity") ---- Bio Cannon + --- Bio Cannon - -- Items Groups - require ("prototypes.Bio_Cannon.item-group") + -- Items Groups + require("prototypes.Bio_Cannon.item-group") - -- Cannon - require ("prototypes.Bio_Cannon.item") - require ("prototypes.Bio_Cannon.recipe") - require ("prototypes.Bio_Cannon.entity") - require ("prototypes.Bio_Cannon.technology") - - -- Projectiles - require ("prototypes.Bio_Cannon.projectiles-item") - require ("prototypes.Bio_Cannon.projectiles-recipe") - require ("prototypes.Bio_Cannon.projectiles-entity") + -- Cannon + require("prototypes.Bio_Cannon.item") + require("prototypes.Bio_Cannon.recipe") + require("prototypes.Bio_Cannon.entity") + require("prototypes.Bio_Cannon.technology") + -- Projectiles + require("prototypes.Bio_Cannon.projectiles-item") + require("prototypes.Bio_Cannon.projectiles-recipe") + require("prototypes.Bio_Cannon.projectiles-entity") end ---- Add Bio Fuel & Plastic, etc. diff --git a/Bio_Industries_2/settings.lua b/Bio_Industries_2/settings.lua index d7d19fe..da8f4d3 100644 --- a/Bio_Industries_2/settings.lua +++ b/Bio_Industries_2/settings.lua @@ -1,5 +1,5 @@ local setting_list = {} - -- Add/enable stuff +-- Add/enable stuff setting_list.BI_Solar_Additions = { type = "bool-setting", name = "BI_Solar_Additions", @@ -48,7 +48,7 @@ setting_list.BI_Bigger_Wooden_Chests = { order = "a[modifier]-b[Bigger_Wooden_Chests]", } - -- Game tweaks +-- Game tweaks setting_list.BI_Game_Tweaks_Emissions_Multiplier = { type = "bool-setting", name = "BI_Game_Tweaks_Emissions_Multiplier", @@ -71,7 +71,7 @@ setting_list.BI_Game_Tweaks_Recipe = { default_value = true, order = "b[tweaks]-c1[Recipe]", } - setting_list.BI_Game_Tweaks_Production_Science = { +setting_list.BI_Game_Tweaks_Production_Science = { type = "bool-setting", name = "BI_Game_Tweaks_Production_Science", setting_type = "startup", @@ -109,32 +109,32 @@ setting_list.BI_Game_Tweaks_Bot = { -- Compatibility with other mods (optional) - -- Industrial Revolution + AAI Industry +-- Industrial Revolution + AAI Industry if not (mods["IndustrialRevolution"] or mods["aai-industry"]) then - setting_list.BI_Game_Tweaks_Disassemble = { - type = "bool-setting", - name = "BI_Game_Tweaks_Disassemble", - setting_type = "startup", - default_value = true, - order = "b[tweaks]-c2[Disassemble]", - } + setting_list.BI_Game_Tweaks_Disassemble = { + type = "bool-setting", + name = "BI_Game_Tweaks_Disassemble", + setting_type = "startup", + default_value = true, + order = "b[tweaks]-c2[Disassemble]", + } end - -- Lua API global Variable Viewer (gvv) +-- Lua API global Variable Viewer (gvv) if mods["gvv"] then - setting_list.BI_Enable_gvv_support = { - type = "bool-setting", - name = "BI_Enable_gvv_support", - setting_type = "startup", - default_value = false, - order = "c[compatibility]-c1[debugging_gvv]", - } + setting_list.BI_Enable_gvv_support = { + type = "bool-setting", + name = "BI_Enable_gvv_support", + setting_type = "startup", + default_value = false, + order = "c[compatibility]-c1[debugging_gvv]", + } end local list = {} for name, setting in pairs(setting_list) do - data:extend({setting}) + data:extend({ setting }) end --[[ Types of settings: diff --git a/Bio_Industries_2/settings_changed.lua b/Bio_Industries_2/settings_changed.lua index a4ea4f0..d5ae878 100644 --- a/Bio_Industries_2/settings_changed.lua +++ b/Bio_Industries_2/settings_changed.lua @@ -9,222 +9,222 @@ local settings_changed = {} -- Adjust the force of hidden poles on Musk floor! settings_changed.musk_floor = function() -log("Entered function settings_changed.musk_floor!") - -- Look for solar panels on every surface. They determine the force poles will use - -- if the electric grid overlay will be shown in mapview. - local sm_panel_name = "bi-musk-mat-hidden-panel" - local sm_pole_name = "bi-musk-mat-hidden-pole" + log("Entered function settings_changed.musk_floor!") + -- Look for solar panels on every surface. They determine the force poles will use + -- if the electric grid overlay will be shown in mapview. + local sm_panel_name = "bi-musk-mat-hidden-panel" + local sm_pole_name = "bi-musk-mat-hidden-pole" - -- If dummy force is not used, force of a hidden pole should be that of the hidden solar panel. - -- That force will be "enemy" for poles/solar panels created with versions of Bio Industries - -- prior to 0.17.45/0.18.13 because of the bug. We can fix that for singleplayer games by setting - -- the force to player force. In multiplayer games, we can do this as well if all players are - -- on the same force. If there are several forces that have players, it's impossible to find out - -- which force built a certain musk floor tile, so "enemy" will still be used. - -- (Only fix in this case: Players must remove and rebuild all existing musk floor tiles!) + -- If dummy force is not used, force of a hidden pole should be that of the hidden solar panel. + -- That force will be "enemy" for poles/solar panels created with versions of Bio Industries + -- prior to 0.17.45/0.18.13 because of the bug. We can fix that for singleplayer games by setting + -- the force to player force. In multiplayer games, we can do this as well if all players are + -- on the same force. If there are several forces that have players, it's impossible to find out + -- which force built a certain musk floor tile, so "enemy" will still be used. + -- (Only fix in this case: Players must remove and rebuild all existing musk floor tiles!) local force = nil - -- Always use dummy force if option is set - if BioInd.UseMuskForce then - force = BioInd.MuskForceName - -- Singleplayer mode: use force of first player - elseif not game.is_multiplayer() then - -- Apparently, this crashed for someone (https://mods.factorio.com/mod/Bio_Industries_2/discussion/649d41b778d997d29385b8cf). - -- Could it be that a game that was originally a multiplayer game has been saved and reused - -- as singleplayer game, but there was no player 1? Let's go over all players and break after - -- the first hit, so we make sure we'll get the single player whatever its index! + -- Always use dummy force if option is set + if BioInd.UseMuskForce then + force = BioInd.MuskForceName + -- Singleplayer mode: use force of first player + elseif not game.is_multiplayer() then + -- Apparently, this crashed for someone (https://mods.factorio.com/mod/Bio_Industries_2/discussion/649d41b778d997d29385b8cf). + -- Could it be that a game that was originally a multiplayer game has been saved and reused + -- as singleplayer game, but there was no player 1? Let's go over all players and break after + -- the first hit, so we make sure we'll get the single player whatever its index! for p, player in pairs(game.players) do - force = player.force.name - break - end - -- Still got no force? Fall back to "player" -- as one of the 3 default forces, - -- it can't be removed, so we can use it! - force = force or "player" - - -- Multiplayer game - else - local count = 0 - -- Count forces with players - for _, check_force in pairs(game.forces) do - if next(check_force.players) then - force = check_force.name - count = count + 1 - end - end - -- Several forces with players: reset force to nil now and use force of panel later - -- (If this happens in a game were musk floor was created the buggy way with "force == nil", - -- it will be impossible to determine which force built it, so the force will still be - -- the default, i.e. "enemy".) - if count > 1 then - force = nil - end - end - - for name, surface in pairs(game.surfaces) do - BioInd.writeDebug("Looking for %s on surface %s", {sm_panel_name, name}) - local sm_panel = surface.find_entities_filtered{name = sm_panel_name} - local sm_pole = {} - - -- Look for hidden poles on position of hidden panels - for p, panel in ipairs(sm_panel) do - sm_pole = surface.find_entities_filtered{ - name = sm_pole_name, - position = panel.position, - } - - -- If more than one hidden pole exists at that position for some reason, remove all but the first! - if #sm_pole > 1 then -BioInd.writeDebug("Number of poles for panel %g: %g", {p, #sm_pole}) - for i = 2, #sm_pole do -BioInd.writeDebug("Destroying pole number %g", {i}) - sm_pole[i].destroy() + force = player.force.name + break end - end + -- Still got no force? Fall back to "player" -- as one of the 3 default forces, + -- it can't be removed, so we can use it! + force = force or "player" - -- Set force of the pole - sm_pole[1].force = force or panel.force + -- Multiplayer game + else + local count = 0 + -- Count forces with players + for _, check_force in pairs(game.forces) do + if next(check_force.players) then + force = check_force.name + count = count + 1 + end + end + -- Several forces with players: reset force to nil now and use force of panel later + -- (If this happens in a game were musk floor was created the buggy way with "force == nil", + -- it will be impossible to determine which force built it, so the force will still be + -- the default, i.e. "enemy".) + if count > 1 then + force = nil + end end - end - BioInd.writeDebug("Electric grid overlay of musk floor will be %s in map view.", - {BioInd.UseMuskForce and "hidden" or "displayed"}) + + for name, surface in pairs(game.surfaces) do + BioInd.writeDebug("Looking for %s on surface %s", { sm_panel_name, name }) + local sm_panel = surface.find_entities_filtered { name = sm_panel_name } + local sm_pole = {} + + -- Look for hidden poles on position of hidden panels + for p, panel in ipairs(sm_panel) do + sm_pole = surface.find_entities_filtered { + name = sm_pole_name, + position = panel.position, + } + + -- If more than one hidden pole exists at that position for some reason, remove all but the first! + if #sm_pole > 1 then + BioInd.writeDebug("Number of poles for panel %g: %g", { p, #sm_pole }) + for i = 2, #sm_pole do + BioInd.writeDebug("Destroying pole number %g", { i }) + sm_pole[i].destroy() + end + end + + -- Set force of the pole + sm_pole[1].force = force or panel.force + end + end + BioInd.writeDebug("Electric grid overlay of musk floor will be %s in map view.", + { BioInd.UseMuskForce and "hidden" or "displayed" }) end settings_changed.bio_garden = function() - BioInd.writeDebug("Entered function settings_changed.bio_garden!") + BioInd.writeDebug("Entered function settings_changed.bio_garden!") - -- 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("Current state of BI_Easy_Bio_Gardens", current) + -- 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("Current state of BI_Easy_Bio_Gardens", current) - if storage.mod_settings.BI_Easy_Bio_Gardens ~= current then -BioInd.writeDebug("Setting has been changed!") - local pole, neighbours - -- This is the unmodified table! - local compound_entity = BioInd.compound_entities["bi-bio-garden"] - local hidden_entities = compound_entity.hidden + if storage.mod_settings.BI_Easy_Bio_Gardens ~= current then + BioInd.writeDebug("Setting has been changed!") + local pole, neighbours + -- This is the unmodified table! + local compound_entity = BioInd.compound_entities["bi-bio-garden"] + local hidden_entities = compound_entity.hidden - -- Check that all gardens are still valid - for g, garden in pairs(storage[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! - for hidden, h_name in pairs(compound_entity.hidden or {}) do -BioInd.show("hidden", hidden) -BioInd.writeDebug("Removing hidden entity %s %s", { - garden[hidden] and garden[hidden].valid and garden[hidden].name or "nil", - garden[hidden] and garden[hidden].valid and garden[hidden].unit_number or "nil"}) - BioInd.remove_entity(garden[hidden]) - garden[hidden] = nil + -- Check that all gardens are still valid + for g, garden in pairs(storage[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! + for hidden, h_name in pairs(compound_entity.hidden or {}) do + BioInd.show("hidden", hidden) + BioInd.writeDebug("Removing hidden entity %s %s", { + garden[hidden] and garden[hidden].valid and garden[hidden].name or "nil", + garden[hidden] and garden[hidden].valid and garden[hidden].unit_number or "nil" }) + BioInd.remove_entity(garden[hidden]) + garden[hidden] = nil + end + storage[compound_entity.tab][garden.entity.unit_number] = nil + end end - storage[compound_entity.tab][garden.entity.unit_number] = nil - end - end - -- For whatever reason, there may be hidden poles that aren't associated - -- with any garden. We want to remove these, so lets' compile a list of all - -- hidden poles first. - local remove_poles = {} - local found_poles - local pole_type = "electric-pole" - for s, surface in pairs(game.surfaces) do - -- Find poles on surface - found_poles = surface.find_entities_filtered{ - name = compound_entity.hidden[pole_type].name, - type = "electric-pole", - } - -- Add them to list of removeable poles, indexed by unit_number - for p, pole in ipairs(found_poles) do - remove_poles[pole.unit_number] = pole - end - end - - -- 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) }) - - -- Restore the list of hidden entities - storage.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 - -- Make sure the base entity exists! - base = garden.base - pole = base and garden[pole_type] -BioInd.show("pole", pole) - -- There is a pole referenced in the table, and it is a valid entity - if pole and pole.valid then - -- Delete pole from list of removeable poles - BioInd.writeDebug("Pole exists -- keep it!") - remove_poles[pole.unit_number] = nil - - -- There is no valid pole, let's create one! - elseif base then - -- Create hidden poles - pole = BioInd.create_entities( - storage[compound_entity.tab], - base, - {pole = hidden_entities[pole_type].name} - ) - - -- Add the new pole to the table - if pole then - storage[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] - }) - end + -- For whatever reason, there may be hidden poles that aren't associated + -- with any garden. We want to remove these, so lets' compile a list of all + -- hidden poles first. + local remove_poles = {} + local found_poles + local pole_type = "electric-pole" + for s, surface in pairs(game.surfaces) do + -- Find poles on surface + found_poles = surface.find_entities_filtered { + name = compound_entity.hidden[pole_type].name, + type = "electric-pole", + } + -- Add them to list of removeable poles, indexed by unit_number + for p, pole in ipairs(found_poles) do + remove_poles[pole.unit_number] = pole + end end - end - -- Setting is off -- disconnect and remove hidden poles! + -- 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) }) + + -- Restore the list of hidden entities + storage.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 + -- Make sure the base entity exists! + base = garden.base + pole = base and garden[pole_type] + BioInd.show("pole", pole) + -- There is a pole referenced in the table, and it is a valid entity + if pole and pole.valid then + -- Delete pole from list of removeable poles + BioInd.writeDebug("Pole exists -- keep it!") + remove_poles[pole.unit_number] = nil + + -- There is no valid pole, let's create one! + elseif base then + -- Create hidden poles + pole = BioInd.create_entities( + storage[compound_entity.tab], + base, + { pole = hidden_entities[pole_type].name } + ) + + -- Add the new pole to the table + if pole then + storage[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] + }) + end + end + end + + -- 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) }) + -- 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 + if garden[pole_type] then + -- Pole really exists: destroy the entity + if garden[pole_type].valid then + -- Disconnect to prevent random connections of other poles when + -- this one is removed + garden[pole_type].disconnect_neighbour() + -- Remove pole from the list of poles not associated with a garden + remove_poles[garden[pole_type].unit_number] = nil + -- Destroy pole + BioInd.remove_entity(garden[pole_type]) + BioInd.show("Removed pole of garden", garden.base.unit_number) + end + garden[pole_type] = nil + BioInd.show("Removed pole from table of garden", garden.base.unit_number) + end + end + + -- 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) + end + + -- Remove any hidden poles that are not associated with a garden + BioInd.writeDebug("Removing %s hidden poles not associated with a bio garden!", + { table_size(remove_poles) }) + for p, pole in pairs(remove_poles) do + pole.destroy() + end + + -- Update setting! + storage.mod_settings.BI_Easy_Bio_Gardens = current + BioInd.show("Updated setting to", storage.mod_settings.BI_Easy_Bio_Gardens) else - BioInd.writeDebug("%s Bio Gardens found -- try to disconnect hidden poles!", - {table_size(storage.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 - if garden[pole_type] then - -- Pole really exists: destroy the entity - if garden[pole_type].valid then - -- Disconnect to prevent random connections of other poles when - -- this one is removed - garden[pole_type].disconnect_neighbour() - -- Remove pole from the list of poles not associated with a garden - remove_poles[garden[pole_type].unit_number] = nil - -- Destroy pole - BioInd.remove_entity(garden[pole_type]) - BioInd.show("Removed pole of garden", garden.base.unit_number) - end - garden[pole_type] = nil - BioInd.show("Removed pole from table of garden", garden.base.unit_number) - end - end - - -- 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) + BioInd.writeDebug("Nothing to do!") end - - -- Remove any hidden poles that are not associated with a garden - BioInd.writeDebug("Removing %s hidden poles not associated with a bio garden!", - {table_size(remove_poles)}) - for p, pole in pairs(remove_poles) do - pole.destroy() - end - - -- Update setting! - storage.mod_settings.BI_Easy_Bio_Gardens = current - BioInd.show("Updated setting to", storage.mod_settings.BI_Easy_Bio_Gardens) - else - BioInd.writeDebug("Nothing to do!") - end end return settings_changed