Skip to content

Commit

Permalink
Added agricultural recipe for agricultural-tower
Browse files Browse the repository at this point in the history
  Changes:
    - Added agricultural recipe for agricultural-tower
    - Added spoil recipe
  • Loading branch information
Helfima committed Nov 7, 2024
1 parent 665b45b commit badf435
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 18 deletions.
8 changes: 7 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
---------------------------------------------------------------------------------------------------
Version: 2.0.6
Date: 2024-11-07
Changes:
- Added agricultural recipe for agricultural-tower
- Added spoil recipe
---------------------------------------------------------------------------------------------------
Version: 2.0.5
Date: 2024-11-06
Changes:
- Reworked custom fluid recipe created by offshore-pump
- Implemented productivity bonus on recipe when technoly researched (need refresh sheet)
- Implemented productivity bonus on recipe when technology researched (need refresh sheet)
Bugfixes:
- Fix error on accumulator recipe
- Fix search recipe in boiler recipes when click a ingredient or a product
Expand Down
13 changes: 11 additions & 2 deletions data/Model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ function Model.newRecipe(model, name, type)
recipeModel.type = type or "recipe"
recipeModel.count = 0
recipeModel.production = 1
recipeModel.factory = Model.newFactory()
--recipeModel.factory = Model.newFactory()
recipeModel.beacons = {}
table.insert(recipeModel.beacons, Model.newBeacon())
--table.insert(recipeModel.beacons, Model.newBeacon())

return recipeModel
end
Expand Down Expand Up @@ -503,6 +503,13 @@ function Model.setFactory(recipe, factory_name, factory_fuel)
if recipe ~= nil then
local factory_prototype = EntityPrototype(factory_name)
if factory_prototype:native() ~= nil then
if recipe.factory == nil then
recipe.factory = Model.newFactory()
if recipe.beacons == nil or #recipe.beacons == 0 then
recipe.beacons = {}
table.insert(recipe.beacons, Model.newBeacon())
end
end
recipe.factory.name = factory_name
recipe.factory.fuel = factory_fuel
if Model.countModulesModel(recipe.factory) >= factory_prototype:getModuleInventorySize() then
Expand Down Expand Up @@ -582,6 +589,8 @@ function Model.getDefaultPrototypeFactory(recipe_prototype)
factories = Player.getBoilersForRecipe(recipe_prototype)
elseif recipe_prototype:getType() == "fluid" then
factories = Player.getProductionsCrafting("fluid", recipe_prototype:native())
elseif recipe_prototype:getType() == "agricultural" then
factories = Player.getAgriculturalTowers()
else
factories = Player.getProductionsCrafting(category, recipe_prototype:native())
end
Expand Down
4 changes: 4 additions & 0 deletions data/ModelCompute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ end
---@param parameters ParametersData
---@return RecipeData
function ModelCompute.computeModuleEffects(recipe, parameters)
if recipe.factory == nil then return end
local factory = recipe.factory
local recipe_productivity = Player.getRecipeProductivityBonus(recipe.name)
factory.effects = { speed = 0, productivity = recipe_productivity, consumption = 0, pollution = 0, quality = 0 }
Expand Down Expand Up @@ -703,6 +704,9 @@ end
---Compute energy, speed, number of factory for recipes
---@param recipe table
function ModelCompute.computeFactory(recipe)
recipe.pollution_amount = 0
recipe.energy_total = 0
if recipe.factory == nil then return end
local recipe_prototype = RecipePrototype(recipe)
local factory_prototype = EntityPrototype(recipe.factory)
recipe.time = recipe_prototype:getEnergy(recipe.factory)
Expand Down
16 changes: 9 additions & 7 deletions dialog/ProductionPanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,16 @@ function ProductionPanel:addTableRowRecipe(gui_table, model, block, recipe)
---col factory
local factory = recipe.factory
local cell_factory = GuiElement.add(gui_table, GuiTable("factory", recipe.id):column(2):style("helmod_table_list"))
local gui_cell_factory = GuiCellFactory(self.classname, "factory-action", model.id, block.id, recipe.id):element(factory):tooltip("tooltip.edit-recipe"):color(recipe_color):byLimit(block.by_limit):controlInfo( "crafting-add")
if block.by_limit == true then
gui_cell_factory:byLimitUri(self.classname, "update-factory-limit", model.id, block.id, recipe.id)
end
if block.by_factory == true then
gui_cell_factory:byFactory(self.classname, "update-factory-number", model.id, block.id, recipe.id)
if factory ~= nil then
local gui_cell_factory = GuiCellFactory(self.classname, "factory-action", model.id, block.id, recipe.id):element(factory):tooltip("tooltip.edit-recipe"):color(recipe_color):byLimit(block.by_limit):controlInfo( "crafting-add")
if block.by_limit == true then
gui_cell_factory:byLimitUri(self.classname, "update-factory-limit", model.id, block.id, recipe.id)
end
if block.by_factory == true then
gui_cell_factory:byFactory(self.classname, "update-factory-number", model.id, block.id, recipe.id)
end
GuiElement.add(cell_factory, gui_cell_factory)
end
GuiElement.add(cell_factory, gui_cell_factory)

