1
0
mirror of https://github.com/veden/Rampant.git synced 2025-03-17 20:58:35 +02:00

fixing temperament scoring around registering and unregistering enemy structures

This commit is contained in:
Aaron Veden 2021-12-09 19:56:26 -08:00
parent 302f703e71
commit e9681f1644
No known key found for this signature in database
GPG Key ID: FF5990B1C6DD3F84
5 changed files with 41 additions and 19 deletions

View File

@ -2,6 +2,7 @@
Version: 2.0.0
Date: 23. 11. 2021
Contributions:
- Special thanks to Garrotte13 for play testing early builds and providing invaluable feedback and bug reports.
- Astorin has provide an updated RU locale up through Rampant 2.0.0
Improvements:
- Removed bounding box check when placing enemy buildings or upgrading buildings inplace

View File

@ -687,7 +687,7 @@ local function onEntitySpawned(event)
event.tick)
end
registerEnemyBaseStructure(map, entity, event.tick, base)
registerEnemyBaseStructure(map, entity, event.tick, base, true)
upgradeEntity(entity,
base,

View File

@ -161,11 +161,11 @@ function chunkProcessor.processPendingUpgrades(universe, tick)
local query = universe.upgradeEntityQuery
query.position = entityData.position or entity.position
query.name = entityData.name
unregisterEnemyBaseStructure(entityData.map, entity)
unregisterEnemyBaseStructure(entityData.map, entity, nil, true)
entity.destroy()
local createdEntity = surface.create_entity(query)
if createdEntity and createdEntity.valid then
registerEnemyBaseStructure(entityData.map, createdEntity, tick, entityData.base)
registerEnemyBaseStructure(entityData.map, createdEntity, tick, entityData.base, true)
if remote.interfaces["kr-creep"] then
remote.call("kr-creep", "spawn_creep_at_position", surface, query.position)
end

View File

@ -47,7 +47,9 @@ function chunkPropertyUtils.addTurretCount(map, chunk, unitNumber)
if not map.chunkToTurretIds[chunk.id][unitNumber] then
map.chunkToTurretIds[chunk.id][unitNumber] = true
map.chunkToTurrets[chunk.id] = (map.chunkToTurrets[chunk.id] or 0) + 1
return true
end
return false
end
function chunkPropertyUtils.removeTurretCount(map, chunk, unitNumber)
@ -58,7 +60,9 @@ function chunkPropertyUtils.removeTurretCount(map, chunk, unitNumber)
map.chunkToTurretIds[chunk.id] = nil
map.chunkToTurrets[chunk.id] = nil
end
return true
end
return false
end
function chunkPropertyUtils.addTrapCount(map, chunk, unitNumber)
@ -69,7 +73,9 @@ function chunkPropertyUtils.addTrapCount(map, chunk, unitNumber)
if not map.chunkToTrapIds[chunk.id][unitNumber] then
map.chunkToTrapIds[chunk.id][unitNumber] = true
map.chunkToTraps[chunk.id] = (map.chunkToTraps[chunk.id] or 0) + 1
return true
end
return false
end
function chunkPropertyUtils.removeTrapCount(map, chunk, unitNumber)
@ -80,7 +86,9 @@ function chunkPropertyUtils.removeTrapCount(map, chunk, unitNumber)
map.chunkToTrapIds[chunk.id] = nil
map.chunkToTraps[chunk.id] = nil
end
return true
end
return false
end
function chunkPropertyUtils.addUtilitiesCount(map, chunk, unitNumber)
@ -91,7 +99,9 @@ function chunkPropertyUtils.addUtilitiesCount(map, chunk, unitNumber)
if not map.chunkToUtilityIds[chunk.id][unitNumber] then
map.chunkToUtilityIds[chunk.id][unitNumber] = true
map.chunkToUtilities[chunk.id] = (map.chunkToUtilities[chunk.id] or 0) + 1
return true
end
return false
end
function chunkPropertyUtils.removeUtilitiesCount(map, chunk, unitNumber)
@ -102,7 +112,9 @@ function chunkPropertyUtils.removeUtilitiesCount(map, chunk, unitNumber)
map.chunkToUtilityIds[chunk.id] = nil
map.chunkToUtilities[chunk.id] = nil
end
return true
end
return false
end
function chunkPropertyUtils.addHiveCount(map, chunk, unitNumber)
@ -113,7 +125,9 @@ function chunkPropertyUtils.addHiveCount(map, chunk, unitNumber)
if not map.chunkToHiveIds[chunk.id][unitNumber] then
map.chunkToHiveIds[chunk.id][unitNumber] = true
map.chunkToHives[chunk.id] = (map.chunkToHives[chunk.id] or 0) + 1
return true
end
return false
end
function chunkPropertyUtils.removeHiveCount(map, chunk, unitNumber)
@ -124,7 +138,9 @@ function chunkPropertyUtils.removeHiveCount(map, chunk, unitNumber)
map.chunkToHiveIds[chunk.id] = nil
map.chunkToHives[chunk.id] = nil
end
return true
end
return false
end
function chunkPropertyUtils.addNestCount(map, chunk, unitNumber)
@ -144,7 +160,9 @@ function chunkPropertyUtils.addNestCount(map, chunk, unitNumber)
}
end
cToN[chunkId].v = cToN[chunkId].v + 1
return true
end
return false
end
function chunkPropertyUtils.removeNestCount(map, chunk, unitNumber)
@ -163,7 +181,9 @@ function chunkPropertyUtils.removeNestCount(map, chunk, unitNumber)
map.universe.processNestIterator = nil
end
end
return true
end
return false
end
function chunkPropertyUtils.getNestCount(map, chunk)

