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

96 lines
4.1 KiB
Lua
Raw Normal View History

local pheromoneUtils = {}
-- imports
local mapUtils = require("MapUtils")
local constants = require("Constants")
local chunkPropertyUtils = require("ChunkPropertyUtils")
-- 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_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-09 07:18:59 +02:00
local PATH_RATING = constants.PATH_RATING
-- imported functions
2016-10-15 02:00:18 +02:00
local getCardinalChunks = mapUtils.getCardinalChunks
2017-08-08 10:19:51 +02:00
local mMax = math.max
local getEnemyStructureCount = chunkPropertyUtils.getEnemyStructureCount
local getPlayerBaseGenerator = chunkPropertyUtils.getPlayerBaseGenerator
local getResourceGenerator = chunkPropertyUtils.getResourceGenerator
2017-08-08 10:19:51 +02:00
-- module code
2017-01-20 07:58:36 +02:00
2018-01-14 07:48:21 +02:00
function pheromoneUtils.scents(map, chunk)
chunk[BASE_PHEROMONE] = chunk[BASE_PHEROMONE] + getPlayerBaseGenerator(map, chunk)
local resourceGenerator = getResourceGenerator(map, chunk)
if (resourceGenerator > 0) and (getEnemyStructureCount(map, chunk) == 0) then
2017-11-21 09:27:03 +02:00
chunk[RESOURCE_PHEROMONE] = chunk[RESOURCE_PHEROMONE] + mMax(resourceGenerator * 100, 90)
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-11-21 09:27:03 +02:00
if value then
2017-08-08 10:19:51 +02:00
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] + (value * 100000)
2017-04-22 01:14:04 +02:00
end
end
2017-01-20 07:58:36 +02:00
function pheromoneUtils.deathScent(chunk)
2017-11-21 09:27:03 +02:00
chunk[MOVEMENT_PHEROMONE] = chunk[MOVEMENT_PHEROMONE] - DEATH_PHEROMONE_GENERATOR_AMOUNT
end
2016-10-15 02:00:18 +02:00
function pheromoneUtils.playerScent(playerChunk)
2017-11-21 09:27:03 +02:00
playerChunk[PLAYER_PHEROMONE] = playerChunk[PLAYER_PHEROMONE] + PLAYER_PHEROMONE_GENERATOR_AMOUNT
end
2018-01-14 07:48:21 +02:00
function pheromoneUtils.processPheromone(map, chunk)
2017-04-22 01:14:04 +02:00
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]
2018-01-14 07:48:21 +02:00
local tempNeighbors = getCardinalChunks(map, chunk.x, chunk.y)
2017-11-21 09:27:03 +02:00
local totalMovement = ((tempNeighbors[1][MOVEMENT_PHEROMONE] - chunkMovement) +
(tempNeighbors[2][MOVEMENT_PHEROMONE] - chunkMovement) +
(tempNeighbors[3][MOVEMENT_PHEROMONE] - chunkMovement) +
(tempNeighbors[4][MOVEMENT_PHEROMONE] - chunkMovement))
local totalBase = ((tempNeighbors[1][BASE_PHEROMONE] - chunkBase) +
(tempNeighbors[2][BASE_PHEROMONE] - chunkBase) +
(tempNeighbors[3][BASE_PHEROMONE] - chunkBase) +
(tempNeighbors[4][BASE_PHEROMONE] - chunkBase))
local totalPlayer = ((tempNeighbors[1][PLAYER_PHEROMONE] - chunkPlayer) +
(tempNeighbors[2][PLAYER_PHEROMONE] - chunkPlayer) +
(tempNeighbors[3][PLAYER_PHEROMONE] - chunkPlayer) +
(tempNeighbors[4][PLAYER_PHEROMONE] - chunkPlayer))
local totalResource = ((tempNeighbors[1][RESOURCE_PHEROMONE] - chunkResource) +
(tempNeighbors[2][RESOURCE_PHEROMONE] - chunkResource) +
(tempNeighbors[3][RESOURCE_PHEROMONE] - chunkResource) +
(tempNeighbors[4][RESOURCE_PHEROMONE] - chunkResource))
2017-08-08 10:19:51 +02:00
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