1 const debugLog = false;
3 var attackerTemplate = "trigger/fauna_arctic_wolf_attack";
13 * Attackers will focus the targetCount closest units that have the targetClasses type.
15 var targetClasses = "Organic+!Domestic";
18 var disabledTechnologies = [
19 "gather_lumbering_ironaxes",
20 "gather_lumbering_sharpaxes",
21 "gather_lumbering_strongeraxes"
24 Trigger.prototype.InitDisableTechnologies = function()
26 for (let i = 1; i < TriggerHelper.GetNumberOfPlayers(); ++i)
27 QueryPlayerIDInterface(i).SetDisabledTechnologies(disabledTechnologies);
30 Trigger.prototype.SpawnWolvesAndAttack = function()
32 let waveSize = Math.round(Math.random() * (maxWaveSize - minWaveSize) + minWaveSize);
33 let attackers = TriggerHelper.SpawnUnitsFromTriggerPoints("A", attackerTemplate, waveSize, 0);
36 print("Spawned " + waveSize + " " + attackerTemplate + " at " + Object.keys(attackers).length + " points\n");
40 let cmpDamage = Engine.QueryInterface(SYSTEM_ENTITY, IID_Damage);
41 let players = new Array(TriggerHelper.GetNumberOfPlayers()).fill(0).map((v, i) => i + 1);
43 for (let spawnPoint in attackers)
45 // TriggerHelper.SpawnUnits is guaranteed to spawn
46 let firstAttacker = attackers[spawnPoint][0];
50 let cmpAttackerPos = Engine.QueryInterface(firstAttacker, IID_Position);
51 if (!cmpAttackerPos || !cmpAttackerPos.IsInWorld())
54 let attackerPos = cmpAttackerPos.GetPosition2D();
56 // The returned entities are sorted by RangeManager already
57 let targets = cmpDamage.EntitiesNearPoint(attackerPos, 200, players).filter(ent => {
58 let cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
59 return cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses);
62 let goodTargets = targets.slice(0, targetCount);
64 // Look through all targets if there aren't enough nearby ones
65 if (goodTargets.length < targetCount)
68 allTargets = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).GetNonGaiaEntities().filter(ent => {
69 let cmpIdentity = Engine.QueryInterface(ent, IID_Identity);
70 return cmpIdentity && MatchesClassList(cmpIdentity.GetClassesList(), targetClasses);
73 let getDistance = target => {
74 let cmpPositionTarget = Engine.QueryInterface(target, IID_Position);
75 if (!cmpPositionTarget || !cmpPositionTarget.IsInWorld())
77 return attackerPos.distanceToSquared(cmpPositionTarget.GetPosition2D());
82 for (let target of allTargets)
84 let dist = getDistance(target);
85 let i = goodDists.findIndex(element => dist < element);
86 if (i != -1 || goodTargets.length < targetCount)
89 i = goodTargets.length;
90 goodTargets.splice(i, 0, target);
91 goodDists.splice(i, 0, dist);
92 if (goodTargets.length > targetCount)
101 for (let target of goodTargets)
104 "entities": attackers[spawnPoint],
110 this.DoAfterDelay((Math.random() * (maxWaveTime - minWaveTime) + minWaveTime) * 60 * 1000, "SpawnWolvesAndAttack", {});
114 let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
115 cmpTrigger.InitDisableTechnologies();
116 cmpTrigger.DoAfterDelay(firstWaveTime * 60 * 1000, "SpawnWolvesAndAttack", {});