Ticket #3606: IdleRegenRate3.patch

File IdleRegenRate3.patch, 6.6 KB (added by Matthew Guttag, 8 years ago)

Updated version of the patch fixes comparisons on line 162, IsIdleOrIdlyGarrisoned renamed to is resting, IdleRegenRate is not optional.

  • 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    if(this.template.IdleRegenRate == undefined)
     53    {
     54        this.idleRegenRate = 0;
     55    }
     56    else
     57    {
     58        this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
     59    }
    4860    this.CheckRegenTimer();
    4961};
    5062
     
    107119    return this.template.Undeletable == "true";
    108120};
    109121
     122Health.prototype.GetIdleRegenRate = function()
     123{
     124    return this.idleRegenRate;
     125};
     126
    110127Health.prototype.GetRegenRate = function()
    111128{
    112129    return this.regenRate;
     
    114131
    115132Health.prototype.ExecuteRegeneration = function()
    116133{
    117     var regen = this.GetRegenRate();
     134    let regen = this.GetRegenRate();
    118135    if (regen > 0)
    119136        this.Increase(regen);
    120137    else
    121138        this.Reduce(-regen);
     139    if(this.GetIdleRegenRate() != 0)
     140    {
     141        let cmpUnitAI = Engine.QueryInterface(this.entity, IID_UnitAI);
     142        if(cmpUnitAI && cmpUnitAI.IsResting())
     143        {
     144            let idleRegen = this.GetIdleRegenRate();
     145            if (idleRegen > 0)
     146                this.Increase(idleRegen);
     147            else
     148                this.Reduce(-idleRegen);
     149        }
     150    }
    122151};
    123152
    124153/*
     
    127156Health.prototype.CheckRegenTimer = function()
    128157{
    129158    // check if we need a timer
    130     if (this.GetRegenRate() == 0 ||
    131         this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 ||
    132         this.GetHitpoints() == 0)
     159    if ((this.GetRegenRate() == 0 && this.GetIdleRegenRate() == 0) ||
     160        (this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() >= 0 && this.GetIdleRegenRate() >= 0) ||
     161         this.GetHitpoints() == 0)
    133162    {
    134163        // we don't need a timer, disable if one exists
    135164        if (this.regenTimer)
     
    325354    if (msg.component != "Health")
    326355        return;
    327356
    328     var oldMaxHitpoints = this.GetMaxHitpoints();
    329     var newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
     357    let oldMaxHitpoints = this.GetMaxHitpoints();
     358    let newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
    330359    if (oldMaxHitpoints != newMaxHitpoints)
    331360    {
    332         var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
     361        let newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
    333362        this.maxHitpoints = newMaxHitpoints;
    334363        this.SetHitpoints(newHitpoints);
    335364    }
    336365
    337     var oldRegenRate = this.regenRate;
     366    let oldRegenRate = this.regenRate;
    338367    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
    339368
    340369    if (this.regenRate != oldRegenRate)
    341370        this.CheckRegenTimer();
     371   
     372    if(this.template.IdleRegenRate != undefined)
     373    {
     374        let oldIdleRegenRate = this.idleRegenRate;
     375        this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
     376   
     377        if (this.idleRegenRate != oldIdleRegenRate)
     378            this.CheckRegenTimer();
     379    }
    342380};
    343381
    344382Health.prototype.OnHealthChanged = function()
  • simulation/components/UnitAI.js

     
    32983298    return this.isGarrisoned;
    32993299};
    33003300
     3301/**
     3302* Returns true if the unit is idle a turret and idle
     3303* or a non-turret garrisoned unit
     3304*/
     3305UnitAI.prototype.IsResting = function()
     3306{
     3307    if(this.IsIdle())
     3308        return true;
     3309    if(this.IsGarrisoned() && !this.IsTurret())
     3310        return true;
     3311    return false;
     3312};
     3313
    33013314UnitAI.prototype.SetGarrisoned = function()
    33023315{
    33033316    this.isGarrisoned = true;
  • 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>