2019-02-16 06:17:30 +02:00
|
|
|
if chunkPropertyUtilsG then
|
|
|
|
return chunkPropertyUtilsG
|
|
|
|
end
|
2018-01-15 09:41:55 +02:00
|
|
|
local chunkPropertyUtils = {}
|
|
|
|
|
2018-09-24 06:56:45 +02:00
|
|
|
local constants = require("Constants")
|
|
|
|
|
2019-12-16 03:16:56 +02:00
|
|
|
-- constants
|
2019-03-08 05:40:55 +02:00
|
|
|
|
2019-12-16 03:16:56 +02:00
|
|
|
local RAIDING_MINIMUM_BASE_THRESHOLD = constants.RAIDING_MINIMUM_BASE_THRESHOLD
|
|
|
|
|
|
|
|
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
|
|
|
|
local BASE_PHEROMONE = constants.BASE_PHEROMONE
|
2018-01-15 09:41:55 +02:00
|
|
|
|
2018-09-26 07:14:13 +02:00
|
|
|
local MOVEMENT_GENERATOR_PERSISTANCE = constants.MOVEMENT_GENERATOR_PERSISTANCE
|
2018-09-24 06:56:45 +02:00
|
|
|
local CHUNK_ALL_DIRECTIONS = constants.CHUNK_ALL_DIRECTIONS
|
2018-01-15 09:41:55 +02:00
|
|
|
|
2019-12-16 03:16:56 +02:00
|
|
|
-- imported functions
|
|
|
|
|
|
|
|
local mMin = math.min
|
|
|
|
|
2018-01-15 09:41:55 +02:00
|
|
|
-- module code
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getNestCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToNests[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
2019-11-30 02:49:22 +02:00
|
|
|
function chunkPropertyUtils.getTurretCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToTurrets[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
2019-11-30 02:49:22 +02:00
|
|
|
function chunkPropertyUtils.getTrapCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToTraps[chunk.id] or 0
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getUtilityCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToUtilities[chunk.id] or 0
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getHiveCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToHives[chunk.id] or 0
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.addTurretCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToTurretIds[chunk.id] then
|
|
|
|
map.chunkToTurretIds[chunk.id] = {}
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
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
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.removeTurretCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToTurretIds[chunk.id] and map.chunkToTurretIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToTurretIds[chunk.id][unitNumber] = nil
|
|
|
|
map.chunkToTurrets[chunk.id] = map.chunkToTurrets[chunk.id] - 1
|
|
|
|
if map.chunkToTurrets[chunk.id] == 0 then
|
|
|
|
map.chunkToTurretIds[chunk.id] = nil
|
|
|
|
map.chunkToTurrets[chunk.id] = nil
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.addTrapCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToTrapIds[chunk.id] then
|
|
|
|
map.chunkToTrapIds[chunk.id] = {}
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
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
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.removeTrapCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToTrapIds[chunk.id] and map.chunkToTrapIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToTrapIds[chunk.id][unitNumber] = nil
|
|
|
|
map.chunkToTraps[chunk.id] = map.chunkToTraps[chunk.id] - 1
|
|
|
|
if map.chunkToTraps[chunk.id] == 0 then
|
|
|
|
map.chunkToTrapIds[chunk.id] = nil
|
|
|
|
map.chunkToTraps[chunk.id] = nil
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2019-11-30 02:49:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.addUtilitiesCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToUtilityIds[chunk.id] then
|
|
|
|
map.chunkToUtilityIds[chunk.id] = {}
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
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
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.removeUtilitiesCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToUtilityIds[chunk.id] and map.chunkToUtilityIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToUtilityIds[chunk.id][unitNumber] = nil
|
|
|
|
map.chunkToUtilities[chunk.id] = map.chunkToUtilities[chunk.id] - 1
|
|
|
|
if map.chunkToUtilities[chunk.id] == 0 then
|
|
|
|
map.chunkToUtilityIds[chunk.id] = nil
|
|
|
|
map.chunkToUtilities[chunk.id] = nil
|
2020-05-20 04:37:16 +02:00
|
|
|
end
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.addHiveCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToHiveIds[chunk.id] then
|
|
|
|
map.chunkToHiveIds[chunk.id] = {}
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
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
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.removeHiveCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToHiveIds[chunk.id] and map.chunkToHiveIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToHiveIds[chunk.id][unitNumber] = nil
|
|
|
|
map.chunkToHives[chunk.id] = map.chunkToHives[chunk.id] - 1
|
|
|
|
if map.chunkToHives[chunk.id] == 0 then
|
|
|
|
map.chunkToHiveIds[chunk.id] = nil
|
|
|
|
map.chunkToHives[chunk.id] = nil
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.addNestCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToNestIds[chunk.id] then
|
|
|
|
map.chunkToNestIds[chunk.id] = {}
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToNestIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToNestIds[chunk.id][unitNumber] = true
|
|
|
|
map.chunkToNests[chunk.id] = (map.chunkToNests[chunk.id] or 0) + 1
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.removeNestCount(map, chunk, unitNumber)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToNestIds[chunk.id] and map.chunkToNestIds[chunk.id][unitNumber] then
|
|
|
|
map.chunkToNestIds[chunk.id][unitNumber] = nil
|
|
|
|
map.chunkToNests[chunk.id] = map.chunkToNests[chunk.id] - 1
|
|
|
|
if map.chunkToNests[chunk.id] == 0 then
|
|
|
|
map.chunkToNestIds[chunk.id] = nil
|
|
|
|
map.chunkToNests[chunk.id] = nil
|
|
|
|
if (map.processMigrationIterator == chunk.id) then
|
2021-12-04 21:04:13 +02:00
|
|
|
map.processMigrationIterator = nil
|
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
if (map.processNestIterator == chunk.id) then
|
2021-12-04 21:04:13 +02:00
|
|
|
map.processNestIterator = nil
|
|
|
|
end
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getNestCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToNests[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getChunkBase(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToBase[chunk.id]
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
2021-12-04 21:04:13 +02:00
|
|
|
function chunkPropertyUtils.removeChunkBase(map, chunk, base)
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToBase[chunk.id] then
|
2021-12-04 23:21:07 +02:00
|
|
|
base.chunkCount = base.chunkCount - 1
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToBase[chunk.id] = nil
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-15 09:41:55 +02:00
|
|
|
function chunkPropertyUtils.setChunkBase(map, chunk, base)
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToBase[chunk.id] then
|
2021-12-04 21:04:13 +02:00
|
|
|
base.chunkCount = base.chunkCount + 1
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToBase[chunk.id] = base
|
2021-12-04 21:04:13 +02:00
|
|
|
end
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getEnemyStructureCount(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return (map.chunkToNests[chunk.id] or 0) + (map.chunkToTurrets[chunk.id] or 0) + (map.chunkToTraps[chunk.id] or 0) +
|
|
|
|
(map.chunkToUtilities[chunk.id] or 0) + (map.chunkToHives[chunk.id] or 0)
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getRetreatTick(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToRetreats[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getRallyTick(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToRallys[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setRallyTick(map, chunk, tick)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToRallys[chunk.id] = tick
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setRetreatTick(map, chunk, tick)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToRetreats[chunk.id] = tick
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setResourceGenerator(map, chunk, resourceGenerator)
|
2019-05-16 07:11:43 +02:00
|
|
|
if (resourceGenerator <= 0) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToResource[chunk.id] = nil
|
2018-01-15 09:41:55 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToResource[chunk.id] = resourceGenerator
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getResourceGenerator(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToResource[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.addResourceGenerator(map, chunk, delta)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToResource[chunk.id] = (map.chunkToResource[chunk.id] or 0) + delta
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
2018-09-24 06:56:45 +02:00
|
|
|
function chunkPropertyUtils.getDeathGenerator(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToDeathGenerator[chunk.id] or 0
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getPassable(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToPassable[chunk.id] or CHUNK_ALL_DIRECTIONS
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
|
2019-02-20 08:16:43 +02:00
|
|
|
|
|
|
|
function chunkPropertyUtils.getRaidNestActiveness(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToActiveRaidNest[chunk.id] or 0
|
2019-02-20 08:16:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setRaidNestActiveness(map, chunk, value)
|
|
|
|
if (value <= 0) then
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToActiveRaidNest[chunk.id] then
|
2021-02-20 09:31:36 +02:00
|
|
|
map.activeRaidNests = map.activeRaidNests - 1
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
if (map.processActiveRaidSpawnerIterator == chunk.id) then
|
2020-05-20 04:37:16 +02:00
|
|
|
map.processActiveRaidSpawnerIterator = nil
|
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToActiveRaidNest[chunk.id] = nil
|
2019-02-20 08:16:43 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToActiveRaidNest[chunk.id] then
|
2021-02-20 09:31:36 +02:00
|
|
|
map.activeRaidNests = map.activeRaidNests + 1
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToActiveRaidNest[chunk.id] = value
|
2019-02-20 08:16:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getNestActiveness(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToActiveNest[chunk.id] or 0
|
2019-02-20 08:16:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setNestActiveness(map, chunk, value)
|
|
|
|
if (value <= 0) then
|
2021-12-05 20:19:04 +02:00
|
|
|
if map.chunkToActiveNest[chunk.id] then
|
2021-02-20 09:31:36 +02:00
|
|
|
map.activeNests = map.activeNests - 1
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
if (map.processActiveSpawnerIterator == chunk.id) then
|
2020-05-20 04:37:16 +02:00
|
|
|
map.processActiveSpawnerIterator = nil
|
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToActiveNest[chunk.id] = nil
|
2019-02-20 08:16:43 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
if not map.chunkToActiveNest[chunk.id] then
|
2021-02-20 09:31:36 +02:00
|
|
|
map.activeNests = map.activeNests + 1
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToActiveNest[chunk.id] = value
|
2019-02-20 08:16:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-24 06:56:45 +02:00
|
|
|
function chunkPropertyUtils.setPassable(map, chunk, value)
|
|
|
|
if (value == CHUNK_ALL_DIRECTIONS) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPassable[chunk.id] = nil
|
2018-09-24 06:56:45 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPassable[chunk.id] = value
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getPathRating(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToPathRating[chunk.id] or 1
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setPathRating(map, chunk, value)
|
|
|
|
if (value == 1) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPathRating[chunk.id] = nil
|
2018-09-24 06:56:45 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPathRating[chunk.id] = value
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-26 07:14:13 +02:00
|
|
|
function chunkPropertyUtils.addDeathGenerator(map, chunk, value)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToDeathGenerator[chunk.id] = (map.chunkToDeathGenerator[chunk.id] or 0) + value
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
|
2020-05-25 01:41:12 +02:00
|
|
|
function chunkPropertyUtils.addVictoryGenerator(map, chunk, value)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToVictory[chunk.id] = (map.chunkToVictory[chunk.id] or 0) + value
|
2020-05-25 01:41:12 +02:00
|
|
|
end
|
|
|
|
|
2018-09-24 06:56:45 +02:00
|
|
|
function chunkPropertyUtils.decayDeathGenerator(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
local gen = map.chunkToDeathGenerator[chunk.id]
|
2020-05-22 20:45:05 +02:00
|
|
|
if gen then
|
2019-10-14 07:49:52 +02:00
|
|
|
gen = gen * MOVEMENT_GENERATOR_PERSISTANCE
|
2018-09-26 07:14:13 +02:00
|
|
|
|
2019-10-14 07:49:52 +02:00
|
|
|
if (gen >= -2) and (gen <= 2) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToDeathGenerator[chunk.id] = nil
|
2019-10-14 07:49:52 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToDeathGenerator[chunk.id] = gen
|
2019-10-14 07:49:52 +02:00
|
|
|
end
|
2019-02-16 06:17:30 +02:00
|
|
|
end
|
2018-09-24 06:56:45 +02:00
|
|
|
end
|
|
|
|
|
2020-05-22 08:57:03 +02:00
|
|
|
function chunkPropertyUtils.addPlayerToChunk(map, chunk, name)
|
|
|
|
local playerChunks = map.playerToChunk
|
|
|
|
local playerCountChunks = map.chunkToPlayerCount
|
|
|
|
local playerChunk = playerChunks[name]
|
|
|
|
if not playerChunk then
|
|
|
|
playerChunks[name] = chunk
|
2021-12-05 20:19:04 +02:00
|
|
|
local playerCount = playerCountChunks[chunk.id]
|
2020-05-22 08:57:03 +02:00
|
|
|
if not playerCount then
|
2021-12-05 20:19:04 +02:00
|
|
|
playerCountChunks[chunk.id] = 1
|
2020-05-22 08:57:03 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
playerCountChunks[chunk.id] = playerCount + 1
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
2021-12-05 20:19:04 +02:00
|
|
|
elseif (playerChunk.id ~= chunk.id) then
|
2020-05-22 08:57:03 +02:00
|
|
|
playerChunks[name] = chunk
|
2021-12-05 20:19:04 +02:00
|
|
|
local playerCount = playerCountChunks[playerChunk.id]
|
2020-05-22 08:57:03 +02:00
|
|
|
chunkPropertyUtils.setPlayersOnChunk(map, playerChunk, playerCount - 1)
|
2021-12-05 20:19:04 +02:00
|
|
|
playerCount = playerCountChunks[chunk.id]
|
2020-05-22 08:57:03 +02:00
|
|
|
if not playerCount then
|
2021-12-05 20:19:04 +02:00
|
|
|
playerCountChunks[chunk.id] = 1
|
2020-05-22 08:57:03 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
playerCountChunks[chunk.id] = playerCount + 1
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setPlayersOnChunk(map, chunk, value)
|
|
|
|
if (value <= 0) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPlayerCount[chunk.id] = nil
|
2020-05-22 08:57:03 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPlayerCount[chunk.id] = value
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getPlayersOnChunk(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToPlayerCount[chunk.id] or 0
|
2020-05-22 08:57:03 +02:00
|
|
|
end
|
|
|
|
|
2018-01-15 09:41:55 +02:00
|
|
|
function chunkPropertyUtils.getPlayerBaseGenerator(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToPlayerBase[chunk.id] or 0
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.addSquadToChunk(map, chunk, squad)
|
2018-02-01 06:01:28 +02:00
|
|
|
local chunkToSquad = map.chunkToSquad
|
2018-01-15 09:41:55 +02:00
|
|
|
|
2021-12-05 20:19:04 +02:00
|
|
|
if (chunk ~= -1) and ((squad.chunk == -1) or (squad.chunk.id ~= chunk.id)) then
|
2019-10-14 07:49:52 +02:00
|
|
|
chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
2021-12-05 20:19:04 +02:00
|
|
|
local squads = chunkToSquad[chunk.id]
|
2019-03-09 02:42:20 +02:00
|
|
|
if not squads then
|
|
|
|
squads = {}
|
2021-12-05 20:19:04 +02:00
|
|
|
chunkToSquad[chunk.id] = squads
|
2019-03-09 02:42:20 +02:00
|
|
|
end
|
2020-05-17 07:06:55 +02:00
|
|
|
squads[squad.groupNumber] = squad
|
2019-03-09 02:42:20 +02:00
|
|
|
squad.chunk = chunk
|
2019-12-09 05:31:51 +02:00
|
|
|
end
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
|
|
|
local chunkToSquad = map.chunkToSquad
|
2018-02-01 06:01:28 +02:00
|
|
|
local chunk = squad.chunk
|
2021-12-05 20:19:04 +02:00
|
|
|
if (chunk ~= -1) then
|
|
|
|
local squads = chunkToSquad[chunk.id]
|
|
|
|
if squads then
|
|
|
|
squads[squad.groupNumber] = nil
|
|
|
|
if (table_size(squads) == 0) then
|
|
|
|
chunkToSquad[chunk.id] = nil
|
|
|
|
end
|
2019-10-14 07:49:52 +02:00
|
|
|
end
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.getSquadsOnChunk(map, chunk)
|
2021-12-05 20:19:04 +02:00
|
|
|
return map.chunkToSquad[chunk.id] or map.emptySquadsOnChunk
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.setPlayerBaseGenerator(map, chunk, playerGenerator)
|
2019-05-16 07:11:43 +02:00
|
|
|
if (playerGenerator <= 0) then
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPlayerBase[chunk.id] = nil
|
2018-01-15 09:41:55 +02:00
|
|
|
else
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPlayerBase[chunk.id] = playerGenerator
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function chunkPropertyUtils.addPlayerBaseGenerator(map, chunk, playerGenerator)
|
2021-12-05 20:19:04 +02:00
|
|
|
map.chunkToPlayerBase[chunk.id] = (map.chunkToPlayerBase[chunk.id] or 0) + playerGenerator
|
2018-01-15 09:41:55 +02:00
|
|
|
end
|
|
|
|
|
2021-02-20 07:41:30 +02:00
|
|
|
function chunkPropertyUtils.processNestActiveness(map, chunk)
|
2019-12-16 03:16:56 +02:00
|
|
|
local nests = chunkPropertyUtils.getNestCount(map, chunk)
|
|
|
|
if (nests > 0) then
|
2021-02-20 09:31:36 +02:00
|
|
|
local surface = map.surface
|
2019-12-16 03:16:56 +02:00
|
|
|
local activeness = chunkPropertyUtils.getNestActiveness(map, chunk)
|
2021-02-20 09:31:36 +02:00
|
|
|
local universe = map.universe
|
2019-12-16 03:16:56 +02:00
|
|
|
local raidActiveness = chunkPropertyUtils.getRaidNestActiveness(map, chunk)
|
2021-02-20 09:31:36 +02:00
|
|
|
if universe.attackUsePlayer and (chunk[PLAYER_PHEROMONE] > universe.attackPlayerThreshold) then
|
2019-12-16 03:16:56 +02:00
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
elseif (chunk[BASE_PHEROMONE] > 0) then
|
|
|
|
if (surface.get_pollution(chunk) > 0) then
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
else
|
|
|
|
local x = chunk.x
|
|
|
|
local y = chunk.y
|
2021-12-05 20:19:04 +02:00
|
|
|
local position = {x=0,y=0}
|
2019-12-16 03:16:56 +02:00
|
|
|
position.x = x + 32
|
|
|
|
position.y = y
|
|
|
|
if (surface.get_pollution(position) > 0) then
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
else
|
|
|
|
position.x = x - 32
|
|
|
|
if (surface.get_pollution(position) > 0) then
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
else
|
|
|
|
position.x = x
|
|
|
|
position.y = y - 32
|
|
|
|
if (surface.get_pollution(position) > 0) then
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
else
|
|
|
|
position.y = y + 32
|
|
|
|
if (surface.get_pollution(position) > 0) then
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, mMin(activeness + 5, 20))
|
|
|
|
else
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, activeness - 2)
|
|
|
|
if (chunk[BASE_PHEROMONE] > RAIDING_MINIMUM_BASE_THRESHOLD) then
|
|
|
|
chunkPropertyUtils.setRaidNestActiveness(map, chunk, mMin(raidActiveness + 3, 20))
|
|
|
|
else
|
|
|
|
chunkPropertyUtils.setRaidNestActiveness(map, chunk, raidActiveness - 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, activeness - 5)
|
|
|
|
chunkPropertyUtils.setRaidNestActiveness(map, chunk, raidActiveness - 5)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
chunkPropertyUtils.setNestActiveness(map, chunk, 0)
|
|
|
|
chunkPropertyUtils.setRaidNestActiveness(map, chunk, 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-02-16 06:17:30 +02:00
|
|
|
chunkPropertyUtilsG = chunkPropertyUtils
|
2018-01-15 09:41:55 +02:00
|
|
|
return chunkPropertyUtils
|