mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2025-02-09 13:13:42 +02:00
Trying to fix a bug with shared spawns when a player leaves. Cleaning up some more of the config settings, regrowth logic and some other minor things.
This commit is contained in:
parent
f5c4b86774
commit
479686059b
26
control.lua
26
control.lua
@ -71,18 +71,18 @@ script.on_init(function(event)
|
||||
-- MUST be before other stuff, but after surface creation.
|
||||
InitSpawnGlobalsAndForces()
|
||||
|
||||
if SILO_FIXED_POSITION then
|
||||
SetFixedSiloPosition(SILO_POSITION)
|
||||
else
|
||||
SetRandomSiloPosition(SILO_NUM_SPAWNS)
|
||||
end
|
||||
|
||||
if FRONTIER_ROCKET_SILO_MODE then
|
||||
GenerateRocketSiloAreas(game.surfaces[GAME_SURFACE_NAME])
|
||||
end
|
||||
|
||||
-- Regardless of whether it's enabled or not, it's good to have this init.
|
||||
OarcRegrowthInit()
|
||||
|
||||
if global.ocfg.frontier_fixed_pos then
|
||||
SetFixedSiloPosition(global.ocfg.frontier_pos_table)
|
||||
else
|
||||
SetRandomSiloPosition(global.ocfg.frontier_silo_count)
|
||||
end
|
||||
|
||||
if global.ocfg.frontier_rocket_silo then
|
||||
GenerateRocketSiloAreas(game.surfaces[GAME_SURFACE_NAME])
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@ -198,7 +198,7 @@ script.on_event(defines.events.on_player_respawned, function(event)
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_left_game, function(event)
|
||||
FindUnusedSpawns(event)
|
||||
FindUnusedSpawns(game.players[event.player_index], true)
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_built_entity, function(event)
|
||||
@ -207,7 +207,7 @@ script.on_event(defines.events.on_built_entity, function(event)
|
||||
end
|
||||
|
||||
if global.ocfg.enable_regrowth then
|
||||
OarcRegrowthOffLimitsChunk(event.created_entity.position)
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
end
|
||||
|
||||
if ENABLE_ANTI_GRIEFING then
|
||||
@ -250,7 +250,7 @@ end)
|
||||
----------------------------------------
|
||||
script.on_event(defines.events.on_robot_built_entity, function (event)
|
||||
if global.ocfg.enable_regrowth then
|
||||
OarcRegrowthOffLimitsChunk(event.created_entity.position)
|
||||
OarcRegrowthOffLimits(event.created_entity.position, 1)
|
||||
end
|
||||
end)
|
||||
script.on_event(defines.events.on_player_mined_entity, function(event)
|
||||
|
@ -61,6 +61,8 @@ function InitOarcConfig()
|
||||
global.ocfg.respawn_cooldown_min = RESPAWN_COOLDOWN_IN_MINUTES
|
||||
global.ocfg.frontier_silo_count = SILO_NUM_SPAWNS
|
||||
global.ocfg.frontier_silo_distance = SILO_CHUNK_DISTANCE
|
||||
global.ocfg.frontier_fixed_pos = SILO_FIXED_POSITION
|
||||
global.ocfg.frontier_pos_table = SILO_POSITION
|
||||
global.ocfg.frontier_silo_vision = ENABLE_SILO_VISION
|
||||
|
||||
-- MOD VERSION
|
||||
@ -181,6 +183,8 @@ function InitOarcConfig()
|
||||
global.ocfg.respawn_cooldown_min = settings.global["oarc-respawn-cooldown-min"].value
|
||||
global.ocfg.frontier_silo_count = settings.global["oarc-frontier-silo-count"].value
|
||||
global.ocfg.frontier_silo_distance = settings.global["oarc-frontier-silo-distance"].value
|
||||
global.ocfg.frontier_fixed_pos = false
|
||||
global.ocfg.frontier_pos_table = {x = 0, y = 100}
|
||||
global.ocfg.frontier_silo_vision = settings.global["oarc-frontier-silo-vision"].value
|
||||
end
|
||||
end
|
@ -152,29 +152,23 @@ function OarcRegrowthMarkForRemoval(pos, chunk_radius)
|
||||
end
|
||||
end
|
||||
|
||||
-- Marks a chunk a position that won't ever be deleted.
|
||||
function OarcRegrowthOffLimitsChunk(pos)
|
||||
-- Marks a chunk containing a position that won't ever be deleted.
|
||||
function OarcRegrowthOffLimitsPos(pos)
|
||||
local c_pos = GetChunkCoordsFromPos(pos)
|
||||
|
||||
if (global.chunk_regrow.map[c_pos.x] == nil) then
|
||||
global.chunk_regrow.map[c_pos.y] = {}
|
||||
global.chunk_regrow.map[c_pos.x] = {}
|
||||
end
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = -1
|
||||
end
|
||||
|
||||
|
||||
-- Marks a safe area around a position that won't ever be deleted.
|
||||
function OarcRegrowthOffLimits(pos, chunk_radius)
|
||||
local c_pos = GetChunkCoordsFromPos(pos)
|
||||
for i=-chunk_radius,chunk_radius do
|
||||
for k=-chunk_radius,chunk_radius do
|
||||
local x = c_pos.x+i
|
||||
local y = c_pos.y+k
|
||||
|
||||
if (global.chunk_regrow.map[x] == nil) then
|
||||
global.chunk_regrow.map[x] = {}
|
||||
end
|
||||
global.chunk_regrow.map[x][y] = -1
|
||||
for i=-chunk_radius,chunk_radius do
|
||||
for j=-chunk_radius,chunk_radius do
|
||||
OarcRegrowthOffLimitsPos({x=c_pos.x+i,y=c_pos.y+j})
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -184,7 +178,7 @@ function OarcRegrowthRefreshChunk(pos, bonus_time)
|
||||
local c_pos = GetChunkCoordsFromPos(pos)
|
||||
|
||||
if (global.chunk_regrow.map[c_pos.x] == nil) then
|
||||
global.chunk_regrow.map[c_pos.y] = {}
|
||||
global.chunk_regrow.map[c_pos.x] = {}
|
||||
end
|
||||
if (global.chunk_regrow.map[c_pos.x][c_pos.y] ~= -1) then
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick + bonus_time
|
||||
@ -197,7 +191,7 @@ function OarcRegrowthForceRefreshChunk(pos, bonus_time)
|
||||
local c_pos = GetChunkCoordsFromPos(pos)
|
||||
|
||||
if (global.chunk_regrow.map[c_pos.x] == nil) then
|
||||
global.chunk_regrow.map[c_pos.y] = {}
|
||||
global.chunk_regrow.map[c_pos.x] = {}
|
||||
end
|
||||
global.chunk_regrow.map[c_pos.x][c_pos.y] = game.tick + bonus_time
|
||||
end
|
||||
|
@ -16,6 +16,11 @@ require("config")
|
||||
-- without shouting.
|
||||
function SeparateSpawnsPlayerCreated(player_index)
|
||||
local player = game.players[player_index]
|
||||
|
||||
if (player.force.name ~= "player") then
|
||||
FindUnusedSpawns(player, false)
|
||||
end
|
||||
|
||||
player.force = global.ocfg.main_force
|
||||
DisplayWelcomeTextGui(player)
|
||||
end
|
||||
@ -47,9 +52,13 @@ function SeparateSpawnsGenerateChunk(event)
|
||||
end
|
||||
|
||||
|
||||
-- Call this if a player leaves the game
|
||||
function FindUnusedSpawns(event)
|
||||
local player = game.players[event.player_index]
|
||||
-- Call this if a player leaves the game or is reset
|
||||
function FindUnusedSpawns(player, remove_player)
|
||||
if not player then
|
||||
log("ERROR - FindUnusedSpawns on NIL Player!")
|
||||
return
|
||||
end
|
||||
|
||||
if (player.online_time < (global.ocfg.minimum_online_time * TICKS_PER_MINUTE)) then
|
||||
|
||||
-- Clear out global variables for that player
|
||||
@ -139,7 +148,9 @@ function FindUnusedSpawns(event)
|
||||
end
|
||||
|
||||
-- Remove the character completely
|
||||
game.remove_offline_players({player})
|
||||
if (remove_player) then
|
||||
game.remove_offline_players({player})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -205,6 +216,31 @@ function SetupAndClearSpawnAreas(surface, chunkArea)
|
||||
end
|
||||
end
|
||||
|
||||
-- Same as GetClosestPosFromTable but specific to global.uniqueSpawns
|
||||
function GetClosestUniqueSpawn(pos)
|
||||
|
||||
local closest_dist = nil
|
||||
local closest_key = nil
|
||||
|
||||
for k,s in pairs(global.uniqueSpawns) do
|
||||
local new_dist = getDistance(pos, s.pos)
|
||||
if (closest_dist == nil) then
|
||||
closest_dist = new_dist
|
||||
closest_key = k
|
||||
elseif (closest_dist > new_dist) then
|
||||
closest_dist = new_dist
|
||||
closest_key = k
|
||||
end
|
||||
end
|
||||
|
||||
if (closest_key == nil) then
|
||||
log("GetClosestUniqueSpawn ERROR - None found?")
|
||||
return nil
|
||||
end
|
||||
|
||||
return global.uniqueSpawns[closest_key]
|
||||
end
|
||||
|
||||
-- I wrote this to ensure everyone gets safer spawns regardless of evolution level.
|
||||
-- This is intended to downgrade any biters/spitters spawning near player bases.
|
||||
-- I'm not sure the performance impact of this but I'm hoping it's not bad.
|
||||
@ -219,27 +255,47 @@ function ModifyEnemySpawnsNearPlayerStartingAreas(event)
|
||||
local surface = event.entity.surface
|
||||
local enemy_name = event.entity.name
|
||||
|
||||
for name,spawn in pairs(global.uniqueSpawns) do
|
||||
if (getDistance(enemy_pos, spawn.pos) < global.ocfg.spawn_config.safe_area.warn_radius) then
|
||||
if ((enemy_name == "big-biter") or (enemy_name == "behemoth-biter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-biter", position = enemy_pos, force = game.forces.enemy}
|
||||
log("Downgraded biter close to spawn.")
|
||||
elseif ((enemy_name == "big-spitter") or (enemy_name == "behemoth-spitter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-spitter", position = enemy_pos, force = game.forces.enemy}
|
||||
log("Downgraded spitter close to spawn.")
|
||||
end
|
||||
elseif (getDistance(enemy_pos, spawn.pos) < global.ocfg.spawn_config.safe_area.danger_radius) then
|
||||
if (enemy_name == "behemoth-biter") then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-biter", position = enemy_pos, force = game.forces.enemy}
|
||||
log("Downgraded biter further from spawn.")
|
||||
elseif (enemy_name == "behemoth-spitter") then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-spitter", position = enemy_pos, force = game.forces.enemy}
|
||||
log("Downgraded spitter further from spawn.")
|
||||
end
|
||||
local closest_spawn = GetClosestUniqueSpawn(enemy_pos)
|
||||
|
||||
if (closest_spawn == nil) then
|
||||
log("GetClosestUniqueSpawn ERROR - None found?")
|
||||
return
|
||||
end
|
||||
|
||||
-- No enemies inside safe radius!
|
||||
if (getDistance(enemy_pos, closest_spawn.pos) < global.ocfg.spawn_config.safe_area.safe_radius) then
|
||||
event.entity.destroy()
|
||||
|
||||
-- Warn distance is all SMALL only.
|
||||
if (getDistance(enemy_pos, closest_spawn.pos) < global.ocfg.spawn_config.safe_area.warn_radius) then
|
||||
if ((enemy_name == "big-biter") or (enemy_name == "behemoth-biter") or (enemy_name == "medium-biter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "small-biter", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded biter close to spawn.")
|
||||
elseif ((enemy_name == "big-spitter") or (enemy_name == "behemoth-spitter") or (enemy_name == "medium-spitter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "small-spitter", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded spitter close to spawn.")
|
||||
elseif ((enemy_name == "big-worm-turret") or (enemy_name == "behemoth-worm-turret") or (enemy_name == "medium-worm-turret")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "small-worm-turret", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded worm close to spawn.")
|
||||
end
|
||||
|
||||
-- Danger distance is MEDIUM max.
|
||||
elseif (getDistance(enemy_pos, closest_spawn.pos) < global.ocfg.spawn_config.safe_area.danger_radius) then
|
||||
if ((enemy_name == "big-biter") or (enemy_name == "behemoth-biter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-biter", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded biter further from spawn.")
|
||||
elseif ((enemy_name == "big-spitter") or (enemy_name == "behemoth-spitter")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-spitter", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded spitter further from spawn
|
||||
elseif ((enemy_name == "big-worm-turret") or (enemy_name == "behemoth-worm-turret")) then
|
||||
event.entity.destroy()
|
||||
surface.create_entity{name = "medium-worm-turret", position = enemy_pos, force = game.forces.enemy}
|
||||
-- log("Downgraded worm further from spawn.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user