1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-04 09:43:00 +02:00

Merge pull request #280 from Oarcinae/dev_2.1.15

Dev 2.1.15
This commit is contained in:
Oarcinae 2024-11-26 22:24:01 -05:00 committed by GitHub
commit 47ddc9fd08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 113 additions and 102 deletions

View File

@ -1,4 +1,15 @@
---------------------------------------------------------------------------------------------------
Version: 2.1.15
Date: 2024-11-27
Bugfixes:
- Fix crash when player spawns due to missing surface configuration due to a missing migration.
Changes:
- Images losslessly compressed to reduce mod size. (Thanks plexpt!)
Modding:
- Adding first_spawn and is_host flags to oarc-mod-on-player-spawned event.
- Add additional remote interfaces: get_unique_spawns, get_player_home_spawn, get_player_primary_spawn.
- Adding new custom event: oarc-mod-on-spawn-choices-gui-displayed. Intended to let other modders customize the spawn choices GUI.
---------------------------------------------------------------------------------------------------
Version: 2.1.14
Date: 2024-11-21
Info:

View File

@ -162,6 +162,15 @@ end)
---@field name integer --For custom events, this is the event ID
---@field tick integer
---@class OarcModOnSpawnChoicesGuiDisplayedEvent: OarcCustomEventBase
---@field player_index integer
---@field gui_element LuaGuiElement
script.on_event("oarc-mod-on-spawn-choices-gui-displayed", function(event)
log("EVENT - oarc-mod-on-spawn-choices-gui-displayed:" .. serpent.block(event --[[@as OarcModOnSpawnChoicesGuiDisplayedEvent]]))
-- The 4 main sub sections are called: spawn_settings_frame, solo_spawn_frame, shared_spawn_frame, and buddy_spawn_frame
end)
---@class OarcModOnSpawnCreatedEvent: OarcCustomEventBase
---@field spawn_data OarcUniqueSpawn
script.on_event("oarc-mod-on-spawn-created", function(event)
@ -182,6 +191,8 @@ end)
---@class OarcModOnPlayerSpawnedEvent: OarcCustomEventBase
---@field player_index integer
---@field first_spawn boolean
---@field is_host boolean
script.on_event("oarc-mod-on-player-spawned", function(event)
log("EVENT - oarc-mod-on-player-spawned:" .. serpent.block(event --[[@as OarcModOnPlayerSpawnedEvent]]))
end)
@ -452,7 +463,19 @@ local oarc_mod_interface =
{
get_mod_settings = function()
return storage.ocfg
end
end,
get_unique_spawns = function()
return storage.unique_spawns
end,
get_player_home_spawn = function(player_name)
return FindPlayerHomeSpawn(player_name)
end,
get_player_primary_spawn = function(player_name)
return FindPrimaryUniqueSpawn(player_name)
end,
}
remote.add_interface("oarc_mod", oarc_mod_interface)

View File

