Ticket #2342: patch_alert_autogarrison_alter.patch
File patch_alert_autogarrison_alter.patch, 4.5 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/components/AlertRaiser.js
11 11 // Remember the units ordered to garrison 12 12 this.garrisonedUnits = []; 13 13 this.walkingUnits = []; 14 15 // Remember production buildings under alert 16 this.prodBuildings = []; 14 17 }; 15 18 16 19 AlertRaiser.prototype.GetLevel = function() … … 34 37 PlaySound(alertString, this.entity); 35 38 }; 36 39 37 AlertRaiser.prototype. IncreaseAlertLevel= function()40 AlertRaiser.prototype.UpdateUnits = function() 38 41 { 39 if(!this.CanIncreaseLevel())40 return false;41 42 42 // Find units owned by this unit's player 43 43 var players = []; 44 44 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 45 45 if (cmpOwnership) 46 46 players = [cmpOwnership.GetOwner()]; 47 48 this.level++;49 this.SoundAlert();50 47 51 48 // Select units to put under alert, ignoring domestic animals (NB : war dogs are not domestic) 52 49 var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); … … 62 59 cmpUnitAI.ReplaceOrder("Alert", {"raiser": this.entity, "force": true}); 63 60 this.walkingUnits.push(unit); 64 61 } 62 } 63 64 AlertRaiser.prototype.IncreaseAlertLevel = function() 65 { 66 if(!this.CanIncreaseLevel()) 67 return false; 68 69 this.level++; 70 this.SoundAlert(); 65 71 72 // Find buildings owned by this unit's player 73 var players = []; 74 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 75 if (cmpOwnership) 76 players = [cmpOwnership.GetOwner()]; 77 78 // Select production buildings to put "under alert", including the raiser itself if possible 79 var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 80 var level = this.GetLevel(); 81 var buildings = rangeMan.ExecuteQuery(this.entity, 0, this.template.Range, players, IID_ProductionQueue); 82 var ownCmpProductionQueue = Engine.QueryInterface(this.entity, IID_ProductionQueue); 83 if (ownCmpProductionQueue) 84 buildings.push(this.entity); 85 86 for each(var building in buildings) 87 { 88 var cmpProductionQueue = Engine.QueryInterface(building, IID_ProductionQueue); 89 cmpProductionQueue.PutUnderAlert(this.entity); 90 this.prodBuildings.push(building); 91 } 92 93 // Put units under alert 94 this.UpdateUnits(); 95 66 96 return true; 67 97 }; 68 98 … … 72 102 73 103 var index = this.walkingUnits.indexOf(msg.unit); 74 104 if (index != -1) 75 this.walkingUnits.splice(index, 1); 76 77 } 105 this.walkingUnits.splice(index, 1); 106 }; 78 107 79 108 AlertRaiser.prototype.EndOfAlert = function() 80 109 { … … 85 114 for each(var unit in this.walkingUnits) 86 115 { 87 116 var cmpUnitAI = Engine.QueryInterface(unit, IID_UnitAI); 117 if(!cmpUnitAI) 118 continue; 88 119 89 120 cmpUnitAI.ResetAlert(); 90 121 … … 100 131 { 101 132 var cmpGarrisonHolder = Engine.QueryInterface(slot.holder, IID_GarrisonHolder); 102 133 var cmpUnitAI = Engine.QueryInterface(slot.unit, IID_UnitAI); 134 if(!cmpUnitAI) 135 continue; 103 136 104 137 if(cmpGarrisonHolder && cmpGarrisonHolder.PerformEject([slot.unit], true)) 105 138 { … … 110 143 } 111 144 this.garrisonedUnits = []; 112 145 146 // Finally, reset production buildings state 147 for each(var building in this.prodBuildings) 148 { 149 var cmpProductionQueue = Engine.QueryInterface(building, IID_ProductionQueue); 150 if(!cmpProductionQueue) 151 continue; 152 153 cmpProductionQueue.ResetAlert(); 154 } 155 this.prodBuildings = []; 156 113 157 return true; 114 158 }; 115 159 -
binaries/data/mods/public/simulation/components/ProductionQueue.js
65 65 66 66 this.entityCache = []; 67 67 this.spawnNotified = false; 68 69 this.alertRaiser = undefined; 68 70 }; 69 71 72 ProductionQueue.prototype.PutUnderAlert = function(raiser) 73 { 74 this.alertRaiser = raiser; 75 }; 76 77 ProductionQueue.prototype.ResetAlert = function() 78 { 79 this.alertRaiser = undefined; 80 }; 81 70 82 /* 71 83 * Returns list of entities that can be trained by this building. 72 84 */ … … 592 604 "owner": cmpOwnership.GetOwner(), 593 605 "metadata": metadata, 594 606 }); 607 608 if(this.alertRaiser) 609 { 610 var cmpAlertRaiser = Engine.QueryInterface(this.alertRaiser, IID_AlertRaiser); 611 if(cmpAlertRaiser) 612 cmpAlertRaiser.UpdateUnits(); 613 } 595 614 } 596 615 597 616 return createdEnts.length;