mirror of
https://github.com/veden/Rampant.git
synced 2024-12-24 20:14:35 +02:00
FACTO-300: Fixed hive drift and hive upgrades
This commit is contained in:
parent
1b0dfb4191
commit
60451e662c
@ -2,6 +2,8 @@
|
||||
Version: 3.3.1
|
||||
Bugfixes:
|
||||
- Fixed hive owned structure cleanup routine from not checking hive id correctly
|
||||
- Fixed hive building cursor drifting
|
||||
- Fixed hive not updating build stats when upgraded
|
||||
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 3.3.0
|
||||
|
@ -441,22 +441,24 @@ function ChunkUtils.colorXY(x, y, surface, color)
|
||||
})
|
||||
end
|
||||
|
||||
local function registerHive(base, entityUnitNumber, hiveType, name, position, tick)
|
||||
local function registerHive(base, entity, hiveType, tick)
|
||||
if hiveType == "hive" then
|
||||
if not Universe.hives[entityUnitNumber] then
|
||||
local tier = BUILDING_HIVE_TIER_LOOKUP[name]
|
||||
local maxNests = HIVE_MAX_NESTS[tier]
|
||||
local maxTurrets = HIVE_MAX_TURRETS[tier]
|
||||
local maxHives
|
||||
local rollHives = Universe.random()
|
||||
if rollHives < 0.05 then
|
||||
maxHives = HIVE_MAX_HIVES[tier]
|
||||
else
|
||||
maxHives = 0
|
||||
end
|
||||
local hiveData = {
|
||||
local entityUnitNumber = entity.unit_number
|
||||
local hiveData = Universe.hives[entityUnitNumber]
|
||||
local tier = BUILDING_HIVE_TIER_LOOKUP[entity.name]
|
||||
local maxNests = HIVE_MAX_NESTS[tier]
|
||||
local maxTurrets = HIVE_MAX_TURRETS[tier]
|
||||
local maxHives = 0
|
||||
local rollHives = Universe.random()
|
||||
if rollHives < 0.05 then
|
||||
maxHives = HIVE_MAX_HIVES[tier]
|
||||
end
|
||||
|
||||
if not hiveData then
|
||||
hiveData = {
|
||||
hiveId = entityUnitNumber,
|
||||
position = position,
|
||||
e = entity,
|
||||
position = entity.position,
|
||||
base = base,
|
||||
hive = 0,
|
||||
nest = 0,
|
||||
@ -475,6 +477,15 @@ local function registerHive(base, entityUnitNumber, hiveType, name, position, ti
|
||||
}
|
||||
Universe.hives[entityUnitNumber] = hiveData
|
||||
Universe.activeHives[entityUnitNumber] = hiveData
|
||||
else
|
||||
hiveData.hiveId = entityUnitNumber
|
||||
hiveData.e = entity
|
||||
hiveData.position = entity.position
|
||||
hiveData.maxNests = ((maxNests > 0) and (Universe.random(maxNests) - 1)) or 0
|
||||
hiveData.maxTurrets = ((maxTurrets > 0) and (Universe.random(maxTurrets) - 1)) or 0
|
||||
hiveData.maxHives = ((maxHives > 0) and (Universe.random(maxHives) - 1)) or 0
|
||||
hiveData.tier = tier
|
||||
Universe.activeHives[entityUnitNumber] = hiveData
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -504,7 +515,7 @@ function ChunkUtils.registerEnemyBaseStructure(entity, base, tick, skipCount)
|
||||
end
|
||||
end
|
||||
end
|
||||
registerHive(base, entityUnitNumber, hiveType, name, entity.position, tick)
|
||||
registerHive(base, entity, hiveType, tick)
|
||||
if added and (not skipCount) then
|
||||
base.builtEnemyBuilding = base.builtEnemyBuilding + 1
|
||||
end
|
||||
|
@ -152,7 +152,6 @@ function MathUtils.distortPosition(rg, position, size)
|
||||
local yDistort = MathUtils.gaussianRandomRangeRG(1, 0.5, 0, 2, rg) - 1
|
||||
position.x = position.x + (xDistort * size)
|
||||
position.y = position.y + (yDistort * size)
|
||||
return position
|
||||
end
|
||||
|
||||
function MathUtils.distortPositionConcentricCircles(rg, position, size, min)
|
||||
@ -173,7 +172,6 @@ function MathUtils.distortPositionConcentricCircles(rg, position, size, min)
|
||||
|
||||
position.x = position.x + xModifier
|
||||
position.y = position.y + yModifier
|
||||
return position
|
||||
end
|
||||
|
||||
MathUtilsG = MathUtils
|
||||
|
@ -21,6 +21,7 @@ local Processor = {}
|
||||
|
||||
--
|
||||
|
||||
local TargetPosition
|
||||
local Universe
|
||||
local Queries
|
||||
|
||||
@ -508,6 +509,11 @@ function Processor.processHives(tick)
|
||||
Universe.activeHives[entityId] = nil
|
||||
return
|
||||
end
|
||||
if not hiveData.e.valid then
|
||||
Universe.activeHives[entityId] = nil
|
||||
Universe.hives[entityId] = nil
|
||||
return
|
||||
end
|
||||
hiveData.tick = tick +
|
||||
gaussianRandomRangeRG(
|
||||
linearInterpolation(Universe.evolutionLevel, MAX_HIVE_TTL, MIN_HIVE_TTL),
|
||||
@ -519,9 +525,12 @@ function Processor.processHives(tick)
|
||||
|
||||
local timeDelay = 0
|
||||
|
||||
local position = distortPositionConcentricCircles(
|
||||
TargetPosition.x = hiveData.position.x
|
||||
TargetPosition.y = hiveData.position.y
|
||||
|
||||
distortPositionConcentricCircles(
|
||||
Universe.random,
|
||||
hiveData.position,
|
||||
TargetPosition,
|
||||
EIGHTH_CHUNK_SIZE * hiveData.tier,
|
||||
EIGHTH_CHUNK_SIZE
|
||||
)
|
||||
@ -531,11 +540,11 @@ function Processor.processHives(tick)
|
||||
if Universe.random() < 0.5 then
|
||||
entityType = "spitter-spawner"
|
||||
end
|
||||
queueCreation(base, position, entityType, timeDelay, hiveData)
|
||||
queueCreation(base, TargetPosition, entityType, timeDelay, hiveData)
|
||||
elseif hiveData.turret < hiveData.maxTurrets then
|
||||
queueCreation(base, position, "turret", timeDelay, hiveData)
|
||||
queueCreation(base, TargetPosition, "turret", timeDelay, hiveData)
|
||||
elseif hiveData.hive < hiveData.maxHives then
|
||||
queueCreation(base, position, "hive", timeDelay, hiveData)
|
||||
queueCreation(base, TargetPosition, "hive", timeDelay, hiveData)
|
||||
else
|
||||
Universe.activeHives[entityId] = nil
|
||||
end
|
||||
@ -722,7 +731,10 @@ end
|
||||
|
||||
function Processor.init(universe)
|
||||
Universe = universe
|
||||
Queries = universe.baseUtilsQueries
|
||||
Queries = universe.processorQueries
|
||||
if Queries then
|
||||
TargetPosition = Queries.targetPosition
|
||||
end
|
||||
end
|
||||
|
||||
ProcessorG = Processor
|
||||
|
@ -294,12 +294,13 @@ local function addCommandSet()
|
||||
}
|
||||
|
||||
-- ppu
|
||||
Universe.baseUtilsQueries = {}
|
||||
Universe.baseUtilsQueries.createEntityQuery = {
|
||||
Universe.processorQueries = {}
|
||||
Universe.processorQueries.createEntityQuery = {
|
||||
name = "",
|
||||
position = {0,0},
|
||||
raise_built = true
|
||||
}
|
||||
Universe.processorQueries.targetPosition = {0,0}
|
||||
|
||||
Universe.squadQueries = {}
|
||||
Universe.squadQueries.targetPosition = {0,0}
|
||||
@ -533,10 +534,12 @@ function Upgrade.addUniverseProperties()
|
||||
end
|
||||
if global.universePropertyVersion < 2 then
|
||||
global.universePropertyVersion = 2
|
||||
addCommandSet()
|
||||
|
||||
Universe.hiveDataIterator = nil
|
||||
end
|
||||
if global.universePropertyVersion < 3 then
|
||||
global.universePropertyVersion = 3
|
||||
addCommandSet()
|
||||
end
|
||||
end
|
||||
|
||||
function Upgrade.attempt()
|
||||
@ -574,15 +577,7 @@ function Upgrade.attempt()
|
||||
|
||||
game.forces.enemy.kill_all_units()
|
||||
|
||||
local lookup = {}
|
||||
for _, map in pairs(Universe.maps) do
|
||||
local entities = map.surface.find_entities_filtered({
|
||||
type = "unit-spawner",
|
||||
force = "enemy"
|
||||
})
|
||||
for i = 1, #entities do
|
||||
lookup[entities[i].unit_number] = true
|
||||
end
|
||||
for _, chunk in pairs(map.processQueue) do
|
||||
chunk[CHUNK_TICK] = 0
|
||||
chunk[BASE_PHEROMONE] = 0
|
||||
@ -592,21 +587,50 @@ function Upgrade.attempt()
|
||||
chunk[KAMIKAZE_PHEROMONE] = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
if global.gameVersion < 3 then
|
||||
global.gameVersion = 3
|
||||
|
||||
for entityId in pairs(Universe.activeHives) do
|
||||
if not lookup[entityId] then
|
||||
Universe.activeHives[entityId] = nil
|
||||
Universe.hives[entityId] = nil
|
||||
local lookup = {}
|
||||
for _, map in pairs(Universe.maps) do
|
||||
local entities = map.surface.find_entities_filtered({
|
||||
type = {"unit-spawner", "turret"},
|
||||
force = "enemy"
|
||||
})
|
||||
for i = 1, #entities do
|
||||
local entity = entities[i]
|
||||
lookup[entity.unit_number] = entity
|
||||
end
|
||||
end
|
||||
for entityId in pairs(Universe.hives) do
|
||||
for entityId, hiveData in pairs(Universe.activeHives) do
|
||||
if not lookup[entityId] then
|
||||
Universe.activeHives[entityId] = nil
|
||||
else
|
||||
Universe.hives[entityId] = hiveData
|
||||
end
|
||||
end
|
||||
for entityId, hiveData in pairs(Universe.hives) do
|
||||
if not lookup[entityId] then
|
||||
Universe.hives[entityId] = nil
|
||||
else
|
||||
hiveData.e = lookup[entityId]
|
||||
hiveData.position = hiveData.e.position
|
||||
end
|
||||
end
|
||||
for entityId, hiveData in pairs(Universe.hiveData) do
|
||||
if not lookup[entityId] then
|
||||
Universe.hiveData[entityId] = nil
|
||||
else
|
||||
if not Universe.hives[hiveData.hiveId] then
|
||||
Universe.hiveData[entityId] = nil
|
||||
elseif not hiveData.e then
|
||||
Universe.hiveData[entityId] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Universe.hiveIterator = nil
|
||||
Universe.hiveDataIterator = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user