[Feature Request] Make Agricultural Towers RCable
Description
The fact that the very first product in the Gleba production chain can't be calculated by the RC is very inconvenient. Factory Planner is able to calculate resources down to the amount of fertile squares you need but that's it. If the game by itself isn't able to internally connect all the data needed (how many squares/seeds you need for X amount of fruit), I'm pretty sure you can read the amount of available fertile squares a Tower has and multiply them by a constant hardcoded number since you always get 50 fruits from one square and all trees seem to grow for the same duration of time (tho that'd only work for SA and not theoretical future mods if those were to use the same mechanic).
Reproduction
No response
it would be nice to know the information. now i just have to keep increasing the squares until it balances
I made a rough implementation for myself.
diff --git a/prototypes/item.lua b/prototypes/item.lua
index 25b202f..828b1bb 100644
--- a/prototypes/item.lua
+++ b/prototypes/item.lua
@@ -33,6 +33,7 @@ local type_filters = {
"rocket-silo",
"solar-panel",
"turret",
+ "agricultural-tower"
}
data:extend({
diff --git a/scripts/calc-util.lua b/scripts/calc-util.lua
index 38390fd..310992f 100644
--- a/scripts/calc-util.lua
+++ b/scripts/calc-util.lua
@@ -210,6 +210,99 @@ function calc_util.process_boiler(set, entity, invert)
calc_util.add_rate(set, "output", "fluid", output_fluid.name, "normal", fluid_usage, invert, entity.name)
end
+function init_agriculatural_tower_data()
+ if calc_util.agricultural_tower_data ~= nil then
+ return
+ end
+
+ calc_util.agricultural_tower_data = {}
+ calc_util.agricultural_tower_data.product_by_tile = {}
+
+ for _, item in pairs(prototypes["item"]) do
+ local plant_prototype = item.plant_result
+ if plant_prototype ~= nil then
+ if plant_prototype.autoplace_specification ~= nil and plant_prototype.mineable_properties ~= nil then
+ local growth_time_s = plant_prototype.growth_ticks / 60
+ local plant_results = {}
+ for _, r in ipairs(plant_prototype.mineable_properties.products) do
+ local plant_result_amount = r.amount * (r.probability or 1) / growth_time_s
+ table.insert(plant_results, {r.name, plant_result_amount})
+ end
+
+ for _, tr in ipairs(plant_prototype.autoplace_specification.tile_restriction) do
+ -- NOTE: Cannot handle multiple seeds working on the same tiles.
+ calc_util.agricultural_tower_data.product_by_tile[tr.first] = plant_results
+ end
+ end
+ end
+ end
+end
+
+--- @param set CalculationSet
+--- @param entity LuaEntity
+--- @param invert boolean
+--- @return double
+function calc_util.process_agricultural_tower(set, entity, invert)
+ init_agriculatural_tower_data()
+
+ -- NOTE: Really unsure about how modded agricultural towers work, no idea how configurable they are, so hardcoded default settings
+
+ local min_x = entity.position.x - 3*7*0.5
+ local min_y = entity.position.y - 3*7*0.5
+ local max_x = entity.position.x + 3*7*0.5
+ local max_y = entity.position.y + 3*7*0.5
+
+ local total_results = {}
+
+ for x=min_x,max_x-2,3 do
+ for y=min_y,max_y-2,3 do
+ local results = nil
+ for dx=0,2,1 do
+ for dy=0,2,1 do
+ local tile = entity.surface.get_tile(x + dx + 0.5, y + dy + 0.5)
+ if tile == nil then
+ break
+ end
+
+ local this_tile_results = calc_util.agricultural_tower_data.product_by_tile[tile.name]
+ if dx == 0 and dy == 0 then
+ results = this_tile_results
+ else
+ if results ~= this_tile_results then
+ results = nil
+ end
+ end
+ end
+ end
+
+ if results ~= nil then
+ for _, result in ipairs(results) do
+ if total_results[result[1]] ~= nil then
+ total_results[result[1]] = total_results[result[1]] + result[2]
+ else
+ total_results[result[1]] = result[2]
+ end
+ end
+ end
+ end
+ end
+
+
+ for product_name, product_amount in pairs(total_results) do
+ calc_util.add_rate(
+ set,
+ "output",
+ "item",
+ product_name,
+ "normal",
+ product_amount,
+ invert,
+ entity.name,
+ nil
+ )
+ end
+end
+
--- @param set CalculationSet
--- @param entity LuaEntity
--- @param invert boolean
diff --git a/scripts/calc.lua b/scripts/calc.lua
index 4e4c42e..f961199 100644
--- a/scripts/calc.lua
+++ b/scripts/calc.lua
@@ -129,6 +129,8 @@ local function process_entity(set, entity, invert)
calc_util.process_offshore_pump(set, entity, invert)
elseif type == "reactor" then
calc_util.process_reactor(set, entity, invert)
+ elseif type == "agricultural-tower" then
+ calc_util.process_agricultural_tower(set, entity, invert)
end
if emissions_per_second > 0 then