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

Merge pull request #165 from Oarcinae/162-change-safewarndanger-setting-distances-to-be-in-chunks-not-tiles

Change safe area settings from tiles to chunks. closes #162
This commit is contained in:
Oarcinae 2024-10-07 22:26:50 -04:00 committed by GitHub
commit f663cd10f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 23 deletions

View File

@ -67,19 +67,19 @@ NAUVIS_SPAWN_CONFIG =
safe_area =
{
-- Safe area has no aliens
-- This is the radius in tiles of safe area.
safe_radius = CHUNK_SIZE*6,
-- This is the radius in chunks of safe area.
safe_radius = 6,
-- Warning area has significantly reduced aliens
-- This is the radius in tiles of warning area.
warn_radius = CHUNK_SIZE*12,
-- This is the radius in chunks of warning area.
warn_radius = 12,
-- 1 : X (spawners alive : spawners destroyed) in this area
warn_reduction = 20,
-- Danger area has slightly reduced aliens
-- This is the radius in tiles of danger area.
danger_radius = CHUNK_SIZE*32,
-- This is the radius in chunks of danger area.
danger_radius = 32,
-- 1 : X (spawners alive : spawners destroyed) in this area
danger_reduction = 5,
@ -505,10 +505,10 @@ OCFG = {
---@field shape SpawnShapeChoice Spawn a circle/octagon/square of trees around this base outline.
---@class OarcConfigSpawnSafeArea
---@field safe_radius number Safe area has no aliens This is the radius in tiles of safe area.
---@field warn_radius number Warning area has significantly reduced aliens This is the radius in tiles of warning area.
---@field safe_radius number Safe area has no aliens This is the radius in chunks of safe area.
---@field warn_radius number Warning area has significantly reduced aliens This is the radius in chunks of warning area.
---@field warn_reduction number 1 : X (spawners alive : spawners destroyed) in this area
---@field danger_radius number Danger area has slightly reduce aliens This is the radius in tiles of danger area.
---@field danger_radius number Danger area has slightly reduce aliens This is the radius in chunks of danger area.
---@field danger_reduction number 1 : X (spawners alive : spawners destroyed) in this area
---@class OarcConfigSpawnWater

View File

@ -310,10 +310,10 @@ function CreateSafeAreaConfig(container, surface_name)
header.tooltip = "This controls how safe the area around the spawns is." -- TODO: Localize
-- TODO: Localize
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Safe Area Radius", "safe_area", "safe_radius", "This is the radius in tiles around the spawn in which no enemies will spawn.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Warn Area Radius", "safe_area", "warn_radius", "This is the radius in tiles around the spawn in which enemies will be significantly reduced.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Safe Area Radius", "safe_area", "safe_radius", "This is the radius in chunks around the spawn in which no enemies will spawn.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Warn Area Radius", "safe_area", "warn_radius", "This is the radius in chunks around the spawn in which enemies will be significantly reduced.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Warn Area Reduction", "safe_area", "warn_reduction", "This is the reduction factor to reduce the number of enemies in the warn area. 10 means (1/10)th the number of enemies.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Danger Area Radius", "safe_area", "danger_radius", "This is the radius in tiles around the spawn in which enemies will be slightly reduced.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Danger Area Radius", "safe_area", "danger_radius", "This is the radius in chunks around the spawn in which enemies will be slightly reduced.")
CreateSpawnConfigIntegerField(safe_area_flow, surface_name, "Danger Area Reduction", "safe_area", "danger_reduction", "This is the reduction factor to reduce the number of enemies in the danger area. 10 means (1/10)th the number of enemies.")
end

View File

@ -132,11 +132,11 @@ function DowngradeAndReduceEnemiesOnChunkGenerate(event)
}
-- Make chunks near a spawn safe by removing enemies
if (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.safe_radius) then
if (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.safe_radius * CHUNK_SIZE) then
RemoveEnemiesInArea(surface, chunk_area)
-- Create a warning area with heavily reduced enemies
elseif (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.warn_radius) then
elseif (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.warn_radius * CHUNK_SIZE) then
-- TODO: Refactor this to reduce calls to find_entities_filtered!
ReduceEnemiesInArea(surface, chunk_area, spawn_config.safe_area.warn_reduction)
@ -144,7 +144,7 @@ function DowngradeAndReduceEnemiesOnChunkGenerate(event)
ConvertEnemiesToOtherForceInArea(surface, chunk_area, ENEMY_FORCE_EASY)
-- Create a third area with moderately reduced enemies
elseif (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.danger_radius) then
elseif (util.distance(closest_spawn.position, chunkAreaCenter) < spawn_config.safe_area.danger_radius * CHUNK_SIZE) then
-- TODO: Refactor this to reduce calls to find_entities_filtered!
ReduceEnemiesInArea(surface, chunk_area, spawn_config.safe_area.danger_reduction)
@ -287,15 +287,15 @@ function ChangeEnemySpawnersToOtherForceOnBuilt(event)
if (closest_spawn == nil) then return end
-- No enemies inside safe radius!
if (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.safe_radius) then
if (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.safe_radius * CHUNK_SIZE) then
event.entity.destroy()
-- Warn distance should be EASY
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.warn_radius) then
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.warn_radius * CHUNK_SIZE) then
event.entity.force = game.forces[ENEMY_FORCE_EASY]
-- Danger distance should be MEDIUM
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius) then
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius * CHUNK_SIZE) then
event.entity.force = game.forces[ENEMY_FORCE_MEDIUM]
-- Otherwise make sure they are on the base enemy force (stops easy enemies from spreading out too far).
@ -328,11 +328,11 @@ function ModifyEnemySpawnsNearPlayerStartingAreas(event)
end
-- No enemies inside safe radius!
if (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.safe_radius) then
if (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.safe_radius * CHUNK_SIZE) then
event.entity.destroy()
-- Warn distance is all SMALL only.
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.warn_radius) then
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.warn_radius * CHUNK_SIZE) then
if ((enemy_name == "biter-spawner") or (enemy_name == "spitter-spawner")) then
event.entity.force = game.forces["enemy-easy"]
@ -351,7 +351,7 @@ function ModifyEnemySpawnsNearPlayerStartingAreas(event)
end
-- Danger distance is MEDIUM max.
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius) then
elseif (util.distance(enemy_pos, closest_spawn.position) < global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius * CHUNK_SIZE) 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 }

