Reformat code

This commit is contained in:
Simon Brodtmann 2025-07-07 23:09:46 +02:00
parent 7134f437e5
commit bac183d1c1
9 changed files with 2438 additions and 2435 deletions

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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)

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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.

View file

@ -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:

View file

@ -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