Merge pull request #486 from bbassie/feature/convert-configs

Convert the remaining scenario configs into features
This commit is contained in:
Bastiaan authored and GitHub committed 2026-10-05 00:33:36 +01:00
1 parent b4ee485b13
commit 757a36fc03
44 files changed
+2137 -2033

No files matched your search

+70 -42
View File
@@ -1,42 +1,70 @@
--[[ Control - Bonus
Various bonus related event handlers
TODO Refactor this fully, this is temp to get it out of the player bonus gui file
]]
local Roles = require("modules/exp_roles")
local config = require("modules/exp_legacy/config/bonus")
--- @param event EventData.on_force_created
local function apply_force_bonus(event)
local force = event.force
for k, v in pairs(config.force_bonus) do
force[k] = math.floor(v.max_value / 2)
end
end
--- @param event EventData.on_surface_created
local function apply_surface_bonus(event)
local surface = assert(game.get_surface(event.surface_index))
for k, v in pairs(config.surface_bonus) do
surface[k] = math.floor(v.max_value / 2)
end
end
--- @param event EventData.on_player_died
local function fast_respawn(event)
local player = assert(game.get_player(event.player_index))
if Roles.player_has_permission(player, "exp_scenario.player.instant_respawn") then
player.ticks_to_respawn = 120
end
end
local e = defines.events
return {
events = {
[e.on_force_created] = apply_force_bonus,
[e.on_surface_created] = apply_surface_bonus,
[e.on_player_died] = fast_respawn,
}
}
--[[ Control - Bonus
Various bonus related event handlers
TODO Refactor this fully, this is temp to get it out of the player bonus gui file
]]
local Roles = require("modules/exp_roles")
--- Force bonuses are started at half their max value
local force_bonus = {
["worker_robots_battery_modifier"] = {
max_value = 1,
value_step = 1,
scale = 1,
cost = 1,
is_percentage = false,
},
["worker_robots_storage_bonus"] = {
max_value = 1,
value_step = 1,
scale = 1,
cost = 1,
is_percentage = false,
},
["following_robots_lifetime_modifier"] = {
max_value = 1,
value_step = 1,
scale = 1,
cost = 1,
is_percentage = false,
},
}
--- Surface bonuses are started at half their max value
local surface_bonus = {}
--- @param event EventData.on_force_created
local function apply_force_bonus(event)
local force = event.force
for k, v in pairs(force_bonus) do
force[k] = math.floor(v.max_value / 2)
end
end
--- @param event EventData.on_surface_created
local function apply_surface_bonus(event)
local surface = assert(game.get_surface(event.surface_index))
for k, v in pairs(surface_bonus) do
surface[k] = math.floor(v.max_value / 2)
end
end
--- @param event EventData.on_player_died
local function fast_respawn(event)
local player = assert(game.get_player(event.player_index))
if Roles.player_has_permission(player, "exp_scenario.player.instant_respawn") then
player.ticks_to_respawn = 120
end
end
local e = defines.events
return {
events = {
[e.on_force_created] = apply_force_bonus,
[e.on_surface_created] = apply_surface_bonus,
[e.on_player_died] = fast_respawn,
}
}
+14 -3
View File
@@ -2,9 +2,20 @@
Changes the starting script and the items given on first join depending on factory production levels
]]
local config = require("modules.exp_legacy.config.advanced_start")
local Feature = require("modules/exp_scenario/features")
local starting_items = require("modules/exp_scenario/config/starting_items")
local floor = math.floor
--- Applied when the map is created
local feature, config = Feature.register("custom_start", {
skip_intro = true, -- skips the intro given in the default factorio free play scenario
skip_victory = true, -- will skip the victory screen when a rocket is launched
friendly_fire = false, -- weather players will be able to attack each other on the same force
disable_crashsite = true, -- weather to disable creation of the crashsite
enemy_expansion = false, -- a catch all for in case the map settings file fails to load
chart_radius = 320, -- the number of tiles that will be charted when the map starts
})
--- Give a player their starting items
--- @param player LuaPlayer
local function give_starting_items(player)
@@ -12,7 +23,7 @@ local function give_starting_items(player)
local get_input_count = get_prod_stats.get_input_count
local insert_param = { name = "", count = 0 }
local insert = player.insert
for item_name, insert_amount in pairs(config.items) do
for item_name, insert_amount in pairs(starting_items) do
insert_param.name = item_name
if type(insert_amount) == "function" then
local count = insert_amount(get_input_count(item_name), get_input_count, player)
@@ -55,7 +66,7 @@ end
local e = defines.events
return {
return feature:guard{
on_init = on_init,
events = {
[e.on_player_created] = on_player_created,
@@ -5,7 +5,16 @@ Log certain actions into a file when events are triggered
local ExpUtil = require("modules/exp_util")
local Storage = require("modules/exp_util/storage")
local Roles = require("modules/exp_roles")
local config = require("modules.exp_legacy.config.deconlog")
local Feature = require("modules/exp_scenario/features")
local feature, config = Feature.register("deconstruction_log", {
decon_area = true, -- log when an area is deconstructed
built_entity = true, -- log when an entity is built
mined_entity = true, -- log when an entity is mined
fired_rocket = true, -- log when a rocket is fired
fired_explosive_rocket = true, -- log when an explosive rocket is fired
fired_nuke = true, -- log when a nuke is fired
})
local seconds_time_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true, seconds = true }
local format_number = require("util").format_number
@@ -90,6 +99,7 @@ end
--- Log when an area is deconstructed
--- @param event EventData.on_player_deconstructed_area
local function on_player_deconstructed_area(event)
if not config.decon_area then return end
local player = get_log_player(event)
if not player then return end
@@ -118,6 +128,7 @@ end
--- Log when an entity is built
--- @param event EventData.on_built_entity
local function on_built_entity(event)
if not config.built_entity then return end
local player = get_log_player(event)
if not player then return end
add_log_line(player, "built_entity", format_entity(event.entity))
@@ -126,16 +137,17 @@ end
--- Log when an entity is mined
--- @param event EventData.on_player_mined_entity
local function on_player_mined_entity(event)
if not config.mined_entity then return end
local player = get_log_player(event)
if not player then return end
add_log_line(player, "mined_entity", format_entity(event.entity))
end
--- Ammo which is logged when fired
local logged_ammo = {
["rocket"] = config.fired_rocket,
["explosive-rocket"] = config.fired_explosive_rocket,
["atomic-bomb"] = config.fired_nuke,
--- The setting which decides if a shot of an ammo is logged
local ammo_settings = {
["rocket"] = "fired_rocket",
["explosive-rocket"] = "fired_explosive_rocket",
["atomic-bomb"] = "fired_nuke",
}
--- @class ExpScenario_DeconstructionLog.AmmoSlot
@@ -186,7 +198,7 @@ local function on_player_ammo_inventory_changed(event)
fired = previous.name
end
if fired and logged_ammo[fired] then
if fired and config[ammo_settings[fired]] then
add_log_line(player, "shot-" .. fired, format_position(player.physical_position), format_position(player.shooting_state.position))
end
end
@@ -206,29 +218,16 @@ local function on_player_left_game(event)
end
local e = defines.events
local events = {
[e.on_multiplayer_init] = clear_log,
}
if config.decon_area then
events[e.on_player_deconstructed_area] = on_player_deconstructed_area
end
if config.built_entity then
events[e.on_built_entity] = on_built_entity
end
if config.mined_entity then
events[e.on_player_mined_entity] = on_player_mined_entity
end
if config.fired_rocket or config.fired_explosive_rocket or config.fired_nuke then
events[e.on_player_ammo_inventory_changed] = on_player_ammo_inventory_changed
events[e.on_player_joined_game] = on_player_character_changed
events[e.on_player_respawned] = on_player_character_changed
events[e.on_player_left_game] = on_player_left_game
end
return {
events = events,
return feature:guard{
events = {
[e.on_multiplayer_init] = clear_log,
[e.on_player_deconstructed_area] = on_player_deconstructed_area,
[e.on_built_entity] = on_built_entity,
[e.on_player_mined_entity] = on_player_mined_entity,
[e.on_player_ammo_inventory_changed] = on_player_ammo_inventory_changed,
[e.on_player_joined_game] = on_player_character_changed,
[e.on_player_respawned] = on_player_character_changed,
[e.on_player_left_game] = on_player_left_game,
},
}
+102 -7
View File
@@ -2,13 +2,108 @@
When a player walks around the tiles under them will degrade over time, the same is true when entites are built
]]
local config = require("modules.exp_legacy.config.scorched_earth")
local Feature = require("modules/exp_scenario/features")
local feature, config = Feature.register("degrading_tiles", {
weakness_value = 70, -- lower value will make tiles more likely to degrade
entities = Feature.set{ -- entities which degrade the tiles under them when they are placed
"stone-furnace", "steel-furnace", "electric-furnace", "assembling-machine-1", "assembling-machine-2", "assembling-machine-3",
"beacon", "centrifuge", "chemical-plant", "oil-refinery", "storage-tank", "nuclear-reactor",
"steam-engine", "steam-turbine", "boiler", "heat-exchanger", "stone-wall", "gate",
"gun-turret", "laser-turret", "flamethrower-turret", "radar", "lab", "big-electric-pole",
"substation", "rocket-silo", "pumpjack", "electric-mining-drill", "roboport", "accumulator",
},
})
local random = math.random
--- How "strong" a tile is, bigger number means less likely to degrade
local strengths = {
-- debug: /interface require('modules.addons.worn-paths')(player.name,true)
-- note: tiles are effected by the tiles around them, so player paths will not degrade as fast when made wider
-- note: values are relative to the tile with the highest value, recommended to keep highest tile as a "nice" number
-- note: tiles not in list will never degrade under any conditions (which is why some are omitted such as water)
["refined-concrete"] = 100,
["refined-hazard-concrete-left"] = 100,
["refined-hazard-concrete-right"] = 100,
["concrete"] = 90,
["hazard-concrete-left"] = 90,
["hazard-concrete-right"] = 90,
["stone-path"] = 80,
["red-desert-0"] = 80,
["dry-dirt"] = 50,
-- grass four (main grass tiles)
["grass-1"] = 50,
["grass-2"] = 40,
["grass-3"] = 30,
["grass-4"] = 25,
-- red three (main red tiles)
["red-desert-1"] = 40,
["red-desert-2"] = 30,
["red-desert-3"] = 25,
-- sand three (main sand tiles)
["sand-1"] = 40,
["sand-2"] = 30,
["sand-3"] = 25,
-- dirt 3 (main dirt tiles)
["dirt-1"] = 40,
["dirt-2"] = 30,
["dirt-3"] = 25,
-- last three/four (all sets of three merge here)
["dirt-4"] = 25,
["dirt-5"] = 30,
["dirt-6"] = 40,
-- ["dirt-7"]=0, -- last tile, nothing to degrade to
-- land fill chain
-- ["landfill"]=50,
-- ["water-shallow"]=90,
-- ["water-mud"]=0, -- last tile, nothing to degrade to
}
--- When a tile degrades it will turn into the next tile given here
local degrade_order = {
["refined-concrete"] = "concrete",
["refined-hazard-concrete-left"] = "hazard-concrete-left",
["refined-hazard-concrete-right"] = "hazard-concrete-right",
["concrete"] = "stone-path",
["hazard-concrete-left"] = "stone-path",
["hazard-concrete-right"] = "stone-path",
["stone-path"] = "dry-dirt",
["red-desert-0"] = "dry-dirt",
["dry-dirt"] = "dirt-4",
-- grass four (main grass tiles)
["grass-1"] = "grass-2",
["grass-2"] = "grass-3",
["grass-3"] = "grass-4",
["grass-4"] = "dirt-4",
-- red three (main red tiles)
["red-desert-1"] = "red-desert-2",
["red-desert-2"] = "red-desert-3",
["red-desert-3"] = "dirt-4",
-- sand three (main sand tiles)
["sand-1"] = "sand-2",
["sand-2"] = "sand-3",
["sand-3"] = "dirt-4",
-- dirt 3 (main dirt tiles)
["dirt-1"] = "dirt-2",
["dirt-2"] = "dirt-3",
["dirt-3"] = "dirt-4",
-- last three/four (all sets of three merge here)
["dirt-4"] = "dirt-5",
["dirt-5"] = "dirt-6",
["dirt-6"] = "dirt-7",
-- ["dirt-7"]=0, -- last tile, nothing to degrade to
-- land fill chain
-- ["landfill"]='grass-2', -- 'water-shallow'
-- ["water-shallow"]='water-mud',
-- ["water-mud"]=0, -- last tile, nothing to degrade to
}
--- Get the max tile strength
local max_strength = 0
for _, strength in pairs(config.strengths) do
for _, strength in pairs(strengths) do
if strength > max_strength then
max_strength = strength
end
@@ -20,7 +115,7 @@ end
local function degrade_tile(surface, position)
local tile = surface.get_tile(position.x, position.y)
local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name]
local degrade_tile_name = degrade_order[tile_name]
if not degrade_tile_name then return end
surface.set_tiles{ { name = degrade_tile_name, position = position } }
end
@@ -39,7 +134,7 @@ local function degrade_entity(entity)
for y = left_top.y, right_bottom.y do
local tile = surface.get_tile(x, y)
local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name]
local degrade_tile_name = degrade_order[tile_name]
if degrade_tile_name then
tiles[#tiles + 1] = { name = degrade_tile_name, position = { x, y } }
end
@@ -63,14 +158,14 @@ end
local function get_tile_strength(surface, position)
local tile = surface.get_tile(position.x, position.y)
local tile_name = tile.name
local strength = config.strengths[tile_name]
local strength = strengths[tile_name]
if not strength then return end
for x = position.x - 1, position.x + 1 do
for y = position.y - 1, position.y + 1 do
local check_tile = surface.get_tile(x, y)
local check_tile_name = check_tile.name
local check_strength = config.strengths[check_tile_name] or 0
local check_strength = strengths[check_tile_name] or 0
strength = strength + check_strength
end
end
@@ -108,7 +203,7 @@ end
local e = defines.events
return {
return feature:guard{
events = {
[e.on_player_changed_position] = on_player_changed_position,
[e.on_robot_built_entity] = on_built_entity,
+38 -7
View File
@@ -2,8 +2,39 @@
Log some extra events to a separate file
]]
local config = require("modules.exp_legacy.config.logging")
local config_res = require("modules.exp_legacy.config.research")
local Feature = require("modules/exp_scenario/features")
local research_data = require("modules/exp_scenario/config/research_data")
local feature, config = Feature.register("extra_logging", {
file_name = "log/logging.log", -- the file the lines are written to
rocket_launch_display_rate = 500, -- after the counts below, log every this many rockets
})
--- Rocket counts which are always logged
local rocket_launch_display = {
[1] = true,
[2] = true,
[5] = true,
[10] = true,
[20] = true,
[50] = true,
[100] = true,
[200] = true,
}
local disconnect_reason = {
[defines.disconnect_reason.quit] = "left the game",
[defines.disconnect_reason.dropped] = "was dropped from the game",
[defines.disconnect_reason.reconnect] = "is reconnecting",
[defines.disconnect_reason.wrong_input] = "was having a wrong input",
[defines.disconnect_reason.desync_limit_reached] = "had desync limit reached",
[defines.disconnect_reason.cannot_keep_up] = "cannot keep up",
[defines.disconnect_reason.afk] = "was afk",
[defines.disconnect_reason.kicked] = "was kicked",
[defines.disconnect_reason.kicked_and_deleted] = "was kicked and deleted",
[defines.disconnect_reason.banned] = "was banned",
[defines.disconnect_reason.switching_servers] = "is switching servers",
}
local concat = table.concat
local write_file = helpers.write_file
@@ -26,7 +57,7 @@ local function on_cargo_pod_finished_ascending(event)
local force = event.cargo_pod.force --[[@as LuaForce]]
if force.rockets_launched >= config.rocket_launch_display_rate and force.rockets_launched % config.rocket_launch_display_rate == 0 then
add_log_line("[ROCKET]", force.rockets_launched, "rockets launched")
elseif config.rocket_launch_display[force.rockets_launched] then
elseif rocket_launch_display[force.rockets_launched] then
add_log_line("[ROCKET]", force.rockets_launched, "rockets launched")
end
end
@@ -53,7 +84,7 @@ local function on_research_finished(event)
return
end
local inf_research_level = config_res.inf_res[config_res.mod_set][event.research.name]
local inf_research_level = research_data.inf_res[research_data.mod_set][event.research.name]
if inf_research_level and event.research.level >= inf_research_level then
add_log_line_locale{ "", "[RES]", event.research.prototype.localised_name, " at level ", event.research.level - 1, " has been researched\n" }
else
@@ -70,17 +101,17 @@ end
--- @param event EventData.on_player_left_game
local function on_player_left_game(event)
local player = assert(game.get_player(event.player_index))
add_log_line("[LEAVE]", player.name, config.disconnect_reason[event.reason])
add_log_line("[LEAVE]", player.name, disconnect_reason[event.reason])
end
local e = defines.events
return {
return feature:guard{
events = {
[e.on_cargo_pod_finished_ascending] = on_cargo_pod_finished_ascending,
[e.on_pre_player_died] = on_pre_player_died,
[e.on_research_finished] = on_research_finished,
[e.on_player_joined_game] = on_player_joined_game,
[e.on_player_left_game] = on_player_left_game,
}
},
}
+32 -5
View File
@@ -4,7 +4,34 @@ Adds friendly biters that walk around and give helpful messages
local Async = require("modules/exp_util/async")
local Storage = require("modules/exp_util/storage")
local config = require("modules.exp_legacy.config.compilatron")
local Feature = require("modules/exp_scenario/features")
local config_server_detail = require("modules.exp_legacy.config.server_detail")
local feature = Feature.register("help_bubbles")
--- Ticks between message changes
local message_cycle = 60 * 15
local locations = {
["Spawn"] = {
spawn_position = { x = 0, y = 0 },
spawn_surface = "nauvis",
entity_name = "small-biter",
messages = {
{ "info.website", config_server_detail["website"] },
{ "info.read-readme" },
{ "info.discord", config_server_detail["discord"] },
{ "info.softmod" },
{ "info.redmew" },
{ "info.custom-commands" },
{ "info.status", config_server_detail["status"] },
{ "info.lhd" },
{ "info.github", config_server_detail["github"] },
{ "info.patreon", config_server_detail["patreon"] },
},
}
}
--- @type table<string, Async.AsyncReturn<any>>
local persistent_locations = {}
@@ -48,7 +75,7 @@ local speech_bubble_task =
task.previous_message = entity.surface.create_entity(speech_bubble_param)
task.current_message_index = index + 1
return Async.status.delay(config.message_cycle, task)
return Async.status.delay(message_cycle, task)
end)
--- Register an entity to start spawning speech bubbles
@@ -66,7 +93,7 @@ end
--- Check all persistent locations from the config are active
local function check_persistent_locations()
for name, location in pairs(config.locations) do
for name, location in pairs(locations) do
local task = persistent_locations[name]
if task and not task.completed then
goto continue
@@ -92,9 +119,9 @@ local function check_persistent_locations()
end
end
return {
return feature:guard{
on_nth_tick = {
[config.message_cycle] = check_persistent_locations,
[message_cycle] = check_persistent_locations,
},
register_entity = register_entity,
}
@@ -6,7 +6,15 @@ on_player_kicked - player_index
]]
local ExpUtil = require("modules/exp_util")
local events = require("modules.exp_legacy.config.inventory_clear")
local Feature = require("modules/exp_scenario/features")
local feature = Feature.register("inventory_clear")
--- The events which clear the inventory of the player
local events = {
defines.events.on_player_banned,
defines.events.on_player_kicked,
}
--- @param event { player_index: number }
local function clear_items(event)
@@ -26,6 +34,6 @@ for _, event_name in ipairs(events) do
event_handlers[event_name] = clear_items
end
return {
return feature:guard{
events = event_handlers,
}
@@ -2,7 +2,16 @@
Makes pollution look much nice of the map, ie not one big red mess
]]
local config = require("modules.exp_legacy.config.pollution_grading")
local Feature = require("modules/exp_scenario/features")
local feature, config = Feature.register("pollution_grading", {
reference_point = { -- where pollution is read from
x = 0,
y = 0,
},
max_scalar = 0.5, -- the scale between true max and max
min_scalar = 0.17, -- the scale between the lowest max and min
})
local function check_surfaces()
local max_reference = 0
@@ -20,8 +29,8 @@ local function check_surfaces()
settings.min_to_show_per_chunk = min
end
return {
return feature:guard{
on_nth_tick = {
[config.update_delay * 3600] = check_surfaces,
}
[15 * 3600] = check_surfaces,
},
}
+62 -48
View File
@@ -1,48 +1,62 @@
--[[ Control - Research
Various research related event handlers
TODO Refactor this fully, this is temp to get it out of the research times gui file
]]
local config = require("modules/exp_legacy/config/research")
--- @param event EventData.on_research_finished
local function on_research_finished(event)
local research_name = event.research.name
if config.bonus_inventory.enabled and config.bonus_inventory.res[research_name] then
event.research.force[config.bonus_inventory.name] = math.min((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit)
end
if config.pollution_ageing_by_research and config.bonus_inventory.res[research_name] then
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
end
end
--- @param event EventData.on_research_started
local function on_research_started(event)
if config.limit_res[event.research.name] and event.research.level > config.limit_res[event.research.name] then
event.research.enabled = false
event.research.visible_when_disabled = true
local rq = event.research.force.research_queue
for i = #rq, 1, -1 do
if rq[i] == event.research.name then
table.remove(rq, i)
end
end
event.research.force.cancel_current_research()
event.research.force.research_queue = rq
end
end
local e = defines.events
return {
events = {
[e.on_research_finished] = on_research_finished,
[e.on_research_reversed] = on_research_finished,
[e.on_research_started] = on_research_started,
[e.on_research_queued] = on_research_started,
}
}
--[[ Control - Research
Various research related event handlers
TODO Refactor this fully, this is temp to get it out of the research times gui file
]]
local Feature = require("modules/exp_scenario/features")
local research_data = require("modules/exp_scenario/config/research_data")
local feature, config = Feature.register("research", {
pollution_ageing_by_research = false, -- pollution ages faster with each level of the bonus inventory researches
bonus_inventory = { -- extra inventory slots for each level of these researches
enabled = true,
res = Feature.set{ "mining-productivity", "mining-productivity-2", "mining-productivity-3", "mining-productivity-4" },
rate = 5,
limit = 20,
},
})
local bonus_inventory_name = "character_inventory_slots_bonus"
--- @param event EventData.on_research_finished
local function on_research_finished(event)
local research_name = event.research.name
if config.bonus_inventory.enabled and config.bonus_inventory.res[research_name] then
event.research.force[bonus_inventory_name] = math.min((event.research.level - 1) * config.bonus_inventory.rate, config.bonus_inventory.limit)
end
if config.pollution_ageing_by_research and config.bonus_inventory.res[research_name] then
game.map_settings.pollution.ageing = math.min(10, event.research.level / 5)
end
end
--- @param event EventData.on_research_started
local function on_research_started(event)
local limit = research_data.limit_res[event.research.name]
if limit and event.research.level > limit then
event.research.enabled = false
event.research.visible_when_disabled = true
local rq = event.research.force.research_queue
for i = #rq, 1, -1 do
if rq[i] == event.research.name then
table.remove(rq, i)
end
end
event.research.force.cancel_current_research()
event.research.force.research_queue = rq
end
end
local e = defines.events
return feature:guard{
events = {
[e.on_research_finished] = on_research_finished,
[e.on_research_reversed] = on_research_finished,
[e.on_research_started] = on_research_started,
[e.on_research_queued] = on_research_started,
}
}
+56 -12
View File
@@ -4,7 +4,43 @@ Stores solar panels, accumulators and landfill in a virtual layer which produces
local ExpUtil = require("modules/exp_util")
local Storage = require("modules/exp_util/storage")
local config = require("modules.exp_legacy.config.vlayer")
local Feature = require("modules/exp_scenario/features")
local items = require("modules/exp_scenario/config/vlayer_items")
local feature, config = Feature.register("vlayer", {
unlimited_capacity = false, -- an unlimited energy capacity, accumulators are not required
unlimited_surface_area = false, -- an unlimited surface area, landfill is not required
modded_auto_downgrade = false, -- modded items are converted into their base game equivalent, the originals can not be recovered
power_on_space = false, -- energy interfaces can be built on platforms
power_on_space_research = { -- the research level needed to build them there
name = "research-productivity",
level = 10,
},
mimic_surface = "nauvis", -- the surface the day cycle is copied from, empty to use the fixed cycle below
interface_limit = { -- how many of each interface can exist
energy = 1, -- >1 allows for disconnected power networks to receive power
circuit = 20,
storage_input = 20,
storage_output = 1, -- >0 allows for item teleportation of the allowed items
},
})
local update_tick_storage = 60
local update_tick_energy = 10
--- The day cycle used when there is no mimic surface, see LuaSurface for details
local surface_settings = {
always_day = false,
solar_power_multiplier = 1,
min_brightness = 0.15,
ticks_per_day = 25200,
daytime = 0,
dusk = 0.25,
evening = 0.45,
morning = 0.55,
dawn = 0.75,
}
local floor = math.floor
local min = math.min
@@ -58,6 +94,9 @@ local mega = 1000000
--- @class ExpScenario_Vlayer
local Vlayer = {
--- The config of the feature, read only
config = config,
feature = feature,
--- @package
events = {},
--- @package
@@ -66,11 +105,11 @@ local Vlayer = {
--- The properties of every allowed item, modded items are derived from their base game equivalent
local allowed_items = {} --- @type table<string, Vlayer.ItemProperties>
for name, properties in pairs(config.allowed_items) do
for name, properties in pairs(items.allowed_items) do
allowed_items[name] = properties
end
for name, properties in pairs(config.modded_items) do
local base = config.allowed_items[properties.base_game_equivalent]
for name, properties in pairs(items.modded_items) do
local base = items.allowed_items[properties.base_game_equivalent]
local multiplier = properties.multiplier
allowed_items[name] = {
starting_value = properties.starting_value or 0,
@@ -103,7 +142,7 @@ local vlayer_data = {
power_items = {},
energy = 0,
},
surface = table.deep_copy(config.surface),
surface = table.deep_copy(surface_settings),
}
Storage.register(vlayer_data, function(tbl)
@@ -490,7 +529,7 @@ local function handle_input_interfaces()
end
if removed > 0 then
local modded = config.modded_items[name]
local modded = items.modded_items[name]
if modded and config.modded_auto_downgrade then
Vlayer.insert_item(modded.base_game_equivalent, stored * modded.multiplier)
elseif vlayer_data.storage.power_items[name] then
@@ -595,7 +634,7 @@ end
local function handle_energy_interfaces()
local storage = vlayer_data.storage
local properties = vlayer_data.properties
local production = properties.production * mega * (config.update_tick_energy / 60)
local production = properties.production * mega * (update_tick_energy / 60)
storage.energy = storage.energy + floor(production * get_production_multiplier())
local interfaces = vlayer_data.interfaces.energy
@@ -634,7 +673,7 @@ end
--- Take the day cycle from the mimic surface when it exists, otherwise from the config
local function update_surface()
if config.mimic_surface then
if config.mimic_surface ~= "" then
local surface = game.get_surface(config.mimic_surface)
if surface then
vlayer_data.surface = surface
@@ -644,7 +683,7 @@ local function update_surface()
-- The config copy never has an index, so this avoids replacing it every time a surface changes
if not vlayer_data.surface.index then
vlayer_data.surface = table.deep_copy(config.surface)
vlayer_data.surface = table.deep_copy(surface_settings)
end
end
@@ -667,7 +706,12 @@ Vlayer.on_init = update_surface -- The default surface exists before on_surface_
Vlayer.events[e.on_surface_created] = update_surface
Vlayer.events[e.on_surface_renamed] = update_surface
Vlayer.events[e.on_surface_imported] = update_surface
Vlayer.on_nth_tick[config.update_tick_storage] = update_storage
Vlayer.on_nth_tick[config.update_tick_energy] = update_energy
Vlayer.events[Feature.events.on_config_updated] = function(event)
if event.feature_name == feature.name and event.path == "mimic_surface" then
update_surface()
end
end
Vlayer.on_nth_tick[update_tick_storage] = update_storage
Vlayer.on_nth_tick[update_tick_energy] = update_energy
return Vlayer
return feature:guard(Vlayer)