Ticket #3606: IdleRegenRate.patch
File IdleRegenRate.patch, 5.9 KB (added by , 8 years ago) |
---|
-
simulation/ai/petra/researchManager.js
156 156 return tech[0]; 157 157 else if (template.modifications[i].value === "Health/RegenRate") 158 158 return tech[0]; 159 else if (template.modifications[i].value === "Health/IdleRegenRate") 160 return tech[0]; 159 161 } 160 162 } 161 163 return false; -
simulation/components/Health.js
5 5 "<a:example>" + 6 6 "<Max>100</Max>" + 7 7 "<RegenRate>1.0</RegenRate>" + 8 "<IdleRegenRate>0</IdleRegenRate>" + 8 9 "<DeathType>corpse</DeathType>" + 9 10 "</a:example>" + 10 11 "<element name='Max' a:help='Maximum hitpoints'>" + … … 23 24 "<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" + 24 25 "<data type='decimal'/>" + 25 26 "</element>" + 27 "<element name='IdleRegenRate' a:help='Hitpoint regeneration rate per second when idle or garrisoned.'>" + 28 "<data type='decimal'/>" + 29 "</element>" + 26 30 "<element name='DeathType' a:help='Behaviour when the unit dies'>" + 27 31 "<choice>" + 28 32 "<value a:help='Disappear instantly'>vanish</value>" + … … 45 49 // (Allowing 0 initial HP would break our death detection code) 46 50 this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints()); 47 51 this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity); 52 this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity); 48 53 this.CheckRegenTimer(); 49 54 }; 50 55 … … 107 112 return this.template.Undeletable == "true"; 108 113 }; 109 114 115 Health.prototype.GetIdleRegenRate = function() 116 { 117 return this.idleRegenRate; 118 }; 119 110 120 Health.prototype.GetRegenRate = function() 111 121 { 112 122 return this.regenRate; 113 123 }; 114 124 125 Health.prototype.ExecuteIdleRegeneration = function() 126 { 127 let regen = this.GetIdleRegenRate(); 128 let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI); 129 if (!cmpUnitAI || (!cmpUnitAI.IsIdle() && !cmpUnitAI.IsGarrisoned())) 130 return; 131 if (regen > 0) 132 this.Increase(regen); 133 else 134 this.Reduce(-regen); 135 }; 136 115 137 Health.prototype.ExecuteRegeneration = function() 116 138 { 117 varregen = this.GetRegenRate();139 let regen = this.GetRegenRate(); 118 140 if (regen > 0) 119 141 this.Increase(regen); 120 142 else 121 143 this.Reduce(-regen); 144 if(this.GetIdleRegenRate() != 0) 145 this.ExecuteIdleRegeneration(); 122 146 }; 123 147 124 148 /* … … 127 151 Health.prototype.CheckRegenTimer = function() 128 152 { 129 153 // check if we need a timer 130 if ( this.GetRegenRate() == 0||131 this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0||132 this.GetHitpoints() == 0)154 if ((this.GetRegenRate() == 0 && this.GetIdleRegenRate() == 0) || 155 (this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 && this.GetIdleRegenRate() > 0) || 156 this.GetHitpoints() == 0) 133 157 { 134 158 // we don't need a timer, disable if one exists 135 159 if (this.regenTimer) … … 325 349 if (msg.component != "Health") 326 350 return; 327 351 328 varoldMaxHitpoints = this.GetMaxHitpoints();329 varnewMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));352 let oldMaxHitpoints = this.GetMaxHitpoints(); 353 let newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity)); 330 354 if (oldMaxHitpoints != newMaxHitpoints) 331 355 { 332 varnewHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);356 let newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints); 333 357 this.maxHitpoints = newMaxHitpoints; 334 358 this.SetHitpoints(newHitpoints); 335 359 } 336 360 337 varoldRegenRate = this.regenRate;361 let oldRegenRate = this.regenRate; 338 362 this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity); 339 363 340 364 if (this.regenRate != oldRegenRate) 341 365 this.CheckRegenTimer(); 366 367 let oldIdleRegenRate = this.idleRegenRate; 368 this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity); 369 370 if (this.idleRegenRate != oldIdleRegenRate) 371 this.CheckRegenTimer(); 342 372 }; 343 373 344 374 Health.prototype.OnHealthChanged = function() -
simulation/data/technologies/health_regen_units.json
7 7 "icon": "bandage.png", 8 8 "researchTime": 40, 9 9 "tooltip": "Organic units will slowly regenerate health over time when idle.", 10 "modifications": [{"value": "Health/ RegenRate", "add": 0.5}],10 "modifications": [{"value": "Health/Idle", "add": 0.5}], 11 11 "affects": ["Unit Organic"], 12 12 "soundComplete": "interface/alarm/alarm_upgradearmory.xml" 13 13 } -
simulation/templates/template_structure.xml
47 47 <Health> 48 48 <DeathType>corpse</DeathType> 49 49 <RegenRate>0</RegenRate> 50 <IdleRegenRate>0</IdleRegenRate> 50 51 <Undeletable>false</Undeletable> 51 52 <Unhealable>true</Unhealable> 52 53 </Health> -
simulation/templates/template_unit.xml
31 31 <DeathType>corpse</DeathType> 32 32 <Max>100</Max> 33 33 <RegenRate>0</RegenRate> 34 <IdleRegenRate>0</IdleRegenRate> 34 35 <Undeletable>false</Undeletable> 35 36 <Unhealable>false</Unhealable> 36 37 </Health>