diff --git a/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js b/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js index 7cd1198024..c44253060e 100644 --- a/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js +++ b/binaries/data/mods/public/maps/random/survivalofthefittest_triggers.js @@ -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!"),