Ticket #1907: corral.diff
File corral.diff, 7.8 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/GarrisonHolder.js
10 10 "</attribute>" + 11 11 "<text/>" + 12 12 "</element>" + 13 "<element name='EjectHealth' a:help=' Percentageof maximum health below which this holder no longer allows garrisoning'>" +13 "<element name='EjectHealth' a:help='Fraction of maximum health below which this holder no longer allows garrisoning'>" + 14 14 "<ref name='nonNegativeDecimal'/>" + 15 15 "</element>" + 16 16 "<element name='BuffHeal' a:help='Number of hit points that will be restored to this holder's garrisoned units each second'>" + … … 18 18 "</element>" + 19 19 "<element name='LoadingRange' a:help='The maximum distance from this holder at which entities are allowed to garrison. Should be about 2.0 for land entities and preferably greater for ships'>" + 20 20 "<ref name='nonNegativeDecimal'/>" + 21 "</element>"; 21 "</element>" + 22 "<optional>" + 23 "<element name='FoodProduction' a:help='Fraction of food that will be produced by this holder's garrisoned units each second'>" + 24 "<ref name='nonNegativeDecimal'/>" + 25 "</element>" + 26 "</optional>"; 22 27 23 28 /** 24 29 * Initialize GarrisonHolder Component … … 28 33 // Garrisoned Units 29 34 this.entities = []; 30 35 this.spaceOccupied = 0; 31 this.timer = undefined; 36 this.healTimer = undefined; 37 this.foodTimer = undefined; 32 38 }; 33 39 34 40 /** … … 75 81 }; 76 82 77 83 /** 84 * Get the heal rate with which garrisoned units will be healed 85 */ 86 GarrisonHolder.prototype.GetFoodRate = function() 87 { 88 if(this.template.FoodProduction) 89 { 90 var foodRate = +this.template.FoodProduction; 91 return ApplyTechModificationsToEntity("GarrisonHolder/FoodProduction", foodRate, this.entity); 92 } 93 else 94 return 0; 95 }; 96 97 /** 78 98 * Get number of garrisoned units capable of shooting arrows 79 99 * Not necessarily archers 80 100 */ … … 113 133 /** 114 134 * Garrison a unit inside. 115 135 * Returns true if successful, false if not 116 * The timer for AutoHeal isstarted here136 * The timers for AutoHeal and food production are started here 117 137 */ 118 138 GarrisonHolder.prototype.Garrison = function(entity) 119 139 { … … 130 150 if (this.GetCapacity() < this.spaceOccupied + 1) 131 151 return false; 132 152 133 if (!this. timer && this.GetHealRate() > 0)153 if (!this.healTimer && this.GetHealRate() > 0) 134 154 { 135 155 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 136 this. timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {});156 this.healTimer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); 137 157 } 138 158 159 if (!this.foodTimer && this.GetFoodRate() > 0) 160 { 161 this.foodProduced = 0; 162 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 163 this.foodTimer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "FoodTimeout", 1000, {}); 164 } 165 139 166 var cmpPosition = Engine.QueryInterface(entity, IID_Position); 140 167 if (cmpPosition) 141 168 { … … 383 410 if (this.entities.length == 0) 384 411 { 385 412 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 386 cmpTimer.CancelTimer(this. timer);387 this. timer = undefined;413 cmpTimer.CancelTimer(this.healTimer); 414 this.healTimer = undefined; 388 415 } 389 416 else 390 417 { … … 399 426 } 400 427 } 401 428 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 402 this. timer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {});429 this.healTimer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "HealTimeout", 1000, {}); 403 430 } 404 431 }; 405 432 433 /** 434 * Called every second. Produce food (in corrals) 435 */ 436 GarrisonHolder.prototype.FoodTimeout = function(data) 437 { 438 if (this.entities.length == 0) 439 { 440 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 441 cmpTimer.CancelTimer(this.foodTimer); 442 this.foodTimer = undefined; 443 } 444 else 445 { 446 var totalFood = 0; 447 for each (var entity in this.entities) 448 { 449 var cmpResourceSupply = Engine.QueryInterface(entity, IID_ResourceSupply); 450 if (cmpResourceSupply && cmpResourceSupply.GetType().generic == "food") 451 totalFood += cmpResourceSupply.GetMaxAmount(); 452 } 453 this.foodProduced += Math.round(totalFood*this.GetFoodRate()*100000); 454 if (this.foodProduced >= 100000) 455 { 456 var newFood = parseInt(this.foodProduced/100000); 457 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 458 cmpPlayer.AddResource("food", newFood); 459 var cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 460 if (cmpStatisticsTracker) 461 cmpStatisticsTracker.IncreaseResourceGatheredCounter("food", newFood, "meat"); 462 this.foodProduced -= newFood*100000; 463 } 464 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 465 this.foodTimer = cmpTimer.SetTimeout(this.entity, IID_GarrisonHolder, "FoodTimeout", 1000, {}); 466 } 467 }; 468 406 469 GarrisonHolder.prototype.UpdateGarrisonFlag = function() 407 470 { 408 471 var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); … … 422 485 */ 423 486 GarrisonHolder.prototype.OnDestroy = function() 424 487 { 425 if (this. timer)488 if (this.healTimer) 426 489 { 427 490 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 428 cmpTimer.CancelTimer(this. timer);491 cmpTimer.CancelTimer(this.healTimer); 429 492 } 493 if (this.foodTimer) 494 { 495 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 496 cmpTimer.CancelTimer(this.foodTimer); 497 } 430 498 }; 431 499 432 500 /** -
binaries/data/mods/public/simulation/components/UnitAI.js
599 599 600 600 if (this.MoveToTarget(this.order.data.target)) 601 601 { 602 this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); 602 if (this.IsAnimal()) 603 this.SetNextState("ANIMAL.GARRISON.APPROACHING"); 604 else 605 this.SetNextState("INDIVIDUAL.GARRISON.APPROACHING"); 603 606 } 604 607 else 605 608 { 606 609 // We do a range check before actually garrisoning 607 610 this.StopMoving(); 608 this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); 611 if (this.IsAnimal()) 612 this.SetNextState("ANIMAL.GARRISON.GARRISONED"); 613 else 614 this.SetNextState("INDIVIDUAL.GARRISON.GARRISONED"); 609 615 } 610 616 }, 611 617 … … 2429 2435 2430 2436 "WALKING": "INDIVIDUAL.WALKING", // reuse the same walking behaviour for animals 2431 2437 // only used for domestic animals 2438 2439 "GARRISON": "INDIVIDUAL.GARRISON", // reuse the same garrison behaviour for animals 2440 // only used for domestic animals 2441 2432 2442 }, 2433 2443 }; 2434 2444 … … 4217 4227 if (!cmpOwnership || !(IsOwnedByPlayer(cmpOwnership.GetOwner(), target) || IsOwnedByMutualAllyOfPlayer(cmpOwnership.GetOwner(), target))) 4218 4228 return false; 4219 4229 4220 // Don't let animals garrison for now 4221 // (If we want to support that, we'll need to change Order.Garrison so it 4222 // doesn't move the animal into an INVIDIDUAL.* state) 4223 if (this.IsAnimal()) 4230 // Don't let non domestic animals garrison for now 4231 if (this.IsAnimal() && !this.IsDomestic()) 4224 4232 return false; 4225 4233 4226 4234 return true; -
binaries/data/mods/public/simulation/templates/template_structure_resource_corral.xml
12 12 </Footprint> 13 13 <GarrisonHolder> 14 14 <Max>10</Max> 15 <EjectHealth>0. 1</EjectHealth>15 <EjectHealth>0.7</EjectHealth> 16 16 <List datatype="tokens">Animal</List> 17 17 <BuffHeal>1</BuffHeal> 18 18 <LoadingRange>2</LoadingRange> 19 <FoodProduction>0.002</FoodProduction> 19 20 </GarrisonHolder> 20 21 <Health> 21 22 <Max>500</Max>