Ticket #2051: regeneration.diff
File regeneration.diff, 21.3 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Health.js
20 20 "<text/>" + 21 21 "</element>" + 22 22 "</optional>" + 23 "<element name='RegenRate' a:help='Hitpoint regeneration rate per second. Not yet implemented'>" +24 "< ref name='nonNegativeDecimal'/>" +23 "<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" + 24 "<data type='decimal'/>" + 25 25 "</element>" + 26 26 "<element name='DeathType' a:help='Behaviour when the unit dies'>" + 27 27 "<choice>" + … … 44 44 // Default to <Initial>, but use <Max> if it's undefined or zero 45 45 // (Allowing 0 initial HP would break our death detection code) 46 46 this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints()); 47 this.regenRate = +this.template.RegenRate; 47 48 }; 48 49 49 50 //// Interface functions //// … … 95 96 || this.GetHitpoints() >= this.GetMaxHitpoints()); 96 97 }; 97 98 99 Health.prototype.GetRegenRate = function() 100 { 101 return this.regenRate; 102 }; 103 104 Health.prototype.ExecuteRegeneration = function() 105 { 106 var regen = this.GetRegenRate(); 107 if (regen > 0) 108 this.Increase(regen); 109 else 110 this.Reduce(-regen); 111 }; 112 113 /* 114 * Check if the regeneration timer needs to be started or stopped 115 */ 116 Health.prototype.CheckRegenTimer = function() 117 { 118 // check if we need a timer 119 if (this.GetRegenRate() == 0 || 120 this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 || 121 this.GetHitpoints() == 0) 122 { 123 // we don't need a timer, disable if one exists 124 if (this.regenTimer) 125 { 126 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 127 cmpTimer.CancelTimer(this.regenTimer); 128 this.regenTimer = undefined; 129 } 130 return; 131 } 132 133 // we need a timer, enable is one doesn't exist 134 if (this.regenTimer) 135 return; 136 137 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 138 this.regenTimer = cmpTimer.SetInterval(this.entity, IID_Health, "ExecuteRegeneration", 1000, 1000, null); 139 }; 140 98 141 Health.prototype.Kill = function() 99 142 { 100 143 this.Reduce(this.hitpoints); … … 164 207 165 208 Health.prototype.Increase = function(amount) 166 209 { 210 if (this.hitpoints == this.GetMaxHitpoints()) 211 { 212 return {"old": this.hitpoints, "new":this.hitpoints}; 213 } 214 167 215 // If we're already dead, don't allow resurrection 168 216 if (this.hitpoints == 0) 169 217 return undefined; … … 284 332 { 285 333 if (msg.component == "Health") 286 334 { 287 var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); 288 if (cmpTechnologyManager) 335 var oldMaxHitpoints = this.GetMaxHitpoints(); 336 var newMaxHitpoints = Math.round(ApplyTechModificationsToEntity("Health/Max", +this.template.Max, this.entity)); 337 if (oldMaxHitpoints != newMaxHitpoints) 289 338 { 290 var oldMaxHitpoints = this.GetMaxHitpoints(); 291 var newMaxHitpoints = Math.round(ApplyTechModificationsToEntity("Health/Max", +this.template.Max, this.entity)); 292 if (oldMaxHitpoints != newMaxHitpoints) 293 { 294 var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints); 295 this.maxHitpoints = newMaxHitpoints; 296 this.SetHitpoints(newHitpoints); 297 } 339 var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints); 340 this.maxHitpoints = newMaxHitpoints; 341 this.SetHitpoints(newHitpoints); 298 342 } 343 344 var oldRegenRate = this.regenRate; 345 this.regenRate = ApplyTechModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity); 346 347 if (this.regenRate != oldRegenRate) 348 this.CheckRegenTimer(); 299 349 } 300 350 }; 301 351 352 Health.prototype.OnHealthChanged = function() 353 { 354 this.CheckRegenTimer(); 355 }; 356 302 357 Engine.RegisterComponentType(IID_Health, "Health", Health); -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant.xml
6 6 </Footprint> 7 7 <Health> 8 8 <Max>200</Max> 9 <RegenRate>1</RegenRate>10 9 </Health> 11 10 <Identity> 12 11 <Civ>gaia</Civ> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_african_bush.xml
39 39 </Footprint> 40 40 <Health> 41 41 <Max>300</Max> 42 <RegenRate>1</RegenRate>43 42 </Health> 44 43 <Identity> 45 44 <Civ>gaia</Civ> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_asian.xml
39 39 </Footprint> 40 40 <Health> 41 41 <Max>250</Max> 42 <RegenRate>1</RegenRate>43 42 </Health> 44 43 <Identity> 45 44 <Civ>gaia</Civ> -
binaries/data/mods/public/simulation/templates/gaia/fauna_elephant_north_african.xml
26 26 </Footprint> 27 27 <Health> 28 28 <Max>200</Max> 29 <RegenRate>1</RegenRate>30 29 </Health> 31 30 <Identity> 32 31 <Civ>gaia</Civ> -
binaries/data/mods/public/simulation/templates/gaia/fauna_giraffe.xml
6 6 </Footprint> 7 7 <Health> 8 8 <Max>150</Max> 9 <RegenRate>1</RegenRate>10 9 </Health> 11 10 <Identity> 12 11 <Civ>gaia</Civ> -
binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
26 26 </Footprint> 27 27 <Health> 28 28 <Max>130</Max> 29 <RegenRate>0.2</RegenRate>30 29 </Health> 31 30 <Identity> 32 31 <Classes datatype="tokens">Cavalry CitizenSoldier Organic</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_champion.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_unit"> 3 3 <Health> 4 <RegenRate>0. 4</RegenRate>4 <RegenRate>0.1</RegenRate> 5 5 </Health> 6 6 <Identity> 7 7 <GenericName>Champion Unit</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt_whale.xml
3 3 <Health> 4 4 <Max>100</Max> 5 5 <DeathType>remain</DeathType> 6 <RegenRate>1</RegenRate>7 6 <Unhealable>true</Unhealable> 8 7 <Repairable>false</Repairable> 9 8 </Health> -
binaries/data/mods/public/simulation/templates/template_unit_hero.xml
31 31 </Cost> 32 32 <Health> 33 33 <Max>600</Max> 34 <RegenRate>0. 5</RegenRate>34 <RegenRate>0.2</RegenRate> 35 35 </Health> 36 36 <Identity> 37 37 <GenericName>Hero</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry.xml
35 35 </Footprint> 36 36 <Health> 37 37 <Max>800</Max> 38 <RegenRate>0.5</RegenRate>39 38 </Health> 40 39 <Identity> 41 40 <GenericName>Hero Cavalry</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_archer.xml
42 42 </Footprint> 43 43 <Health> 44 44 <Max>800</Max> 45 <RegenRate>0.5</RegenRate>46 45 </Health> 47 46 <Identity> 48 47 <Classes datatype="tokens">Hero Bow -Javelin</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_hero_cavalry_javelinist.xml
34 34 </Footprint> 35 35 <Health> 36 36 <Max>800</Max> 37 <RegenRate>0.5</RegenRate>38 37 </Health> 39 38 <Identity> 40 39 <Classes datatype="tokens">Hero</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry.xml
33 33 </Footprint> 34 34 <Health> 35 35 <Max>600</Max> 36 <RegenRate>0.5</RegenRate>37 36 </Health> 38 37 <Identity> 39 38 <Classes datatype="tokens">Hero Infantry</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_archer.xml
34 34 </Footprint> 35 35 <Health> 36 36 <Max>600</Max> 37 <RegenRate>0.5</RegenRate>38 37 </Health> 39 38 <Identity> 40 39 <GenericName>Hero Archer</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_hero_infantry_javelinist.xml
40 40 </Footprint> 41 41 <Health> 42 42 <Max>600</Max> 43 <RegenRate>0.5</RegenRate>44 43 </Health> 45 44 <Identity> 46 45 <Classes datatype="tokens">Hero</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_hero_ranged.xml
26 26 </Cost> 27 27 <Health> 28 28 <Max>500</Max> 29 <RegenRate>0.2</RegenRate>30 29 </Health> 31 30 <Identity> 32 31 <GenericName>Hero</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
44 44 </Footprint> 45 45 <Health> 46 46 <Max>100</Max> 47 <RegenRate>0.2</RegenRate>48 47 </Health> 49 48 <Identity> 50 49 <GenericName>Infantry</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_infantry_melee.xml
25 25 </Cost> 26 26 <Health> 27 27 <Max>100</Max> 28 <RegenRate>0.2</RegenRate>29 28 </Health> 30 29 <Identity> 31 30 <GenericName>Melee Infantry</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_infantry_ranged.xml
17 17 </Attack> 18 18 <Health> 19 19 <Max>90</Max> 20 <RegenRate>0.2</RegenRate>21 20 </Health> 22 21 <Identity> 23 22 <GenericName>Ranged</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml
28 28 </Footprint> 29 29 <Health> 30 30 <Max>500</Max> 31 <RegenRate>-3</RegenRate> 31 32 </Health> 32 33 <Identity> 33 34 <GenericName>Fire Ship</GenericName> … … 42 43 <BarHeight>0.5</BarHeight> 43 44 <HeightOffset>6.0</HeightOffset> 44 45 </StatusBars> 45 <TerritoryDecay>46 <HealthDecayRate>3</HealthDecayRate>47 </TerritoryDecay>48 46 <ResourceGatherer disable=""/> 49 47 <UnitMotion> 50 48 <WalkSpeed>16.0</WalkSpeed> -
binaries/data/mods/public/simulation/templates/template_unit_support.xml
8 8 <Cost> 9 9 <BuildTime>15</BuildTime> 10 10 </Cost> 11 <Health>12 <RegenRate>0.2</RegenRate>13 </Health>14 11 <Identity> 15 12 <GenericName>Support</GenericName> 16 13 <Classes datatype="tokens">Support Organic</Classes> -
binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
47 47 </Cost> 48 48 <Health> 49 49 <Max>75</Max> 50 <RegenRate>0.3</RegenRate>51 50 </Health> 52 51 <Identity> 53 52 <GenericName>Female Citizen</GenericName> -
binaries/data/mods/public/simulation/templates/template_unit_support_healer.xml
14 14 </Cost> 15 15 <Health> 16 16 <Max>85</Max> 17 <RegenRate>0. 3</RegenRate>17 <RegenRate>0.1</RegenRate> 18 18 </Health> 19 19 <Identity> 20 20 <Classes datatype="tokens">Healer</Classes> -
binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_a.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>95</Max> 16 <RegenRate>0.3</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Advanced</Rank> -
binaries/data/mods/public/simulation/templates/units/athen_infantry_archer_e.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>105</Max> 16 <RegenRate>0.4</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Elite</Rank> -
binaries/data/mods/public/simulation/templates/units/brit_support_female_citizen.xml
7 7 </Attack> 8 8 <Health> 9 9 <Max>75</Max> 10 <RegenRate>0.5</RegenRate>11 10 </Health> 12 11 <Identity> 13 12 <Civ>brit</Civ> -
binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_a.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>95</Max> 16 <RegenRate>0.3</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Advanced</Rank> -
binaries/data/mods/public/simulation/templates/units/cart_infantry_archer_e.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>105</Max> 16 <RegenRate>0.4</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Elite</Rank> -
binaries/data/mods/public/simulation/templates/units/celt_support_female_citizen.xml
12 12 </Builder> 13 13 <Health> 14 14 <Max>75</Max> 15 <RegenRate>0.5</RegenRate>16 15 </Health> 17 16 <Identity> 18 17 <Civ>celt</Civ> -
binaries/data/mods/public/simulation/templates/units/gaul_support_female_citizen.xml
12 12 </Builder> 13 13 <Health> 14 14 <Max>75</Max> 15 <RegenRate>0.5</RegenRate>16 15 </Health> 17 16 <Identity> 18 17 <Civ>gaul</Civ> -
binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_a.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>95</Max> 16 <RegenRate>0.3</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Advanced</Rank> -
binaries/data/mods/public/simulation/templates/units/hele_infantry_archer_e.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>105</Max> 16 <RegenRate>0.4</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Elite</Rank> -
binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_a.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>95</Max> 16 <RegenRate>0.3</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Advanced</Rank> -
binaries/data/mods/public/simulation/templates/units/mace_infantry_archer_e.xml
13 13 </Attack> 14 14 <Health> 15 15 <Max>105</Max> 16 <RegenRate>0.4</RegenRate>17 16 </Health> 18 17 <Identity> 19 18 <Rank>Elite</Rank>