mirror of
https://github.com/veden/Rampant.git
synced 2024-12-30 21:19:46 +02:00
mostly working, potentially removing movement pheromone
This commit is contained in:
parent
000d85e360
commit
2325169c62
@ -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
|
||||
|
37
control.lua
37
control.lua
@ -373,10 +373,16 @@ local function rebuildMap()
|
||||
end
|
||||
end
|
||||
|
||||
map.filteredEntitiesPlayerQueryLowest = { area=map.area, force=map.activePlayerForces, type={"wall",
|
||||
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",
|
||||
map.filteredEntitiesPlayerQueryLow = { area=map.area,
|
||||
force=map.activePlayerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={"splitter",
|
||||
"pump",
|
||||
"offshore-pump",
|
||||
"lamp",
|
||||
@ -387,7 +393,10 @@ local function rebuildMap()
|
||||
"turret",
|
||||
"ammo-turret"}}
|
||||
|
||||
map.filteredEntitiesPlayerQueryHigh = { area=map.area, force=map.activePlayerForces, type={"furnace",
|
||||
map.filteredEntitiesPlayerQueryHigh = { area=map.area,
|
||||
force=map.activePlayerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={"furnace",
|
||||
"lab",
|
||||
"roboport",
|
||||
"beacon",
|
||||
@ -398,9 +407,13 @@ local function rebuildMap()
|
||||
"fluid-turret",
|
||||
"mining-drill"}}
|
||||
|
||||
map.filteredEntitiesPlayerQueryHighest = { area=map.area, force=map.activePlayerForces, type={"artillery-turret",
|
||||
map.filteredEntitiesPlayerQueryHighest = { area=map.area,
|
||||
force=map.activePlayerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={"artillery-turret",
|
||||
"reactor",
|
||||
"rocket-silo"}}
|
||||
"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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
@ -53,40 +57,44 @@ function movementUtils.findMovementPositionDistort(surface, position)
|
||||
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,11 +119,14 @@ 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
|
||||
canMoveChunkDirection(map, x, highestChunk, neighborChunk)) then
|
||||
local score = scoreFunction(natives, squad, neighborChunk)
|
||||
@ -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
|
||||
|
@ -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)
|
||||
@ -293,7 +293,7 @@ function pheromoneUtils.processStaticPheromone(map, chunk)
|
||||
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
|
||||
|
@ -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)
|
||||
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user