2016-08-04 21:47:51 -07:00
|
|
|
local pheromoneUtils = {}
|
|
|
|
|
|
|
|
local mapUtils = require("MapUtils")
|
|
|
|
local constants = require("Constants")
|
|
|
|
local mMin = math.min
|
|
|
|
local mFloor = math.floor
|
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
local nearestEnemyPosition = {x=1,y=2}
|
|
|
|
local nearestTable = {position=nearestEnemyPosition,
|
|
|
|
max_distance=constants.CHUNK_SIZE,
|
|
|
|
force="enemy"}
|
|
|
|
|
|
|
|
function pheromoneUtils.deathScent(regionMap, surface, x, y, amount)
|
|
|
|
|
|
|
|
-- nearestEnemyPosition.x = x
|
|
|
|
-- nearestEnemyPosition.y = y
|
|
|
|
-- local playerKiller = surface.find_nearest_enemy(nearestTable)
|
|
|
|
-- if (playerKiller ~= nil) then
|
|
|
|
-- local chunk = regionMap[mathFloor(playerKiller.position.x * 0.03125)]
|
|
|
|
-- if (chunk ~= nil) then
|
|
|
|
-- chunk = chunk[mathFloor(playerKiller.position.y * 0.03125)]
|
|
|
|
-- if (chunk ~= nil) then
|
|
|
|
-- chunk[DEATH_PHEROMONE] = chunk[DEATH_PHEROMONE] + amount
|
|
|
|
-- end
|
|
|
|
-- end
|
|
|
|
-- end
|
2016-08-06 20:38:47 -07:00
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
local chunk = mapUtils.getChunkByPosition(regionMap, x, y)
|
2016-08-06 20:38:47 -07:00
|
|
|
if (chunk ~= nil) then
|
2016-08-17 22:55:08 -07:00
|
|
|
chunk[constants.DEATH_PHEROMONE] = chunk[constants.DEATH_PHEROMONE] + amount
|
2016-08-06 20:38:47 -07:00
|
|
|
end
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
function pheromoneUtils.playerDefenseScent(regionMap, surface, natives, chunk, neighbors)
|
|
|
|
local baseScore = chunk[constants.PLAYER_DEFENSE_GENERATOR]
|
|
|
|
if (baseScore > 0) then
|
|
|
|
chunk[constants.PLAYER_DEFENSE_PHEROMONE] = chunk[constants.PLAYER_DEFENSE_PHEROMONE] + baseScore
|
|
|
|
end
|
|
|
|
end
|
2016-08-06 20:38:47 -07:00
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
function pheromoneUtils.playerBaseScent(regionMap, surface, natives, chunk, neighbors)
|
|
|
|
local baseScore = chunk[constants.PLAYER_BASE_GENERATOR]
|
|
|
|
if (baseScore > 0) then
|
|
|
|
chunk[constants.PLAYER_BASE_PHEROMONE] = chunk[constants.PLAYER_BASE_PHEROMONE] + baseScore
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function pheromoneUtils.enemyBaseScent(regionMap, surface, natives, chunk, neighbors)
|
|
|
|
local spawners = chunk[constants.ENEMY_BASE_GENERATOR]
|
2016-08-06 20:38:47 -07:00
|
|
|
if (spawners > 0) then
|
2016-08-17 22:55:08 -07:00
|
|
|
chunk[constants.ENEMY_BASE_PHEROMONE] = chunk[constants.ENEMY_BASE_PHEROMONE] + spawners
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function pheromoneUtils.playerScent(regionMap, players)
|
2016-08-17 22:55:08 -07:00
|
|
|
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
2016-08-04 21:47:51 -07:00
|
|
|
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
|
2016-08-17 22:55:08 -07:00
|
|
|
local getChunkByPosition = mapUtils.getChunkByPosition
|
2016-08-04 21:47:51 -07:00
|
|
|
local mathFloor = mFloor
|
|
|
|
|
|
|
|
for i=1, #players do
|
|
|
|
local playerPosition = players[i].position
|
2016-08-17 22:55:08 -07:00
|
|
|
local playerChunk = getChunkByPosition(regionMap, playerPosition.x, playerPosition.y)
|
|
|
|
if (playerChunk ~= nil) then
|
|
|
|
playerChunk[PLAYER_PHEROMONE] = playerChunk[PLAYER_PHEROMONE] + PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
|
|
|
end
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
function pheromoneUtils.processPheromone(regionMap, surface, natives, chunk, neighbors)
|
|
|
|
local STANDARD_PHERONOME_DIFFUSION_AMOUNT = constants.STANDARD_PHERONOME_DIFFUSION_AMOUNT
|
|
|
|
local DEATH_PHEROMONE_DIFFUSION_AMOUNT = constants.DEATH_PHEROMONE_DIFFUSION_AMOUNT
|
2016-08-06 20:38:47 -07:00
|
|
|
local DEATH_PHEROMONE = constants.DEATH_PHEROMONE
|
2016-08-17 22:55:08 -07:00
|
|
|
-- local MOVEMENT_PHEROMONE = constants.MOVEMENT_PHEROMONE
|
2016-08-04 21:47:51 -07:00
|
|
|
|
2016-08-17 22:55:08 -07:00
|
|
|
for x=1,5 do
|
2016-08-06 20:38:47 -07:00
|
|
|
local diffusionAmount
|
2016-08-17 22:55:08 -07:00
|
|
|
local persistence
|
2016-08-06 20:38:47 -07:00
|
|
|
if (x == DEATH_PHEROMONE) then
|
2016-08-17 22:55:08 -07:00
|
|
|
diffusionAmount = DEATH_PHEROMONE_DIFFUSION_AMOUNT
|
|
|
|
persistence = 0.99
|
2016-08-06 20:38:47 -07:00
|
|
|
else
|
2016-08-17 22:55:08 -07:00
|
|
|
diffusionAmount = STANDARD_PHERONOME_DIFFUSION_AMOUNT
|
|
|
|
persistence = 0.98
|
2016-08-06 20:38:47 -07:00
|
|
|
end
|
2016-08-17 22:55:08 -07:00
|
|
|
local totalDiffused = 0
|
|
|
|
for i=1,4 do
|
|
|
|
local neighborChunk = neighbors[i]
|
|
|
|
if (neighborChunk ~= nil) then
|
|
|
|
local diffusedAmount = (chunk[x] * diffusionAmount)
|
|
|
|
totalDiffused = totalDiffused + diffusedAmount
|
|
|
|
neighborChunk[x] = neighborChunk[x] + diffusedAmount
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
end
|
2016-08-17 22:55:08 -07:00
|
|
|
chunk[x] = chunk[x] - totalDiffused
|
|
|
|
chunk[x] = chunk[x] * persistence
|
2016-08-04 21:47:51 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return pheromoneUtils
|