1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-12 10:13:58 +02:00

Add a way to offset the player spawn location by changing the config. Add migration for new random resource order config.

This commit is contained in:
Oarcinae 2024-12-09 11:38:18 -05:00
parent 1fb4dfb545
commit 72bc4b2ab8
5 changed files with 26 additions and 10 deletions

View File

@ -520,6 +520,7 @@ OCFG = {
---@field solid_resources table<string, OarcConfigSolidResource> Spawn area config for solid resource tiles
---@field fluid_resources table<string, OarcConfigFluidResource> Spawn area config for fluid resource patches (like oil)
---@field gleba_resources table<string, OarcConfigGlebaResource> Spawn area config for gleba-style resources (like plants and stromatolites)
---@field player_spawn_offset MapPosition The offset from the center of the spawn area where players will spawn. Can be nil.
---@class OarcConfigSpawnGeneral
---@field spawn_radius_tiles number THIS IS WHAT SETS THE SPAWN CIRCLE SIZE! Create a circle of land area for the spawn If you make this much bigger than a few chunks, good luck.

View File

@ -425,7 +425,7 @@ function SpawnCtrlTabGuiClick(event)
return
end
SetPlayerRespawn(player.name, surface_name, player.character.position, true)
SetPlayerRespawn(player.name, surface_name, player.character.position, true, false)
OarcGuiRefreshContent(player)
CompatSend(player, { "oarc-spawn-point-updated" })
@ -537,7 +537,7 @@ function SpawnCtrlTabGuiClick(event)
for player_name, unique_spawn in pairs(unique_spawn_entry) do
if (player_name == player.name) then
table.insert(unique_spawn.joiners, joining_player_name)
SetPlayerRespawn(joining_player_name, surface_name, unique_spawn.position, true)
SetPlayerRespawn(joining_player_name, surface_name, unique_spawn.position, true, true)
end
end
end

View File

@ -171,7 +171,9 @@ NAUVIS_SPAWN_CONFIG =
}
},
gleba_resources = {}
gleba_resources = {},
player_spawn_offset = nil,
}
---@type OarcConfigSurface

View File

@ -1501,7 +1501,7 @@ function QueuePlayerForSpawn(player_name, delayed_spawn)
SafeTeleport(player, game.surfaces[HOLDING_PEN_SURFACE_NAME], {x=0,y=0})
end
SetPlayerRespawn(player_name, delayed_spawn.surface_name, delayed_spawn.position, true)
SetPlayerRespawn(player_name, delayed_spawn.surface_name, delayed_spawn.position, true, true)
CompatSend(game.players[player_name], { "oarc-generating-spawn-please-wait" }, { volume_modifier = 0})
@ -1520,13 +1520,20 @@ end
---@param surface_name string
---@param position MapPosition
---@param reset_cooldown boolean
---@param use_offset boolean
---@return nil
function SetPlayerRespawn(player_name, surface_name, position, reset_cooldown)
function SetPlayerRespawn(player_name, surface_name, position, reset_cooldown, use_offset)
---@type OarcPlayerSpawn
local updatedPlayerSpawn = {}
updatedPlayerSpawn.surface = surface_name
updatedPlayerSpawn.position = position
-- Allow modders to set a custom offset for the player spawn point.
local offset = storage.ocfg.surfaces_config[surface_name].spawn_config.player_spawn_offset
if use_offset and (offset ~= nil) then
updatedPlayerSpawn.position = { x = position.x + offset.x, y = position.y + offset.y }
end
storage.player_respawns[player_name][surface_name] = updatedPlayerSpawn
@ -1683,7 +1690,7 @@ function SecondarySpawn(player, surface_name, send_player)
if send_player then
QueuePlayerForSpawn(player_name, delayed_spawn)
else
SetPlayerRespawn(player_name, delayed_spawn.surface_name, delayed_spawn.position, true)
SetPlayerRespawn(player_name, delayed_spawn.surface_name, delayed_spawn.position, true, true)
end
-- Handle special buddy spawns:
@ -1692,14 +1699,14 @@ function SecondarySpawn(player, surface_name, send_player)
local buddy_choices = storage.spawn_choices[spawn_choices.buddy]
GenerateNewSpawn(spawn_choices.buddy, surface_name, buddy_position, buddy_choices, false)
SetPlayerRespawn(spawn_choices.buddy, surface_name, buddy_position, false)
SetPlayerRespawn(spawn_choices.buddy, surface_name, buddy_position, false, true)
-- Make sure host and joiners all have their new respawn position set for this surface.
elseif (#storage.unique_spawns[surface_name][host_name].joiners > 0) then
SetPlayerRespawn(host_name, surface_name, spawn_position, false)
SetPlayerRespawn(host_name, surface_name, spawn_position, false, true)
for _,joiner_name in pairs(storage.unique_spawns[surface_name][host_name].joiners) do
SetPlayerRespawn(joiner_name, surface_name, spawn_position, false)
SetPlayerRespawn(joiner_name, surface_name, spawn_position, false, true)
end
end

View File

@ -1,5 +1,11 @@
-- Add the new remove decoratives setting
if storage.ocfg.spawn_general.remove_decoratives == nil then
log("Adding new remove_decoratives setting to spawn_general config.")
storage.ocfg.spawn_general.remove_decoratives = false -- Defaults to false
storage.ocfg.spawn_general.remove_decoratives = false
end
-- Add the new random order setting
if storage.ocfg.resource_placement.random_order == nil then
log("Adding new random_order setting to resource_placement config.")
storage.ocfg.resource_placement.random_order = true
end