diff --git a/Upgrade.lua b/Upgrade.lua index 64c6e69..541b564 100755 --- a/Upgrade.lua +++ b/Upgrade.lua @@ -334,6 +334,9 @@ function upgrade.attempt(natives) end end + natives.baseOrdering = {} + natives.baseOrdering.len = 0 + natives.pendingAttack.len = #natives.pendingAttack natives.squads.len = #natives.squads natives.maxOverflowPoints = AI_MAX_OVERFLOW_POINTS diff --git a/control.lua b/control.lua index d58d675..738ce70 100755 --- a/control.lua +++ b/control.lua @@ -259,6 +259,8 @@ local function rebuildMap() SENTINEL_IMPASSABLE_CHUNK } + map.mapOrdering = {} + map.mapOrdering.len = 0 map.enemiesToSquad = {} map.enemiesToSquad.len = 0 map.chunkRemovals = {} diff --git a/libs/BaseUtils.lua b/libs/BaseUtils.lua index 72d9351..ba1ec0e 100755 --- a/libs/BaseUtils.lua +++ b/libs/BaseUtils.lua @@ -175,17 +175,20 @@ local mRandom = math.random -- module code -local function nonRepeatingRandom(evoTable, rg) - local ordering = {} +local function nonRepeatingRandom(natives, evoTable, rg) + local ordering = natives.baseOrdering + local baseCount = 0 for evo in pairs(evoTable) do - ordering[#ordering+1] = evo + baseCount = baseCount + 1 + ordering[baseCount] = evo end - for i=#ordering,1,-1 do + for i=baseCount,1,-1 do local s = rg(i) local t = ordering[i] ordering[i] = ordering[s] ordering[s] = t end + ordering.len = baseCount return ordering end @@ -316,8 +319,9 @@ local function findBaseInitialAlignment(evoIndex, natives, evolutionTable) local pickedEvo local alignment - for i=1,#natives.evolutionTableAlignmentOrder do - local evo = natives.evolutionTableAlignmentOrder[i] + local alignmentTable = natives.evolutionTableAlignmentOrder + for i=1,alignmentTable.len do + local evo = alignmentTable[i] local entitySet = evolutionTable[evo] if (evo <= evoTop) and entitySet and (#entitySet > 0) then if not pickedEvo then @@ -413,11 +417,11 @@ function baseUtils.upgradeEntity(entity, surface, baseAlignment, natives, evolut end local function findMutation(natives, evolutionFactor) - local shuffled = nonRepeatingRandom(natives.evolutionTableAlignment, natives.randomGenerator) + local shuffled = nonRepeatingRandom(natives, natives.evolutionTableAlignment, natives.randomGenerator) local evoTable = natives.evolutionTableAlignment local alignment - for i=1,#shuffled do + for i=1,shuffled.len do local evo = shuffled[i] if (evo <= evolutionFactor) then local alignmentSet = evoTable[evo] @@ -655,7 +659,7 @@ function baseUtils.rebuildNativeTables(natives, surface, rg) natives.evolutionTableAlignment) end - natives.evolutionTableAlignmentOrder = nonRepeatingRandom(natives.evolutionTableAlignment, natives.randomGenerator) + natives.evolutionTableAlignmentOrder = nonRepeatingRandom(natives, natives.evolutionTableAlignment, natives.randomGenerator) if ENABLED_NE_UNITS then processNEUnitClass(natives, surface) diff --git a/libs/Constants.lua b/libs/Constants.lua index 9dc5edc..b57a032 100755 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -359,19 +359,19 @@ if constants.ENABLED_NE_UNITS then constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE] = 0.1 if settings.startup["NE_Blue_Spawners"].value then - constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_BLUE] = 0.1 + constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_BLUE] = 0.1 end if settings.startup["NE_Red_Spawners"].value then - constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_RED] = 0.1 + constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_RED] = 0.1 end if settings.startup["NE_Pink_Spawners"].value then - constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_PINK] = 0.1 + constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_PINK] = 0.1 end if settings.startup["NE_Green_Spawners"].value then - constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_GREEN] = 0.1 + constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_GREEN] = 0.1 end if settings.startup["NE_Yellow_Spawners"].value then - constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_YELLOW] = 0.1 + constants.BASE_ALIGNMENT_EVOLUTION_BASELINE[constants.BASE_ALIGNMENT_NE_YELLOW] = 0.1 end end @@ -599,8 +599,8 @@ local function buildTier(size, tiers) local step = (tierEnd - tierStart) / (size - 1) local i = tierStart for _=1,size do - tiers[#tiers+1] = roundToNearest(i, 1) - i = i + step + tiers[#tiers+1] = roundToNearest(i, 1) + i = i + step end end diff --git a/libs/MapProcessor.lua b/libs/MapProcessor.lua index 0318e5f..c445cff 100755 --- a/libs/MapProcessor.lua +++ b/libs/MapProcessor.lua @@ -89,17 +89,20 @@ local mRandom = math.random -- module code -local function nonRepeatingRandom(players) - local ordering = {} +local function nonRepeatingRandom(map, players) + local ordering = map.mapOrdering + local playerCount = 0 for _,player in pairs(players) do - ordering[#ordering+1] = player.index + playerCount = playerCount + 1 + ordering[playerCount] = player.index end - for i=#ordering,1,-1 do + for i=playerCount,1,-1 do local s = mRandom(i) local t = ordering[i] ordering[i] = ordering[s] ordering[s] = t end + ordering.len = playerCount return ordering end @@ -181,7 +184,7 @@ end function mapProcessor.processPlayers(players, map, surface, natives, tick) -- put down player pheromone for player hunters -- randomize player order to ensure a single player isn't singled out - local playerOrdering = nonRepeatingRandom(players) + local playerOrdering = nonRepeatingRandom(map, players) local roll = mRandom() @@ -192,7 +195,7 @@ function mapProcessor.processPlayers(players, map, surface, natives, tick) local squads = allowingAttacks and (0.11 <= roll) and (roll <= 0.20) and (natives.points >= AI_SQUAD_COST) -- not looping everyone because the cost is high enough already in multiplayer - if (#playerOrdering > 0) then + if (playerOrdering.len > 0) then local player = players[playerOrdering[1]] if validPlayer(player, natives) then local playerChunk = getChunkByPosition(map, player.character.position) @@ -261,7 +264,7 @@ function mapProcessor.processPlayers(players, map, surface, natives, tick) end end - for i=1,#playerOrdering do + for i=1,playerOrdering.len do local player = players[playerOrdering[i]] if validPlayer(player, natives) then local playerChunk = getChunkByPosition(map, player.character.position) diff --git a/libs/PheromoneUtils.lua b/libs/PheromoneUtils.lua index c1770f4..46feac6 100755 --- a/libs/PheromoneUtils.lua +++ b/libs/PheromoneUtils.lua @@ -83,7 +83,9 @@ function pheromoneUtils.commitPheromone(map, chunk, staging, tick) chunk[BASE_PHEROMONE] = staging[BASE_PHEROMONE] + getPlayerBaseGenerator(map, chunk) chunk[PLAYER_PHEROMONE] = staging[PLAYER_PHEROMONE] if (resourceGenerator > 0) and (getEnemyStructureCount(map, chunk) == 0) then - chunk[RESOURCE_PHEROMONE] = staging[RESOURCE_PHEROMONE] + (linearInterpolation(resourceGenerator, 15000, 20000)) + chunk[RESOURCE_PHEROMONE] = staging[RESOURCE_PHEROMONE] + (linearInterpolation(resourceGenerator, 15000, 20000)) + else + chunk[RESOURCE_PHEROMONE] = staging[RESOURCE_PHEROMONE] end end diff --git a/visual.rkt b/visual.rkt index 8c1f28a..b2ce8ed 100755 --- a/visual.rkt +++ b/visual.rkt @@ -72,7 +72,7 @@ (define siteBox2 (new message% [parent panel] [label ""] - [vert-margin 270])) + [vert-margin 300])) (new button% [parent mainFrame]