@ -24,19 +24,24 @@ data:extend({
oarc_linked_chest, oarc_linked_power,
})
-- See control.lua for the event type defs to see what each event provides you.
data:extend({
-- A player was presented with the spawn options
{
type = "custom-event",
name = "oarc-mod-on-spawn-choices-gui-displayed",
},
-- A spawn area was created (and is finished generating)
{
type = "custom-event",
name = "oarc-mod-on-spawn-created",
-- Provides data table called spawn_data
},
-- A spawn area was REQUESTED to be removed. (Not that it has been removed already.)
{
type = "custom-event",
name = "oarc-mod-on-spawn-remove-request",
-- Provides data table called spawn_data
},
-- A player was reset (also called when a player is removed)
@ -44,21 +49,18 @@ data:extend({
{
type = "custom-event",
name = "oarc-mod-on-player-reset",
-- Provides player_index
},
-- A player was spawned (sent to a new spawn OR joined a shared spawn)
{
type = "custom-event",
name = "oarc-mod-on-player-spawned",
-- Provides player_index
},
-- A player moved from surface to space platform
{
type = "custom-event",
name = "oarc-mod-character-surface-changed",
-- Provides player_index, old_surface_name, new_surface_name
},
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,6 +1,6 @@
{
"name": "oarc-mod",
"version": "2.1.14",
"version": "2.1.15",
"factorio_version": "2.0",
"title": "Oarc Multiplayer Spawn",
"author": "Oarcinae",

View File

@ -543,7 +543,7 @@ function SpawnCtrlTabGuiClick(event)
end
-- Send player to the host's primary spawn.
SendPlayerToNewSpawn(joining_player_name, primary_spawn.surface_name, true)
SendPlayerToNewSpawn(joining_player_name, primary_spawn.surface_name, true, false)
-- Render some welcoming text...
DisplayWelcomeGroundTextAtSpawn(primary_spawn.surface_name, primary_spawn.position)

View File

@ -431,7 +431,9 @@ function GenerateStartingResources(surface, position)
local y_offset = storage.ocfg.resource_placement.distance_to_edge
local fluid_ref_pos = { x = position.x, y = position.y + radius - y_offset }
for r_name, r_data in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources --[[@as table<string, OarcConfigFluidResource>]]) do
local fluid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources
if fluid_resources ~= nil then
for r_name, r_data in pairs(fluid_resources) do
local spacing = r_data.spacing
local oil_patch_x = fluid_ref_pos.x - (((r_data.num_patches-1) * spacing) / 2)
@ -448,11 +450,14 @@ function GenerateStartingResources(surface, position)
fluid_ref_pos.y = fluid_ref_pos.y - spacing
end
end
-- This places using specified offsets if auto placement is disabled.
else
local fluid_ref_pos = { x = position.x, y = position.y + radius }
for r_name, r_data in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources --[[@as table<string, OarcConfigFluidResource>]]) do
local fluid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.fluid_resources
if fluid_resources ~= nil then
for r_name, r_data in pairs(fluid_resources) do
local oil_patch_x = fluid_ref_pos.x + r_data.x_offset_start
local oil_patch_y = fluid_ref_pos.y + r_data.y_offset_start
for i = 1, r_data.num_patches do
@ -467,6 +472,7 @@ function GenerateStartingResources(surface, position)
end
end
end
end
---Places starting resource deposits in a semi-circle around the spawn point.
---@param surface LuaSurface
@ -479,17 +485,24 @@ function PlaceResourcesInSemiCircle(surface, position, size_mod, amount_mod)
-- Create list of resource tiles
---@type table<string>
local r_list = {}
for r_name, _ in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.solid_resources) do
local solid_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.solid_resources
if solid_resources ~= nil then
for r_name, _ in pairs(solid_resources) do
if (r_name ~= "") then
table.insert(r_list, r_name)
end
end
end
for g_name,_ in pairs(storage.ocfg.surfaces_config[surface.name].spawn_config.gleba_resources) do
-- Gleba style resources like plants
local gleba_resources = storage.ocfg.surfaces_config[surface.name].spawn_config.gleba_resources
if gleba_resources ~= nil then
for g_name, _ in pairs(gleba_resources) do
if (g_name ~= "") then
table.insert(r_list, g_name)
end
end
end
---@type table<string>
local shuffled_list = FYShuffle(r_list)
@ -658,15 +671,16 @@ end
---@param player_name string
---@param surface_name string
---@param first_spawn boolean
---@param is_host boolean
---@return nil
function SendPlayerToNewSpawn(player_name, surface_name, first_spawn)
function SendPlayerToNewSpawn(player_name, surface_name, first_spawn, is_host)
local player = game.players[player_name]
-- Check if player character is nil
if (player.character == nil) then
log("Player character is nil, can't send to spawn point just yet: " .. player_name)
QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn)
QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn, is_host)
return
end
@ -681,10 +695,10 @@ function SendPlayerToNewSpawn(player_name, surface_name, first_spawn)
-- Only first time spawns get starter items.
if first_spawn then
GivePlayerStarterItems(player)
end
-- Trigger the event that player was spawned too.
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index})
end
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index, first_spawn = first_spawn, is_host = is_host})
end
---Displays some welcoming text at the spawn point on the ground. Fades out over time.
@ -852,51 +866,6 @@ end
--]]
-- ---Resets the player and destroys their force if they are not on the main one.
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndDestroyForce(player)
-- local player_old_force = player.force
-- player.force = storage.ocfg.gameplay.main_force_name
-- if ((#player_old_force.players == 0) and (player_old_force.name ~= storage.ocfg.gameplay.main_force_name)) then
-- SendBroadcastMsg("Team " ..
-- player_old_force.name .. " has been destroyed! All buildings will slowly be destroyed now.") --: localize
-- log("DestroyForce - FORCE DESTROYED: " .. player_old_force.name)
-- game.merge_forces(player_old_force, DESTROYED_FORCE_NAME)
-- end
-- RemoveOrResetPlayer(player, false, false, true, true)
-- SeparateSpawnsInitPlayer(player.index)
-- end
-- ---Resets the player and merges their force into the abandoned_force.
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndAbandonForce(player)
-- local player_old_force = player.force
-- player.force = storage.ocfg.gameplay.main_force_name
-- if ((#player_old_force.players == 0) and (player_old_force.name ~= storage.ocfg.gameplay.main_force_name)) then
-- SendBroadcastMsg("Team " .. player_old_force.name .. " has been abandoned!") --: localize
-- log("AbandonForce - FORCE ABANDONED: " .. player_old_force.name)
-- game.merge_forces(player_old_force, ABANDONED_FORCE_NAME)
-- end
-- RemoveOrResetPlayer(player, false, false, false, false)
-- SeparateSpawnsInitPlayer(player.index)
-- end
-- ---Reset player and merge their force to neutral
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndMergeForceToNeutral(player)
-- RemoveOrResetPlayer(player, false, true, true, true)
-- SeparateSpawnsInitPlayer(player.index)
-- end
---Call this if a player leaves the game early (or a player wants an early game reset)
---@param player LuaPlayer
---@param remove_player boolean Deletes player from the game assuming they are offline.
@ -1197,10 +1166,11 @@ end
---@param player_name string
---@param surface_name string
---@param first_spawn boolean
---@param is_host boolean
---@return nil
function QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn)
function QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn, is_host)
if (storage.nil_character_teleport_queue[player_name] == nil) then
storage.nil_character_teleport_queue[player_name] = { surface_name = surface_name, first_spawn = first_spawn }
storage.nil_character_teleport_queue[player_name] = { surface_name = surface_name, first_spawn = first_spawn, is_host = is_host }
end
end
@ -1218,7 +1188,7 @@ function OnTickNilCharacterTeleportQueue()
-- And hope to high heaven this doesn't recurse infinitely.
elseif (player.character ~= nil) then
storage.nil_character_teleport_queue[player_name] = nil
SendPlayerToNewSpawn(player_name, data.surface_name, data.first_spawn)
SendPlayerToNewSpawn(player_name, data.surface_name, data.first_spawn, data.is_host)
end
end
end
@ -1678,7 +1648,7 @@ function DelayedSpawnOnTick()
for _,player_name in pairs(delayed_spawn.waiting_players) do
local player = game.players[player_name]
if (player ~= nil) then
SendPlayerToNewSpawn(player_name, delayed_spawn.surface_name, delayed_spawn.primary)
SendPlayerToNewSpawn(player_name, delayed_spawn.surface_name, delayed_spawn.primary, delayed_spawn.host_name == player_name)
end
end
@ -1865,4 +1835,4 @@ SPAWN_TEAM_CHOICE = {
---@alias OarcSurfaceSpawnSetting { primary: boolean, secondary: boolean}
---Entry for a nil_character_teleport_queue
---@alias OarcNilCharacterTeleportQueueEntry { surface_name: string, first_spawn: boolean }
---@alias OarcNilCharacterTeleportQueueEntry { surface_name: string, first_spawn: boolean, is_host: boolean }

View File

@ -127,15 +127,6 @@ function CreateSpawnMenuGuiFrame(player)
}
subhead.style.height = 46
subhead.style.horizontally_stretchable = true
-- changelog_subheader_frame =
-- {
-- type = "frame_style",
-- parent = "subheader_frame",
-- left_padding = 12,
-- right_padding = 12,
-- top_padding = 4,
-- horizontally_stretchable = "on"
-- }
AddLabel(subhead, "warning_lbl1", { "oarc-click-info-btn-help" }, my_note_style)
return inside_frame
@ -623,6 +614,8 @@ function DisplaySpawnOptions(player)
CreateSoloSpawnFrame(sGui, gameplay.enable_shared_spawns, gameplay.number_of_players_per_shared_spawn) -- The primary method of spawning
CreateSharedSpawnFrame(sGui, gameplay.enable_shared_spawns) -- Spawn options to join another player's base.
CreateBuddySpawnFrame(sGui, player, gameplay.enable_buddy_spawn, gameplay.enable_separate_teams) -- Awesome buddy spawning system
script.raise_event("oarc-mod-on-spawn-choices-gui-displayed", { player_index = player.index, gui_element = sGui })
end

View File

@ -0,0 +1,12 @@
--Fix missing gleba_resources for the surfaces that I didn't update in 2.1.13.
if (storage.ocfg.surfaces_config["nauvis"].spawn_config.gleba_resources == nil) then
storage.ocfg.surfaces_config["nauvis"].spawn_config.gleba_resources = {}
log("Fixing nauvis config with empty gleba_resources entry.")
end
if script.active_mods["space-age"] ~= nil then
if (storage.ocfg.surfaces_config["fulgora"].spawn_config.gleba_resources == nil) then
storage.ocfg.surfaces_config["fulgora"].spawn_config.gleba_resources = {}
log("Fixing fulgora config with empty gleba_resources entry.")
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 464 KiB

After

Width:  |  Height:  |  Size: 177 KiB