mirror of
https://github.com/veden/Rampant.git
synced 2025-01-14 02:23:01 +02:00
pre-allocated structures don't cross function boundaries
This commit is contained in:
parent
d462e8f32d
commit
1561456ba9
229
Upgrade.lua
229
Upgrade.lua
@ -52,23 +52,6 @@ local function addCommandSet(queriesAndCommands)
|
||||
-1,
|
||||
-1
|
||||
}
|
||||
queriesAndCommands.position = {
|
||||
x=0,
|
||||
y=0
|
||||
}
|
||||
queriesAndCommands.position2 = {
|
||||
x=0,
|
||||
y=0
|
||||
}
|
||||
queriesAndCommands.position3 = {
|
||||
x=0,
|
||||
y=0
|
||||
}
|
||||
|
||||
queriesAndCommands.playerForces = {}
|
||||
queriesAndCommands.enemyForces = {}
|
||||
queriesAndCommands.npcForces = {}
|
||||
queriesAndCommands.nonPlayerForces = {}
|
||||
|
||||
queriesAndCommands.chunkOverlapArray = {
|
||||
-1,
|
||||
@ -77,48 +60,14 @@ local function addCommandSet(queriesAndCommands)
|
||||
-1
|
||||
}
|
||||
|
||||
queriesAndCommands.position2Top = {0, 0}
|
||||
queriesAndCommands.position2Bottom = {0, 0}
|
||||
--this is shared between two different queries
|
||||
queriesAndCommands.area = {
|
||||
{0, 0},
|
||||
{0, 0}
|
||||
}
|
||||
queriesAndCommands.area2 = {
|
||||
queriesAndCommands.position2Top,
|
||||
queriesAndCommands.position2Bottom
|
||||
}
|
||||
queriesAndCommands.buildPositionTop = {0, 0}
|
||||
queriesAndCommands.buildPositionBottom = {0, 0}
|
||||
queriesAndCommands.buildArea = {
|
||||
queriesAndCommands.buildPositionTop,
|
||||
queriesAndCommands.buildPositionBottom
|
||||
}
|
||||
queriesAndCommands.countResourcesQuery = {
|
||||
area=queriesAndCommands.area,
|
||||
type="resource"
|
||||
}
|
||||
queriesAndCommands.filteredEntitiesUnitQuery = {
|
||||
area=queriesAndCommands.area,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
type="unit"
|
||||
}
|
||||
queriesAndCommands.hasPlayerStructuresQuery = {
|
||||
area=queriesAndCommands.area,
|
||||
force=queriesAndCommands.nonPlayerForces,
|
||||
invert=true,
|
||||
limit=1
|
||||
}
|
||||
queriesAndCommands.filteredEntitiesEnemyStructureQuery = {
|
||||
area=queriesAndCommands.area,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.filteredEntitiesPointQueryLimited = {
|
||||
position = queriesAndCommands.position,
|
||||
queriesAndCommands.playerForces = {}
|
||||
queriesAndCommands.enemyForces = {}
|
||||
queriesAndCommands.npcForces = {}
|
||||
queriesAndCommands.nonPlayerForces = {}
|
||||
|
||||
-- pb
|
||||
queriesAndCommands.pbFilteredEntitiesPointQueryLimited = {
|
||||
position = {0, 0},
|
||||
radius = 10,
|
||||
limit = 1,
|
||||
force = queriesAndCommands.enemyForces,
|
||||
@ -127,13 +76,39 @@ local function addCommandSet(queriesAndCommands)
|
||||
"turret"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.createBuildCloudQuery = {
|
||||
name = "build-clear-cloud-rampant",
|
||||
position = queriesAndCommands.position
|
||||
|
||||
-- msec
|
||||
queriesAndCommands.msecFilteredEntitiesEnemyStructureQuery = {
|
||||
area={
|
||||
{0,0},
|
||||
{0,0}
|
||||
},
|
||||
force=queriesAndCommands.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.filteredEntitiesPlayerQueryLowest = {
|
||||
area=queriesAndCommands.area,
|
||||
-- oba
|
||||
queriesAndCommands.obaCreateBuildCloudQuery = {
|
||||
name = "build-clear-cloud-rampant",
|
||||
position = {0,0}
|
||||
}
|
||||
|
||||
-- sp
|
||||
local spbSharedChunkArea = {
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.spbHasPlayerStructuresQuery = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.nonPlayerForces,
|
||||
invert=true,
|
||||
limit=1
|
||||
}
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryLowest = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -141,9 +116,8 @@ local function addCommandSet(queriesAndCommands)
|
||||
"transport-belt"
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.filteredEntitiesPlayerQueryLow = {
|
||||
area=queriesAndCommands.area,
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryLow = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -159,9 +133,8 @@ local function addCommandSet(queriesAndCommands)
|
||||
"ammo-turret"
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.filteredEntitiesPlayerQueryHigh = {
|
||||
area=queriesAndCommands.area,
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryHigh = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -177,9 +150,8 @@ local function addCommandSet(queriesAndCommands)
|
||||
"mining-drill"
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.filteredEntitiesPlayerQueryHighest = {
|
||||
area=queriesAndCommands.area,
|
||||
queriesAndCommands.spbFilteredEntitiesPlayerQueryHighest = {
|
||||
area=spbSharedChunkArea,
|
||||
force=queriesAndCommands.playerForces,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
@ -189,8 +161,52 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
}
|
||||
|
||||
queriesAndCommands.filteredEntitiesChunkNeutral = {
|
||||
area=queriesAndCommands.area,
|
||||
-- is
|
||||
local isSharedChunkArea = {
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.isFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=isSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesChunkNeutral = {
|
||||
area=isSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"tree",
|
||||
"simple-entity"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesEnemyStructureQuery = {
|
||||
area=isSharedChunkArea,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
type={
|
||||
"turret",
|
||||
"unit-spawner"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.isCountResourcesQuery = {
|
||||
area=isSharedChunkArea,
|
||||
type="resource"
|
||||
}
|
||||
queriesAndCommands.isFilteredEntitiesUnitQuery = {
|
||||
area=isSharedChunkArea,
|
||||
force=queriesAndCommands.enemyForces,
|
||||
type="unit"
|
||||
}
|
||||
|
||||
-- cps
|
||||
local cpsSharedChunkArea = {
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.cpsFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=cpsSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.cpsFilteredEntitiesChunkNeutral = {
|
||||
area=cpsSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"tree",
|
||||
@ -198,55 +214,76 @@ local function addCommandSet(queriesAndCommands)
|
||||
}
|
||||
}
|
||||
|
||||
local sharedArea = {
|
||||
-- msrc
|
||||
local msrcSharedChunkArea = {
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.filteredEntitiesCliffQuery = {
|
||||
area=sharedArea,
|
||||
queriesAndCommands.msrcFilteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=msrcSharedChunkArea
|
||||
}
|
||||
queriesAndCommands.msrcFilteredEntitiesChunkNeutral = {
|
||||
area=msrcSharedChunkArea,
|
||||
collision_mask = "player-layer",
|
||||
type={
|
||||
"tree",
|
||||
"simple-entity"
|
||||
}
|
||||
}
|
||||
queriesAndCommands.msrcCountResourcesQuery = {
|
||||
area=msrcSharedChunkArea,
|
||||
type="resource"
|
||||
}
|
||||
|
||||
-- sp
|
||||
local spSharedAreaChunk = {
|
||||
{0,0},
|
||||
{0,0}
|
||||
}
|
||||
queriesAndCommands.spFilteredEntitiesCliffQuery = {
|
||||
area=spSharedAreaChunk,
|
||||
type="cliff",
|
||||
limit = 1
|
||||
}
|
||||
queriesAndCommands.filteredTilesPathQuery = {
|
||||
area=sharedArea,
|
||||
queriesAndCommands.spFilteredTilesPathQuery = {
|
||||
area=spSharedAreaChunk,
|
||||
collision_mask="water-tile",
|
||||
limit = 1
|
||||
}
|
||||
queriesAndCommands.cliffQuery = {
|
||||
area=queriesAndCommands.area2,
|
||||
|
||||
-- ouc
|
||||
queriesAndCommands.oucCliffQuery = {
|
||||
area={
|
||||
{0,0},
|
||||
{0,0}
|
||||
},
|
||||
type="cliff"
|
||||
}
|
||||
queriesAndCommands.canPlaceQuery = {
|
||||
name="",
|
||||
position={0,0}
|
||||
}
|
||||
queriesAndCommands.filteredTilesQuery = {
|
||||
collision_mask="water-tile",
|
||||
area=queriesAndCommands.area
|
||||
}
|
||||
|
||||
queriesAndCommands.upgradeEntityQuery = {
|
||||
-- ppu
|
||||
queriesAndCommands.ppuUpgradeEntityQuery = {
|
||||
name = "",
|
||||
position = {0,0}
|
||||
}
|
||||
|
||||
queriesAndCommands.attackCommand = {
|
||||
type = DEFINES_COMMAND_ATTACK_AREA,
|
||||
destination = queriesAndCommands.position,
|
||||
destination = {0,0},
|
||||
radius = CHUNK_SIZE * 1.5,
|
||||
distraction = DEFINES_DISTRACTION_BY_ANYTHING
|
||||
}
|
||||
|
||||
queriesAndCommands.moveCommand = {
|
||||
type = DEFINES_COMMAND_GO_TO_LOCATION,
|
||||
destination = queriesAndCommands.position,
|
||||
destination = {0,0},
|
||||
pathfind_flags = { cache = true },
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
}
|
||||
|
||||
queriesAndCommands.settleCommand = {
|
||||
type = DEFINES_COMMAND_BUILD_BASE,
|
||||
destination = queriesAndCommands.position,
|
||||
destination = {0,0},
|
||||
distraction = DEFINES_DISTRACTION_BY_ENEMY,
|
||||
ignore_planner = true
|
||||
}
|
||||
@ -428,8 +465,8 @@ function upgrade.attempt(universe)
|
||||
|
||||
universe.maxPoints = 0
|
||||
end
|
||||
if global.version < 202 then
|
||||
global.version = 202
|
||||
if global.version < 203 then
|
||||
global.version = 203
|
||||
|
||||
addCommandSet(universe)
|
||||
universe.eventId = 0
|
||||
|
@ -91,6 +91,7 @@ Date: 23. 11. 2021
|
||||
- Moved config methods into relevant code files
|
||||
- Removed unnecessary unregisterResource called on onMine event
|
||||
- Cleaned up energy thief code in control
|
||||
- Pre-allocated objects no longer cross function boundaries
|
||||
Removals:
|
||||
- Removed map deadzones as they were breaking regional bases
|
||||
- Removed make building safe mod option, now each individual toggle works as people are expecting
|
||||
|
21
control.lua
21
control.lua
@ -19,6 +19,7 @@ local chunkUtils = require("libs/ChunkUtils")
|
||||
local upgrade = require("Upgrade")
|
||||
local aiPredicates = require("libs/AIPredicates")
|
||||
local stringUtils = require("libs/StringUtils")
|
||||
local queryUtils = require("libs/QueryUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -35,6 +36,9 @@ local RETREAT_SPAWNER_GRAB_RADIUS = constants.RETREAT_SPAWNER_GRAB_RADIUS
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setPointAreaInQuery = queryUtils.setPointAreaInQuery
|
||||
local setPositionInQuery = queryUtils.setPositionInQuery
|
||||
|
||||
local nextMap = mapUtils.nextMap
|
||||
|
||||
local distortPosition = mathUtils.distortPosition
|
||||
@ -619,13 +623,8 @@ local function onUsedCapsule(event)
|
||||
return
|
||||
end
|
||||
if (event.item.name == "cliff-explosives") then
|
||||
local position2Top = universe.position2Top
|
||||
local position2Bottom = universe.position2Bottom
|
||||
position2Top.x = event.position.x-0.75
|
||||
position2Top.y = event.position.y-0.75
|
||||
position2Bottom.x = event.position.x+0.75
|
||||
position2Bottom.y = event.position.y+0.75
|
||||
local cliffs = surface.find_entities_filtered(universe.cliffQuery)
|
||||
setPointAreaInQuery(universe.oucCliffQuery, event.position, 0.75)
|
||||
local cliffs = surface.find_entities_filtered(universe.oucCliffQuery)
|
||||
for i=1,#cliffs do
|
||||
entityForPassScan(map, cliffs[i])
|
||||
end
|
||||
@ -894,9 +893,6 @@ local function onBuilderArrived(event)
|
||||
elseif (builder.force.name ~= "enemy") then
|
||||
return
|
||||
end
|
||||
local targetPosition = universe.position
|
||||
targetPosition.x = builder.position.x
|
||||
targetPosition.y = builder.position.y
|
||||
|
||||
local map = universe.maps[builder.surface.index]
|
||||
if not map then
|
||||
@ -906,9 +902,10 @@ local function onBuilderArrived(event)
|
||||
local squad = universe.groupNumberToSquad[builder.group_number]
|
||||
squad.commandTick = event.tick + COMMAND_TIMEOUT * 10
|
||||
if universe.aiPointsPrintSpendingToChat then
|
||||
game.print("Settled: [gps=" .. targetPosition.x .. "," .. targetPosition.y .."]")
|
||||
game.print("Settled: [gps=" .. builder.position.x .. "," .. builder.position.y .."]")
|
||||
end
|
||||
map.surface.create_entity(universe.createBuildCloudQuery)
|
||||
setPositionInQuery(universe.obaCreateBuildCloudQuery, builder.position)
|
||||
map.surface.create_entity(universe.obaCreateBuildCloudQuery)
|
||||
end
|
||||
|
||||
-- hooks
|
||||
|
@ -219,7 +219,6 @@ function aiAttackWave.formSettlers(map, chunk)
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
universe.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
@ -278,7 +277,6 @@ function aiAttackWave.formVengenceSquad(map, chunk)
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
universe.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
@ -329,7 +327,6 @@ function aiAttackWave.formSquads(map, chunk)
|
||||
local squadPosition = surface.find_non_colliding_position("chunk-scanner-squad-rampant",
|
||||
positionFromDirectionAndChunk(squadDirection,
|
||||
chunk,
|
||||
universe.position,
|
||||
0.98),
|
||||
CHUNK_SIZE,
|
||||
4,
|
||||
|
@ -9,6 +9,7 @@ local mathUtils = require("MathUtils")
|
||||
local constants = require("Constants")
|
||||
local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
local mapUtils = require("MapUtils")
|
||||
local queryUtils = require("QueryUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -37,6 +38,8 @@ local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setPositionXYInQuery = queryUtils.setPositionXYInQuery
|
||||
|
||||
local randomTickEvent = mathUtils.randomTickEvent
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
@ -390,14 +393,13 @@ function baseUtils.processBase(chunk, map, tick, base)
|
||||
|
||||
local surface = map.surface
|
||||
local universe = map.universe
|
||||
local point = universe.position
|
||||
|
||||
point.x = chunk.x + (CHUNK_SIZE * map.random())
|
||||
point.y = chunk.y + (CHUNK_SIZE * map.random())
|
||||
setPositionXYInQuery(universe.pbFilteredEntitiesPointQueryLimited,
|
||||
chunk.x + (CHUNK_SIZE * map.random()),
|
||||
chunk.y + (CHUNK_SIZE * map.random()))
|
||||
|
||||
local upgradeRoll = map.random()
|
||||
if (base.state == BASE_AI_STATE_ACTIVE) and (base.points >= MINIMUM_BUILDING_COST) and (upgradeRoll < 0.30) then
|
||||
local entities = surface.find_entities_filtered(universe.filteredEntitiesPointQueryLimited)
|
||||
local entities = surface.find_entities_filtered(universe.pbFilteredEntitiesPointQueryLimited)
|
||||
if #entities ~= 0 then
|
||||
local entity = entities[1]
|
||||
local cost = (universe.costLookup[entity.name] or MAGIC_MAXIMUM_NUMBER)
|
||||
|
@ -6,14 +6,13 @@ local chunkProcessor = {}
|
||||
-- imports
|
||||
|
||||
local chunkUtils = require("ChunkUtils")
|
||||
local constants = require("Constants")
|
||||
local queryUtils = require("QueryUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setPositionInQuery = queryUtils.setPositionInQuery
|
||||
local registerEnemyBaseStructure = chunkUtils.registerEnemyBaseStructure
|
||||
local unregisterEnemyBaseStructure = chunkUtils.unregisterEnemyBaseStructure
|
||||
|
||||
@ -56,10 +55,6 @@ local function removeProcessQueueChunk(processQueue, chunk)
|
||||
end
|
||||
|
||||
function chunkProcessor.processPendingChunks(universe, tick, flush)
|
||||
local area = universe.area
|
||||
local topOffset = area[1]
|
||||
local bottomOffset = area[2]
|
||||
|
||||
local pendingChunks = universe.pendingChunks
|
||||
local eventId = universe.chunkProcessorIterator
|
||||
local event
|
||||
@ -98,11 +93,6 @@ function chunkProcessor.processPendingChunks(universe, tick, flush)
|
||||
local x = topLeft.x
|
||||
local y = topLeft.y
|
||||
|
||||
topOffset[1] = x
|
||||
topOffset[2] = y
|
||||
bottomOffset[1] = x + CHUNK_SIZE
|
||||
bottomOffset[2] = y + CHUNK_SIZE
|
||||
|
||||
if not map[x] then
|
||||
map[x] = {}
|
||||
end
|
||||
@ -158,8 +148,8 @@ function chunkProcessor.processPendingUpgrades(universe, tick)
|
||||
universe.pendingUpgradeIterator = next(universe.pendingUpgrades, entityId)
|
||||
universe.pendingUpgrades[entityId] = nil
|
||||
local surface = entity.surface
|
||||
local query = universe.upgradeEntityQuery
|
||||
query.position = entityData.position or entity.position
|
||||
local query = universe.ppuUpgradeEntityQuery
|
||||
setPositionInQuery(query, entityData.position or entity.position)
|
||||
query.name = entityData.name
|
||||
unregisterEnemyBaseStructure(entityData.map, entity, nil, true)
|
||||
entity.destroy()
|
||||
@ -202,14 +192,6 @@ function chunkProcessor.processScanChunks(universe)
|
||||
end
|
||||
local chunk = chunkPack.chunk
|
||||
|
||||
local area = universe.area
|
||||
local topOffset = area[1]
|
||||
local bottomOffset = area[2]
|
||||
topOffset[1] = chunk.x
|
||||
topOffset[2] = chunk.y
|
||||
bottomOffset[1] = chunk.x + CHUNK_SIZE
|
||||
bottomOffset[2] = chunk.y + CHUNK_SIZE
|
||||
|
||||
if (chunkPassScan(chunk, map) == -1) then
|
||||
removeProcessQueueChunk(map.processQueue, chunk)
|
||||
map[chunk.x][chunk.y] = nil
|
||||
|
@ -48,7 +48,9 @@ local GENERATOR_PHEROMONE_LEVEL_6 = constants.GENERATOR_PHEROMONE_LEVEL_6
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setAreaInQuery = queryUtils.setAreaInQuery
|
||||
local setAreaInQueryChunkSize = queryUtils.setAreaInQueryChunkSize
|
||||
local setAreaXInQuery = queryUtils.setAreaXInQuery
|
||||
local setAreaYInQuery = queryUtils.setAreaYInQuery
|
||||
|
||||
local setPlayerBaseGenerator = chunkPropertyUtils.setPlayerBaseGenerator
|
||||
local addPlayerBaseGenerator = chunkPropertyUtils.addPlayerBaseGenerator
|
||||
@ -142,22 +144,18 @@ local function scanPaths(chunk, map)
|
||||
local y = chunk.y
|
||||
|
||||
local universe = map.universe
|
||||
local filteredEntitiesCliffQuery = universe.filteredEntitiesCliffQuery
|
||||
local filteredTilesPathQuery = universe.filteredTilesPathQuery
|
||||
local filteredEntitiesCliffQuery = universe.spFilteredEntitiesCliffQuery
|
||||
local filteredTilesPathQuery = universe.spFilteredTilesPathQuery
|
||||
local count_entities_filtered = surface.count_entities_filtered
|
||||
local count_tiles_filtered = surface.count_tiles_filtered
|
||||
|
||||
local passableNorthSouth = false
|
||||
local passableEastWest = false
|
||||
|
||||
local topPosition = filteredEntitiesCliffQuery.area[1]
|
||||
local bottomPosition = filteredEntitiesCliffQuery.area[2]
|
||||
topPosition[2] = y
|
||||
bottomPosition[2] = y + 32
|
||||
setAreaYInQuery(filteredEntitiesCliffQuery, y, y + CHUNK_SIZE)
|
||||
|
||||
for xi=x, x + 32 do
|
||||
topPosition[1] = xi
|
||||
bottomPosition[1] = xi + 1
|
||||
for xi=x, x + CHUNK_SIZE do
|
||||
setAreaXInQuery(filteredEntitiesCliffQuery, xi, xi + 1)
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
(count_tiles_filtered(filteredTilesPathQuery) == 0)
|
||||
then
|
||||
@ -166,12 +164,10 @@ local function scanPaths(chunk, map)
|
||||
end
|
||||
end
|
||||
|
||||
topPosition[1] = x
|
||||
bottomPosition[1] = x + 32
|
||||
setAreaXInQuery(filteredEntitiesCliffQuery, x, x + CHUNK_SIZE)
|
||||
|
||||
for yi=y, y + 32 do
|
||||
topPosition[2] = yi
|
||||
bottomPosition[2] = yi + 1
|
||||
for yi=y, y + CHUNK_SIZE do
|
||||
setAreaYInQuery(filteredEntitiesCliffQuery, yi, yi + 1)
|
||||
if (count_entities_filtered(filteredEntitiesCliffQuery) == 0) and
|
||||
(count_tiles_filtered(filteredTilesPathQuery) == 0)
|
||||
then
|
||||
@ -190,14 +186,15 @@ local function scanPaths(chunk, map)
|
||||
return pass
|
||||
end
|
||||
|
||||
local function scorePlayerBuildings(map)
|
||||
local function scorePlayerBuildings(map, chunk)
|
||||
local surface = map.surface
|
||||
local universe = map.universe
|
||||
if surface.count_entities_filtered(universe.hasPlayerStructuresQuery) > 0 then
|
||||
return (surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryLowest) * GENERATOR_PHEROMONE_LEVEL_1) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryLow) * GENERATOR_PHEROMONE_LEVEL_3) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryHigh) * GENERATOR_PHEROMONE_LEVEL_5) +
|
||||
(surface.count_entities_filtered(universe.filteredEntitiesPlayerQueryHighest) * GENERATOR_PHEROMONE_LEVEL_6)
|
||||
setAreaInQueryChunkSize(universe.spbHasPlayerStructuresQuery, chunk)
|
||||
if surface.count_entities_filtered(universe.spbHasPlayerStructuresQuery) > 0 then
|
||||
return (surface.count_entities_filtered(universe.spbFilteredEntitiesPlayerQueryLowest) * GENERATOR_PHEROMONE_LEVEL_1) +
|
||||
(surface.count_entities_filtered(universe.spbFilteredEntitiesPlayerQueryLow) * GENERATOR_PHEROMONE_LEVEL_3) +
|
||||
(surface.count_entities_filtered(universe.spbFilteredEntitiesPlayerQueryHigh) * GENERATOR_PHEROMONE_LEVEL_5) +
|
||||
(surface.count_entities_filtered(universe.spbFilteredEntitiesPlayerQueryHighest) * GENERATOR_PHEROMONE_LEVEL_6)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
@ -205,23 +202,24 @@ end
|
||||
function chunkUtils.initialScan(chunk, map, tick)
|
||||
local surface = map.surface
|
||||
local universe = map.universe
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local enemyBuildings = surface.find_entities_filtered(universe.filteredEntitiesEnemyStructureQuery)
|
||||
setAreaInQueryChunkSize(universe.isFilteredTilesQuery, chunk)
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.isFilteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local enemyBuildings = surface.find_entities_filtered(universe.isFilteredEntitiesEnemyStructureQuery)
|
||||
|
||||
if (waterTiles >= CHUNK_PASS_THRESHOLD) or (#enemyBuildings > 0) then
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.isFilteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
local pass = scanPaths(chunk, map)
|
||||
|
||||
local playerObjects = scorePlayerBuildings(map)
|
||||
local playerObjects = scorePlayerBuildings(map, chunk)
|
||||
|
||||
if ((playerObjects > 0) or (#enemyBuildings > 0)) and (pass == CHUNK_IMPASSABLE) then
|
||||
pass = CHUNK_ALL_DIRECTIONS
|
||||
end
|
||||
|
||||
if (pass ~= CHUNK_IMPASSABLE) then
|
||||
local resources = surface.count_entities_filtered(universe.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
local resources = surface.count_entities_filtered(universe.isCountResourcesQuery) * RESOURCE_NORMALIZER
|
||||
|
||||
local buildingHiveTypeLookup = universe.buildingHiveTypeLookup
|
||||
local counts = map.chunkScanCounts
|
||||
@ -236,7 +234,7 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
base = createBase(map, chunk, tick)
|
||||
end
|
||||
|
||||
local unitList = surface.find_entities_filtered(universe.filteredEntitiesUnitQuery)
|
||||
local unitList = surface.find_entities_filtered(universe.isFilteredEntitiesUnitQuery)
|
||||
for i=1,#unitList do
|
||||
local unit = unitList[i]
|
||||
if (unit.valid) then
|
||||
@ -276,11 +274,12 @@ end
|
||||
function chunkUtils.chunkPassScan(chunk, map)
|
||||
local surface = map.surface
|
||||
local universe = map.universe
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
setAreaInQueryChunkSize(universe.cpsFilteredTilesQuery, chunk)
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.cpsFilteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
|
||||
if (waterTiles >= CHUNK_PASS_THRESHOLD) then
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.cpsFilteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
local pass = scanPaths(chunk, map)
|
||||
|
||||
@ -306,27 +305,27 @@ function chunkUtils.chunkPassScan(chunk, map)
|
||||
end
|
||||
|
||||
function chunkUtils.mapScanPlayerChunk(chunk, map)
|
||||
local playerObjects = scorePlayerBuildings(map)
|
||||
local playerObjects = scorePlayerBuildings(map, chunk)
|
||||
setPlayerBaseGenerator(map, chunk, playerObjects)
|
||||
end
|
||||
|
||||
function chunkUtils.mapScanResourceChunk(chunk, map)
|
||||
local surface = map.surface
|
||||
local universe = map.universe
|
||||
local resources = surface.count_entities_filtered(universe.countResourcesQuery) * RESOURCE_NORMALIZER
|
||||
setAreaInQueryChunkSize(universe.msrcCountResourcesQuery, chunk)
|
||||
local surface = map.surface
|
||||
local resources = surface.count_entities_filtered(universe.msrcCountResourcesQuery) * RESOURCE_NORMALIZER
|
||||
setResourceGenerator(map, chunk, resources)
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.filteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local waterTiles = (1 - (surface.count_tiles_filtered(universe.msrcFilteredTilesQuery) * 0.0009765625)) * 0.80
|
||||
local neutralObjects = mMax(0,
|
||||
mMin(1 - (surface.count_entities_filtered(universe.filteredEntitiesChunkNeutral) * 0.005),
|
||||
mMin(1 - (surface.count_entities_filtered(universe.msrcFilteredEntitiesChunkNeutral) * 0.005),
|
||||
1) * 0.20)
|
||||
setPathRating(map, chunk, waterTiles + neutralObjects)
|
||||
end
|
||||
|
||||
function chunkUtils.mapScanEnemyChunk(chunk, map, tick)
|
||||
local universe = map.universe
|
||||
local query = universe.filteredEntitiesEnemyStructureQuery
|
||||
setAreaInQuery(query, chunk, CHUNK_SIZE)
|
||||
local buildings = map.surface.find_entities_filtered(query)
|
||||
setAreaInQueryChunkSize(universe.msecFilteredEntitiesEnemyStructureQuery, chunk)
|
||||
local buildings = map.surface.find_entities_filtered(universe.msecFilteredEntitiesEnemyStructureQuery)
|
||||
local counts = map.chunkScanCounts
|
||||
for i=1,#HIVE_BUILDINGS_TYPES do
|
||||
counts[HIVE_BUILDINGS_TYPES[i]] = 0
|
||||
|
@ -309,9 +309,6 @@ function mapProcessor.scanPlayerMap(map, tick)
|
||||
end
|
||||
local index = map.scanPlayerIndex
|
||||
|
||||
local area = map.universe.area
|
||||
local offset = area[2]
|
||||
local chunkBox = area[1]
|
||||
local processQueue = map.processQueue
|
||||
local processQueueLength = #processQueue
|
||||
|
||||
@ -322,15 +319,7 @@ function mapProcessor.scanPlayerMap(map, tick)
|
||||
end
|
||||
|
||||
for x=index,endIndex do
|
||||
local chunk = processQueue[x]
|
||||
|
||||
chunkBox[1] = chunk.x
|
||||
chunkBox[2] = chunk.y
|
||||
|
||||
offset[1] = chunk.x + CHUNK_SIZE
|
||||
offset[2] = chunk.y + CHUNK_SIZE
|
||||
|
||||
mapScanPlayerChunk(chunk, map)
|
||||
mapScanPlayerChunk(processQueue[x], map)
|
||||
end
|
||||
|
||||
if (endIndex == processQueueLength) then
|
||||
@ -375,9 +364,6 @@ function mapProcessor.scanResourceMap(map, tick)
|
||||
end
|
||||
local index = map.scanResourceIndex
|
||||
|
||||
local area = map.universe.area
|
||||
local offset = area[2]
|
||||
local chunkBox = area[1]
|
||||
local processQueue = map.processQueue
|
||||
local processQueueLength = #processQueue
|
||||
|
||||
@ -388,15 +374,7 @@ function mapProcessor.scanResourceMap(map, tick)
|
||||
end
|
||||
|
||||
for x=index,endIndex do
|
||||
local chunk = processQueue[x]
|
||||
|
||||
chunkBox[1] = chunk.x
|
||||
chunkBox[2] = chunk.y
|
||||
|
||||
offset[1] = chunk.x + CHUNK_SIZE
|
||||
offset[2] = chunk.y + CHUNK_SIZE
|
||||
|
||||
mapScanResourceChunk(chunk, map)
|
||||
mapScanResourceChunk(processQueue[x], map)
|
||||
end
|
||||
|
||||
if (endIndex == processQueueLength) then
|
||||
|
@ -185,7 +185,8 @@ function mapUtils.getCardinalChunks(map, x, y)
|
||||
return neighbors
|
||||
end
|
||||
|
||||
function mapUtils.positionFromDirectionAndChunk(direction, startPosition, endPosition, scaling)
|
||||
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)
|
||||
@ -214,7 +215,7 @@ function mapUtils.positionFromDirectionAndChunk(direction, startPosition, endPos
|
||||
return endPosition
|
||||
end
|
||||
|
||||
function mapUtils.positionFromDirectionAndFlat(direction, startPosition, endPosition, multipler)
|
||||
function mapUtils.positionFromDirectionAndFlat(direction, startPosition, multipler)
|
||||
local lx = startPosition.x
|
||||
local ly = startPosition.y
|
||||
if not multipler then
|
||||
@ -241,8 +242,10 @@ function mapUtils.positionFromDirectionAndFlat(direction, startPosition, endPosi
|
||||
lx = lx + CHUNK_SIZE * multipler
|
||||
ly = ly + CHUNK_SIZE * multipler
|
||||
end
|
||||
endPosition.x = lx
|
||||
endPosition.y = ly
|
||||
return {
|
||||
x = lx,
|
||||
y = ly
|
||||
}
|
||||
end
|
||||
|
||||
mapUtilsG = mapUtils
|
||||
|
@ -3,12 +3,28 @@ if queryUtilsG then
|
||||
end
|
||||
local queryUtils = {}
|
||||
|
||||
local constants = require("Constants")
|
||||
|
||||
local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
|
||||
function queryUtils.setPositionInQuery(query, position)
|
||||
local point = query.position
|
||||
point[1] = position.x
|
||||
point[2] = position.y
|
||||
end
|
||||
|
||||
function queryUtils.setPositionInCommand(cmd, position)
|
||||
local point = cmd.destination
|
||||
point[1] = position.x
|
||||
point[2] = position.y
|
||||
end
|
||||
|
||||
function queryUtils.setPositionXYInQuery(query, x, y)
|
||||
local point = query.position
|
||||
point[1] = x
|
||||
point[2] = y
|
||||
end
|
||||
|
||||
function queryUtils.setAreaInQuery(query, topLeftPosition, size)
|
||||
local area = query.area
|
||||
area[1][1] = topLeftPosition.x
|
||||
@ -17,5 +33,33 @@ function queryUtils.setAreaInQuery(query, topLeftPosition, size)
|
||||
area[2][2] = topLeftPosition.y + size
|
||||
end
|
||||
|
||||
function queryUtils.setAreaInQueryChunkSize(query, topLeftPosition)
|
||||
local area = query.area
|
||||
area[1][1] = topLeftPosition.x
|
||||
area[1][2] = topLeftPosition.y
|
||||
area[2][1] = topLeftPosition.x + CHUNK_SIZE
|
||||
area[2][2] = topLeftPosition.y + CHUNK_SIZE
|
||||
end
|
||||
|
||||
function queryUtils.setPointAreaInQuery(query, position, size)
|
||||
local area = query.area
|
||||
area[1][1] = position.x - size
|
||||
area[1][2] = position.y - size
|
||||
area[2][1] = position.x + size
|
||||
area[2][2] = position.y + size
|
||||
end
|
||||
|
||||
function queryUtils.setAreaYInQuery(query, y1, y2)
|
||||
local area = query.area
|
||||
area[1][2] = y1
|
||||
area[2][2] = y2
|
||||
end
|
||||
|
||||
function queryUtils.setAreaXInQuery(query, x1, x2)
|
||||
local area = query.area
|
||||
area[1][1] = x1
|
||||
area[2][1] = x2
|
||||
end
|
||||
|
||||
queryUtilsG = queryUtils
|
||||
return queryUtils
|
||||
|
@ -10,6 +10,7 @@ local mapUtils = require("MapUtils")
|
||||
local movementUtils = require("MovementUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
local chunkPropertyUtils = require("ChunkPropertyUtils")
|
||||
local queryUtils = require("QueryUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
@ -37,6 +38,8 @@ local DEFINES_DISTRACTION_BY_ANYTHING = defines.distraction.by_anything
|
||||
|
||||
-- imported functions
|
||||
|
||||
local setPositionInCommand = queryUtils.setPositionInCommand
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
local findMovementPosition = movementUtils.findMovementPosition
|
||||
@ -101,9 +104,8 @@ end
|
||||
|
||||
local function settleMove(map, squad)
|
||||
local universe = map.universe
|
||||
local targetPosition = universe.position
|
||||
local targetPosition2 = universe.position2
|
||||
local group = squad.group
|
||||
local targetPosition = {x=0,y=0}
|
||||
|
||||
local groupPosition = group.position
|
||||
local x, y = positionToChunkXY(groupPosition)
|
||||
@ -146,9 +148,6 @@ local function settleMove(map, squad)
|
||||
position = groupPosition
|
||||
end
|
||||
|
||||
targetPosition.x = position.x
|
||||
targetPosition.y = position.y
|
||||
|
||||
cmd = universe.settleCommand
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
@ -156,6 +155,8 @@ local function settleMove(map, squad)
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
|
||||
setPositionInCommand(cmd, position)
|
||||
|
||||
squad.status = SQUAD_BUILDING
|
||||
|
||||
group.set_command(cmd)
|
||||
@ -178,20 +179,44 @@ local function settleMove(map, squad)
|
||||
if (nextAttackChunk ~= -1) then
|
||||
if (getPlayerBaseGenerator(map,nextAttackChunk) == 0) or (map.state ~= AI_STATE_SIEGE) then
|
||||
attackChunk = nextAttackChunk
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition)
|
||||
positionFromDirectionAndFlat(nextAttackDirection, targetPosition, targetPosition2)
|
||||
position = findMovementPosition(surface, targetPosition2)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextAttackDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
)
|
||||
)
|
||||
else
|
||||
positionFromDirectionAndFlat(nextAttackDirection, groupPosition, targetPosition, 1.3)
|
||||
position = findMovementPosition(surface, targetPosition)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextAttackDirection,
|
||||
groupPosition,
|
||||
1.3
|
||||
)
|
||||
)
|
||||
if not position then
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition, 1.3)
|
||||
position = findMovementPosition(surface, targetPosition)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition,
|
||||
1.3
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
else
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition)
|
||||
position = findMovementPosition(surface, targetPosition)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if position then
|
||||
@ -210,8 +235,6 @@ local function settleMove(map, squad)
|
||||
|
||||
if (nextAttackChunk ~= -1) and (map.state == AI_STATE_SIEGE) and (getPlayerBaseGenerator(map, nextAttackChunk) ~= 0) then
|
||||
cmd = universe.settleCommand
|
||||
cmd.destination.x = targetPosition.x
|
||||
cmd.destination.y = targetPosition.y
|
||||
squad.status = SQUAD_BUILDING
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
@ -238,8 +261,8 @@ local function settleMove(map, squad)
|
||||
end
|
||||
else
|
||||
cmd = universe.settleCommand
|
||||
cmd.destination.x = groupPosition.x
|
||||
cmd.destination.y = groupPosition.y
|
||||
targetPosition.x = groupPosition.x
|
||||
targetPosition.y = groupPosition.y
|
||||
|
||||
if squad.kamikaze then
|
||||
cmd.distraction = DEFINES_DISTRACTION_NONE
|
||||
@ -250,6 +273,8 @@ local function settleMove(map, squad)
|
||||
squad.status = SQUAD_BUILDING
|
||||
end
|
||||
|
||||
setPositionInCommand(cmd, targetPosition)
|
||||
|
||||
group.set_command(cmd)
|
||||
end
|
||||
end
|
||||
@ -257,8 +282,7 @@ end
|
||||
local function attackMove(map, squad)
|
||||
|
||||
local universe = map.universe
|
||||
local targetPosition = universe.position
|
||||
local targetPosition2 = universe.position2
|
||||
local targetPosition = {0,0}
|
||||
|
||||
local group = squad.group
|
||||
|
||||
@ -293,14 +317,28 @@ local function attackMove(map, squad)
|
||||
cmd = universe.wanderCommand
|
||||
group.set_command(cmd)
|
||||
return
|
||||
elseif (nextAttackChunk ~= -1) then
|
||||
end
|
||||
|
||||
if (nextAttackChunk ~= -1) then
|
||||
attackChunk = nextAttackChunk
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition)
|
||||
positionFromDirectionAndFlat(nextAttackDirection, targetPosition, targetPosition2)
|
||||
position = findMovementPosition(surface, targetPosition2)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextAttackDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
)
|
||||
)
|
||||
else
|
||||
positionFromDirectionAndFlat(attackDirection, groupPosition, targetPosition)
|
||||
position = findMovementPosition(surface, targetPosition)
|
||||
position = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
attackDirection,
|
||||
groupPosition
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if not position then
|
||||
@ -335,6 +373,7 @@ local function attackMove(map, squad)
|
||||
cmd.distraction = DEFINES_DISTRACTION_BY_ENEMY
|
||||
end
|
||||
end
|
||||
setPositionInCommand(cmd, targetPosition)
|
||||
|
||||
group.set_command(cmd)
|
||||
end
|
||||
@ -342,16 +381,15 @@ end
|
||||
local function buildMove(map, squad)
|
||||
local group = squad.group
|
||||
local universe = map.universe
|
||||
local position = universe.position
|
||||
local groupPosition = findMovementPosition(map.surface, group.position)
|
||||
local groupPosition = group.position
|
||||
local newGroupPosition = findMovementPosition(map.surface, groupPosition)
|
||||
|
||||
if not groupPosition then
|
||||
groupPosition = group.position
|
||||
if not newGroupPosition then
|
||||
setPositionInCommand(universe.settleCommand, groupPosition)
|
||||
else
|
||||
setPositionInCommand(universe.settleCommand, newGroupPosition)
|
||||
end
|
||||
|
||||
position.x = groupPosition.x
|
||||
position.y = groupPosition.y
|
||||
|
||||
group.set_command(universe.compoundSettleCommand)
|
||||
end
|
||||
|
||||
|
@ -63,22 +63,34 @@ function aiDefense.retreatUnits(chunk, cause, map, tick, radius)
|
||||
scoreRetreatLocation,
|
||||
map)
|
||||
local universe = map.universe
|
||||
local position = universe.position
|
||||
local targetPosition2 = universe.position2
|
||||
local position = {
|
||||
x = chunk.x + 16,
|
||||
y = chunk.y + 16
|
||||
}
|
||||
local retreatPosition
|
||||
position.x = chunk.x + 16
|
||||
position.y = chunk.y + 16
|
||||
local surface = map.surface
|
||||
if (exitPath == -1) then
|
||||
return
|
||||
elseif (nextExitPath ~= -1) then
|
||||
positionFromDirectionAndFlat(exitDirection, position, targetPosition2)
|
||||
positionFromDirectionAndFlat(nextExitDirection, targetPosition2, position)
|
||||
retreatPosition = findMovementPosition(surface, position)
|
||||
retreatPosition = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
nextExitDirection,
|
||||
positionFromDirectionAndFlat(
|
||||
exitDirection,
|
||||
position
|
||||
)
|
||||
)
|
||||
)
|
||||
exitPath = nextExitPath
|
||||
else
|
||||
positionFromDirectionAndFlat(exitDirection, position, targetPosition2)
|
||||
retreatPosition = findMovementPosition(surface, targetPosition2)
|
||||
retreatPosition = findMovementPosition(
|
||||
surface,
|
||||
positionFromDirectionAndFlat(
|
||||
exitDirection,
|
||||
position
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if retreatPosition then
|
||||
|
Loading…
Reference in New Issue
Block a user