View File

@ -417,7 +417,7 @@ function SendPlayerToNewSpawnAndCreateIt(delayed_spawn)
local spawn_config = ocfg.surfaces_config[delayed_spawn.surface].spawn_config
-- DOUBLE CHECK and make sure the area is super safe.
ClearNearbyEnemies(delayed_spawn.position, spawn_config.safe_area.safe_radius,
ClearNearbyEnemies(delayed_spawn.position, spawn_config.safe_area.safe_radius * CHUNK_SIZE,
game.surfaces[delayed_spawn.surface])
-- Generate water strip only if we don't have a moat.
@ -649,7 +649,7 @@ function DowngradeResourcesDistanceBasedOnChunkGenerate(surface, chunkArea)
local distance = util.distance(chunkArea.left_top, closestSpawn.position)
-- Adjust multiplier to bring it in or out
local modifier = (distance / (global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius * 1)) ^ 3
local modifier = (distance / (global.ocfg.surfaces_config[surface.name].spawn_config.safe_area.danger_radius * CHUNK_SIZE * 1)) ^ 3
if modifier < 0.1 then modifier = 0.1 end
if modifier > 1 then return end

View File

@ -0,0 +1,16 @@
-- Migrate safe_radius, warn_radius and danger_radius to be chunks instead of tiles.
for surface_name, surface_config in pairs(global.ocfg.surfaces_config) do
-- If the safe_area is greater than 3 chunks, then it's likely in chunks...
if surface_config.spawn_config.safe_area.safe_radius >= (3 * 32) then
log("Oarc-mod: Migrating safe_radius, warn_radius and danger_radius to be chunks instead of tiles.")
local safe_radius = surface_config.spawn_config.safe_area.safe_radius
global.ocfg.surfaces_config[surface_name].spawn_config.safe_area.safe_radius = math.ceil(safe_radius / 32)
local warn_radius = surface_config.spawn_config.safe_area.warn_radius
global.ocfg.surfaces_config[surface_name].spawn_config.safe_area.warn_radius = math.ceil(warn_radius / 32)
local danger_radius = surface_config.spawn_config.safe_area.danger_radius
global.ocfg.surfaces_config[surface_name].spawn_config.safe_area.danger_radius = math.ceil(danger_radius / 32)
end
end