Ticket #3983: damageVariants.2.diff

File damageVariants.2.diff, 8.8 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/art/actors/structures/iberians/fireship.xml

     
    22<actor version="1">
    33  <castshadow/>
    44  <group>
    5     <variant frequency="1" name="firea">
     5    <variant frequency="1" name="base">
    66      <mesh>structural/iber_fireship.dae</mesh>
    77      <props>
    88        <prop actor="props/structures/iberians/fireship_wood.xml" attachpoint="root"/>
    9         <prop actor="particle/flame_med.xml" attachpoint="fire1"/>
    10         <prop actor="particle/smoke_med.xml" attachpoint="fire1"/>
    11         <prop actor="particle/flame.xml" attachpoint="fire2"/>
    12         <prop actor="" attachpoint="fire3"/>
     9      </props>
     10      <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures>
     11    </variant>
     12  </group>
     13  <group>
     14    <variant name="healthy" frequency="1">
     15      <props>
     16        <prop actor="particle/flame_jav.xml" attachpoint="fire1"/>
     17        <prop actor="particle/smoke_jav.xml" attachpoint="fire1"/>
    1318        <prop actor="particle/flame_jav.xml" attachpoint="fire4"/>
    1419        <prop actor="particle/smoke_jav.xml" attachpoint="fire4"/>
    15         <prop actor="particle/flame.xml" attachpoint="fire5"/>
    16         <prop actor="particle/smoke_catapult.xml" attachpoint="fire5"/>
    1720      </props>
    18       <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures>
    1921    </variant>
    20     <variant frequency="1" name="fireb">
    21       <mesh>structural/iber_fireship.dae</mesh>
     22    <variant name="lightDamage">
    2223      <props>
    23         <prop actor="props/structures/iberians/fireship_wood.xml" attachpoint="root"/>
    24         <prop actor="particle/flame_jav.xml" attachpoint="fire1"/>
     24        <prop actor="particle/flame.xml" attachpoint="fire1"/>
    2525        <prop actor="particle/smoke.xml" attachpoint="fire1"/>
    26         <prop actor="particle/flame.xml" attachpoint="fire2"/>
    27         <prop actor="particle/flame_med.xml" attachpoint="fire3"/>
    28         <prop actor="particle/smoke_med.xml" attachpoint="fire3"/>
     26        <prop actor="particle/flame_jav.xml" attachpoint="fire3"/>
     27        <prop actor="particle/smoke_jav.xml" attachpoint="fire3"/>
     28        <prop actor="particle/flame.xml" attachpoint="fire4"/>
     29        <prop actor="particle/smoke_jav.xml" attachpoint="fire4"/>
     30      </props>
     31    </variant>
     32    <variant name="mediumDamage">
     33      <props>
     34        <prop actor="particle/flame.xml" attachpoint="fire1"/>
     35        <prop actor="particle/smoke.xml" attachpoint="fire1"/>
     36        <prop actor="particle/flame_jav.xml" attachpoint="fire2"/>
     37        <prop actor="particle/flame.xml" attachpoint="fire3"/>
     38        <prop actor="particle/smoke.xml" attachpoint="fire3"/>
     39        <prop actor="particle/flame.xml" attachpoint="fire4"/>
     40        <prop actor="particle/smoke.xml" attachpoint="fire4"/>
    2941        <prop actor="particle/flame_jav.xml" attachpoint="fire5"/>
    30         <prop actor="particle/smoke_jav.xml" attachpoint="fire5"/>
    3142      </props>
    32       <textures><texture file="structural/iber_ship.dds" name="baseTex"/></textures>
    3343    </variant>
     44    <variant name="heavyDamage">
     45      <props>
     46        <prop actor="particle/flame_large.xml" attachpoint="fire1"/>
     47        <prop actor="particle/smoke_med.xml" attachpoint="fire1"/>
     48        <prop actor="particle/flame.xml" attachpoint="fire2"/>
     49        <prop actor="particle/flame_large.xml" attachpoint="fire3"/>
     50        <prop actor="particle/smoke.xml" attachpoint="fire3"/>
     51        <prop actor="particle/flame.xml" attachpoint="fire4"/>
     52        <prop actor="particle/flame_large.xml" attachpoint="fire4"/>
     53        <prop actor="particle/smoke_med.xml" attachpoint="fire5"/>
     54      </props>
     55    </variant>
     56    <variant name="death">
     57    </variant>
    3458  </group>
    3559  <material>player_trans.xml</material>
    3660</actor>
  • binaries/data/mods/public/simulation/components/Health.js

     
    1717        "</element>" +
    1818    "</optional>" +
    1919    "<optional>" +
    20         "<element name='SpawnEntityOnDeath' a:help='Entity template to spawn when this entity dies. Note: this is different than the corpse, which retains the original entity&apos;s appearance'>" +
    21             "<text/>" +
     20        "<element name='DamageVariants'>" +
     21            "<oneOrMore>" +
     22                "<element a:help='Name of the variant to select when health drops under the defined ratio'>" +
     23                    "<anyName/>" +
     24                    "<data type='decimal'>" +
     25                        "<param name='minInclusive'>0</param>" +
     26                        "<param name='maxInclusive'>1</param>" +
     27                    "</data>" +
     28                "</element>" +
     29            "</oneOrMore>" +
    2230        "</element>" +
    2331    "</optional>" +
    2432    "<element name='RegenRate' a:help='Hitpoint regeneration rate per second.'>" +
     
    3442            "<value a:help='Remain in the world with 0 health'>remain</value>" +
    3543        "</choice>" +
    3644    "</element>" +
     45    "<optional>" +
     46        "<element name='SpawnEntityOnDeath' a:help='Entity template to spawn when this entity dies. Note: this is different than the corpse, which retains the original entity&apos;s appearance'>" +
     47            "<text/>" +
     48        "</element>" +
     49    "</optional>" +
    3750    "<element name='Undeletable' a:help='Prevent players from deleting this entity.'>" +
    3851        "<data type='boolean'/>" +
    3952    "</element>" +
     
    5164    this.regenRate = ApplyValueModificationsToEntity("Health/RegenRate", +this.template.RegenRate, this.entity);
    5265    this.idleRegenRate = ApplyValueModificationsToEntity("Health/IdleRegenRate", +this.template.IdleRegenRate, this.entity);
    5366    this.CheckRegenTimer();
     67    this.UpdateActor();
    5468};
    5569
    5670//// Interface functions ////
     
    92106            cmpRangeManager.SetEntityFlag(this.entity, "injured", false);
    93107    }
    94108
    95     Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints });
     109    this.RegisterHealthChanged(old);
    96110};
    97111
    98112Health.prototype.IsRepairable = function()
     
    223237            }
    224238
    225239            this.hitpoints = 0;
    226 
    227             Engine.PostMessage(this.entity, MT_HealthChanged, { "from": oldHitpoints, "to": this.hitpoints });
     240            this.RegisterHealthChanged(oldHitpoints);
    228241        }
    229242
    230243    }
     
    231244    else
    232245    {
    233246        this.hitpoints -= amount;
    234 
    235         Engine.PostMessage(this.entity, MT_HealthChanged, { "from": oldHitpoints, "to": this.hitpoints });
     247        this.RegisterHealthChanged(oldHitpoints);
    236248    }
    237249    state.change = this.hitpoints - oldHitpoints;
    238250    return state;
     
    262274            cmpRangeManager.SetEntityFlag(this.entity, "injured", false);
    263275    }
    264276
    265     Engine.PostMessage(this.entity, MT_HealthChanged, { "from": old, "to": this.hitpoints });
     277    this.RegisterHealthChanged({ "from": old, "to": this.hitpoints });
     278
    266279    // We return the old and the actual hp
    267280    return { "old": old, "new": this.hitpoints};
    268281};
     
    337350    return spawnedEntity;
    338351};
    339352
     353Health.prototype.UpdateActor = function()
     354{
     355    if (!this.template.DamageVariants)
     356        return;
     357    let ratio = this.GetHitpoints() / this.GetMaxHitpoints();
     358    let newSelection = "alive";
     359    if (ratio > 0)
     360    {
     361        let minTreshold = 1;
     362        for (let key in this.template.DamageVariants)
     363        {
     364            let treshold = +this.template.DamageVariants[key];
     365            if (treshold < ratio || treshold > minTreshold)
     366                continue;
     367            newSelection = key;
     368            minTreshold = treshold;
     369        }
     370    }
     371    else
     372        newSelection = "death";
     373
     374    if (this.currentSelection && this.currentSelection == newSelection)
     375        return;
     376
     377    let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
     378    if (cmpVisual)
     379        cmpVisual.SetVariant("health", newSelection);
     380};
     381
    340382Health.prototype.OnValueModification = function(msg)
    341383{
    342384    if (msg.component != "Health")
     
    361403        this.CheckRegenTimer();
    362404};
    363405
    364 Health.prototype.OnHealthChanged = function()
     406Health.prototype.RegisterHealthChanged = function(from)
    365407{
    366408    this.CheckRegenTimer();
     409    this.UpdateActor()
     410    Engine.PostMessage(this.entity, MT_HealthChanged, { "from": from, "to": this.hitpoints });
    367411};
    368412
    369413Engine.RegisterComponentType(IID_Health, "Health", Health);
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml

     
    2929  <Health>
    3030    <Max>500</Max>
    3131    <RegenRate>-3</RegenRate>
     32    <DamageVariants>
     33      <lightdamage>0.85</lightdamage>
     34      <mediumdamage>0.65</mediumdamage>
     35      <heavydamage>0.35</heavydamage>
     36    </DamageVariants>
    3237  </Health>
    3338  <Identity>
    3439    <GenericName>Fire Ship</GenericName>