Ticket #3606: IdleRegenRate5.patch

File IdleRegenRate5.patch, 5.7 KB (added by Matthew Guttag, 8 years ago)

Removed changes from UnitAI, cleaned up the code.

  • simulation/ai/petra/researchManager.js

     
    156156                return tech[0];
    157157            else if (template.modifications[i].value === "Health/RegenRate")
    158158                return tech[0];
     159            else if (template.modifications[i].value === "Health/IdleRegenRate")
     160                return tech[0];
    159161        }
    160162    }
    161163    return false;
  • simulation/components/Health.js

     
    55    "<a:example>" +
    66        "<Max>100</Max>" +
    77        "<RegenRate>1.0</RegenRate>" +
     8        "<IdleRegenRate>0</IdleRegenRate>" +
    89        "<DeathType>corpse</DeathType>" +
    910    "</a:example>" +
    1011    "<element name='Max' a:help='Maximum hitpoints'>" +
     
    2324    "<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" +
    2425        "<data type='decimal'/>" +
    2526    "</element>" +
     27    "<element name='IdleRegenRate' a:help='Hitpoint regeneration rate per second when idle or garrisoned.'>" +
     28        "<data type='decimal'/>" +
     29    "</element>" +
    2630    "<element name='DeathType' a:help='Behaviour when the unit dies'>" +
    2731        "<choice>" +
    2832            "<value a:help='Disappear instantly'>vanish</value>" +
     
    4549    // (Allowing 0 initial HP would break our death detection code)
    4650    this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints());
    4751    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
     52    this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
    4853    this.CheckRegenTimer();
    4954};
    5055
     
    107112    return this.template.Undeletable == "true";
    108113};
    109114
     115Health.prototype.GetIdleRegenRate = function()
     116{
     117    return this.idleRegenRate;
     118};
     119
    110120Health.prototype.GetRegenRate = function()
    111121{
    112122    return this.regenRate;
     
    114124
    115125Health.prototype.ExecuteRegeneration = function()
    116126{
    117     var regen = this.GetRegenRate();
     127    let regen = this.GetRegenRate();
     128    if (this.GetIdleRegenRate() != 0)
     129    {
     130        let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
     131        if (cmpUnitAI && (cmpUnitAI.IsIdle() || cmpUnitAI.IsGarrisoned() && !cmpUnitAI.IsTurret()))
     132            regen += this.GetIdleRegenRate();
     133    }
    118134    if (regen > 0)
    119135        this.Increase(regen);
    120136    else
     
    127143Health.prototype.CheckRegenTimer = function()
    128144{
    129145    // check if we need a timer
    130     if (this.GetRegenRate() == 0 ||
    131         this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 ||
    132         this.GetHitpoints() == 0)
     146    if ((this.GetRegenRate() == 0 && this.GetIdleRegenRate() == 0) ||
     147        (this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() >= 0 && this.GetIdleRegenRate() >= 0) ||
     148         this.GetHitpoints() == 0)
    133149    {
    134150        // we don't need a timer, disable if one exists
    135151        if (this.regenTimer)
     
    325341    if (msg.component != "Health")
    326342        return;
    327343
    328     var oldMaxHitpoints = this.GetMaxHitpoints();
    329     var newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
     344    let oldMaxHitpoints = this.GetMaxHitpoints();
     345    let newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
    330346    if (oldMaxHitpoints != newMaxHitpoints)
    331347    {
    332         var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
     348        let newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
    333349        this.maxHitpoints = newMaxHitpoints;
    334350        this.SetHitpoints(newHitpoints);
    335351    }
    336352
    337     var oldRegenRate = this.regenRate;
     353    let oldRegenRate = this.regenRate;
    338354    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
    339 
    340     if (this.regenRate != oldRegenRate)
     355   
     356    let oldIdleRegenRate = this.idleRegenRate;
     357    this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
     358   
     359    if (this.regenRate != oldRegenRate || this.idleRegenRate != oldIdleRegenRate)
    341360        this.CheckRegenTimer();
    342361};
    343362
  • simulation/data/technologies/health_regen_units.json

     
    77    "icon": "bandage.png",
    88    "researchTime": 40,
    99    "tooltip": "Organic units will slowly regenerate health over time when idle.",
    10     "modifications": [{"value": "Health/RegenRate", "add": 0.5}],
     10    "modifications": [{"value": "Health/IdleRegenRate", "add": 0.5}],
    1111    "affects": ["Unit Organic"],
    1212    "soundComplete": "interface/alarm/alarm_upgradearmory.xml"
    1313}
  • simulation/templates/template_structure.xml

     
    4747  <Health>
    4848    <DeathType>corpse</DeathType>
    4949    <RegenRate>0</RegenRate>
     50    <IdleRegenRate>0</IdleRegenRate>
    5051    <Undeletable>false</Undeletable>
    5152    <Unhealable>true</Unhealable>
    5253  </Health>
  • simulation/templates/template_unit.xml

     
    3131    <DeathType>corpse</DeathType>
    3232    <Max>100</Max>
    3333    <RegenRate>0</RegenRate>
     34    <IdleRegenRate>0</IdleRegenRate>
    3435    <Undeletable>false</Undeletable>
    3536    <Unhealable>false</Unhealable>
    3637  </Health>