Skip to content

Commit

Permalink
fixed settler max distance and added greater variance to distance
Browse files Browse the repository at this point in the history
  • Loading branch information
veden committed Dec 28, 2021
1 parent 0152b40 commit 50bfae2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
13 changes: 11 additions & 2 deletions Upgrade.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local chunkUtils = require("libs/ChunkUtils")

-- constants

local MINIMUM_EXPANSION_DISTANCE = constants.MINIMUM_EXPANSION_DISTANCE
local DEFINES_COMMAND_GROUP = defines.command.group
local DEFINES_COMMAND_WANDER = defines.command.wander
local DEFINES_COMMAND_BUILD_BASE = defines.command.build_base
Expand Down Expand Up @@ -452,7 +453,6 @@ function upgrade.attempt(universe)

universe.expansion = game.map_settings.enemy_expansion.enabled
universe.expansionMaxDistance = game.map_settings.enemy_expansion.max_expansion_distance * CHUNK_SIZE
universe.expansionMaxDistanceDerivation = universe.expansionMaxDistance * 0.33
universe.expansionMinTime = game.map_settings.enemy_expansion.min_expansion_cooldown
universe.expansionMaxTime = game.map_settings.enemy_expansion.max_expansion_cooldown
universe.expansionMinSize = game.map_settings.enemy_expansion.settler_group_min_size
Expand Down Expand Up @@ -559,8 +559,17 @@ function upgrade.attempt(universe)
if universe.NEW_ENEMIES then
addBasesToAllEnemyStructures(universe, game.tick)
end
end
if global.version < 208 then
global.version = 208

