From 76d648349dd7ef34d59bea7f728610bbe4dc4579 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 24 Apr 2018 12:46:59 +0000 Subject: [PATCH] Fix gaia units ignoring players without CCs. As demonstrated by Dizaka, it allowed players to win a game by deleting all buildings, sending one unit across the map and having the enemy get defeated by the double gaia count. It also means that players that still have buildings but no CCs/Wonders are targetted by elephants. This was SVN commit r21777. --- .../maps/random/jebel_barkal_triggers.js | 26 ++++++++----------- .../mods/public/maps/scripts/TriggerHelper.js | 2 +- .../simulation/components/PlayerManager.js | 3 +++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/binaries/data/mods/public/maps/random/jebel_barkal_triggers.js b/binaries/data/mods/public/maps/random/jebel_barkal_triggers.js index 1749785fca..a786a11192 100644 --- a/binaries/data/mods/public/maps/random/jebel_barkal_triggers.js +++ b/binaries/data/mods/public/maps/random/jebel_barkal_triggers.js @@ -142,12 +142,6 @@ var jebelBarkal_cityPatrolGroup_triggerPointPath = "A"; */ var jebelBarkal_attackerGroup_triggerPointPatrol = "B"; - -/** - * Attacker groups approach these player buildings and attack enemies of the given classes encountered. - */ -var jebelBarkal_pathTargetClasses = "CivCentre Wonder"; - /** * Number of points the attackers patrol. */ @@ -515,26 +509,27 @@ Trigger.prototype.JebelBarkal_SpawnAttackerGroups = function() if (!this.jebelBarkal_attackerGroupSpawnPoints) return; - let targets = TriggerHelper.GetAllPlayersEntitiesByClass(jebelBarkal_pathTargetClasses); - if (!targets.length) - { - this.JebelBarkal_StartAttackTimer(jebelBarkal_attackInterval()); - return; - } - this.debugLog("Attacker wave (at most " + (jebelBarkal_maxPopulation - this.jebelBarkal_attackerUnits.length) + " attackers)"); let time = TriggerHelper.GetMinutes(); + let activePlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetActivePlayers(); + let playerEntities = activePlayers.map(playerID => TriggerHelper.GetEntitiesByPlayer(playerID)); let patrolPoints = this.GetTriggerPoints(jebelBarkal_attackerGroup_triggerPointPatrol); let groupSizeFactor = jebelBarkal_attackerGroup_sizeFactor( - Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetActivePlayers().length, + activePlayers.length, this.numInitialSpawnPoints, this.GetDifficulty()); let spawnedAnything = false; for (let spawnPointBalancing of jebelBarkal_attackerGroup_balancing) + { + let targets = playerEntities.reduce((allTargets, playerEnts) => + allTargets.concat(shuffleArray(TriggerHelper.MatchEntitiesByClass(playerEnts, spawnPointBalancing.targetClasses())).slice(0, 10)), []); + + if (!targets.length) + continue; + for (let spawnEnt of TriggerHelper.MatchEntitiesByClass(this.jebelBarkal_attackerGroupSpawnPoints, spawnPointBalancing.buildingClasses)) { - let unitCount = Math.min( jebelBarkal_maxPopulation - this.jebelBarkal_attackerUnits.length, groupSizeFactor * spawnPointBalancing.unitCount(time)); @@ -580,6 +575,7 @@ Trigger.prototype.JebelBarkal_SpawnAttackerGroups = function() }); } } + } if (spawnedAnything) Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface).PushNotification({ diff --git a/binaries/data/mods/public/maps/scripts/TriggerHelper.js b/binaries/data/mods/public/maps/scripts/TriggerHelper.js index 02e3976cf6..fb360fd196 100644 --- a/binaries/data/mods/public/maps/scripts/TriggerHelper.js +++ b/binaries/data/mods/public/maps/scripts/TriggerHelper.js @@ -267,7 +267,7 @@ TriggerHelper.DefeatPlayer = function(playerID, defeatReason) }; /** - * Returns the number of current players + * Returns the number of players including gaia and defeated ones. */ TriggerHelper.GetNumberOfPlayers = function() { diff --git a/binaries/data/mods/public/simulation/components/PlayerManager.js b/binaries/data/mods/public/simulation/components/PlayerManager.js index fa4a85f3ec..e1b6fc2377 100644 --- a/binaries/data/mods/public/simulation/components/PlayerManager.js +++ b/binaries/data/mods/public/simulation/components/PlayerManager.js @@ -85,6 +85,9 @@ PlayerManager.prototype.GetPlayerByID = function(id) return INVALID_ENTITY; }; +/** + * Returns the number of players including gaia. + */ PlayerManager.prototype.GetNumPlayers = function() { return this.playerEntities.length;