Ticket #3488: 3488 - TestCase.patch
File 3488 - TestCase.patch, 4.3 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GarrisonHolder.js
45 45 "<element name='Z'>" + 46 46 "<data type='decimal'/>" + 47 47 "</element>" + 48 "<optional>" + 49 "<element name='VisibleGarrisonAllowedClasses'>" + 50 "<attribute name='datatype'>" + 51 "<value>tokens</value>" + 52 "</attribute>" + 53 "<text/>" + 54 "</element>" + 55 "</optional>" + 48 56 "</interleave>" + 49 57 "</element>" + 50 58 "</zeroOrMore>" + … … 72 80 o.x = +offset.X; 73 81 o.y = +offset.Y; 74 82 o.z = +offset.Z; 75 this.visibleGarrisonPoints.push({"offset":o, "entity": null });83 this.visibleGarrisonPoints.push({"offset":o, "entity": null,"allowedClass" : offset.VisibleGarrisonAllowedClasses}); 76 84 } 77 85 } 78 86 }; … … 100 108 return IsOwnedByPlayer(player, ent); 101 109 }; 102 110 103 104 111 /** 105 112 * Return the list of entities garrisoned inside 106 113 */ … … 221 228 }; 222 229 223 230 /** 231 * Returns an array of restricted classes from the original string. 232 */ 233 GarrisonHolder.prototype.GetVisibleGarrisonAllowedClasses = function(classList) 234 { 235 if (classList) 236 return classList._string.split(/\s+/); 237 238 return []; 239 }; 240 241 /** 242 * Returns true if the unit is allowed be visible on that garrison point, false otherwise. 243 */ 244 GarrisonHolder.prototype.AllowedToVisibleGarrisoning = function(visibleGarrisonPoint) 245 { 246 var allowedClassesList = this.GetVisibleGarrisonAllowedClasses(visibleGarrisonPoint.allowedClass); 247 //If classlist is empty, everybody can garrison. 248 if (!allowedClassesList) 249 return true; 250 251 var entityClasses = (Engine.QueryInterface(visibleGarrisonPoint.entity, IID_Identity)).GetClassesList(); 252 for (let allowedClasses of allowedClassesList) 253 if(entityClasses.indexOf(allowedClasses) == -1) 254 return false 255 256 return true; 257 } 258 259 /** 224 260 * Garrison a unit inside. 225 261 * Returns true if successful, false if not 226 262 * The timer for AutoHeal is started here … … 246 282 break; 247 283 } 248 284 } 249 250 285 if (visibleGarrisonPoint) 251 286 { 252 287 visibleGarrisonPoint.entity = entity; 253 cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset); 254 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 255 if (cmpUnitAI) 256 cmpUnitAI.SetTurretStance(); 288 let IsAllowed = this.AllowedToVisibleGarrisoning(visibleGarrisonPoint); 289 290 if (IsAllowed) 291 { 292 cmpPosition.SetTurretParent(this.entity, visibleGarrisonPoint.offset); 293 let cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 294 if (cmpUnitAI) 295 cmpUnitAI.SetTurretStance(); 296 } 297 else 298 { 299 visibleGarrisonPoint.entity = undefined; // We have to undefine the garrison point else it's marked as used. 300 cmpPosition.MoveOutOfWorld(); 301 } 257 302 } 258 303 else 259 304 cmpPosition.MoveOutOfWorld(); 260 261 305 return true; 262 306 }; 263 307 … … 713 757 } 714 758 }; 715 759 716 717 760 /** 718 761 * Eject all foreign garrisoned entities which are no more allied 719 762 */ -
binaries/data/mods/public/simulation/templates/structures/maur_fortress.xml
6 6 <History>Fortress.</History> 7 7 <Tooltip>Train heroes and champion units.</Tooltip> 8 8 </Identity> 9 <GarrisonHolder> 10 <Max>150</Max> 11 <List datatype="tokens"> 12 Ranged 13 Infantry 14 Cavalry 15 Elephant 16 </List> 17 <EjectHealth>0.1</EjectHealth> 18 <EjectClassesOnDestroy datatype="tokens">Unit</EjectClassesOnDestroy> 19 <BuffHeal>0</BuffHeal> 20 <LoadingRange>2</LoadingRange> 21 <VisibleGarrisonPoints> 22 <Archer1> 23 <X>10.5</X><Y>13.75</Y><Z>9.5</Z> 24 <VisibleGarrisonAllowedClasses datatype="tokens"> 25 Infantry 26 Ranged 27 </VisibleGarrisonAllowedClasses> 28 </Archer1> 29 </VisibleGarrisonPoints> 30 </GarrisonHolder> 9 31 <ProductionQueue> 10 32 <Entities datatype="tokens"> 11 33 units/{civ}_hero_chanakya