mirror of
https://github.com/veden/Rampant.git
synced 2025-03-17 20:58:35 +02:00
cf049a3: changing upgrade entity into a queue processed over time
This commit is contained in:
parent
6c1c709a19
commit
fbd2961b27
@ -525,7 +525,6 @@ function upgrade.attempt(universe)
|
||||
universe.maps = {}
|
||||
universe.chunkIdToChunk = {}
|
||||
universe.groupNumberToSquad = {}
|
||||
universe.pendingUpgrades = {}
|
||||
universe.chunkToVictory = {}
|
||||
universe.pendingChunks = {}
|
||||
universe.processActiveNest = {}
|
||||
@ -632,6 +631,8 @@ function upgrade.attempt(universe)
|
||||
universe.expansionHighTargetDistance = (universe.expansionMaxDistance + MINIMUM_EXPANSION_DISTANCE) * 0.75
|
||||
universe.expansionDistanceDeviation = universe.expansionMediumTargetDistance * 0.33
|
||||
|
||||
universe.pendingUpgrades = {}
|
||||
|
||||
for _,base in pairs(universe.bases) do
|
||||
base.maxExpansionGroups = 0
|
||||
base.sentExpansionGroups = 0
|
||||
|
45
control.lua
45
control.lua
@ -150,7 +150,7 @@ local unregisterResource = chunkUtils.unregisterResource
|
||||
|
||||
local cleanSquads = squadAttack.cleanSquads
|
||||
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
local queueUpgrade = baseUtils.queueUpgrade
|
||||
local rebuildNativeTables = baseUtils.rebuildNativeTables
|
||||
|
||||
local tRemove = table.remove
|
||||
@ -357,12 +357,11 @@ local function onEnemyBaseBuild(event)
|
||||
registerEnemyBaseStructure(map, entity, base)
|
||||
|
||||
if universe.NEW_ENEMIES then
|
||||
upgradeEntity(entity,
|
||||
base,
|
||||
map,
|
||||
nil,
|
||||
true,
|
||||
true)
|
||||
queueUpgrade(entity,
|
||||
base,
|
||||
nil,
|
||||
true,
|
||||
true)
|
||||
end
|
||||
else
|
||||
local x,y = positionToChunkXY(entity.position)
|
||||
@ -694,17 +693,16 @@ local function onEntitySpawned(entity, tick)
|
||||
|
||||
local meanTTL = linearInterpolation(universe.evolutionLevel, MAX_HIVE_TTL, MIN_HIVE_TTL)
|
||||
|
||||
upgradeEntity(entity,
|
||||
base,
|
||||
map,
|
||||
disPos,
|
||||
true,
|
||||
true,
|
||||
tick + gaussianRandomRangeRG(meanTTL,
|
||||
DEV_HIVE_TTL,
|
||||
MIN_HIVE_TTL,
|
||||
MAX_HIVE_TTL,
|
||||
universe.random))
|
||||
queueUpgrade(entity,
|
||||
base,
|
||||
disPos,
|
||||
true,
|
||||
true,
|
||||
tick + gaussianRandomRangeRG(meanTTL,
|
||||
DEV_HIVE_TTL,
|
||||
MIN_HIVE_TTL,
|
||||
MAX_HIVE_TTL,
|
||||
universe.random))
|
||||
else
|
||||
local x,y = positionToChunkXY(entity.position)
|
||||
onChunkGenerated({
|
||||
@ -980,8 +978,9 @@ script.on_event(defines.events.on_tick,
|
||||
local gameRef = game
|
||||
local tick = gameRef.tick
|
||||
local pick = tick % 8
|
||||
|
||||
-- local profiler = game.create_profiler()
|
||||
-- if not universe.profiler then
|
||||
-- universe.profiler = game.create_profiler()
|
||||
-- end
|
||||
|
||||
local map = universe.activeMap
|
||||
if (not map) or (universe.processedChunks > (#map.processQueue * 0.05)) then
|
||||
@ -1035,7 +1034,11 @@ script.on_event(defines.events.on_tick,
|
||||
processPendingUpgrades(universe, tick)
|
||||
cleanSquads(universe, tick)
|
||||
|
||||
-- game.print({"", "--dispatch4 ", profiler, ", ", pick, ", ", game.tick, " ", universe.random()})
|
||||
-- if (game.tick % 20 == 0) then
|
||||
-- universe.profiler.divide(60)
|
||||
-- game.print({"", "--dispatch4 ", universe.profiler})
|
||||
-- universe.profiler.reset()
|
||||
-- end
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_chunk_deleted, onChunkDeleted)
|
||||
|
@ -199,7 +199,7 @@ local function entityUpgrade(baseAlignment, tier, maxTier, originalEntity, map)
|
||||
return entity
|
||||
end
|
||||
|
||||
local function findEntityUpgrade(baseAlignment, currentEvo, evoIndex, originalEntity, map, evolve)
|
||||
function baseUtils.findEntityUpgrade(baseAlignment, currentEvo, evoIndex, originalEntity, map, evolve)
|
||||
local universe = map.universe
|
||||
local adjCurrentEvo = mMax(
|
||||
((baseAlignment ~= ENEMY_ALIGNMENT_LOOKUP[originalEntity.name]) and 0) or currentEvo,
|
||||
@ -287,51 +287,15 @@ function baseUtils.recycleBases(universe)
|
||||
end
|
||||
end
|
||||
|
||||
function baseUtils.upgradeEntity(entity, base, map, disPos, evolve, register, timeDelay)
|
||||
local position = entity.position
|
||||
local currentEvo = entity.prototype.build_base_evolution_requirement or 0
|
||||
|
||||
local distance = mMin(1, euclideanDistancePoints(position.x, position.y, 0, 0) * BASE_DISTANCE_TO_EVO_INDEX)
|
||||
local evoIndex = mMax(distance, map.universe.evolutionLevel)
|
||||
local baseAlignment = base.alignment
|
||||
|
||||
local pickedBaseAlignment
|
||||
if baseAlignment[2] then
|
||||
if map.random() < 0.75 then
|
||||
pickedBaseAlignment = baseAlignment[2]
|
||||
else
|
||||
pickedBaseAlignment = baseAlignment[1]
|
||||
end
|
||||
else
|
||||
pickedBaseAlignment = baseAlignment[1]
|
||||
end
|
||||
|
||||
local spawnerName = findEntityUpgrade(pickedBaseAlignment,
|
||||
currentEvo,
|
||||
evoIndex,
|
||||
entity,
|
||||
map,
|
||||
evolve)
|
||||
|
||||
if spawnerName and (spawnerName ~= entity.name) then
|
||||
local entityData = {
|
||||
["name"] = spawnerName,
|
||||
["position"] = disPos,
|
||||
["register"] = register,
|
||||
["map"] = map,
|
||||
["base"] = base,
|
||||
["entity"] = entity,
|
||||
["delayTLL"] = timeDelay
|
||||
}
|
||||
map.universe.pendingUpgrades[entity.unit_number] = entityData
|
||||
return spawnerName
|
||||
end
|
||||
if entity.valid then
|
||||
if PROXY_ENTITY_LOOKUP[entity.name] then
|
||||
entity.destroy()
|
||||
end
|
||||
end
|
||||
return nil
|
||||
function baseUtils.queueUpgrade(entity, base, disPos, evolve, register, timeDelay)
|
||||
base.universe.pendingUpgrades[entity.unit_number] = {
|
||||
["position"] = disPos,
|
||||
["register"] = register,
|
||||
["evolve"] = evolve,
|
||||
["base"] = base,
|
||||
["entity"] = entity,
|
||||
["delayTLL"] = timeDelay
|
||||
}
|
||||
end
|
||||
|
||||
local function pickMutationFromDamageType(universe, damageType, roll, base)
|
||||
@ -459,13 +423,8 @@ function baseUtils.processBaseMutation(chunk, map, base)
|
||||
local entity = entities[1]
|
||||
local cost = (COST_LOOKUP[entity.name] or MAGIC_MAXIMUM_NUMBER)
|
||||
if (base.points >= cost) then
|
||||
local newEntity = baseUtils.upgradeEntity(entity, base, map)
|
||||
if newEntity then
|
||||
if universe.printBaseUpgrades then
|
||||
surface.print("[gps=".. entity.position.x ..",".. entity.position.y .."] " .. "Scheduled upgrade for ".. entity.name .. " to " .. newEntity)
|
||||
end
|
||||
base.points = base.points - cost
|
||||
end
|
||||
baseUtils.queueUpgrade(entity, base, nil, false, true)
|
||||
base.points = base.points - cost
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,13 +24,16 @@ local chunkProcessor = {}
|
||||
local chunkUtils = require("ChunkUtils")
|
||||
local queryUtils = require("QueryUtils")
|
||||
local mapUtils = require("MapUtils")
|
||||
local mathUtils = require("MathUtils")
|
||||
local constants = require("Constants")
|
||||
local baseUtils = require("BaseUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
-- local CHUNK_SIZE = constants.CHUNK_SIZE
|
||||
-- local HALF_CHUNK_SIZE = constants.HALF_CHUNK_SIZE
|
||||
-- local QUARTER_CHUNK_SIZE = constants.QUARTER_CHUNK_SIZE
|
||||
local COST_LOOKUP = constants.COST_LOOKUP
|
||||
|
||||
local PROXY_ENTITY_LOOKUP = constants.PROXY_ENTITY_LOOKUP
|
||||
local BASE_DISTANCE_TO_EVO_INDEX = constants.BASE_DISTANCE_TO_EVO_INDEX
|
||||
|
||||
local BUILDING_SPACE_LOOKUP = constants.BUILDING_SPACE_LOOKUP
|
||||
|
||||
@ -41,11 +44,16 @@ local removeChunkFromMap = mapUtils.removeChunkFromMap
|
||||
local setPositionInQuery = queryUtils.setPositionInQuery
|
||||
local registerEnemyBaseStructure = chunkUtils.registerEnemyBaseStructure
|
||||
local unregisterEnemyBaseStructure = chunkUtils.unregisterEnemyBaseStructure
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
local findEntityUpgrade = baseUtils.findEntityUpgrade
|
||||
|
||||
local createChunk = chunkUtils.createChunk
|
||||
local initialScan = chunkUtils.initialScan
|
||||
local chunkPassScan = chunkUtils.chunkPassScan
|
||||
|
||||
local mMin = math.min
|
||||
local mMax = math.max
|
||||
local next = next
|
||||
local table_size = table_size
|
||||
|
||||
@ -148,21 +156,66 @@ function chunkProcessor.processPendingUpgrades(universe, tick)
|
||||
return
|
||||
end
|
||||
universe.pendingUpgrades[entityId] = nil
|
||||
local base = entityData.base
|
||||
local map = base.map
|
||||
local baseAlignment = base.alignment
|
||||
local position = entityData.position or entity.position
|
||||
|
||||
local pickedBaseAlignment
|
||||
if baseAlignment[2] then
|
||||
if map.random() < 0.75 then
|
||||
pickedBaseAlignment = baseAlignment[2]
|
||||
else
|
||||
pickedBaseAlignment = baseAlignment[1]
|
||||
end
|
||||
else
|
||||
pickedBaseAlignment = baseAlignment[1]
|
||||
end
|
||||
|
||||
local currentEvo = entity.prototype.build_base_evolution_requirement or 0
|
||||
|
||||
local distance = mMin(1, euclideanDistancePoints(position.x, position.y, 0, 0) * BASE_DISTANCE_TO_EVO_INDEX)
|
||||
local evoIndex = mMax(distance, universe.evolutionLevel)
|
||||
|
||||
local name = findEntityUpgrade(pickedBaseAlignment,
|
||||
currentEvo,
|
||||
evoIndex,
|
||||
entity,
|
||||
map,
|
||||
entityData.evolve)
|
||||
|
||||
local entityName = entity.name
|
||||
if not name and PROXY_ENTITY_LOOKUP[entityName] then
|
||||
entity.destroy()
|
||||
return
|
||||
elseif (name == entityName) or not name then
|
||||
return
|
||||
end
|
||||
|
||||
local surface = entity.surface
|
||||
local query = universe.ppuUpgradeEntityQuery
|
||||
local position = entityData.position or entity.position
|
||||
query.name = entityData.name
|
||||
unregisterEnemyBaseStructure(entityData.map, entity, nil, true)
|
||||
query.name = name
|
||||
|
||||
unregisterEnemyBaseStructure(map, entity, nil, true)
|
||||
entity.destroy()
|
||||
local foundPosition = surface.find_non_colliding_position(BUILDING_SPACE_LOOKUP[entityData.name],
|
||||
local foundPosition = surface.find_non_colliding_position(BUILDING_SPACE_LOOKUP[name],
|
||||
position,
|
||||
2,
|
||||
1,
|
||||
true)
|
||||
setPositionInQuery(query, foundPosition or position)
|
||||
local createdEntity = surface.create_entity(query)
|
||||
|
||||
local createdEntity = surface.create_entity({
|
||||
name = query.name,
|
||||
position = query.position
|
||||
})
|
||||
if createdEntity and createdEntity.valid then
|
||||
registerEnemyBaseStructure(entityData.map, createdEntity, entityData.base, true)
|
||||
if entityData.register then
|
||||
registerEnemyBaseStructure(map, createdEntity, base, true)
|
||||
end
|
||||
if not entityData.evolve and universe.printBaseUpgrades then
|
||||
surface.print("[gps=".. position.x ..",".. position.y .."] " .. "Scheduled upgrade for ".. entityName .. " to " .. name)
|
||||
end
|
||||
if remote.interfaces["kr-creep"] then
|
||||
remote.call("kr-creep", "spawn_creep_at_position", surface, foundPosition or position)
|
||||
end
|
||||
|
@ -100,7 +100,7 @@ local getEnemyStructureCount = chunkPropertyUtils.getEnemyStructureCount
|
||||
local findNearbyBase = chunkPropertyUtils.findNearbyBase
|
||||
local createBase = baseUtils.createBase
|
||||
|
||||
local upgradeEntity = baseUtils.upgradeEntity
|
||||
local queueUpgrade = baseUtils.queueUpgrade
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
|
||||
@ -272,7 +272,11 @@ function chunkUtils.initialScan(chunk, map, tick)
|
||||
local entityName = enemyBuilding.name
|
||||
local isVanilla = VANILLA_ENTITY_TYPE_LOOKUP[entityName]
|
||||
if isVanilla or (not isVanilla and not BUILDING_HIVE_TYPE_LOOKUP[entityName]) then
|
||||
upgradeEntity(enemyBuilding, base, map, nil, true)
|
||||
queueUpgrade(enemyBuilding,
|
||||
base,
|
||||
nil,
|
||||
true,
|
||||
true)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user