Skip to content

Commit

Permalink
Merge pull request #280 from Oarcinae/dev_2.1.15
Browse files Browse the repository at this point in the history
Dev 2.1.15
  • Loading branch information
Oarcinae authored Nov 27, 2024
2 parents 032d173 + dda40a5 commit 47ddc9f
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 104 deletions.
11 changes: 11 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
25 changes: 24 additions & 1 deletion control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
12 changes: 7 additions & 5 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,43 @@ 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)
-- If you want just player removed, use native on_player_removed and/or on_pre_player_removed
{
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
},
})

Expand Down
Binary file modified graphics/hr-oarc-electric-pole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified graphics/hr-oarc-linked-chest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified icon_40x40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/gui_tabs/spawn_controls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
144 changes: 57 additions & 87 deletions lib/separate_spawns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -431,38 +431,44 @@ 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 spacing = r_data.spacing
local oil_patch_x = fluid_ref_pos.x - (((r_data.num_patches-1) * spacing) / 2)
local oil_patch_y = fluid_ref_pos.y

for i = 1, r_data.num_patches do
surface.create_entity({
name = r_name,
amount = r_data.amount,
position = { oil_patch_x, oil_patch_y }
})
oil_patch_x = oil_patch_x + spacing
end
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)
local oil_patch_y = fluid_ref_pos.y

for i = 1, r_data.num_patches do
surface.create_entity({
name = r_name,
amount = r_data.amount,
position = { oil_patch_x, oil_patch_y }
})
oil_patch_x = oil_patch_x + spacing
end

fluid_ref_pos.y = fluid_ref_pos.y - spacing
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 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
surface.create_entity({
name = r_name,
amount = r_data.amount,
position = { oil_patch_x, oil_patch_y }
})
oil_patch_x = oil_patch_x + r_data.x_offset_next
oil_patch_y = oil_patch_y + r_data.y_offset_next
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
surface.create_entity({
name = r_name,
amount = r_data.amount,
position = { oil_patch_x, oil_patch_y }
})
oil_patch_x = oil_patch_x + r_data.x_offset_next
oil_patch_y = oil_patch_y + r_data.y_offset_next
end
end
end
end
Expand All @@ -479,15 +485,22 @@ 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
if (r_name ~= "") then
table.insert(r_list, r_name)
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
if (g_name ~= "") then
table.insert(r_list, g_name)
-- 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

Expand Down Expand Up @@ -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

Expand All @@ -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)

-- Trigger the event that player was spawned too.
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index})
end

-- Trigger the event that player was spawned too.
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 }
11 changes: 2 additions & 9 deletions lib/separate_spawns_guis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
12 changes: 12 additions & 0 deletions migrations/oarc-mod-v2.1.15.lua
Original file line number Diff line number Diff line change
@@ -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 modified thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 47ddc9f

Please sign in to comment.