universe.expansionMaxDistanceDerivation = nil
universe.expansionLowTargetDistance = (universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.33
universe.expansionMediumTargetDistance = (universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.50
universe.expansionHighTargetDistance = (universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.75
universe.expansionDistanceDeviation = universe.expansionMediumTargetDistance * 0.33

game.print("Rampant - Version 2.1.0")
game.print("Rampant - Version 2.1.1")
end

return (starting ~= global.version) and global.version
Expand Down
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---------------------------------------------------------------------------------------------------
Version: 2.1.1
Date: 28. 12. 2021
Improvements:
- Settlers now have a 40% chance to move roughly 50% of max expansion distance, 25% chance to move roughly 33% of max expansion distance, and 25% chance to move roughly 75% of max expansion distance, 5% chance to settler where the group formed, 5% chance to go 100% of max expansion distance
Bugfixes:
- Settlers in some cases not setting a maxDistance which caused settlers to build where they were formed

---------------------------------------------------------------------------------------------------
Version: 2.1.0
Date: 27. 12. 2021
Expand Down
2 changes: 0 additions & 2 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS
-- imported functions

local addBasesToAllEnemyStructures = chunkUtils.addBasesToAllEnemyStructures
local getChunkById = mapUtils.getChunkById
local setChunkBase = chunkPropertyUtils.setChunkBase

local setPointAreaInQuery = queryUtils.setPointAreaInQuery
local setPositionInQuery = queryUtils.setPositionInQuery
Expand Down
8 changes: 2 additions & 6 deletions libs/AIAttackWave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ local baseUtils = require("BaseUtils")

-- constants

local MINIMUM_EXPANSION_DISTANCE = constants.MINIMUM_EXPANSION_DISTANCE

local BASE_PHEROMONE = constants.BASE_PHEROMONE
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
local RESOURCE_PHEROMONE = constants.RESOURCE_PHEROMONE
Expand Down Expand Up @@ -226,12 +228,6 @@ function aiAttackWave.formSettlers(map, chunk)
if squadPosition then
local squad = createSquad(squadPosition, map, nil, true)

squad.maxDistance = gaussianRandomRangeRG(universe.expansionMaxDistance * 0.5,
universe.expansionMaxDistanceDerivation,
10,
universe.expansionMaxDistance,
universe.random)

local scaledWaveSize = settlerWaveScaling(universe)
universe.formGroupCommand.group = squad.group
universe.formCommand.unit_count = scaledWaveSize
Expand Down
2 changes: 2 additions & 0 deletions libs/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ constants.SQUAD_BUILDING = 6

-- Squad Related

constants.MINIMUM_EXPANSION_DISTANCE = 10

constants.RETREAT_GRAB_RADIUS = 24
constants.RETREAT_SPAWNER_GRAB_RADIUS = 75

Expand Down
9 changes: 3 additions & 6 deletions libs/MovementUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local movementUtils = {}
local constants = require("Constants")
local mapUtils = require("MapUtils")
local mathUtils = require("MathUtils")
local unitGroupUtils = require("UnitGroupUtils")

-- constants

Expand All @@ -17,7 +18,7 @@ local SQUAD_SETTLING = constants.SQUAD_SETTLING

-- imported functions

local gaussianRandomRangeRG = mathUtils.gaussianRandomRangeRG
local calculateSettlerMaxDistance = unitGroupUtils.calculateSettlerMaxDistance

local canMoveChunkDirection = mapUtils.canMoveChunkDirection
local getNeighborChunks = mapUtils.getNeighborChunks
Expand Down Expand Up @@ -66,11 +67,7 @@ function movementUtils.addMovementPenalty(squad, chunk)
squad.settler = true
squad.originPosition.x = squad.group.position.x
squad.originPosition.y = squad.group.position.y
squad.maxDistance = gaussianRandomRangeRG(universe.expansionMaxDistance * 0.5,
universe.expansionMaxDistanceDerivation,
10,
universe.expansionMaxDistance,
universe.random)
squad.maxDistance = calculateSettlerMaxDistance(universe)

squad.status = SQUAD_SETTLING
else
Expand Down
29 changes: 29 additions & 0 deletions libs/UnitGroupUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ local unitGroupUtils = {}
local mapUtils = require("MapUtils")
local constants = require("Constants")
local chunkPropertyUtils = require("ChunkPropertyUtils")
local mathUtils = require("MathUtils")

-- constants

local MINIMUM_EXPANSION_DISTANCE = constants.MINIMUM_EXPANSION_DISTANCE
local SQUAD_RETREATING = constants.SQUAD_RETREATING
local SQUAD_GUARDING = constants.SQUAD_GUARDING

-- imported functions

local gaussianRandomRangeRG = mathUtils.gaussianRandomRangeRG

local getSquadsOnChunk = chunkPropertyUtils.getSquadsOnChunk

local getNeighborChunks = mapUtils.getNeighborChunks
Expand Down Expand Up @@ -73,6 +77,27 @@ function unitGroupUtils.findNearbySquad(map, chunk)
return nil
end

function unitGroupUtils.calculateSettlerMaxDistance(universe)
local targetDistance
local distanceRoll = universe.random()
if distanceRoll < 0.05 then
return 0
elseif distanceRoll < 0.30 then
targetDistance = universe.expansionLowTargetDistance
elseif distanceRoll < 0.70 then
targetDistance = universe.expansionMediumTargetDistance
elseif distanceRoll < 0.95 then
targetDistance = universe.expansionHighTargetDistance
else
return universe.expansionMaxDistance
end
return gaussianRandomRangeRG(targetDistance,
universe.expansionDistanceDeviation,
MINIMUM_EXPANSION_DISTANCE,
universe.expansionMaxDistance,
universe.random)
end

function unitGroupUtils.createSquad(position, map, group, settlers)
local unitGroup = group or map.surface.create_unit_group({position=position})

Expand All @@ -97,6 +122,10 @@ function unitGroupUtils.createSquad(position, map, group, settlers)
chunk = -1
}

if settlers then
squad.maxDistance = unitGroupUtils.calculateSettlerMaxDistance(map.universe)
end

if position then
squad.originPosition.x = position.x
squad.originPosition.y = position.y
Expand Down

0 comments on commit 50bfae2

Please sign in to comment.