1
0
mirror of https://github.com/veden/Rampant.git synced 2025-01-03 22:52:20 +02:00
Rampant/libs/PheromoneUtils.lua

111 lines
3.9 KiB
Lua
Raw Normal View History

local pheromoneUtils = {}
-- imports
local mapUtils = require("MapUtils")
local constants = require("Constants")
-- constants
2016-10-15 02:00:18 +02:00
local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE
local BASE_PHEROMONE = constants.BASE_PHEROMONE
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
2017-06-08 02:57:24 +02:00
local RESOURCE_PHEROMONE = constants.RESOURCE_PHEROMONE
2017-04-22 01:14:04 +02:00
local BUILDING_PHEROMONES = constants.BUILDING_PHEROMONES
local PLAYER_BASE_GENERATOR = constants.PLAYER_BASE_GENERATOR
2017-06-08 02:57:24 +02:00
local RESOURCE_GENERATOR = constants.RESOURCE_GENERATOR
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
2017-04-22 01:14:04 +02:00
local DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT
2016-10-15 02:00:18 +02:00
local MOVEMENT_PHEROMONE_PERSISTANCE = constants.MOVEMENT_PHEROMONE_PERSISTANCE
2017-04-22 01:14:04 +02:00
local BASE_PHEROMONE_PERSISTANCE = constants.BASE_PHEROMONE_PERSISTANCE
local PLAYER_PHEROMONE_PERSISTANCE = constants.PLAYER_PHEROMONE_PERSISTANCE
2017-06-08 02:57:24 +02:00
local RESOURCE_PHEROMONE_PERSISTANCE = constants.RESOURCE_PHEROMONE_PERSISTANCE
2016-08-21 23:48:55 +02:00
2017-06-10 10:38:20 +02:00
local CHUNK_IMPASSABLE = constants.CHUNK_IMPASSABLE
local PASSABLE = constants.PASSABLE
2017-04-16 08:04:22 +02:00
2017-06-08 02:57:24 +02:00
local NEST_COUNT = constants.NEST_COUNT
2017-06-09 07:18:59 +02:00
local PATH_RATING = constants.PATH_RATING
2017-04-22 01:14:04 +02:00
local IMPASSABLE_TERRAIN_GENERATOR_AMOUNT = constants.IMPASSABLE_TERRAIN_GENERATOR_AMOUNT
-- imported functions
2016-10-15 02:00:18 +02:00
local getCardinalChunks = mapUtils.getCardinalChunks
-- module code
2017-01-20 07:58:36 +02:00
function pheromoneUtils.scents(chunk)
2017-04-22 01:14:04 +02:00
2017-06-10 10:38:20 +02:00
if (chunk[PASSABLE] == CHUNK_IMPASSABLE) then
2017-04-22 01:14:04 +02:00
chunk[BASE_PHEROMONE] = IMPASSABLE_TERRAIN_GENERATOR_AMOUNT;
2017-04-16 08:04:22 +02:00
else
2017-05-06 11:03:28 +02:00
chunk[BASE_PHEROMONE] = chunk[BASE_PHEROMONE] + chunk[PLAYER_BASE_GENERATOR]
2017-06-09 07:18:59 +02:00
if (chunk[NEST_COUNT] == 0) then
2017-06-08 02:57:24 +02:00
chunk[RESOURCE_PHEROMONE] = chunk[RESOURCE_PHEROMONE] + chunk[RESOURCE_GENERATOR]
end
2017-04-16 08:04:22 +02:00
end
end
2017-01-20 07:58:36 +02:00
2017-04-22 01:14:04 +02:00
function pheromoneUtils.victoryScent(chunk, entityType)
local value = BUILDING_PHEROMONES[entityType]
2017-06-10 10:38:20 +02:00
if (value ~= nil) and (chunk[PASSABLE] ~= CHUNK_IMPASSABLE) then
2017-04-22 01:14:04 +02:00
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value * 10000)
end
end
2017-01-20 07:58:36 +02:00
function pheromoneUtils.deathScent(chunk)
2017-06-10 10:38:20 +02:00
if (chunk[PASSABLE] ~= CHUNK_IMPASSABLE) then
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - DEATH_PHEROMONE_GENERATOR_AMOUNT
end
end
2016-10-15 02:00:18 +02:00
function pheromoneUtils.playerScent(playerChunk)
2017-06-10 10:38:20 +02:00
if (playerChunk[PASSABLE] ~= CHUNK_IMPASSABLE) then
playerChunk[PLAYER_PHEROMONE] = playerChunk[PLAYER_PHEROMONE] + PLAYER_PHEROMONE_GENERATOR_AMOUNT
end
end
2017-06-10 10:38:20 +02:00
function pheromoneUtils.processPheromone(regionMap, chunk)
2017-04-22 01:14:04 +02:00
2017-06-10 10:38:20 +02:00
if (chunk[PASSABLE] == CHUNK_IMPASSABLE) then
2017-04-22 01:14:04 +02:00
return
end
2017-06-01 03:46:53 +02:00
2017-06-10 10:38:20 +02:00
local tempNeighbors = getCardinalChunks(regionMap, chunk.cX, chunk.cY)
local chunkMovement = chunk[MOVEMENT_PHEROMONE]
local chunkBase = chunk[BASE_PHEROMONE]
local chunkPlayer = chunk[PLAYER_PHEROMONE]
2017-06-08 02:57:24 +02:00
local chunkResource = chunk[RESOURCE_PHEROMONE]
2017-06-09 07:18:59 +02:00
local chunkPathRating = chunk[PATH_RATING]
2017-04-22 01:14:04 +02:00
local totalMovement = 0
local totalBase = 0
local totalPlayer = 0
2017-06-08 02:57:24 +02:00
local totalResource = 0
for i=1,4 do
2017-06-01 03:46:53 +02:00
local neighborChunk = tempNeighbors[i]
if neighborChunk then
totalMovement = totalMovement + (neighborChunk[MOVEMENT_PHEROMONE] - chunkMovement)
totalBase = totalBase + (neighborChunk[BASE_PHEROMONE] - chunkBase)
totalPlayer = totalPlayer + (neighborChunk[PLAYER_PHEROMONE] - chunkPlayer)
2017-06-08 02:57:24 +02:00
totalResource = totalResource + (neighborChunk[RESOURCE_PHEROMONE] - chunkResource)
2016-09-14 13:16:33 +02:00
end
end
2017-06-09 07:18:59 +02:00
chunk[MOVEMENT_PHEROMONE] = (chunkMovement + (0.125 * totalMovement)) * MOVEMENT_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[BASE_PHEROMONE] = (chunkBase + (0.25 * totalBase)) * BASE_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[PLAYER_PHEROMONE] = (chunkPlayer + (0.25 * totalPlayer)) * PLAYER_PHEROMONE_PERSISTANCE * chunkPathRating
chunk[RESOURCE_PHEROMONE] = (chunkResource + (0.25 * totalResource)) * RESOURCE_PHEROMONE_PERSISTANCE * chunkPathRating
end
return pheromoneUtils