mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
FACTO-256: Squad movement cleanup
This commit is contained in:
parent
3a9f5b05cd
commit
449b12446f
@ -1029,7 +1029,7 @@ script.on_event(defines.events.on_tick,
|
||||
processClouds(tick)
|
||||
elseif (pick == 4) then
|
||||
if map then
|
||||
scanResourceMap(map, tick)
|
||||
scanResourceMap(map)
|
||||
scanEnemyMap(map, tick)
|
||||
end
|
||||
elseif (pick == 5) then
|
||||
@ -1038,7 +1038,7 @@ script.on_event(defines.events.on_tick,
|
||||
end
|
||||
elseif (pick == 6) then
|
||||
if map then
|
||||
scanPlayerMap(map, tick)
|
||||
scanPlayerMap(map)
|
||||
end
|
||||
elseif (pick == 7) then
|
||||
processPendingChunks(tick)
|
||||
|
@ -23,6 +23,7 @@ local MapUtils = {}
|
||||
|
||||
local Universe
|
||||
local NeighborChunks
|
||||
local MapPosition
|
||||
|
||||
-- imports
|
||||
|
||||
@ -222,7 +223,8 @@ function MapUtils.prepMap(surface)
|
||||
local tick = game.tick
|
||||
for chunk in surface.get_chunks() do
|
||||
if surface.is_chunk_generated(chunk) then
|
||||
MapUtils.queueGeneratedChunk({
|
||||
MapUtils.queueGeneratedChunk(
|
||||
{
|
||||
surface = surface,
|
||||
tick = tick,
|
||||
area = {
|
||||
@ -231,7 +233,7 @@ function MapUtils.prepMap(surface)
|
||||
y = chunk.y * 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -425,67 +427,56 @@ function MapUtils.canMoveChunkDirection(direction, startChunk, endChunk)
|
||||
return canMove
|
||||
end
|
||||
|
||||
function MapUtils.positionFromDirectionAndChunk(direction, startPosition, scaling)
|
||||
local endPosition = {}
|
||||
if (direction == 1) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 2) then
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling + 0.25)
|
||||
elseif (direction == 3) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y - CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 4) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
elseif (direction == 5) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling + 0.25)
|
||||
endPosition.y = startPosition.y
|
||||
elseif (direction == 6) then
|
||||
endPosition.x = startPosition.x - CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
elseif (direction == 7) then
|
||||
endPosition.x = startPosition.x
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling + 0.25)
|
||||
elseif (direction == 8) then
|
||||
endPosition.x = startPosition.x + CHUNK_SIZE * (scaling - 0.1)
|
||||
endPosition.y = startPosition.y + CHUNK_SIZE * (scaling - 0.1)
|
||||
end
|
||||
return endPosition
|
||||
end
|
||||
|
||||
function MapUtils.positionFromDirectionAndFlat(direction, startPosition, multipler)
|
||||
function MapUtils.positionFromScaledDirections(startPosition, multipler, direction, nextDirection)
|
||||
local lx = startPosition.x
|
||||
local ly = startPosition.y
|
||||
if not multipler then
|
||||
multipler = 1
|
||||
end
|
||||
if (direction == 1) then
|
||||
lx = lx - CHUNK_SIZE * multipler
|
||||
ly = ly - CHUNK_SIZE * multipler
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 2) then
|
||||
ly = ly - CHUNK_SIZE * multipler
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 3) then
|
||||
lx = lx + CHUNK_SIZE * multipler
|
||||
ly = ly - CHUNK_SIZE * multipler
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 4) then
|
||||
lx = lx - CHUNK_SIZE * multipler
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 5) then
|
||||
lx = lx + CHUNK_SIZE * multipler
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 6) then
|
||||
lx = lx - CHUNK_SIZE * multipler
|
||||
ly = ly + CHUNK_SIZE * multipler
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 7) then
|
||||
ly = ly + CHUNK_SIZE * multipler
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
elseif (direction == 8) then
|
||||
lx = lx + CHUNK_SIZE * multipler
|
||||
ly = ly + CHUNK_SIZE * multipler
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
end
|
||||
return {
|
||||
x = lx,
|
||||
y = ly
|
||||
}
|
||||
if nextDirection then
|
||||
if (nextDirection == 1) then
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 2) then
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 3) then
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
ly = ly - (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 4) then
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 5) then
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 6) then
|
||||
lx = lx - (CHUNK_SIZE * multipler)
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 7) then
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
elseif (nextDirection == 8) then
|
||||
lx = lx + (CHUNK_SIZE * multipler)
|
||||
ly = ly + (CHUNK_SIZE * multipler)
|
||||
end
|
||||
end
|
||||
MapPosition.x = lx
|
||||
MapPosition.y = ly
|
||||
return MapPosition
|
||||
end
|
||||
|
||||
function MapUtils.victoryScent(chunk, entityType)
|
||||
@ -608,7 +599,8 @@ end
|
||||
|
||||
function MapUtils.init(universe)
|
||||
Universe = universe
|
||||
NeighborChunks = universe.neighbors
|
||||
NeighborChunks = universe.mapUtilsQueries.neighbors
|
||||
MapPosition = universe.mapUtilsQueries.position
|
||||
end
|
||||
|
||||
MapUtilsG = MapUtils
|
||||
|
204
libs/Squad.lua
204
libs/Squad.lua
@ -22,6 +22,8 @@ local Squad = {}
|
||||
--
|
||||
|
||||
local Universe
|
||||
local TargetPosition
|
||||
local Queries
|
||||
|
||||
-- imports
|
||||
|
||||
@ -45,6 +47,8 @@ local BASE_PHEROMONE = Constants.BASE_PHEROMONE
|
||||
local ENEMY_PHEROMONE = Constants.ENEMY_PHEROMONE
|
||||
local RESOURCE_PHEROMONE = Constants.RESOURCE_PHEROMONE
|
||||
|
||||
local HALF_CHUNK_SIZE = Constants.HALF_CHUNK_SIZE
|
||||
|
||||
local FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT = Constants.FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT
|
||||
|
||||
local SQUAD_BUILDING = Constants.SQUAD_BUILDING
|
||||
@ -79,7 +83,6 @@ local CHUNK_ALL_DIRECTIONS = Constants.CHUNK_ALL_DIRECTIONS
|
||||
local getPassable = ChunkPropertyUtils.getPassable
|
||||
local getRallyTick = ChunkPropertyUtils.getRallyTick
|
||||
local setRallyTick = ChunkPropertyUtils.setRallyTick
|
||||
local positionFromDirectionAndChunk = MapUtils.positionFromDirectionAndChunk
|
||||
local modifyBaseUnitPoints = BaseUtils.modifyBaseUnitPoints
|
||||
|
||||
local tableRemove = table.remove
|
||||
@ -109,7 +112,7 @@ local getNeighborChunks = MapUtils.getNeighborChunks
|
||||
local addSquadToChunk = ChunkPropertyUtils.addSquadToChunk
|
||||
local getChunkByXY = MapUtils.getChunkByXY
|
||||
local positionToChunkXY = MapUtils.positionToChunkXY
|
||||
local positionFromDirectionAndFlat = MapUtils.positionFromDirectionAndFlat
|
||||
local positionFromScaledDirections = MapUtils.positionFromScaledDirections
|
||||
|
||||
local euclideanDistanceNamed = MathUtils.euclideanDistanceNamed
|
||||
|
||||
@ -265,9 +268,9 @@ local function scoreNeighborsForSettling(map, chunk, neighborDirectionChunks, sc
|
||||
return highestChunk, highestDirection, nextHighestChunk, nextHighestDirection
|
||||
end
|
||||
|
||||
local function settleMove(map, squad)
|
||||
local function settleMove(squad)
|
||||
local group = squad.group
|
||||
local targetPosition = {x=0,y=0}
|
||||
local map = squad.map
|
||||
|
||||
local groupPosition = group.position
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
@ -309,7 +312,7 @@ local function settleMove(map, squad)
|
||||
position = groupPosition
|
||||
end
|
||||
|
||||
cmd = Universe.settleCommand
|
||||
cmd = Queries.settleCommand
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
@ -322,34 +325,44 @@ local function settleMove(map, squad)
|
||||
|
||||
group.set_command(cmd)
|
||||
else
|
||||
local attackChunk,
|
||||
attackDirection,
|
||||
nextAttackChunk,
|
||||
nextAttackDirection = scoreNeighborsForSettling(map,
|
||||
chunk,
|
||||
getNeighborChunks(map, x, y),
|
||||
scoreFunction)
|
||||
local attackChunk, attackDirection,
|
||||
nextAttackChunk, nextAttackDirection = scoreNeighborsForSettling(
|
||||
map,
|
||||
chunk,
|
||||
getNeighborChunks(map, x, y),
|
||||
scoreFunction
|
||||
)
|
||||
|
||||
if (attackChunk == -1) then
|
||||
cmd = Universe.wanderCommand
|
||||
cmd = Queries.wanderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
elseif (attackDirection ~= 0) then
|
||||
elseif (attackDirection == 0) then
|
||||
cmd = Queries.settleCommand
|
||||
TargetPosition.x = groupPosition.x
|
||||
TargetPosition.y = groupPosition.y
|
||||
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
|
||||
squad.status = SQUAD_BUILDING
|
||||
else
|
||||
local attackPlayerThreshold = Universe.attackPlayerThreshold
|
||||
|
||||
if (nextAttackChunk ~= -1) then
|
||||
if (not nextAttackChunk.playerBaseGenerator)
|
||||
and ((nextAttackChunk.playerGenerator or 0) < PLAYER_PHEROMONE_GENERATOR_THRESHOLD)
|
||||
then
|
||||
attackChunk = nextAttackChunk
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextAttackDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
positionFromScaledDirections(
|
||||
groupPosition,
|
||||
1,
|
||||
attackDirection,
|
||||
nextAttackDirection
|
||||
)
|
||||
)
|
||||
else
|
||||
@ -358,23 +371,24 @@ local function settleMove(map, squad)
|
||||
else
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
positionFromScaledDirections(
|
||||
groupPosition,
|
||||
1,
|
||||
attackDirection
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if position then
|
||||
targetPosition.x = position.x
|
||||
targetPosition.y = position.y
|
||||
TargetPosition.x = position.x
|
||||
TargetPosition.y = position.y
|
||||
if nextAttackChunk ~= -1 then
|
||||
addDeathGenerator(nextAttackChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
else
|
||||
addDeathGenerator(attackChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
end
|
||||
else
|
||||
cmd = Universe.wanderCommand
|
||||
cmd = Queries.wanderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
end
|
||||
@ -385,7 +399,7 @@ local function settleMove(map, squad)
|
||||
or ((nextAttackChunk.playerBaseGenerator or 0) >= PLAYER_PHEROMONE_GENERATOR_THRESHOLD)
|
||||
)
|
||||
then
|
||||
cmd = Universe.settleCommand
|
||||
cmd = Queries.settleCommand
|
||||
squad.status = SQUAD_BUILDING
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
@ -395,7 +409,7 @@ local function settleMove(map, squad)
|
||||
elseif attackChunk.playerBaseGenerator
|
||||
or (attackChunk[PLAYER_PHEROMONE] >= attackPlayerThreshold)
|
||||
then
|
||||
cmd = Universe.attackCommand
|
||||
cmd = Queries.attackCommand
|
||||
|
||||
if not squad.rabid then
|
||||
squad.frenzy = true
|
||||
@ -403,28 +417,16 @@ local function settleMove(map, squad)
|
||||
squad.frenzyPosition.y = groupPosition.y
|
||||
end
|
||||
else
|
||||
cmd = Universe.moveCommand
|
||||
cmd = Queries.moveCommand
|
||||
if squad.rabid or squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
end
|
||||
else
|
||||
cmd = Universe.settleCommand
|
||||
targetPosition.x = groupPosition.x
|
||||
targetPosition.y = groupPosition.y
|
||||
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
|
||||
squad.status = SQUAD_BUILDING
|
||||
end
|
||||
|
||||
setPositionInCommand(cmd, targetPosition)
|
||||
setPositionInCommand(cmd, TargetPosition)
|
||||
|
||||
group.set_command(cmd)
|
||||
end
|
||||
@ -475,17 +477,13 @@ local function scoreNeighborsForAttack(map, chunk, neighborDirectionChunks, scor
|
||||
return highestChunk, highestDirection, nextHighestChunk, nextHighestDirection
|
||||
end
|
||||
|
||||
local function attackMove(map, squad)
|
||||
local targetPosition = {0,0}
|
||||
|
||||
local function attackMove(squad)
|
||||
local group = squad.group
|
||||
|
||||
local surface = map.surface
|
||||
local position
|
||||
local groupPosition = group.position
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
local map = squad.map
|
||||
local chunk = getChunkByXY(map, x, y)
|
||||
local attackScorer = scoreAttackLocation
|
||||
local squadChunk = squad.chunk
|
||||
if squadChunk ~= -1 then
|
||||
addDeathGenerator(squadChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
@ -497,6 +495,9 @@ local function attackMove(map, squad)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local attackScorer = scoreAttackLocation
|
||||
|
||||
squad.frenzy = (squad.frenzy and (euclideanDistanceNamed(groupPosition, squad.frenzyPosition) < 100))
|
||||
local attackChunk, attackDirection,
|
||||
nextAttackChunk, nextAttackDirection = scoreNeighborsForAttack(map,
|
||||
@ -505,51 +506,50 @@ local function attackMove(map, squad)
|
||||
attackScorer)
|
||||
local cmd
|
||||
if (attackChunk == -1) then
|
||||
cmd = Universe.wanderCommand
|
||||
cmd = Queries.wanderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
end
|
||||
|
||||
local position
|
||||
local surface = map.surface
|
||||
|
||||
if (nextAttackChunk ~= -1) then
|
||||
attackChunk = nextAttackChunk
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextAttackDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
positionFromScaledDirections(
|
||||
groupPosition,
|
||||
1,
|
||||
attackDirection,
|
||||
nextAttackDirection
|
||||
)
|
||||
)
|
||||
else
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
positionFromScaledDirections(
|
||||
groupPosition,
|
||||
1,
|
||||
attackDirection
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if not position then
|
||||
cmd = Universe.wanderCommand
|
||||
cmd = Queries.wanderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
else
|
||||
targetPosition.x = position.x
|
||||
targetPosition.y = position.y
|
||||
if (nextAttackChunk ~= -1) then
|
||||
addDeathGenerator(nextAttackChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
else
|
||||
addDeathGenerator(attackChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
end
|
||||
TargetPosition.x = position.x
|
||||
TargetPosition.y = position.y
|
||||
addDeathGenerator(attackChunk, -FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT)
|
||||
end
|
||||
|
||||
if attackChunk.playerBaseGenerator and
|
||||
(attackChunk[PLAYER_PHEROMONE] >= Universe.attackPlayerThreshold)
|
||||
then
|
||||
cmd = Universe.attackCommand
|
||||
cmd = Queries.attackCommand
|
||||
|
||||
if not squad.rabid then
|
||||
squad.frenzy = true
|
||||
@ -557,14 +557,14 @@ local function attackMove(map, squad)
|
||||
squad.frenzyPosition.y = groupPosition.y
|
||||
end
|
||||
else
|
||||
cmd = Universe.moveCommand
|
||||
cmd = Queries.moveCommand
|
||||
if squad.rabid or squad.frenzy then
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
else
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
end
|
||||
setPositionInCommand(cmd, targetPosition)
|
||||
setPositionInCommand(cmd, TargetPosition)
|
||||
|
||||
group.set_command(cmd)
|
||||
end
|
||||
@ -575,12 +575,12 @@ local function buildMove(map, squad)
|
||||
local newGroupPosition = findMovementPosition(map.surface, groupPosition)
|
||||
|
||||
if not newGroupPosition then
|
||||
setPositionInCommand(Universe.settleCommand, groupPosition)
|
||||
setPositionInCommand(Queries.settleCommand, groupPosition)
|
||||
else
|
||||
setPositionInCommand(Universe.settleCommand, newGroupPosition)
|
||||
setPositionInCommand(Queries.settleCommand, newGroupPosition)
|
||||
end
|
||||
|
||||
group.set_command(Universe.compoundSettleCommand)
|
||||
group.set_command(Queries.compoundSettleCommand)
|
||||
end
|
||||
|
||||
function Squad.cleanSquads(tick)
|
||||
@ -633,7 +633,7 @@ function Squad.cleanSquads(tick)
|
||||
squad.group.destroy()
|
||||
else
|
||||
squad.wanders = squad.wanders + 1
|
||||
local cmd = Universe.wander2Command
|
||||
local cmd = Queries.wander2Command
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
group.set_command(cmd)
|
||||
group.start_moving()
|
||||
@ -648,18 +648,18 @@ function Squad.squadDispatch(map, squad, tick)
|
||||
local status = squad.status
|
||||
if (status == SQUAD_RAIDING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
attackMove(map, squad)
|
||||
attackMove(squad)
|
||||
elseif (status == SQUAD_SETTLING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
settleMove(map, squad)
|
||||
settleMove(squad)
|
||||
elseif (status == SQUAD_RETREATING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
settleMove(map, squad)
|
||||
settleMove(squad)
|
||||
else
|
||||
squad.status = SQUAD_RAIDING
|
||||
attackMove(map, squad)
|
||||
attackMove(squad)
|
||||
end
|
||||
elseif (status == SQUAD_BUILDING) then
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
@ -669,10 +669,10 @@ function Squad.squadDispatch(map, squad, tick)
|
||||
squad.commandTick = tick + COMMAND_TIMEOUT
|
||||
if squad.settlers then
|
||||
squad.status = SQUAD_SETTLING
|
||||
settleMove(map, squad)
|
||||
settleMove(squad)
|
||||
else
|
||||
squad.status = SQUAD_RAIDING
|
||||
attackMove(map, squad)
|
||||
attackMove(squad)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -776,21 +776,21 @@ function Squad.retreatUnits(chunk, cause, map, tick, radius)
|
||||
elseif (nextExitPath ~= -1) then
|
||||
retreatPosition = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextExitDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
exitDirection,
|
||||
position
|
||||
)
|
||||
positionFromScaledDirections(
|
||||
position,
|
||||
1,
|
||||
exitDirection,
|
||||
nextExitDirection
|
||||
)
|
||||
)
|
||||
exitPath = nextExitPath
|
||||
else
|
||||
retreatPosition = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
exitDirection,
|
||||
position
|
||||
positionFromScaledDirections(
|
||||
position,
|
||||
1,
|
||||
exitDirection
|
||||
)
|
||||
)
|
||||
end
|
||||
@ -818,12 +818,12 @@ function Squad.retreatUnits(chunk, cause, map, tick, radius)
|
||||
end
|
||||
end
|
||||
|
||||
Universe.fleeCommand.from = cause
|
||||
Universe.retreatCommand.group = newSquad.group
|
||||
Queries.fleeCommand.from = cause
|
||||
Queries.retreatCommand.group = newSquad.group
|
||||
|
||||
Universe.formRetreatCommand.unit_search_distance = radius
|
||||
Queries.formRetreatCommand.unit_search_distance = radius
|
||||
|
||||
local foundUnits = surface.set_multi_command(Universe.formRetreatCommand)
|
||||
local foundUnits = surface.set_multi_command(Queries.formRetreatCommand)
|
||||
|
||||
if (foundUnits == 0) then
|
||||
if created then
|
||||
@ -1079,12 +1079,16 @@ local function deploySquad(name, chunk, cost, vengence, attacker)
|
||||
|
||||
local map = chunk.map
|
||||
local surface = map.surface
|
||||
TargetPosition.x = chunk.x + HALF_CHUNK_SIZE
|
||||
TargetPosition.y = chunk.y + HALF_CHUNK_SIZE
|
||||
|
||||
local squadPosition = findDeploymentPosition(
|
||||
surface,
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
0.98)
|
||||
positionFromScaledDirections(
|
||||
TargetPosition,
|
||||
1.25,
|
||||
squadDirection
|
||||
)
|
||||
)
|
||||
|
||||
if not squadPosition then
|
||||
@ -1099,9 +1103,9 @@ local function deploySquad(name, chunk, cost, vengence, attacker)
|
||||
else
|
||||
scaledWaveSize = settlerWaveScaling()
|
||||
end
|
||||
Universe.formGroupCommand.group = squad.group
|
||||
Universe.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(Universe.formCommand)
|
||||
Queries.formGroupCommand.group = squad.group
|
||||
Queries.formCommand.unit_count = scaledWaveSize
|
||||
local foundUnits = surface.set_multi_command(Queries.formCommand)
|
||||
if (foundUnits == 0) then
|
||||
if squad.group.valid then
|
||||
squad.group.destroy()
|
||||
@ -1149,6 +1153,8 @@ end
|
||||
|
||||
function Squad.init(universe)
|
||||
Universe = universe
|
||||
Queries = Universe.squadQueries
|
||||
TargetPosition = Universe.squadQueries.targetPosition
|
||||
end
|
||||
|
||||
SquadG = Squad
|
||||
|
152
libs/Upgrade.lua
152
libs/Upgrade.lua
@ -51,9 +51,15 @@ local TICKS_A_MINUTE = Constants.TICKS_A_MINUTE
|
||||
|
||||
-- module code
|
||||
|
||||
local function addCommandSet(queriesAndCommands)
|
||||
local function addCommandSet()
|
||||
-- preallocating memory to be used in code, making it fast by reducing garbage generated.
|
||||
queriesAndCommands.neighbors = {
|
||||
Universe.playerForces = {}
|
||||
Universe.enemyForces = {}
|
||||
Universe.npcForces = {}
|
||||
Universe.nonPlayerForces = {}
|
||||
|
||||
Universe.mapUtilsQueries = {}
|
||||
Universe.mapUtilsQueries.neighbors = {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
@ -63,34 +69,24 @@ local function addCommandSet(queriesAndCommands)
|
||||
-1,
|
||||
-1
|
||||
}
|
||||
queriesAndCommands.cardinalNeighbors = {
|
||||
Universe.mapUtilsQueries.position = {0,0}
|
||||
|
||||
Universe.chunkOverlapArray = {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
}
|
||||
|
||||
queriesAndCommands.chunkOverlapArray = {
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
}
|
||||
|
||||
queriesAndCommands.playerForces = {}
|
||||
queriesAndCommands.enemyForces = {}
|
||||
queriesAndCommands.npcForces = {}
|
||||
queriesAndCommands.nonPlayerForces = {}
|
||||
|
||||
queriesAndCommands.chunkPropertyUtilsQueries = {}
|
||||
queriesAndCommands.chunkPropertyUtilsQueries.position = {0,0}
|
||||
Universe.chunkPropertyUtilsQueries = {}
|
||||
Universe.chunkPropertyUtilsQueries.position = {0,0}
|
||||
|
||||
-- pb
|
||||
queriesAndCommands.pbFilteredEntitiesPointQueryLimited = {
|
||||
Universe.pbFilteredEntitiesPointQueryLimited = {
|
||||
position = {0, 0},
|
||||
radius = 10,
|
||||
limit = 1,
|
||||
force = queriesAndCommands.enemyForces,
|
||||
force = Universe.enemyForces,
|
||||
type = {
|
||||
"unit-spawner",
|
||||
"turret"
|
||||
@ -98,12 +94,12 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
|
||||
-- msec
|
||||
queriesAndCommands.msecFilteredEntitiesEnemyStructureQuery = {
|
||||
Universe.msecFilteredEntitiesEnemyStructureQuery = {
|
||||
area={
|
||||
{0,0},
|
||||
{0,0}
|
||||
},
|
||||
force=queriesAndCommands.enemyForces,
|
||||
force=Universe.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
@ -111,7 +107,7 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
|
||||
-- oba
|
||||
queriesAndCommands.obaCreateBuildCloudQuery = {
|
||||
Universe.obaCreateBuildCloudQuery = {
|
||||
name = "build-clear-cloud-rampant",
|
||||
position = {0,0}
|
||||
}
|
||||
@ -121,24 +117,24 @@ local function addCommandSet(queriesAndCommands)
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.spbHasPlayerStructuresQuery = {
|
||||
Universe.spbHasPlayerStructuresQuery = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.nonPlayerForces,
|
||||
force=Universe.nonPlayerForces,
|
||||
invert=true,
|
||||
limit=1
|
||||
}
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryLowest = {
|
||||
Universe.spbFilteredEntitiesPlayerQueryLowest = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
force=Universe.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"wall",
|
||||
"transport-belt"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryLow = {
|
||||
Universe.spbFilteredEntitiesPlayerQueryLow = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
force=Universe.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"splitter",
|
||||
@ -153,9 +149,9 @@ local function addCommandSet(queriesAndCommands)
|
||||
"ammo-turret"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryHigh = {
|
||||
Universe.spbFilteredEntitiesPlayerQueryHigh = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
force=Universe.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"furnace",
|
||||
@ -170,9 +166,9 @@ local function addCommandSet(queriesAndCommands)
|
||||
"mining-drill"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryHighest = {
|
||||
Universe.spbFilteredEntitiesPlayerQueryHighest = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
force=Universe.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"artillery-turret",
|
||||
@ -186,11 +182,11 @@ local function addCommandSet(queriesAndCommands)
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.isFilteredTilesQuery = {
|
||||
Universe.isFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=isSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesChunkNeutral = {
|
||||
Universe.isFilteredEntitiesChunkNeutral = {
|
||||
area=isSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -198,21 +194,21 @@ local function addCommandSet(queriesAndCommands)
|
||||
"simple-entity"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesEnemyStructureQuery = {
|
||||
Universe.isFilteredEntitiesEnemyStructureQuery = {
|
||||
area=isSharedChunkArea,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
force=Universe.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.isCountResourcesQuery = {
|
||||
Universe.isCountResourcesQuery = {
|
||||
area=isSharedChunkArea,
|
||||
type="resource"
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesUnitQuery = {
|
||||
Universe.isFilteredEntitiesUnitQuery = {
|
||||
area=isSharedChunkArea,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
force=Universe.enemyForces,
|
||||
type="unit"
|
||||
}
|
||||
|
||||
@ -221,11 +217,11 @@ local function addCommandSet(queriesAndCommands)
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.cpsFilteredTilesQuery = {
|
||||
Universe.cpsFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=cpsSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.cpsFilteredEntitiesChunkNeutral = {
|
||||
Universe.cpsFilteredEntitiesChunkNeutral = {
|
||||
area=cpsSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -233,9 +229,9 @@ local function addCommandSet(queriesAndCommands)
|
||||
"simple-entity"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.cpsFilteredEnemyAnyFound = {
|
||||
Universe.cpsFilteredEnemyAnyFound = {
|
||||
area=cpsSharedChunkArea,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
force=Universe.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
@ -248,11 +244,11 @@ local function addCommandSet(queriesAndCommands)
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.msrcFilteredTilesQuery = {
|
||||
Universe.msrcFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=msrcSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.msrcFilteredEntitiesChunkNeutral = {
|
||||
Universe.msrcFilteredEntitiesChunkNeutral = {
|
||||
area=msrcSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -260,7 +256,7 @@ local function addCommandSet(queriesAndCommands)
|
||||
"simple-entity"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.msrcCountResourcesQuery = {
|
||||
Universe.msrcCountResourcesQuery = {
|
||||
area=msrcSharedChunkArea,
|
||||
type="resource"
|
||||
}
|
||||
@ -270,19 +266,19 @@ local function addCommandSet(queriesAndCommands)
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.spFilteredEntitiesCliffQuery = {
|
||||
Universe.spFilteredEntitiesCliffQuery = {
|
||||
area=spSharedAreaChunk,
|
||||
type="cliff",
|
||||
limit = 1
|
||||
}
|
||||
queriesAndCommands.spFilteredTilesPathQuery = {
|
||||
Universe.spFilteredTilesPathQuery = {
|
||||
area=spSharedAreaChunk,
|
||||
collision_mask="water-tile",
|
||||
limit = 1
|
||||
}
|
||||
|
||||
-- ouc
|
||||
queriesAndCommands.oucCliffQuery = {
|
||||
Universe.oucCliffQuery = {
|
||||
area={
|
||||
{0,0},
|
||||
{0,0}
|
||||
@ -291,97 +287,87 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
|
||||
-- ppu
|
||||
queriesAndCommands.ppuUpgradeEntityQuery = {
|
||||
Universe.ppuUpgradeEntityQuery = {
|
||||
name = "",
|
||||
position = {0,0}
|
||||
}
|
||||
|
||||
queriesAndCommands.attackCommand = {
|
||||
Universe.squadQueries = {}
|
||||
Universe.squadQueries.targetPosition = {0,0}
|
||||
Universe.squadQueries.attackCommand = {
|
||||
type = DEFINES_COMMAND_ATTACK_AREA,
|
||||
destination = {0,0},
|
||||
radius = CHUNK_SIZE * 1.5,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
}
|
||||
|
||||
queriesAndCommands.moveCommand = {
|
||||
Universe.squadQueries.moveCommand = {
|
||||
type = DEFINES_COMMAND_GO_TO_LOCATION,
|
||||
destination = {0,0},
|
||||
pathfind_flags = { cache = true },
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
}
|
||||
|
||||
queriesAndCommands.settleCommand = {
|
||||
Universe.squadQueries.settleCommand = {
|
||||
type = DEFINES_COMMAND_BUILD_BASE,
|
||||
destination = {0,0},
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY,
|
||||
ignore_planner = true
|
||||
}
|
||||
|
||||
queriesAndCommands.wanderCommand = {
|
||||
Universe.squadQueries.wanderCommand = {
|
||||
type = DEFINES_COMMAND_WANDER,
|
||||
wander_in_group = false,
|
||||
radius = TRIPLE_CHUNK_SIZE*2,
|
||||
ticks_to_wait = 20 * 60
|
||||
}
|
||||
|
||||
queriesAndCommands.wander2Command = {
|
||||
Universe.squadQueries.wander2Command = {
|
||||
type = DEFINES_COMMAND_WANDER,
|
||||
wander_in_group = true,
|
||||
radius = TRIPLE_CHUNK_SIZE*2,
|
||||
ticks_to_wait = 2 * 60
|
||||
}
|
||||
|
||||
queriesAndCommands.stopCommand = {
|
||||
Universe.squadQueries.stopCommand = {
|
||||
type = DEFINES_COMMAND_STOP
|
||||
}
|
||||
|
||||
queriesAndCommands.compoundSettleCommand = {
|
||||
Universe.squadQueries.compoundSettleCommand = {
|
||||
type = DEFINES_COMMMAD_COMPOUND,
|
||||
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
|
||||
commands = {
|
||||
queriesAndCommands.wonder2Command,
|
||||
queriesAndCommands.settleCommand
|
||||
Universe.squadQueries.wonder2Command,
|
||||
Universe.squadQueries.settleCommand
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.retreatCommand = {
|
||||
Universe.squadQueries.retreatCommand = {
|
||||
type = DEFINES_COMMAND_GROUP,
|
||||
group = nil,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING,
|
||||
use_group_distraction = true
|
||||
}
|
||||
|
||||
queriesAndCommands.fleeCommand = {
|
||||
Universe.squadQueries.fleeCommand = {
|
||||
type = DEFINES_COMMAND_FLEE,
|
||||
from = nil,
|
||||
distraction = DEFINES_DISTRACTION_NONE
|
||||
}
|
||||
|
||||
queriesAndCommands.compoundRetreatGroupCommand = {
|
||||
Universe.squadQueries.compoundRetreatGroupCommand = {
|
||||
type = DEFINES_COMMMAD_COMPOUND,
|
||||
structure_type = DEFINES_COMPOUND_COMMAND_RETURN_LAST,
|
||||
commands = {
|
||||
queriesAndCommands.stopCommand,
|
||||
queriesAndCommands.fleeCommand,
|
||||
queriesAndCommands.retreatCommand
|
||||
Universe.squadQueries.stopCommand,
|
||||
Universe.squadQueries.fleeCommand,
|
||||
Universe.squadQueries.retreatCommand
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.formGroupCommand = {
|
||||
Universe.squadQueries.formGroupCommand = {
|
||||
type = DEFINES_COMMAND_GROUP,
|
||||
group = nil,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING,
|
||||
use_group_distraction = false
|
||||
}
|
||||
|
||||
queriesAndCommands.formCommand = {
|
||||
command = queriesAndCommands.formGroupCommand,
|
||||
Universe.squadQueries.formCommand = {
|
||||
command = Universe.squadQueries.formGroupCommand,
|
||||
unit_count = 0,
|
||||
unit_search_distance = TRIPLE_CHUNK_SIZE
|
||||
}
|
||||
|
||||
queriesAndCommands.formRetreatCommand = {
|
||||
command = queriesAndCommands.compoundRetreatGroupCommand,
|
||||
Universe.squadQueries.formRetreatCommand = {
|
||||
command = Universe.squadQueries.compoundRetreatGroupCommand,
|
||||
unit_count = 1,
|
||||
unit_search_distance = CHUNK_SIZE
|
||||
}
|
||||
@ -499,7 +485,7 @@ function Upgrade.addUniverseProperties()
|
||||
Universe.maxPoints = 0
|
||||
Universe.maxOverflowPoints = 0
|
||||
|
||||
addCommandSet(Universe)
|
||||
addCommandSet()
|
||||
|
||||
Universe.bases = {}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user