1
0
mirror of https://github.com/veden/Rampant.git synced 2024-12-28 21:08:22 +02:00

moved processUpgrades into chunk processor

This commit is contained in:
Aaron Veden 2021-11-28 17:59:51 -08:00
parent bbb99102cc
commit b7b1a783a6
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
3 changed files with 66 additions and 60 deletions

View File

@ -47,7 +47,7 @@ local ENERGY_THIEF_LOOKUP = constants.ENERGY_THIEF_LOOKUP
local queueGeneratedChunk = mapUtils.queueGeneratedChunk
local isRampantSetting = stringUtils.isRampantSetting
local processPendingUpgrades = chunkUtils.processPendingUpgrades
local processPendingUpgrades = chunkProcessor.processPendingUpgrades
local canMigrate = aiPredicates.canMigrate
local convertTypeToDrainCrystal = unitUtils.convertTypeToDrainCrystal

View File

@ -7,6 +7,8 @@ local chunkProcessor = {}
local chunkUtils = require("ChunkUtils")
local constants = require("Constants")
local baseUtils = require("BaseUtils")
local mapUtils = require("MapUtils")
-- constants
@ -14,6 +16,12 @@ local CHUNK_SIZE = constants.CHUNK_SIZE
-- imported functions
local queueGeneratedChunk = mapUtils.queueGeneratedChunk
local getChunkByPosition = mapUtils.getChunkByPosition
local findNearbyBase = baseUtils.findNearbyBase
local createBase = baseUtils.createBase
local mapScanEnemyChunk = chunkUtils.mapScanEnemyChunk
local mapScanPlayerChunk = chunkUtils.mapScanPlayerChunk
local mapScanResourceChunk = chunkUtils.mapScanResourceChunk
@ -117,6 +125,63 @@ function chunkProcessor.processPendingChunks(map, tick, flush)
map.chunkProcessorIterator = event
end
function chunkProcessor.processPendingUpgrades(map, tick)
local pendingUpgrades = map.pendingUpgrades
local entity = map.pendingUpgradeIterator
local entityData
if not entity then
entity, entityData = next(pendingUpgrades, nil)
else
entityData = pendingUpgrades[entity]
end
if entity then
if entity.valid then
map.pendingUpgradeIterator = next(pendingUpgrades, entity)
pendingUpgrades[entity] = nil
local universe = map.universe
local query = universe.upgradeEntityQuery
query.position = entityData.position or entity.position
query.name = entityData.name
local surface = entity.surface
entity.destroy()
if remote.interfaces["kr-creep"] then
remote.call("kr-creep", "spawn_creep_at_position", surface, query.position)
end
local createdEntity = surface.create_entity(query)
if createdEntity and createdEntity.valid and entityData.register then
local chunk = getChunkByPosition(map, createdEntity.position)
if (chunk ~= -1) then
local base = findNearbyBase(map, chunk)
if not base then
base = createBase(map,
chunk,
tick)
end
if base then
chunkUtils.registerEnemyBaseStructure(map, createdEntity, base)
end
else
queueGeneratedChunk(
universe,
{
surface = createdEntity.surface,
area = {
left_top = {
x = createdEntity.position.x,
y = createdEntity.position.y
}
}
}
)
end
end
else
map.pendingUpgradeIterator = next(pendingUpgrades, entity)
pendingUpgrades[entity] = nil
end
end
end
function chunkProcessor.processScanChunks(map)
local area = map.universe.area

View File

@ -81,9 +81,7 @@ local setChunkBase = chunkPropertyUtils.setChunkBase
local setPassable = chunkPropertyUtils.setPassable
local setPathRating = chunkPropertyUtils.setPathRating
local getChunkByPosition = mapUtils.getChunkByPosition
local getChunkByXY = mapUtils.getChunkByXY
local queueGeneratedChunk = mapUtils.queueGeneratedChunk
local mMin = math.min
local mMax = math.max
@ -421,63 +419,6 @@ function chunkUtils.colorXY(x, y, surface, color)
})
end
function chunkUtils.processPendingUpgrades(map, tick)
local pendingUpgrades = map.pendingUpgrades
local entity = map.pendingUpgradeIterator
local entityData
if not entity then
entity, entityData = next(pendingUpgrades, nil)
else
entityData = pendingUpgrades[entity]
end
if entity then
if entity.valid then
map.pendingUpgradeIterator = next(pendingUpgrades, entity)
pendingUpgrades[entity] = nil
local universe = map.universe
local query = universe.upgradeEntityQuery
query.position = entityData.position or entity.position
query.name = entityData.name
local surface = entity.surface
entity.destroy()
if remote.interfaces["kr-creep"] then
remote.call("kr-creep", "spawn_creep_at_position", surface, query.position)
end
local createdEntity = surface.create_entity(query)
if createdEntity and createdEntity.valid and entityData.register then
local chunk = getChunkByPosition(map, createdEntity.position)
if (chunk ~= -1) then
local base = findNearbyBase(map, chunk)
if not base then
base = createBase(map,
chunk,
tick)
end
if base then
chunkUtils.registerEnemyBaseStructure(map, createdEntity, base)
end
else
queueGeneratedChunk(
universe,
{
surface = createdEntity.surface,
area = {
left_top = {
x = createdEntity.position.x,
y = createdEntity.position.y
}
}
}
)
end
end
else
map.pendingUpgradeIterator = next(pendingUpgrades, entity)
pendingUpgrades[entity] = nil
end
end
end
function chunkUtils.registerEnemyBaseStructure(map, entity, base)
local entityType = entity.type
if ((entityType == "unit-spawner") or (entityType == "turret")) and (entity.force.name == "enemy") then