Ticket #3488: 3488.5 - Testcase.diff
File 3488.5 - Testcase.diff, 8.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/BuildingAI.js
32 32 33 33 BuildingAI.prototype.OnGarrisonedUnitsChanged = function(msg) 34 34 { 35 if(msg.visible) 36 return; 35 37 let classes = this.template.GarrisonArrowClasses; 36 38 37 39 for (let ent of msg.added) -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
1 /** 2 * @class Defines an entity's ability to garrison units. 3 */ 1 4 function GarrisonHolder() {} 2 5 3 6 GarrisonHolder.prototype.Schema = … … 45 48 "<element name='Z'>" + 46 49 "<data type='decimal'/>" + 47 50 "</element>" + 51 "<optional>" + 52 "<element name='VisibleGarrisonAllowedClasses'>" + 53 "<attribute name='datatype'>" + 54 "<value>tokens</value>" + 55 "</attribute>" + 56 "<text/>" + 57 "</element>" + 58 "</optional>" + 48 59 "</interleave>" + 49 60 "</element>" + 50 61 "</zeroOrMore>" + … … 72 83 o.x = +offset.X; 73 84 o.y = +offset.Y; 74 85 o.z = +offset.Z; 75 this.visibleGarrisonPoints.push({ "offset":o, "entity": null});86 this.visibleGarrisonPoints.push({ "offset": o, "entity": null, "allowedClass": offset.VisibleGarrisonAllowedClasses }); 76 87 } 77 88 } 78 89 }; … … 100 111 return IsOwnedByPlayer(player, ent); 101 112 }; 102 113 103 104 114 /** 105 115 * Return the list of entities garrisoned inside 106 116 */ … … 204 214 }; 205 215 206 216 /** 217 * Returns true if the unit is allowed be visible on that garrison point, false otherwise. 218 */ 219 GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(visibleGarrisonPoint, entity) 220 { 221 let allowedClassesList = visibleGarrisonPoint.allowedClass._string; 222 // If classlist is empty, everybody can garrison. 223 if (!allowedClassesList) 224 return true; 225 226 return MatchesClassList(Engine.QueryInterface(entity, IID_Identity).GetClassesList(), allowedClassesList); 227 }; 228 229 /** 207 230 * Garrison a unit inside. 208 231 * Returns true if successful, false if not 209 232 * The timer for AutoHeal is started here … … 229 252 break; 230 253 } 231 254 } 232 233 255 if (visibleGarrisonPoint) 234 { 235 visibleGarrisonPoint.entity = entity; 236 cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset); 237 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 238 if (cmpUnitAI) 239 cmpUnitAI.SetTurretStance(); 256 { 257 if (this.AllowedToVisibleGarrisoning(visibleGarrisonPoint, entity)) 258 { 259 visibleGarrisonPoint.entity = entity; 260 cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset); 261 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 262 if (cmpUnitAI) 263 cmpUnitAI.SetTurretStance(); 264 } 265 else 266 cmpPosition.MoveOutOfWorld(); 240 267 } 241 268 else 242 269 cmpPosition.MoveOutOfWorld(); 243 270 // Should only be called after the garrison has been performed else the visible Garrison Points are not updated yet. 271 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [entity], "visible": this.IsVisiblyGarrisoned(entity), "removed": [] }); 244 272 return true; 245 273 }; 246 274 275 /** 276 * Garrison units inside the entity 277 * @return true if successful, false if not 278 */ 247 279 GarrisonHolder.prototype.PerformGarrison = function(entity) 248 280 { 249 281 if (!this.HasEnoughHealth()) … … 250 282 return false; 251 283 252 284 // Check if the unit is allowed to be garrisoned inside the building 253 if (!this.AllowedToGarrison(entity))285 if (!this.AllowedToGarrison(entity)) 254 286 return false; 255 287 256 // check the capacity288 // Check the capacity 257 289 var extraCount = 0; 258 290 var cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); 259 291 if (cmpGarrisonHolder) … … 278 310 if (cmpAura && cmpAura.HasGarrisonAura()) 279 311 cmpAura.ApplyGarrisonBonus(this.entity); 280 312 281 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] });282 283 313 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 284 314 if (cmpUnitAI && cmpUnitAI.IsUnderAlert()) 285 315 Engine.PostMessage(cmpUnitAI.GetAlertRaiser(), MT_UnitGarrisonedAfterAlert, {"holder": this.entity, "unit": entity}); … … 326 356 327 357 var cmpNewPosition = Engine.QueryInterface(entity, IID_Position); 328 358 this.entities.splice(entityIndex, 1); 329 359 // Should only be called before the ejection has been performed else the visible Garrison Points will be empty. 360 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [], "visible": this.IsVisiblyGarrisoned(entity), "removed": [entity] }); 330 361 for (var vgp of this.visibleGarrisonPoints) 331 362 { 332 363 if (vgp.entity != entity) … … 356 387 cmpNewPosition.SetHeightOffset(0); 357 388 // TODO: what direction should they face in? 358 389 359 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [entity] });360 390 361 391 return true; 362 392 }; … … 620 650 if (cmpHealth && cmpHealth.GetHitpoints() == 0) 621 651 { 622 652 this.entities.splice(entityIndex, 1); 623 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] });653 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [], "visible": this.IsVisiblyGarrisoned(entity), "removed": [msg.entity] }); 624 654 this.UpdateGarrisonFlag(); 625 655 626 656 for (var pt of this.visibleGarrisonPoints) … … 634 664 635 665 /** 636 666 * Update list of garrisoned entities if one gets renamed (e.g. by promotion) 667 * vgpEntity is only defined in some peculiar case where we want to reuse the same visibleGarrisonPoint, 668 * in case of promotion for example, and thus should always be allowed. 637 669 */ 638 670 GarrisonHolder.prototype.OnGlobalEntityRenamed = function(msg) 639 671 { … … 670 702 } 671 703 }; 672 704 673 674 705 /** 675 706 * Eject all foreign garrisoned entities which are no more allied 676 707 */ … … 712 743 } 713 744 714 745 if (killedEntities.length > 0) 715 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed" : killedEntities }); 746 for (let entity of killedEntities) 747 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added": [], "visible": this.IsVisiblyGarrisoned(entity), "removed" : [entity] }); 716 748 this.UpdateGarrisonFlag(); 717 749 }; 718 750 719 751 /** 752 * Gives insight about the unit type of garrisoning. 753 * @return{bool} returns true if the unit is visible on the structure 754 * @param {int} the entity's id 755 */ 756 GarrisonHolder.prototype.IsVisiblyGarrisoned = function(entity) 757 { 758 return this.visibleGarrisonPoints.some(point => point.entity === entity); 759 }; 760 761 /** 720 762 * Checks if an entity is ejectable on destroy if possible 721 763 */ 722 764 GarrisonHolder.prototype.IsEjectable = function(entity) -
binaries/data/mods/public/simulation/templates/structures/maur_fortress.xml
5 5 <SpecificName>Durg</SpecificName> 6 6 <Tooltip>Train heroes and champion units.</Tooltip> 7 7 </Identity> 8 <GarrisonHolder> 9 <Max>150</Max> 10 <List datatype="tokens"> 11 Ranged 12 Infantry 13 Cavalry 14 Elephant 15 </List> 16 <EjectHealth>0.1</EjectHealth> 17 <EjectClassesOnDestroy datatype="tokens">Unit</EjectClassesOnDestroy> 18 <BuffHeal>0</BuffHeal> 19 <LoadingRange>2</LoadingRange> 20 <VisibleGarrisonPoints> 21 <Archer1> 22 <X>10.5</X><Y>13.75</Y><Z>-9.5</Z> 23 <VisibleGarrisonAllowedClasses datatype="tokens"> 24 Infantry+Ranged 25 </VisibleGarrisonAllowedClasses> 26 </Archer1> 27 <Archer2> 28 <X>-10.5</X><Y>13.75</Y><Z>9.5</Z> 29 <VisibleGarrisonAllowedClasses datatype="tokens"> 30 Infantry+Ranged 31 </VisibleGarrisonAllowedClasses> 32 </Archer2> 33 <Archer3> 34 <X>-10.5</X><Y>13.75</Y><Z>-9.5</Z> 35 <VisibleGarrisonAllowedClasses datatype="tokens"> 36 Infantry+Ranged 37 </VisibleGarrisonAllowedClasses> 38 </Archer3> 39 <Archer4> 40 <X>10.5</X><Y>13.75</Y><Z>9.5</Z> 41 <VisibleGarrisonAllowedClasses datatype="tokens"> 42 Ranged+Catapult 43 </VisibleGarrisonAllowedClasses> 44 </Archer4> 45 </VisibleGarrisonPoints> 46 </GarrisonHolder> 8 47 <ProductionQueue> 9 48 <Entities datatype="tokens"> 10 49 units/{civ}_hero_chanakya