mirror of
https://github.com/veden/Rampant.git
synced 2024-12-26 20:54:12 +02:00
276 lines
7.4 KiB
Lua
Executable File
276 lines
7.4 KiB
Lua
Executable File
if chunkPropertyUtilsG then
|
|
return chunkPropertyUtilsG
|
|
end
|
|
local chunkPropertyUtils = {}
|
|
|
|
local constants = require("Constants")
|
|
|
|
local tRemove = table.remove
|
|
|
|
-- imported functions
|
|
|
|
local MOVEMENT_GENERATOR_PERSISTANCE = constants.MOVEMENT_GENERATOR_PERSISTANCE
|
|
local CHUNK_ALL_DIRECTIONS = constants.CHUNK_ALL_DIRECTIONS
|
|
|
|
-- module code
|
|
|
|
function chunkPropertyUtils.getNestCount(map, chunk)
|
|
return map.chunkToNests[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getTurretCount(map, chunk)
|
|
return map.chunkToTurrets[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getTrapCount(map, chunk)
|
|
return map.chunkToTraps[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getUtilityCount(map, chunk)
|
|
return map.chunkToUtilities[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getHiveCount(map, chunk)
|
|
return map.chunkToHives[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.setTurretCount(map, chunk, count)
|
|
if (count <= 0) then
|
|
map.chunkToTurrets[chunk] = nil
|
|
else
|
|
map.chunkToTurrets[chunk] = count
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.setHiveCount(map, chunk, count)
|
|
if (count <= 0) then
|
|
map.chunkToHives[chunk] = nil
|
|
else
|
|
map.chunkToHives[chunk] = count
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.setTrapCount(map, chunk, count)
|
|
if (count <= 0) then
|
|
map.chunkToTraps[chunk] = nil
|
|
else
|
|
map.chunkToTraps[chunk] = count
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.setUtilityCount(map, chunk, count)
|
|
if (count <= 0) then
|
|
map.chunkToUtilities[chunk] = nil
|
|
else
|
|
map.chunkToUtilities[chunk] = count
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.setNestCount(map, chunk, count)
|
|
if (count <= 0) then
|
|
map.chunkToNests[chunk] = nil
|
|
else
|
|
map.chunkToNests[chunk] = count
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getChunkSettlerTick(map, chunk)
|
|
return map.chunkToSettler[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.setChunkSettlerTick(map, chunk, tick)
|
|
if (tick <= 0) then
|
|
map.chunkToSettler[chunk] = nil
|
|
else
|
|
map.chunkToSettler[chunk] = tick
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getNestCount(map, chunk)
|
|
return map.chunkToNests[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getChunkBase(map, chunk)
|
|
return map.chunkToBase[chunk]
|
|
end
|
|
|
|
function chunkPropertyUtils.setChunkBase(map, chunk, base)
|
|
map.chunkToBase[chunk] = base
|
|
end
|
|
|
|
function chunkPropertyUtils.getEnemyStructureCount(map, chunk)
|
|
return (map.chunkToNests[chunk] or 0) + (map.chunkToTurrets[chunk] or 0) + (map.chunkToTraps[chunk] or 0) +
|
|
(map.chunkToUtilities[chunk] or 0) + (map.chunkToHives[chunk] or 0)
|
|
end
|
|
|
|
function chunkPropertyUtils.getRetreatTick(map, chunk)
|
|
return map.chunkToRetreats[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getRallyTick(map, chunk)
|
|
return map.chunkToRallys[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.setRallyTick(map, chunk, tick)
|
|
map.chunkToRallys[chunk] = tick
|
|
end
|
|
|
|
function chunkPropertyUtils.setRetreatTick(map, chunk, tick)
|
|
map.chunkToRetreats[chunk] = tick
|
|
end
|
|
|
|
function chunkPropertyUtils.setResourceGenerator(map, chunk, resourceGenerator)
|
|
if (resourceGenerator <= 0) then
|
|
map.chunkToResource[chunk] = nil
|
|
else
|
|
map.chunkToResource[chunk] = resourceGenerator
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getResourceGenerator(map, chunk)
|
|
return map.chunkToResource[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.addResourceGenerator(map, chunk, delta)
|
|
map.chunkToResource[chunk] = (map.chunkToResource[chunk] or 0) + delta
|
|
end
|
|
|
|
function chunkPropertyUtils.getDeathGenerator(map, chunk)
|
|
return map.chunkToDeathGenerator[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.getPassable(map, chunk)
|
|
return map.chunkToPassable[chunk] or CHUNK_ALL_DIRECTIONS
|
|
end
|
|
|
|
|
|
function chunkPropertyUtils.getRaidNestActiveness(map, chunk)
|
|
return map.chunkToActiveRaidNest[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.setRaidNestActiveness(map, chunk, value)
|
|
if (value <= 0) then
|
|
if (map.chunkToActiveRaidNest[chunk] ~= nil) then
|
|
map.natives.activeRaidNests = map.natives.activeRaidNests - 1
|
|
end
|
|
map.chunkToActiveRaidNest[chunk] = nil
|
|
else
|
|
if (map.chunkToActiveRaidNest[chunk] == nil) then
|
|
map.natives.activeRaidNests = map.natives.activeRaidNests + 1
|
|
end
|
|
map.chunkToActiveRaidNest[chunk] = value
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getNestActiveness(map, chunk)
|
|
return map.chunkToActiveNest[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.setNestActiveness(map, chunk, value)
|
|
if (value <= 0) then
|
|
if (map.chunkToActiveNest[chunk] ~= nil) then
|
|
map.natives.activeNests = map.natives.activeNests - 1
|
|
end
|
|
map.chunkToActiveNest[chunk] = nil
|
|
else
|
|
if (map.chunkToActiveNest[chunk] == nil) then
|
|
map.natives.activeNests = map.natives.activeNests + 1
|
|
end
|
|
map.chunkToActiveNest[chunk] = value
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.setPassable(map, chunk, value)
|
|
if (value == CHUNK_ALL_DIRECTIONS) then
|
|
map.chunkToPassable[chunk] = nil
|
|
else
|
|
map.chunkToPassable[chunk] = value
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getPathRating(map, chunk)
|
|
return map.chunkToPathRating[chunk] or 1
|
|
end
|
|
|
|
function chunkPropertyUtils.setPathRating(map, chunk, value)
|
|
if (value == 1) then
|
|
map.chunkToPathRating[chunk] = nil
|
|
else
|
|
map.chunkToPathRating[chunk] = value
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.addDeathGenerator(map, chunk, value)
|
|
map.chunkToDeathGenerator[chunk] = (map.chunkToDeathGenerator[chunk] or 0) + value
|
|
end
|
|
|
|
function chunkPropertyUtils.decayDeathGenerator(map, chunk)
|
|
local gen = map.chunkToDeathGenerator[chunk]
|
|
if gen and (gen > 0) then
|
|
gen = gen * MOVEMENT_GENERATOR_PERSISTANCE
|
|
|
|
if (gen >= -2) and (gen <= 2) then
|
|
map.chunkToDeathGenerator[chunk] = nil
|
|
else
|
|
map.chunkToDeathGenerator[chunk] = gen
|
|
end
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getPlayerBaseGenerator(map, chunk)
|
|
return map.chunkToPlayerBase[chunk] or 0
|
|
end
|
|
|
|
function chunkPropertyUtils.addSquadToChunk(map, chunk, squad)
|
|
local chunkToSquad = map.chunkToSquad
|
|
|
|
if squad.chunk ~= chunk then
|
|
chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
|
local squads = chunkToSquad[chunk]
|
|
if not squads then
|
|
squads = {}
|
|
chunkToSquad[chunk] = squads
|
|
end
|
|
squads[#squads+1] = squad
|
|
|
|
squad.chunk = chunk
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.removeSquadFromChunk(map, squad)
|
|
local chunkToSquad = map.chunkToSquad
|
|
local chunk = squad.chunk
|
|
if chunk then
|
|
local squads = chunkToSquad[chunk]
|
|
if squads then
|
|
for i=#squads,1,-1 do
|
|
if (squads[i] == squad) then
|
|
tRemove(squads, i)
|
|
end
|
|
end
|
|
if (#squads == 0) then
|
|
chunkToSquad[chunk] = nil
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.getSquadsOnChunk(map, chunk)
|
|
return map.chunkToSquad[chunk] or map.emptySquadsOnChunk
|
|
end
|
|
|
|
function chunkPropertyUtils.setPlayerBaseGenerator(map, chunk, playerGenerator)
|
|
if (playerGenerator <= 0) then
|
|
map.chunkToPlayerBase[chunk] = nil
|
|
else
|
|
map.chunkToPlayerBase[chunk] = playerGenerator
|
|
end
|
|
end
|
|
|
|
function chunkPropertyUtils.addPlayerBaseGenerator(map, chunk, playerGenerator)
|
|
map.chunkToPlayerBase[chunk] = (map.chunkToPlayerBase[chunk] or 0) + playerGenerator
|
|
end
|
|
|
|
chunkPropertyUtilsG = chunkPropertyUtils
|
|
return chunkPropertyUtils
|