Ticket #3606: IdleRegenRate4.patch

File IdleRegenRate4.patch, 6.2 KB (added by Matthew Guttag, 8 years ago)

Requested changes made

  • 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.IsResting())
     132        {
     133            regen += this.GetIdleRegenRate();
     134        }
     135    }
    118136    if (regen > 0)
    119137        this.Increase(regen);
    120138    else
     
    127145Health.prototype.CheckRegenTimer = function()
    128146{
    129147    // check if we need a timer
    130     if (this.GetRegenRate() == 0 ||
    131         this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() > 0 ||
    132         this.GetHitpoints() == 0)
     148    if ((this.GetRegenRate() == 0 && this.GetIdleRegenRate() == 0) ||
     149        (this.GetHitpoints() == this.GetMaxHitpoints() && this.GetRegenRate() >= 0 && this.GetIdleRegenRate() >= 0) ||
     150         this.GetHitpoints() == 0)
    133151    {
    134152        // we don't need a timer, disable if one exists
    135153        if (this.regenTimer)
     
    325343    if (msg.component != "Health")
    326344        return;
    327345
    328     var oldMaxHitpoints = this.GetMaxHitpoints();
    329     var newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
     346    let oldMaxHitpoints = this.GetMaxHitpoints();
     347    let newMaxHitpoints = Math.round(ApplyValueModificationsToEntity("Health/Max", +this.template.Max, this.entity));
    330348    if (oldMaxHitpoints != newMaxHitpoints)
    331349    {
    332         var newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
     350        let newHitpoints = Math.round(this.GetHitpoints() * newMaxHitpoints/oldMaxHitpoints);
    333351        this.maxHitpoints = newMaxHitpoints;
    334352        this.SetHitpoints(newHitpoints);
    335353    }
    336354
    337     var oldRegenRate = this.regenRate;
     355    let oldRegenRate = this.regenRate;
    338356    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
    339 
    340     if (this.regenRate != oldRegenRate)
     357   
     358    let oldIdleRegenRate = this.idleRegenRate;
     359    this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
     360   
     361    if (this.regenRate != oldRegenRate || this.idleRegenRate != oldIdleRegenRate)
    341362        this.CheckRegenTimer();
    342363};
    343364
  • 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>