diff --git a/README.md b/README.md index 3cacc56..e4a9493 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,8 @@ Configure Options not in game menu: - Optimization: Precompute retreatThreshold, maxSquads, rallyThreshold, formSquadThreshold, attackWaveSize, attackWaveSizeLowerBound, attackWaveSizeUpperBound, attackWaveSizeDeviation, kamikazeThreshold, attackWaveThreshold once per logic cycle - Optimization: Reduced garbage generated by pheromone map processing - Optimization: Reduced garbage generated by attack formation scanning -- Framework: renamed chunk pX to x, so chunks could be used in calls to things like get_pollution +- Optimization: Capped squad regrouping attempts to 15 per logic cycle +- Framework: renamed chunk pX,pY to x,y, so chunks could be used in calls to things like get_pollution 0.15.10 - - Fix: nil chunk in pheromone utils(https://mods.factorio.com/mods/Veden/Rampant/discussion/13806) diff --git a/Upgrade.lua b/Upgrade.lua index c7d926f..34b46b2 100644 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -123,6 +123,8 @@ function upgrade.attempt(natives, regionMap) natives.attackWaveUpperBound = 0 natives.unitRefundAmount = 0 natives.attackWaveThreshold = 0 + + natives.regroupIndex = 1 natives.useCustomAI = settings.startup["rampant-useCustomAI"].value if natives.useCustomAI then diff --git a/control.lua b/control.lua index 1cff498..75bd874 100644 --- a/control.lua +++ b/control.lua @@ -188,7 +188,7 @@ local function onTick(event) surface) cleanSquads(natives) - -- regroupSquads(natives) + regroupSquads(natives) processPlayers(players, regionMap, surface, natives, tick) diff --git a/libs/Constants.lua b/libs/Constants.lua index e4bfedd..e72fcb1 100644 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -21,6 +21,7 @@ constants.RETREAT_MOVEMENT_PHEROMONE_LEVEL = 10000 constants.PROCESS_QUEUE_SIZE = 450 constants.SCAN_QUEUE_SIZE = 6 constants.BASE_QUEUE_SIZE = 1 +constants.SQUAD_QUEUE_SIZE = 5 constants.PROCESS_PLAYER_BOUND = 4 constants.TICKS_A_SECOND = 60 diff --git a/libs/UnitGroupUtils.lua b/libs/UnitGroupUtils.lua index be6dc35..23d439f 100644 --- a/libs/UnitGroupUtils.lua +++ b/libs/UnitGroupUtils.lua @@ -9,6 +9,8 @@ local constants = require("Constants") local MOVEMENT_PHEROMONE_GENERATOR_AMOUNT = constants.MOVEMENT_PHEROMONE_GENERATOR_AMOUNT +local SQUAD_QUEUE_SIZE = constants.SQUAD_QUEUE_SIZE + local DEFINES_GROUP_STATE_FINISHED = defines.group_state.finished local DEFINES_GROUP_STATE_ATTACKING_TARGET = defines.group_state.attacking_target local DEFINES_GROUP_STATE_ATTACKING_DISTRACTION = defines.group_state.attacking_distraction @@ -29,6 +31,8 @@ local AI_MAX_BITER_GROUP_SIZE = constants.AI_MAX_BITER_GROUP_SIZE local mLog = math.log10 +local mMin = math.min + local tableRemove = table.remove local tableInsert = table.insert local euclideanDistanceNamed = mapUtils.euclideanDistanceNamed @@ -169,11 +173,11 @@ function unitGroupUtils.cleanSquads(natives) group.destroy() else local status = squad.status - local squadPosition = group.position local cycles = squad.cycles if (status == SQUAD_RETREATING) and (cycles == 0) then squad.status = SQUAD_GUARDING squad.frenzy = true + local squadPosition = group.position squad.frenzyPosition.x = squadPosition.x squad.frenzyPosition.y = squadPosition.y elseif (group.state == DEFINES_GROUP_STATE_FINISHED) then @@ -196,20 +200,23 @@ function unitGroupUtils.regroupSquads(natives) local squads = natives.squads local squadCount = #squads + + local startIndex = natives.regroupIndex - for i=1,squadCount do + local maxSquadIndex = mMin(startIndex + SQUAD_QUEUE_SIZE, squadCount) + for i=startIndex,maxSquadIndex do local squad = squads[i] local group = squad.group if group.valid and not isAttacking(group) then local status = squad.status - local memberCount = #group.members + local memberCount = #group.members if (memberCount < groupThreshold) then local squadPosition = group.position local mergedSquads = false for x=i+1,squadCount do local mergeSquad = squads[x] local mergeGroup = mergeSquad.group - if mergeGroup.valid and (mergeSquad.status == status) and not isAttacking(mergeGroup) and (euclideanDistanceNamed(squadPosition, mergeGroup.position) < GROUP_MERGE_DISTANCE) then + if mergeGroup.valid and (euclideanDistanceNamed(squadPosition, mergeGroup.position) < GROUP_MERGE_DISTANCE) and (mergeSquad.status == status) and not isAttacking(mergeGroup) then local mergeMembers = mergeGroup.members local mergeCount = #mergeMembers if ((mergeCount + memberCount) < AI_MAX_BITER_GROUP_SIZE) then @@ -236,7 +243,13 @@ function unitGroupUtils.regroupSquads(natives) end end end - end + end + + if (maxSquadIndex == squadCount) then + natives.regroupIndex = 1 + else + natives.regroupIndex = maxSquadIndex + end end return unitGroupUtils