From 72bc4b2ab8cc6eed9ac49de8a97a1d6740e463d8 Mon Sep 17 00:00:00 2001 From: Oarcinae Date: Mon, 9 Dec 2024 11:38:18 -0500 Subject: [PATCH] Add a way to offset the player spawn location by changing the config. Add migration for new random resource order config. --- lib/config.lua | 1 + lib/gui_tabs/spawn_controls.lua | 4 ++-- lib/planet_configs/nauvis.lua | 4 +++- lib/separate_spawns.lua | 19 +++++++++++++------ migrations/oarc-mod-V2.1.17.lua | 8 +++++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/config.lua b/lib/config.lua index 307aace..e7003a0 100644 --- a/lib/config.lua +++ b/lib/config.lua @@ -520,6 +520,7 @@ OCFG = { ---@field solid_resources table Spawn area config for solid resource tiles ---@field fluid_resources table Spawn area config for fluid resource patches (like oil) ---@field gleba_resources table 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. diff --git a/lib/gui_tabs/spawn_controls.lua b/lib/gui_tabs/spawn_controls.lua index 91de3ca..7e306cf 100644 --- a/lib/gui_tabs/spawn_controls.lua +++ b/lib/gui_tabs/spawn_controls.lua @@ -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 diff --git a/lib/planet_configs/nauvis.lua b/lib/planet_configs/nauvis.lua index 9ec3bb2..3e2181f 100644 --- a/lib/planet_configs/nauvis.lua +++ b/lib/planet_configs/nauvis.lua @@ -171,7 +171,9 @@ NAUVIS_SPAWN_CONFIG = } }, - gleba_resources = {} + gleba_resources = {}, + + player_spawn_offset = nil, } ---@type OarcConfigSurface diff --git a/lib/separate_spawns.lua b/lib/separate_spawns.lua index eb26b79..c297590 100644 --- a/lib/separate_spawns.lua +++ b/lib/separate_spawns.lua @@ -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 diff --git a/migrations/oarc-mod-V2.1.17.lua b/migrations/oarc-mod-V2.1.17.lua index 32c03fa..20780ee 100644 --- a/migrations/oarc-mod-V2.1.17.lua +++ b/migrations/oarc-mod-V2.1.17.lua @@ -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 \ No newline at end of file