Files
factorio-expcluster/exp_scenario/module/control/custom_start.lua
T
Bastiaan 757a36fc03 Merge pull request #486 from bbassie/feature/convert-configs
Convert the remaining scenario configs into features
2026-10-05 00:33:36 +01:00

76 lines
3.1 KiB
Lua

--[[-- Control - Custom Start
Changes the starting script and the items given on first join depending on factory production levels
]]
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)
local get_prod_stats = (player.force --[[@as LuaForce]]).get_item_production_statistics(player.physical_surface)
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(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)
if count >= 1 then
insert_param.count = floor(count)
insert(insert_param)
end
elseif insert_amount >= 1 then
insert_param.count = floor(insert_amount)
insert(insert_param)
end
end
end
--- Calls remote interfaces to configure the base game scenarios
local function on_init()
game.forces.player.friendly_fire = config.friendly_fire
game.map_settings.enemy_expansion.enabled = config.enemy_expansion
if remote.interfaces["freeplay"] then
remote.call("freeplay", "set_created_items", {})
remote.call("freeplay", "set_disable_crashsite", config.disable_crashsite)
remote.call("freeplay", "set_skip_intro", config.skip_intro)
remote.call("freeplay", "set_chart_distance", config.chart_radius)
end
if remote.interfaces["silo_script"] then
remote.call("silo_script", "set_no_victory", config.skip_victory)
end
if remote.interfaces["space_finish_script"] then
remote.call("space_finish_script", "set_no_victory", config.skip_victory)
end
end
--- Give a player starting items when they first join
--- @param event EventData.on_player_created
local function on_player_created(event)
-- We can't trust on_init to work for clusterio
if event.player_index == 1 then on_init() end
give_starting_items(assert(game.get_player(event.player_index)))
end
local e = defines.events
return feature:guard{
on_init = on_init,
events = {
[e.on_player_created] = on_player_created,
},
give_starting_items = give_starting_items,
}