Ticket #4291: unitAI_isGarrisoned_v2.patch
File unitAI_isGarrisoned_v2.patch, 5.9 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/session/utility_functions.js
function getTradingTooltip(gain) 110 110 * Returns the entity itself except when garrisoned where it returns its garrisonHolder 111 111 */ 112 112 function getEntityOrHolder(ent) 113 113 { 114 114 var entState = GetEntityState(ent); 115 if (entState && !entState.position && entState.unitAI && entState.unitAI.orders.length && 116 (entState.unitAI.orders[0].type == "Garrison" || entState.unitAI.orders[0].type == "Autogarrison")) 117 return entState.unitAI.orders[0].data.target; 115 if (entState && !entState.position && entState.unitAI) 116 return entState.unitAI.isGarrisoned; 118 117 119 118 return ent; 120 119 } 121 120 122 121 /** -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
GarrisonHolder.prototype.PerformGarrison 251 251 252 252 // Check if the unit is allowed to be garrisoned inside the building 253 253 if(!this.AllowedToGarrison(entity)) 254 254 return false; 255 255 256 // check the capacity256 // Check the capacity 257 257 var extraCount = 0; 258 258 var cmpGarrisonHolder = Engine.QueryInterface(entity, IID_GarrisonHolder); 259 259 if (cmpGarrisonHolder) 260 260 extraCount += cmpGarrisonHolder.GetGarrisonedEntitiesCount(); 261 261 if (this.GetGarrisonedEntitiesCount() + extraCount >= this.GetCapacity()) … … GarrisonHolder.prototype.PerformGarrison 276 276 277 277 var cmpAura = Engine.QueryInterface(entity, IID_Auras); 278 278 if (cmpAura && cmpAura.HasGarrisonAura()) 279 279 cmpAura.ApplyGarrisonBonus(this.entity); 280 280 281 // Let entities recall their garrison holder 282 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); 283 if (cmpUnitAI) 284 cmpUnitAI.SetGarrisoned(this.entity); 285 281 286 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] }); 282 287 283 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI);284 288 if (cmpUnitAI && cmpUnitAI.IsUnderAlert()) 285 289 Engine.PostMessage(cmpUnitAI.GetAlertRaiser(), MT_UnitGarrisonedAfterAlert, {"holder": this.entity, "unit": entity}); 286 290 287 291 return true; 288 292 }; … … GarrisonHolder.prototype.OnGlobalInitGam 735 739 return; 736 740 737 741 for (let ent of this.initGarrison) 738 742 { 739 743 let cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 740 if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity) && this.Garrison(ent))741 cmpUnitAI.SetGarrisoned();744 if (cmpUnitAI && cmpUnitAI.CanGarrison(this.entity)) 745 this.Garrison(ent); 742 746 } 743 747 this.initGarrison = undefined; 744 748 }; 745 749 746 750 Engine.RegisterComponentType(IID_GarrisonHolder, "GarrisonHolder", GarrisonHolder); -
binaries/data/mods/public/simulation/components/GuiInterface.js
GuiInterface.prototype.GetEntityState = 372 372 "hasWorkOrders": cmpUnitAI.HasWorkOrders(), 373 373 "canGuard": cmpUnitAI.CanGuard(), 374 374 "isGuarding": cmpUnitAI.IsGuardOf(), 375 375 "possibleStances": cmpUnitAI.GetPossibleStances(), 376 376 "isIdle":cmpUnitAI.IsIdle(), 377 "isGarrisoned": cmpUnitAI.IsGarrisoned() 377 378 }; 378 379 // Add some information needed for ungarrisoning 379 380 if (cmpUnitAI.IsGarrisoned() && ret.player !== undefined) 380 381 ret.template = "p" + ret.player + "&" + ret.template; 381 382 } -
binaries/data/mods/public/simulation/components/Promotion.js
Promotion.prototype.Promote = function(p 81 81 cmpPromotedUnitAI.SetHeldPosition(pos.x, pos.z); 82 82 if (cmpCurrentUnitAI.GetStanceName()) 83 83 cmpPromotedUnitAI.SwitchToStance(cmpCurrentUnitAI.GetStanceName()); 84 84 85 85 var orders = cmpCurrentUnitAI.GetOrders(); 86 if (cmpCurrentUnitAI.IsGarrisoned())87 cmpPromotedUnitAI.SetGarrisoned(); 86 cmpPromotedUnitAI.SetGarrisoned(cmpCurrentUnitAI.IsGarrisoned()); 87 88 88 if (cmpCurrentUnitPosition.IsInWorld()) // do not cheer if not visibly garrisoned 89 89 cmpPromotedUnitAI.Cheer(); 90 90 cmpPromotedUnitAI.AddOrders(orders); 91 91 92 92 var workOrders = cmpCurrentUnitAI.GetWorkOrders(); -
binaries/data/mods/public/simulation/components/UnitAI.js
UnitAI.prototype.UnitFsmSpec = { 2997 2997 { 2998 2998 var cmpGarrisonHolder = Engine.QueryInterface(target, IID_GarrisonHolder); 2999 2999 // Check that garrisoning succeeds 3000 3000 if (cmpGarrisonHolder.Garrison(this.entity)) 3001 3001 { 3002 this.isGarrisoned = true;3003 3004 3002 if (this.formationController) 3005 3003 { 3006 3004 var cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation); 3007 3005 if (cmpFormation) 3008 3006 { … … UnitAI.prototype.UnitFsmSpec = { 3078 3076 }, 3079 3077 }, 3080 3078 3081 3079 "AUTOGARRISON": { 3082 3080 "enter": function() { 3083 this.isGarrisoned = true;3084 3081 return false; 3085 3082 }, 3086 3083 3087 3084 "leave": function() { 3088 3085 } … … UnitAI.prototype.IsIdle = function() 3422 3419 UnitAI.prototype.IsGarrisoned = function() 3423 3420 { 3424 3421 return this.isGarrisoned; 3425 3422 }; 3426 3423 3427 UnitAI.prototype.SetGarrisoned = function( )3424 UnitAI.prototype.SetGarrisoned = function(target) 3428 3425 { 3429 this.isGarrisoned = t rue;3426 this.isGarrisoned = target; 3430 3427 }; 3431 3428 3432 3429 UnitAI.prototype.IsFleeing = function() 3433 3430 { 3434 3431 var state = this.GetCurrentState().split(".").pop();