View File

@ -411,7 +411,7 @@ function chunkUtils.colorXY(x, y, surface, color)
})
end
function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase)
function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase, skipCount)
local entityType = entity.type
local addFunc
@ -419,29 +419,24 @@ function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase)
local hiveTypeLookup = universe.buildingHiveTypeLookup
local hiveType = hiveTypeLookup[entity.name]
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addNestCount
elseif (hiveType == "turret") then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addTurretCount
elseif (hiveType == "trap") then
addFunc = addTrapCount
elseif (hiveType == "utility") then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addUtilityCount
elseif (hiveType == "hive") then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addHiveCount
else
if (entityType == "turret") then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addTurretCount
else
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
addFunc = addNestCount
end
end
local added = false
local entityUnitNumber = entity.unit_number
local chunks = getEntityOverlapChunks(map, entity)
for i=1,#chunks do
@ -457,45 +452,46 @@ function chunkUtils.registerEnemyBaseStructure(map, entity, tick, incomingBase)
end
setChunkBase(map, chunk, base)
end
addFunc(map, chunk, entityUnitNumber)
if addFunc(map, chunk, entityUnitNumber) then
added = true
end
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
processNestActiveness(map, chunk)
end
end
end
if added and (not skipCount) then
map.builtEnemyBuilding = map.builtEnemyBuilding + 1
end
end
function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType)
function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType, skipCount)
local entityType = entity.type
local removeFunc
local hiveTypeLookup = map.universe.buildingHiveTypeLookup
local hiveType = hiveTypeLookup[entity.name]
if (hiveType == "spitter-spawner") or (hiveType == "biter-spawner") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeNestCount
elseif (hiveType == "turret") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeTurretCount
elseif (hiveType == "trap") then
removeFunc = removeTrapCount
elseif (hiveType == "utility") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeUtilityCount
elseif (hiveType == "hive") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeHiveCount
else
if (entityType == "turret") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeTurretCount
else
hiveType = "biter-spawner"
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
removeFunc = removeNestCount
end
end
local removed = false
local entityUnitNumber = entity.unit_number
local usedBases = {}
local chunks = getEntityOverlapChunks(map, entity)
@ -506,7 +502,9 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType)
setRaidNestActiveness(map, chunk, 0)
setNestActiveness(map, chunk, 0)
end
removeFunc(map, chunk, entityUnitNumber)
if removeFunc(map, chunk, entityUnitNumber) then
removed = true
end
if map.universe.NEW_ENEMIES then
local base = getChunkBase(map, chunk)
if damageType and usedBases[base.id] then
@ -521,6 +519,9 @@ function chunkUtils.unregisterEnemyBaseStructure(map, entity, damageType)
end
end
end
if removed and (not skipCount) and (hiveType ~= "trap") then
map.lostEnemyBuilding = map.lostEnemyBuilding + 1
end
end
function chunkUtils.accountPlayerEntity(entity, map, addObject, creditNatives)