| 1 | Trigger.prototype.CheckRegicideDefeat = function(data) |
| 2 | { |
| 3 | if (data.entity == this.heroes[data.from]) |
| 4 | TriggerHelper.DefeatPlayer(data.from); |
| 5 | }; |
| 6 | |
| 7 | Trigger.prototype.InitRegicideGame = function(msg) |
| 8 | { |
| 9 | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); |
| 10 | let unitTemplates = cmpTemplateManager.FindAllTemplates(false).filter(temp => temp.substring(0,6) == "units/"); |
| 11 | let heroTemplates = []; |
| 12 | |
| 13 | for (let temp of unitTemplates) |
| 14 | { |
| 15 | let tempClasses = GetIdentityClasses(cmpTemplateManager.GetTemplate(temp).Identity); |
| 16 | if (tempClasses.indexOf("Hero") != -1 && tempClasses.indexOf("Elephant") == -1) |
| 17 | heroTemplates.push(temp); |
| 18 | } |
| 19 | |
| 20 | for (let i = 1; i < TriggerHelper.GetNumberOfPlayers(); ++i) |
| 21 | { |
| 22 | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); |
| 23 | let playerEntities = cmpRangeManager.GetEntitiesByPlayer(i); |
| 24 | let spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "CivilCentre")); |
| 25 | |
| 26 | if (!spawnPoints.length) |
| 27 | spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "Structure")); |
| 28 | |
| 29 | if (!spawnPoints.length) |
| 30 | spawnPoints = playerEntities.filter(p => TriggerHelper.EntityHasClass(p, "Ship")); |
| 31 | |
| 32 | if (!spawnPoints.length) |
| 33 | spawnPoints = playerEntities; |
| 34 | |
| 35 | let cmpPlayer = QueryPlayerIDInterface(i); |
| 36 | let civHeros = heroTemplates.filter(hero => hero.indexOf(cmpPlayer.GetCiv()) != -1); |
| 37 | |
| 38 | this.heroes[i] = TriggerHelper.SpawnUnits(spawnPoints[0], civHeros[Math.floor(Math.random() * civHeros.length)], 1, i); |
| 39 | |
| 40 | if (!this.heroes[i].length) |
| 41 | error("Couldn't spawn hero for player " + i); |
| 42 | |
| 43 | if (TriggerHelper.EntityHasClass(spawnPoints[0], "Ship")) |
| 44 | { |
| 45 | let cmpGarrisonHolder = Engine.QueryInterface(spawnPoints[0], IID_GarrisonHolder); |
| 46 | let cmpUnitAI = Engine.QueryInterface(this.heroes[i], IID_UnitAI); |
| 47 | |
| 48 | if (!cmpGarrisonHolder.IsFull()) |
| 49 | cmpUnitAI.Garrison(spawnPoints[0]); |
| 50 | } |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); |
| 55 | cmpTrigger.heroes = []; |
| 56 | cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); |
| 57 | |
| 58 | cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); |