---col beacon
local beacons = recipe.beacons
Expand Down
10 changes: 7 additions & 3 deletions edition/RecipeEdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ function RecipeEdition:onUpdate(event)
local model, block, recipe = self:getParameterObjects()
---header
self:updateHeader(event)
if recipe ~= nil then
if recipe ~= nil and recipe.type ~= "spoiling" then
if recipe.type == "energy" then
self:updateFactoryInfo(event)
else
Expand Down Expand Up @@ -669,6 +669,8 @@ function RecipeEdition:updateFactoryInfo(event)
factories = Player.getProductionsCrafting("fluid", recipe)
elseif recipe.type == "boiler" then
factories = Player.getBoilersForRecipe(recipe_prototype)
elseif recipe.type == "agricultural" then
factories = Player.getAgriculturalTowers()
else
factories = Player.getProductionsCrafting(category, recipe)
end
Expand Down Expand Up @@ -1162,8 +1164,10 @@ function RecipeEdition:updateBeaconModulesPriority(beacon_module_panel)
local tooltip = GuiTooltipModule("tooltip.add-module"):element({type="item", name=element.name}):withControlInfo(control_info)
local module = ItemPrototype(element.name)
if Player.checkBeaconLimitationModule(beacon, recipe, module:native()) == false then
if (module:native().limitation_message_key ~= nil) and (module:native().limitation_message_key ~= "") then
tooltip = {"item-limitation."..module:native().limitation_message_key}
local limitation_message = Player.getBeaconLimitationModuleMessage(module:native(), recipe);

if limitation_message ~= nil then
tooltip = limitation_message
else
tooltip = ""
end
Expand Down
8 changes: 8 additions & 0 deletions gui/GuiCell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ function GuiCell:add_icon_info(button, info_icon)
tooltip = "tooltip.resource-recipe"
sprite_name = GuiElement.getSprite(defines.sprite_info.mining)
end
if type == "agricultural" then
tooltip = "tooltip.resource-recipe"
sprite_name = GuiElement.getSprite(defines.sprite_info.developer)
end
if type == "spoiling" then
tooltip = "tooltip.resource-recipe"
sprite_name = GuiElement.getSprite(defines.sprite_info.developer)
end
if type == "technology" then
tooltip = "tooltip.technology-recipe"
sprite_name = GuiElement.getSprite(defines.sprite_info.education)
Expand Down
7 changes: 7 additions & 0 deletions gui/GuiElement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,17 @@ function GuiElement.infoRecipe(parent, element)
local caption = Format.formatNumberKilo(element.output_fluid_temperature, "°")
local label = GuiElement.add(parent, GuiLabel("temperature"):caption(caption):style(style):ignored_by_interaction())
label.style.top_padding = -5
elseif element.type == "agricultural" then
sprite_name = GuiElement.getSprite(defines.sprite_info.developer)
tooltip = {"tooltip.resource-recipe"}
elseif element.type == "spoiling" then
sprite_name = GuiElement.getSprite(defines.sprite_info.developer)
tooltip = {"tooltip.resource-recipe"}
elseif element.type ~= "recipe" then
sprite_name = GuiElement.getSprite(defines.sprite_info.mining)
tooltip = {"tooltip.resource-recipe"}
end

if sprite_name ~= nil then
local container = GuiElement.add(parent, GuiFlow("recipe-info"))
container.style.top_padding = -4
Expand Down
10 changes: 8 additions & 2 deletions math/SolverLinkedMatrix.lua
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ function SolverLinkedMatrix:get_block_matrix(block, parameters)
child_info.type = recipe.type
child_info.tooltip = recipe.name .. "\nRecette"
child_info.recipe_energy = recipe_prototype:getEnergy(recipe.factory)
child_info.factory_count = recipe.factory.input or 0
child_info.factory_count = 0
if recipe.factory ~= nil then
child_info.factory_count = recipe.factory.input or 0
end
child_info.consumer = recipe.consumer

recipe.base_time = block.time
Expand All @@ -478,7 +481,10 @@ function SolverLinkedMatrix:get_block_matrix(block, parameters)
ModelCompute.computeFactory(recipe)
end

child_info.factory_speed = recipe.factory.speed or 0
child_info.factory_speed = 0
if recipe.factory ~= nil then
child_info.factory_speed = recipe.factory.speed or 0
end

child_info.products = recipe_prototype:getProducts(recipe.factory)
child_info.ingredients = recipe_prototype:getIngredients(recipe.factory)
Expand Down
12 changes: 12 additions & 0 deletions model/EntityPrototype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,18 @@ function EntityPrototype:speedFactory(recipe)
return researching_speed
elseif recipe.type == "energy" then
return self:getSpeedModifier()
elseif recipe.type == "agricultural" then
local growth_grid_tile_size = self.lua_prototype.growth_grid_tile_size or 3
local tile_width = self.lua_prototype.tile_width or 3
local tile_height = self.lua_prototype.tile_height or 3
local machine_area = tile_width*tile_height
local logistic_area = 9 -- area necessary for input/output and power
local max_grid_tile_size = 21
local max_area = max_grid_tile_size * max_grid_tile_size
local growing_area = growth_grid_tile_size * growth_grid_tile_size
local growable_area = max_area - machine_area - logistic_area
local speed = growable_area/growing_area
return speed
else
return self:getCraftingSpeed()
end
Expand Down
Loading

0 comments on commit badf435

Please sign in to comment.