mirror of
https://github.com/veden/Rampant.git
synced 2025-01-14 02:23:01 +02:00
fffc7f9: fixed players disconnecting not tracked correctly
This commit is contained in:
parent
b7ae56c1a2
commit
fab7f0cc6c
@ -20,7 +20,7 @@ local upgrade = {}
|
||||
|
||||
local constants = require("libs/Constants")
|
||||
local chunkProcessor = require("libs/ChunkProcessor")
|
||||
local chunkPropertyUtils = require("libs/chunkPropertyUtils")
|
||||
local chunkPropertyUtils = require("libs/ChunkPropertyUtils")
|
||||
local mapUtils = require("libs/MapUtils")
|
||||
|
||||
-- constants
|
||||
@ -659,6 +659,7 @@ function upgrade.attempt(universe)
|
||||
end
|
||||
end
|
||||
|
||||
map.chunkToPlayerGenerator = {}
|
||||
map.chunkToPermanentDeathGenerator = {}
|
||||
end
|
||||
end
|
||||
@ -721,6 +722,7 @@ function upgrade.prepMap(universe, surface)
|
||||
map.chunkToPathRating = {}
|
||||
map.chunkToDeathGenerator = {}
|
||||
map.chunkToPermanentDeathGenerator = {}
|
||||
map.chunkToPlayerGenerator = {}
|
||||
|
||||
map.chunkScanCounts = {}
|
||||
|
||||
|
@ -50,6 +50,7 @@ Version: 3.2.0
|
||||
- Fixed crash when walls or gates didn't have a resistence property with the add acid resistance to walls mod settings
|
||||
- Fixed projectiles not being able to collide with spawner eggs and wasps
|
||||
- Fixed bases being able to mutate to the same factions
|
||||
- Fixed players disconnecting on multiplayer could leave residual player pheromone that never dissipated
|
||||
Optimizations:
|
||||
- Moved most constants out of global
|
||||
- Removed new enemy variations setting
|
||||
|
@ -24,6 +24,9 @@ local mathUtils = require("MathUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local PLAYER_GENERATOR_PERSISTANCE = constants.PLAYER_GENERATOR_PERSISTANCE
|
||||
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
||||
|
||||
local COOLDOWN_DRAIN = constants.COOLDOWN_DRAIN
|
||||
|
||||
local RAIDING_MINIMUM_BASE_THRESHOLD = constants.RAIDING_MINIMUM_BASE_THRESHOLD
|
||||
@ -542,42 +545,32 @@ function chunkPropertyUtils.decayDeathGenerator(map, chunk)
|
||||
end
|
||||
end
|
||||
|
||||
function chunkPropertyUtils.addPlayerToChunk(map, chunk, name)
|
||||
local playerCountChunks = map.chunkToPlayerCount
|
||||
local playerChunk = map.playerToChunk[name]
|
||||
if not playerChunk then
|
||||
map.playerToChunk[name] = chunk
|
||||
local playerCount = playerCountChunks[chunk.id]
|
||||
if not playerCount then
|
||||
playerCountChunks[chunk.id] = 1
|
||||
function chunkPropertyUtils.decayPlayerGenerator(map, chunk)
|
||||
local gen = map.chunkToPlayerGenerator[chunk.id]
|
||||
if gen then
|
||||
local v = gen * PLAYER_GENERATOR_PERSISTANCE
|
||||
if (v < 0.0001) and (v > -0.0001) then
|
||||
map.chunkToPlayerGenerator[chunk.id] = nil
|
||||
else
|
||||
playerCountChunks[chunk.id] = playerCount + 1
|
||||
end
|
||||
elseif (playerChunk.id ~= chunk.id) then
|
||||
map.playerToChunk[name] = chunk
|
||||
local playerCount = playerCountChunks[playerChunk.id]
|
||||
if playerCount then
|
||||
chunkPropertyUtils.setPlayersOnChunk(map, playerChunk, playerCount - 1)
|
||||
end
|
||||
playerCount = playerCountChunks[chunk.id]
|
||||
if not playerCount then
|
||||
playerCountChunks[chunk.id] = 1
|
||||
else
|
||||
playerCountChunks[chunk.id] = playerCount + 1
|
||||
map.chunkToPlayerGenerator[chunk.id] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function chunkPropertyUtils.setPlayersOnChunk(map, chunk, value)
|
||||
if (value <= 0) then
|
||||
map.chunkToPlayerCount[chunk.id] = nil
|
||||
function chunkPropertyUtils.addPlayerGenerator(map, chunk, playerMaxGenerator)
|
||||
local value = map.chunkToPlayerGenerator[chunk.id]
|
||||
if value then
|
||||
map.chunkToPlayerGenerator[chunk.id] = mMin(
|
||||
value + PLAYER_PHEROMONE_GENERATOR_AMOUNT,
|
||||
playerMaxGenerator
|
||||
)
|
||||
else
|
||||
map.chunkToPlayerCount[chunk.id] = value
|
||||
map.chunkToPlayerGenerator[chunk.id] = PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
||||
end
|
||||
end
|
||||
|
||||
function chunkPropertyUtils.getPlayersOnChunk(map, chunk)
|
||||
return map.chunkToPlayerCount[chunk.id] or 0
|
||||
function chunkPropertyUtils.getPlayerGenerator(map, chunk)
|
||||
return map.chunkToPlayerGenerator[chunk.id] or 0
|
||||
end
|
||||
|
||||
function chunkPropertyUtils.getPlayerBaseGenerator(map, chunk)
|
||||
|
@ -173,12 +173,14 @@ constants.DOUBLE_DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GE
|
||||
constants.TEN_DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT * 10
|
||||
constants.FIVE_DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT * 5
|
||||
constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT = 300
|
||||
constants.PLAYER_PHEROMONE_GENERATOR_THRESHOLD = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT * 0.85
|
||||
|
||||
constants.IMPASSABLE_TERRAIN_GENERATOR_AMOUNT = 0
|
||||
|
||||
-- pheromone diffusion amounts
|
||||
|
||||
constants.MOVEMENT_GENERATOR_PERSISTANCE = 0.92
|
||||
constants.PLAYER_GENERATOR_PERSISTANCE = 0.92
|
||||
|
||||
-- chunk attributes
|
||||
|
||||
|
@ -34,6 +34,7 @@ local baseUtils = require("BaseUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
||||
local DURATION_ACTIVE_NEST = constants.DURATION_ACTIVE_NEST
|
||||
|
||||
local PROCESS_QUEUE_SIZE = constants.PROCESS_QUEUE_SIZE
|
||||
@ -63,6 +64,7 @@ local COOLDOWN_RETREAT = constants.COOLDOWN_RETREAT
|
||||
|
||||
local setPositionInQuery = queryUtils.setPositionInQuery
|
||||
|
||||
local addPlayerGenerator = chunkPropertyUtils.addPlayerGenerator
|
||||
local findNearbyBase = chunkPropertyUtils.findNearbyBase
|
||||
|
||||
local removeChunkToNest = mapUtils.removeChunkToNest
|
||||
@ -87,8 +89,6 @@ local getChunkById = mapUtils.getChunkById
|
||||
|
||||
local validPlayer = playerUtils.validPlayer
|
||||
|
||||
local addPlayerToChunk = chunkPropertyUtils.addPlayerToChunk
|
||||
|
||||
local mapScanEnemyChunk = chunkUtils.mapScanEnemyChunk
|
||||
local mapScanPlayerChunk = chunkUtils.mapScanPlayerChunk
|
||||
local mapScanResourceChunk = chunkUtils.mapScanResourceChunk
|
||||
@ -218,7 +218,9 @@ function mapProcessor.processPlayers(players, universe, tick)
|
||||
-- put down player pheromone for player hunters
|
||||
-- randomize player order to ensure a single player isn't singled out
|
||||
-- not looping everyone because the cost is high enough already in multiplayer
|
||||
for i=1,#players do
|
||||
local playerCount = #players
|
||||
local playerMaxGenerator = playerCount * PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
||||
for i=1,playerCount do
|
||||
local player = players[i]
|
||||
if validPlayer(player) then
|
||||
local char = player.character
|
||||
@ -227,7 +229,7 @@ function mapProcessor.processPlayers(players, universe, tick)
|
||||
local playerChunk = getChunkByPosition(map, char.position)
|
||||
|
||||
if (playerChunk ~= -1) then
|
||||
addPlayerToChunk(map, playerChunk, player.name)
|
||||
addPlayerGenerator(map, playerChunk, playerMaxGenerator)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -40,19 +40,18 @@ local ENEMY_PHEROMONE = constants.ENEMY_PHEROMONE
|
||||
|
||||
local VICTORY_SCENT = constants.VICTORY_SCENT
|
||||
|
||||
local PLAYER_PHEROMONE_GENERATOR_AMOUNT = constants.PLAYER_PHEROMONE_GENERATOR_AMOUNT
|
||||
|
||||
local DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.DEATH_PHEROMONE_GENERATOR_AMOUNT
|
||||
local TEN_DEATH_PHEROMONE_GENERATOR_AMOUNT = constants.TEN_DEATH_PHEROMONE_GENERATOR_AMOUNT
|
||||
|
||||
-- imported functions
|
||||
|
||||
local decayPlayerGenerator = chunkPropertyUtils.decayPlayerGenerator
|
||||
local addVictoryGenerator = chunkPropertyUtils.addVictoryGenerator
|
||||
local getCombinedDeathGenerator = chunkPropertyUtils.getCombinedDeathGenerator
|
||||
local getCombinedDeathGeneratorRating = chunkPropertyUtils.getCombinedDeathGeneratorRating
|
||||
local setDeathGenerator = chunkPropertyUtils.setDeathGenerator
|
||||
|
||||
local getPlayersOnChunk = chunkPropertyUtils.getPlayersOnChunk
|
||||
local getPlayerGenerator = chunkPropertyUtils.getPlayerGenerator
|
||||
|
||||
local addPermanentDeathGenerator = chunkPropertyUtils.addPermanentDeathGenerator
|
||||
|
||||
@ -168,10 +167,12 @@ function pheromoneUtils.processPheromone(map, chunk, player)
|
||||
decayDeathGenerator(map, chunk)
|
||||
end
|
||||
|
||||
decayPlayerGenerator(map, chunk)
|
||||
|
||||
local chunkDeathRating = getCombinedDeathGeneratorRating(map, chunk) * getPathRating(map, chunk)
|
||||
|
||||
chunk[PLAYER_PHEROMONE] = chunkDeathRating * mMax(
|
||||
getPlayersOnChunk(map, chunk) * PLAYER_PHEROMONE_GENERATOR_AMOUNT,
|
||||
getPlayerGenerator(map, chunk),
|
||||
(chunkPlayer / chunkCount) * 0.98
|
||||
)
|
||||
|
||||
|
@ -30,6 +30,7 @@ local queryUtils = require("QueryUtils")
|
||||
|
||||
-- constants
|
||||
|
||||
local PLAYER_PHEROMONE_GENERATOR_THRESHOLD = constants.PLAYER_PHEROMONE_GENERATOR_THRESHOLD
|
||||
local COMMAND_TIMEOUT = constants.COMMAND_TIMEOUT
|
||||
local PLAYER_PHEROMONE = constants.PLAYER_PHEROMONE
|
||||
local BASE_PHEROMONE = constants.BASE_PHEROMONE
|
||||
@ -56,6 +57,7 @@ local DEFINES_DISTRACTION_BY_ANYTHING = defines.distraction.by_anything
|
||||
|
||||
-- imported functions
|
||||
|
||||
local getPlayerGenerator = chunkPropertyUtils.getPlayerGenerator
|
||||
local setPositionInCommand = queryUtils.setPositionInCommand
|
||||
|
||||
local euclideanDistancePoints = mathUtils.euclideanDistancePoints
|
||||
@ -65,7 +67,6 @@ local findMovementPosition = movementUtils.findMovementPosition
|
||||
local removeSquadFromChunk = chunkPropertyUtils.removeSquadFromChunk
|
||||
local addDeathGenerator = chunkPropertyUtils.addDeathGenerator
|
||||
|
||||
local getPlayersOnChunk = chunkPropertyUtils.getPlayersOnChunk
|
||||
local getHiveCount = chunkPropertyUtils.getHiveCount
|
||||
local getNestCount = chunkPropertyUtils.getNestCount
|
||||
|
||||
@ -179,7 +180,8 @@ local function settleMove(map, squad)
|
||||
local attackPlayerThreshold = universe.attackPlayerThreshold
|
||||
|
||||
if (nextAttackChunk ~= -1) then
|
||||
if (getPlayerBaseGenerator(map, nextAttackChunk) == 0) and (getPlayersOnChunk(map, nextAttackChunk) == 0)
|
||||
if (getPlayerBaseGenerator(map, nextAttackChunk) == 0)
|
||||
and (getPlayerGenerator(map, nextAttackChunk) < PLAYER_PHEROMONE_GENERATOR_THRESHOLD)
|
||||
then
|
||||
attackChunk = nextAttackChunk
|
||||
position = findMovementPosition(
|
||||
@ -220,7 +222,8 @@ local function settleMove(map, squad)
|
||||
end
|
||||
|
||||
if (nextAttackChunk ~= -1) and
|
||||
((getPlayerBaseGenerator(map, nextAttackChunk) ~= 0) or (getPlayersOnChunk(map, nextAttackChunk) ~= 0))
|
||||
((getPlayerBaseGenerator(map, nextAttackChunk) ~= 0)
|
||||
or (getPlayerGenerator(map, nextAttackChunk) >= PLAYER_PHEROMONE_GENERATOR_THRESHOLD))
|
||||
then
|
||||
cmd = universe.settleCommand
|
||||
squad.status = SQUAD_BUILDING
|
||||
|
Loading…
Reference in New Issue
Block a user