From 2325169c62795616d08534e12711bb97c761e7af Mon Sep 17 00:00:00 2001 From: Aaron Veden Date: Fri, 22 May 2020 21:22:40 -0700 Subject: [PATCH] mostly working, potentially removing movement pheromone --- changelog.txt | 4 +- control.lua | 77 +++++++++++++++++++-------------- libs/Constants.lua | 4 -- libs/MovementUtils.lua | 95 ++++++++++++++++++++++------------------- libs/PheromoneUtils.lua | 76 ++++++++++++++++----------------- libs/SquadAttack.lua | 71 ++++++++++-------------------- libs/SquadDefense.lua | 2 +- libs/UnitGroupUtils.lua | 2 - parseState.rkt | 7 +-- tests.lua | 3 +- 10 files changed, 161 insertions(+), 180 deletions(-) diff --git a/changelog.txt b/changelog.txt index da6a1ce..6204031 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,16 +1,18 @@ --------------------------------------------------------------------------------------------------- -Version: 0.18.12 +Version: 0.18.13 Date: 16. 4 2020 Improvements: - Swapped to ai command completed for unit movements - When squads reach a movement threshold for being in the same spots to much they switch to kamikaze mode - Added effect when spawners build to destroy build site - Integrated vanilla AI into Rampant for pollution management + - Map processing sweep now does and forward and reverse pass Tweaks: - Changed ai credits per rocket launched to 5000 Bugfixes: - fixed add movement penalty not using squad chunk - fixed landfill and waterfill getting registered properly + - fixed surface filter queries grabbing player buildings that didn't have a collision mask Optimizations: - Cleaned up regroup squads - Cleaned up invalid group detection diff --git a/control.lua b/control.lua index 789534b..59c2e80 100755 --- a/control.lua +++ b/control.lua @@ -373,34 +373,47 @@ local function rebuildMap() end end - map.filteredEntitiesPlayerQueryLowest = { area=map.area, force=map.activePlayerForces, type={"wall", - "transport-belt"}} + map.filteredEntitiesPlayerQueryLowest = { area=map.area, + force=map.activePlayerForces, + collision_mask = "player-layer", + type={"wall", + "transport-belt"}} - map.filteredEntitiesPlayerQueryLow = { area=map.area, force=map.activePlayerForces, type={"splitter", - "pump", - "offshore-pump", - "lamp", - "solar-panel", - "programmable-speaker", - "accumulator", - "assembling-machine", - "turret", - "ammo-turret"}} + map.filteredEntitiesPlayerQueryLow = { area=map.area, + force=map.activePlayerForces, + collision_mask = "player-layer", + type={"splitter", + "pump", + "offshore-pump", + "lamp", + "solar-panel", + "programmable-speaker", + "accumulator", + "assembling-machine", + "turret", + "ammo-turret"}} - map.filteredEntitiesPlayerQueryHigh = { area=map.area, force=map.activePlayerForces, type={"furnace", - "lab", - "roboport", - "beacon", - "radar", - "electric-turret", - "boiler", - "generator", - "fluid-turret", - "mining-drill"}} + map.filteredEntitiesPlayerQueryHigh = { area=map.area, + force=map.activePlayerForces, + collision_mask = "player-layer", + type={"furnace", + "lab", + "roboport", + "beacon", + "radar", + "electric-turret", + "boiler", + "generator", + "fluid-turret", + "mining-drill"}} - map.filteredEntitiesPlayerQueryHighest = { area=map.area, force=map.activePlayerForces, type={"artillery-turret", - "reactor", - "rocket-silo"}} + map.filteredEntitiesPlayerQueryHighest = { area=map.area, + force=map.activePlayerForces, + collision_mask = "player-layer", + type={"artillery-turret", + "reactor", + "rocket-silo"} + } local sharedArea = {{0,0},{0,0}} map.filteredEntitiesCliffQuery = { area=sharedArea, type="cliff", limit = 1 } @@ -1038,16 +1051,14 @@ local function onCommandComplete(event) if group and group.valid and (group.surface.name == natives.activeSurface) then if (event.result == DEFINES_BEHAVIOR_RESULT_FAIL) then - print("count", #group.members) if (#group.members == 0) then - print("dropping") local deathGen = getDeathGenerator(map, squad.chunk) - local penalties = squad.penalties - for xc=1,mMin(#squad.penalties,5) do - addDeathGenerator(map, - penalties[xc].c, - deathGen * DIVISOR_DEATH_TRAIL_TABLE[xc]) - end + -- local penalties = squad.penalties + -- for xc=1,mMin(#squad.penalties,5) do + -- addDeathGenerator(map, + -- penalties[xc].c, + -- deathGen * DIVISOR_DEATH_TRAIL_TABLE[xc]) + -- end removeSquadFromChunk(map, squad) group.destroy() else diff --git a/libs/Constants.lua b/libs/Constants.lua index f308bc6..ab6c899 100755 --- a/libs/Constants.lua +++ b/libs/Constants.lua @@ -207,10 +207,6 @@ constants.IMPASSABLE_TERRAIN_GENERATOR_AMOUNT = 0 -- pheromone diffusion amounts constants.MOVEMENT_GENERATOR_PERSISTANCE = 0.90 -constants.MOVEMENT_PHEROMONE_PERSISTANCE = 0.975 -constants.BASE_PHEROMONE_PERSISTANCE = 0.99 -constants.PLAYER_PHEROMONE_PERSISTANCE = 0.97 -constants.RESOURCE_PHEROMONE_PERSISTANCE = 0.97 -- chunk attributes diff --git a/libs/MovementUtils.lua b/libs/MovementUtils.lua index dfff86c..77892e8 100755 --- a/libs/MovementUtils.lua +++ b/libs/MovementUtils.lua @@ -8,15 +8,19 @@ local movementUtils = {} local constants = require("Constants") local mapUtils = require("MapUtils") local mathUtils = require("MathUtils") +local chunkPropertyUtils = require("ChunkPropertyUtils") -- constants +local DOUBLE_DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DOUBLE_DEATH_PHEROMONE_GENERATOR_AMOUNT local MOVEMENT_PENALTY_AMOUNT = constants.MOVEMENT_PENALTY_AMOUNT +local BASE_PHEROMONE = constants.BASE_PHEROMONE local MAGIC_MAXIMUM_NUMBER = constants.MAGIC_MAXIMUM_NUMBER -- imported functions +local addDeathGenerator = chunkPropertyUtils.addDeathGenerator local canMoveChunkDirection = mapUtils.canMoveChunkDirection local getNeighborChunks = mapUtils.getNeighborChunks @@ -32,7 +36,7 @@ local distortPosition = mathUtils.distortPosition function movementUtils.findMovementPosition(surface, position) local pos = position -- if not surface.can_place_entity({name="chunk-scanner-squad-movement-rampant", position=pos}) then - pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", pos, 10, 2, false) + pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", pos, 10, 2, false) -- end return pos end @@ -40,7 +44,7 @@ end function movementUtils.findMovementPositionEntity(entityName, surface, position) local pos = position -- if not surface.can_place_entity({name=entityName, position=pos}) then - pos = surface.find_non_colliding_position(entityName, pos, 5, 4, true) + pos = surface.find_non_colliding_position(entityName, pos, 5, 4, true) -- end return pos end @@ -48,45 +52,49 @@ end function movementUtils.findMovementPositionDistort(surface, position) local pos = position -- if not surface.can_place_entity({name="chunk-scanner-squad-movement-rampant", position=pos}) then - pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", pos, 10, 2, false) + pos = surface.find_non_colliding_position("chunk-scanner-squad-movement-rampant", pos, 10, 2, false) -- end return distortPosition(pos, 8) end -function movementUtils.addMovementPenalty(squad, chunk) +function movementUtils.addMovementPenalty(map, squad, chunk) if (chunk == -1) then return end - local penalties = squad.penalties - for i=1,#penalties do - local penalty = penalties[i] - if (penalty.c == chunk) then - penalty.v = (2 * penalty.v) + MOVEMENT_PENALTY_AMOUNT - if (penalty.v >= MOVEMENT_PENALTY_AMOUNT * 5) then - squad.kamikaze = true - end - return - end - end - if (#penalties == 7) then - tableRemove(penalties, 7) - end - tableInsert(penalties, - 1, - { v = MOVEMENT_PENALTY_AMOUNT, - c = chunk }) + -- addDeathGenerator(map, chunk, DOUBLE_DEATH_PHEROMONE_GENERATOR_AMOUNT * 10) + chunk[BASE_PHEROMONE] = 0 + + -- local penalties = squad.penalties + -- for i=1,#penalties do + -- local penalty = penalties[i] + -- if (penalty.c == chunk) then + -- penalty.v = (2 * penalty.v) + MOVEMENT_PENALTY_AMOUNT + -- -- if (penalty.v >= MOVEMENT_PENALTY_AMOUNT * 10) then + -- print("movementThreshold", squad.group.group_number, penalty.v, squad.settlers, squad.kamikaze, squad.status) + -- -- squad.kamikaze = true + -- -- end + -- return + -- end + -- end + -- if (#penalties == 7) then + -- tableRemove(penalties, 7) + -- end + -- tableInsert(penalties, + -- 1, + -- { v = MOVEMENT_PENALTY_AMOUNT, + -- c = chunk }) end -function movementUtils.lookupMovementPenalty(squad, chunk) - local penalties = squad.penalties - for i=1,#penalties do - local penalty = penalties[i] - if (penalty.c == chunk) then - return penalty.v - end - end - return 0 -end +-- function movementUtils.lookupMovementPenalty(squad, chunk) +-- local penalties = squad.penalties +-- for i=1,#penalties do +-- local penalty = penalties[i] +-- if (penalty.c == chunk) then +-- return penalty.v +-- end +-- end +-- return 0 +-- end --[[ Expects all neighbors adjacent to a chunk @@ -96,15 +104,9 @@ function movementUtils.scoreNeighborsForAttack(map, chunk, neighborDirectionChun local highestScore = -MAGIC_MAXIMUM_NUMBER local highestDirection - local nextHighestChunk = -1 - local nextHighestScore = -MAGIC_MAXIMUM_NUMBER - local nextHighestDirection - local natives = map.natives - for x=1,8 do local neighborChunk = neighborDirectionChunks[x] - if (neighborChunk ~= -1) then if canMoveChunkDirection(map, x, chunk, neighborChunk) or (chunk == -1) then local score = scoreFunction(natives, squad, neighborChunk) @@ -117,12 +119,15 @@ function movementUtils.scoreNeighborsForAttack(map, chunk, neighborDirectionChun end end + local nextHighestChunk = -1 + local nextHighestScore = highestScore + local nextHighestDirection + if (highestChunk ~= -1) then neighborDirectionChunks = getNeighborChunks(map, highestChunk.x, highestChunk.y) for x=1,8 do local neighborChunk = neighborDirectionChunks[x] - - if ((neighborChunk ~= -1) and (neighborChunk ~= chunk) and + if ((neighborChunk ~= -1) and (neighborChunk ~= chunk) and canMoveChunkDirection(map, x, highestChunk, neighborChunk)) then local score = scoreFunction(natives, squad, neighborChunk) if (score > nextHighestScore) then @@ -165,7 +170,7 @@ function movementUtils.scoreNeighborsForSettling(map, chunk, neighborDirectionCh end local nextHighestChunk = -1 - local nextHighestScore = -MAGIC_MAXIMUM_NUMBER + local nextHighestScore = highestScore local nextHighestDirection = 0 if (highestChunk ~= -1) then @@ -221,10 +226,6 @@ function movementUtils.scoreNeighborsForRetreat(chunk, neighborDirectionChunks, local highestScore = -MAGIC_MAXIMUM_NUMBER local highestDirection - local nextHighestChunk = -1 - local nextHighestScore = -MAGIC_MAXIMUM_NUMBER - local nextHighestDirection - for x=1,8 do local neighborChunk = neighborDirectionChunks[x] if (neighborChunk ~= -1) then @@ -239,6 +240,10 @@ function movementUtils.scoreNeighborsForRetreat(chunk, neighborDirectionChunks, end end + local nextHighestChunk = -1 + local nextHighestScore = highestScore + local nextHighestDirection + if (highestChunk ~= -1) then neighborDirectionChunks = getNeighborChunks(map, highestChunk.x, highestChunk.y) for x=1,8 do diff --git a/libs/PheromoneUtils.lua b/libs/PheromoneUtils.lua index 048ede6..f746756 100755 --- a/libs/PheromoneUtils.lua +++ b/libs/PheromoneUtils.lua @@ -30,8 +30,6 @@ local VICTORY_SCENT = constants.VICTORY_SCENT local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT -local MOVEMENT_PHEROMONE_PERSISTANCE = constants.MOVEMENT_PHEROMONE_PERSISTANCE -local BASE_PHEROMONE_PERSISTANCE = constants.BASE_PHEROMONE_PERSISTANCE local PLAYER_PHEROMONE_PERSISTANCE = constants.PLAYER_PHEROMONE_PERSISTANCE local RESOURCE_PHEROMONE_PERSISTANCE = constants.RESOURCE_PHEROMONE_PERSISTANCE @@ -56,6 +54,8 @@ local decayDeathGenerator = chunkPropertyUtils.decayDeathGenerator local linearInterpolation = mathUtils.linearInterpolation +local mAbs = math.abs + -- module code function pheromoneUtils.victoryScent(map, chunk, entityType) @@ -66,7 +66,7 @@ function pheromoneUtils.victoryScent(map, chunk, entityType) end function pheromoneUtils.deathScent(map, chunk) - addDeathGenerator(map, chunk, DEATH_PHEROMONE_GENERATOR_AMOUNT) + -- addDeathGenerator(map, chunk, DEATH_PHEROMONE_GENERATOR_AMOUNT) end function pheromoneUtils.processStaticPheromone(map, chunk) @@ -278,22 +278,22 @@ function pheromoneUtils.processStaticPheromone(map, chunk) chunkResource = chunkResource * 0.9 local pheromone = getResourceGenerator(map, chunk) if chunkResource < pheromone then - if clear then + if clear then chunk[RESOURCE_PHEROMONE] = pheromone * chunkPathRating else chunk[RESOURCE_PHEROMONE] = pheromone * chunkPathRating * 0.1 - end + end else if clear then chunk[RESOURCE_PHEROMONE] = chunkResource * chunkPathRating else chunk[RESOURCE_PHEROMONE] = chunkResource * chunkPathRating * 0.1 - end + end end end function pheromoneUtils.processPheromone(map, chunk) - local chunkMovement = -MAGIC_MAXIMUM_NUMBER + local chunkMovement = 0 local chunkPlayer = -MAGIC_MAXIMUM_NUMBER local chunkPathRating = getPathRating(map, chunk) @@ -310,7 +310,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_NORTH_SOUTH)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -325,7 +325,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_NORTH_SOUTH)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -340,7 +340,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_EAST_WEST)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -355,7 +355,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_EAST_WEST)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -369,10 +369,10 @@ function pheromoneUtils.processPheromone(map, chunk) if (neighbor ~= -1) then neighborPass = getPassable(map, neighbor) if (neighborPass == CHUNK_ALL_DIRECTIONS) then - pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then - chunkMovement = pheromone - end + -- pheromone = neighbor[MOVEMENT_PHEROMONE] + -- if mAbs(chunkMovement) < mAbs(pheromone) then + -- chunkMovement = pheromone + -- end pheromone = neighbor[PLAYER_PHEROMONE] if chunkPlayer < pheromone then chunkPlayer = pheromone @@ -384,10 +384,10 @@ function pheromoneUtils.processPheromone(map, chunk) if (neighbor ~= -1) then neighborPass = getPassable(map, neighbor) if (neighborPass == CHUNK_ALL_DIRECTIONS) then - pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then - chunkMovement = pheromone - end + -- pheromone = neighbor[MOVEMENT_PHEROMONE] + -- if mAbs(chunkMovement) < mAbs(pheromone) then + -- chunkMovement = pheromone + -- end pheromone = neighbor[PLAYER_PHEROMONE] if chunkPlayer < pheromone then chunkPlayer = pheromone @@ -399,10 +399,10 @@ function pheromoneUtils.processPheromone(map, chunk) if (neighbor ~= -1) then neighborPass = getPassable(map, neighbor) if (neighborPass == CHUNK_ALL_DIRECTIONS) then - pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then - chunkMovement = pheromone - end + -- pheromone = neighbor[MOVEMENT_PHEROMONE] + -- if mAbs(chunkMovement) < mAbs(pheromone) then + -- chunkMovement = pheromone + -- end pheromone = neighbor[PLAYER_PHEROMONE] if chunkPlayer < pheromone then chunkPlayer = pheromone @@ -414,10 +414,10 @@ function pheromoneUtils.processPheromone(map, chunk) if (neighbor ~= -1) then neighborPass = getPassable(map, neighbor) if (neighborPass == CHUNK_ALL_DIRECTIONS) then - pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then - chunkMovement = pheromone - end + -- pheromone = neighbor[MOVEMENT_PHEROMONE] + -- if mAbs(chunkMovement) < mAbs(pheromone) then + -- chunkMovement = pheromone + -- end pheromone = neighbor[PLAYER_PHEROMONE] if chunkPlayer < pheromone then chunkPlayer = pheromone @@ -431,7 +431,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_EAST_WEST)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -446,7 +446,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_EAST_WEST)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -462,7 +462,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_NORTH_SOUTH)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -477,7 +477,7 @@ function pheromoneUtils.processPheromone(map, chunk) neighborPass = getPassable(map, neighbor) if ((neighborPass == CHUNK_ALL_DIRECTIONS) or (neighborPass == CHUNK_NORTH_SOUTH)) then pheromone = neighbor[MOVEMENT_PHEROMONE] - if chunkMovement < pheromone then + if mAbs(chunkMovement) < mAbs(pheromone) then chunkMovement = pheromone end pheromone = neighbor[PLAYER_PHEROMONE] @@ -488,16 +488,16 @@ function pheromoneUtils.processPheromone(map, chunk) end end - chunkMovement = chunkMovement * 0.9 + chunkMovement = chunkMovement * 0.50 local pheromone = -getDeathGenerator(map, chunk) - if chunkMovement < pheromone then - chunk[MOVEMENT_PHEROMONE] = pheromone * chunkPathRating - else - chunk[MOVEMENT_PHEROMONE] = chunkMovement * chunkPathRating - end + -- if (mAbs(chunkMovement) < mAbs(pheromone)) then + -- chunk[MOVEMENT_PHEROMONE] = pheromone * chunkPathRating + -- else + -- chunk[MOVEMENT_PHEROMONE] = chunkMovement * chunkPathRating + -- end decayDeathGenerator(map, chunk) - chunkPlayer = chunkPlayer * 0.9 + chunkPlayer = chunkPlayer * 0.45 local pheromone = getPlayersOnChunk(map, chunk) * PLAYER_PHEROMONE_GENERATOR_AMOUNT if chunkPlayer < pheromone then chunk[PLAYER_PHEROMONE] = pheromone * chunkPathRating diff --git a/libs/SquadAttack.lua b/libs/SquadAttack.lua index a7a8bac..b4992a4 100755 --- a/libs/SquadAttack.lua +++ b/libs/SquadAttack.lua @@ -89,31 +89,24 @@ local scoreNeighborsForSettling = movementUtils.scoreNeighborsForSettling local function scoreResourceLocation(squad, neighborChunk) local settle = neighborChunk[MOVEMENT_PHEROMONE] + neighborChunk[RESOURCE_PHEROMONE] - return settle -- - lookupMovementPenalty(squad, neighborChunk) - - (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) + return settle - (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) end local function scoreSiegeLocation(squad, neighborChunk) local settle = neighborChunk[MOVEMENT_PHEROMONE] + neighborChunk[BASE_PHEROMONE] + neighborChunk[RESOURCE_PHEROMONE] + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) - return settle -- - lookupMovementPenalty(squad, neighborChunk) + return settle end local function scoreAttackLocation(natives, squad, neighborChunk) - local damage - local movementPheromone = neighborChunk[MOVEMENT_PHEROMONE] + local damage = (2 * neighborChunk[MOVEMENT_PHEROMONE]) + neighborChunk[BASE_PHEROMONE] + + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) - if (movementPheromone >= 0) then - damage = movementPheromone + (neighborChunk[BASE_PHEROMONE]) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) - else - damage = (neighborChunk[BASE_PHEROMONE] * (1 - (movementPheromone / -natives.retreatThreshold))) + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) + (getPlayerBaseGenerator(natives.map, neighborChunk) * PLAYER_PHEROMONE_MULTIPLER) - end - - return damage -- - lookupMovementPenalty(squad, neighborChunk) + return damage end local function scoreAttackKamikazeLocation(natives, squad, neighborChunk) - local damage = neighborChunk[BASE_PHEROMONE] + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) + (getPlayerBaseGenerator(natives.map, neighborChunk) * PLAYER_PHEROMONE_MULTIPLER) - return damage -- - lookupMovementPenalty(squad, neighborChunk) + local damage = neighborChunk[BASE_PHEROMONE] + (neighborChunk[PLAYER_PHEROMONE] * PLAYER_PHEROMONE_MULTIPLER) + return damage end @@ -131,7 +124,7 @@ local function settleMove(map, squad, surface) if (natives.state == AI_STATE_SIEGE) then scoreFunction = scoreSiegeLocation end - addMovementPenalty(squad, squad.chunk) + addMovementPenalty(map, squad, squad.chunk) addSquadToChunk(map, chunk, squad) local distance = euclideanDistancePoints(groupPosition.x, groupPosition.y, @@ -163,10 +156,6 @@ local function settleMove(map, squad, surface) surface.create_entity(map.createBuildCloudQuery) - if (euclideanDistanceNamed(targetPosition, group.position) > 200) then - print("fuck") - end - group.set_command(cmd) else local attackChunk, attackDirection, nextAttackChunk, nextAttackDirection = scoreNeighborsForSettling(map, @@ -188,30 +177,19 @@ local function settleMove(map, squad, surface) positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition) positionFromDirectionAndFlat(nextAttackDirection, targetPosition, targetPosition2) position = findMovementPosition(surface, targetPosition2) - - if position and (euclideanDistanceNamed(position, group.position) > 200) then - print("tp2", serpent.dump(targetPosition)) - print("tp3", serpent.dump(targetPosition2)) - print("tp", serpent.dump(position)) - print("gp", serpent.dump(group.position)) - print("fuck set2") - end else positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition) position = findMovementPosition(surface, targetPosition) - - if position and (euclideanDistanceNamed(position, group.position) > 200) then - print("tp2", serpent.dump(targetPosition)) - print("tp", serpent.dump(position)) - print("gp", serpent.dump(group.position)) - print("fuck set3") - end - end if position then targetPosition.x = position.x targetPosition.y = position.y + if nextAttackChunk then + addMovementPenalty(map, squad, nextAttackChunk) + else + addMovementPenalty(map, squad, attackChunk) + end else cmd = map.wonderCommand group.set_command(cmd) @@ -240,7 +218,7 @@ local function settleMove(map, squad, surface) cmd = map.settleCommand cmd.destination.x = groupPosition.x cmd.destination.y = groupPosition.y - + if squad.kamikaze then cmd.distraction = DEFINES_DISTRACTION_NONE else @@ -252,12 +230,6 @@ local function settleMove(map, squad, surface) surface.create_entity(map.createBuildCloudQuery) end - if (euclideanDistanceNamed(targetPosition, group.position) > 200) then - print("tp", serpent.dump(targetPosition)) - print("gp", serpent.dump(group.position)) - print("fuck set") - end - group.set_command(cmd) end end @@ -278,7 +250,7 @@ local function attackMove(map, squad, surface) attackScorer = scoreAttackKamikazeLocation end local squadChunk = squad.chunk - addMovementPenalty(squad, squadChunk) + addMovementPenalty(map, squad, squadChunk) addSquadToChunk(map, chunk, squad) squad.frenzy = (squad.frenzy and (euclideanDistanceNamed(groupPosition, squad.frenzyPosition) < 100)) local attackChunk, attackDirection, nextAttackChunk, nextAttackDirection = scoreNeighborsForAttack(map, @@ -307,6 +279,11 @@ local function attackMove(map, squad, surface) else targetPosition.x = position.x targetPosition.y = position.y + if nextAttackChunk then + addMovementPenalty(map, squad, nextAttackChunk) + else + addMovementPenalty(map, squad, attackChunk) + end end if (getPlayerBaseGenerator(map, attackChunk) ~= 0) and @@ -328,12 +305,6 @@ local function attackMove(map, squad, surface) end end - if (euclideanDistanceNamed(targetPosition, group.position) > 200) then - print("tp", serpent.dump(targetPosition)) - print("gp", serpent.dump(group.position)) - print("fuck atk") - end - group.set_command(cmd) end @@ -349,6 +320,8 @@ local function buildMove(map, squad, surface) position.x = groupPosition.x position.y = groupPosition.y + surface.create_entity(map.createBuildCloudQuery) + group.set_command(map.compoundSettleCommand) end diff --git a/libs/SquadDefense.lua b/libs/SquadDefense.lua index 7d1178f..ce49513 100755 --- a/libs/SquadDefense.lua +++ b/libs/SquadDefense.lua @@ -153,7 +153,7 @@ function aiDefense.retreatUnits(chunk, position, group, map, surface, tick, radi newSquad.frenzyPosition.x = squadPosition.x newSquad.frenzyPosition.y = squadPosition.y end - addMovementPenalty(newSquad, chunk) + addMovementPenalty(map, newSquad, chunk) addSquadToChunk(map, chunk, newSquad) end end diff --git a/libs/UnitGroupUtils.lua b/libs/UnitGroupUtils.lua index 77d93e2..d6168ec 100755 --- a/libs/UnitGroupUtils.lua +++ b/libs/UnitGroupUtils.lua @@ -118,14 +118,12 @@ function unitGroupUtils.createSquad(position, surface, group, settlers) local squad = { group = unitGroup, status = SQUAD_GUARDING, - penalties = {}, rabid = false, frenzy = false, settlers = settlers or false, kamikaze = false, frenzyPosition = {x = 0, y = 0}, - cycles = 10, maxDistance = 0, groupNumber = unitGroup.group_number, originPosition = {x = 0, diff --git a/parseState.rkt b/parseState.rkt index 07e8505..fc2d6f8 100755 --- a/parseState.rkt +++ b/parseState.rkt @@ -98,11 +98,8 @@ (cons (+ (string->number movement) (string->number resource)) (cons (+ ;; (* 2 (string->number movement)) - (* (string->number base) - (if (< (string->number movement) 0) - (- 1 (/ (string->number movement) - -100000)) - 1)) + (* 2 (string->number movement)) + (string->number base) (* (string->number player) 2500)) (map string->number (list x y movement base player resource passable tick rating nest diff --git a/tests.lua b/tests.lua index a5b4e7c..993bc0b 100755 --- a/tests.lua +++ b/tests.lua @@ -431,7 +431,7 @@ function tests.exportAiState() game.get_surface(global.natives.activeSurface).get_pollution(chunk), chunkPropertyUtils.getNestActiveness(global.map, chunk), chunkPropertyUtils.getRaidNestActiveness(global.map, chunk), - #chunkPropertyUtils.getSquadsOnChunk(global.map, chunk), + table_size(chunkPropertyUtils.getSquadsOnChunk(global.map, chunk)), alignmentCount, chunkPropertyUtils.getHiveCount(global.map, chunk), chunkPropertyUtils.getTrapCount(global.map, chunk), @@ -539,7 +539,6 @@ function tests.unitGroupBuild() end - function tests.dumpEnvironment(x) print (serpent.dump(global[x])) end