Don't spawn units for defeated players and players who won on survival of the fittest. Refs #3102.

The previous code errored as the trigger point became gaia, consequently
trying to access the undefined playerCivicCenter of gaia.
Remove two useless loops by sending the command for all entities instead
of one command for each entity.
Rename attackerEntities to attackerTemplates and attackerCount to
attackersPerTemplate.

This was SVN commit r18913.
This commit is contained in:
elexis 2016-11-06 01:46:56 +00:00
parent d124b32f6a
commit 0555ace16e

View File

@ -88,40 +88,42 @@ var attackerEntityTemplates =
Trigger.prototype.StartAnEnemyWave = function()
{
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
let attackerEntities = attackerEntityTemplates[Math.floor(Math.random() * attackerEntityTemplates.length)];
let attackerTemplates = attackerEntityTemplates[Math.floor(Math.random() * attackerEntityTemplates.length)];
// A soldier for each 2-3 minutes of the game. Should be waves of 20 soldiers after an hour
let nextTime = Math.round(120000 + Math.random() * 60000);
let attackerCount = Math.round(cmpTimer.GetTime() / nextTime / attackerEntities.length);
let attackersPerTemplate = Math.round(cmpTimer.GetTime() / nextTime / attackerTemplates.length);
let spawned = false;
// spawn attackers
let attackers = [];
for (let attackerEntity of attackerEntities)
attackers.push(TriggerHelper.SpawnUnitsFromTriggerPoints("A", attackerEntity, attackerCount, 0));
for (let entityType of attackers)
for (let point of this.GetTriggerPoints("A"))
{
for (let origin in entityType)
let cmpPlayer = QueryOwnerInterface(point, IID_Player);
if (cmpPlayer.GetPlayerID() == 0 || cmpPlayer.GetState() != "active")
continue;
let cmpPosition = Engine.QueryInterface(this.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position);
if (!cmpPosition || !cmpPosition.IsInWorld)
continue;
let targetPos = cmpPosition.GetPosition();
for (let template of attackerTemplates)
{
let cmpPlayer = QueryOwnerInterface(+origin, IID_Player);
if (cmpPlayer.GetState() != "active")
continue;
let entities = TriggerHelper.SpawnUnits(point, template, attackersPerTemplate, 0);
let cmpPosition = Engine.QueryInterface(this.playerCivicCenter[cmpPlayer.GetPlayerID()], IID_Position);
// this shouldn't happen if the player is still active
if (!cmpPosition || !cmpPosition.IsInWorld)
continue;
// store the x and z coordinates in the command
let cmd = cmpPosition.GetPosition();
cmd.type = "attack-walk";
cmd.entities = entityType[origin];
cmd.queued = true;
cmd.targetClasses = undefined;
// send the attack-walk command
ProcessCommand(0, cmd);
ProcessCommand(0, {
"type": "attack-walk",
"entities": entities,
"x": targetPos.x,
"z": targetPos.z,
"queued": true,
"targetClasses": undefined
});
}
spawned = true;
}
if (!spawned)
return;
let cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
cmpGUIInterface.PushNotification({
"message": markForTranslation("An enemy wave is attacking!"),