Ticket #3983: damageVariants.diff

File damageVariants.diff, 7.1 KB (added by sanderd17, 3 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/HealthVisualization.js

     
     1function HealthVisualization() {}
     2
     3HealthVisualization.prototype.Schema =
     4    "<a:example>" +
     5        "<VariantSelection>" +
     6            "<LightDamage>0.75</LightDamage>" +
     7            "<MediumDamage>0.50</MediumDamage>" +
     8            "<HeavyDamage>0.25</HeavyDamage>" +
     9        "</VariantSelection>" +
     10    "</a:example>" +
     11    "<element name='VariantSelection'>" +
     12        "<oneOrMore>" +
     13            "<element>" +
     14                "<anyName/>" +
     15                "<data type='decimal'>" +
     16                    "<param name='minInclusive'>0</param>" +
     17                    "<param name='maxInclusive'>1</param>" +
     18                "</data>" +
     19            "</element>" +
     20        "</oneOrMore>" +
     21    "</element>";
     22
     23HealthVisualization.prototype.Init = function()
     24{
     25    this.currentSelection = "healthy";
     26};
     27
     28HealthVisualization.prototype.OnHealthChanged = function(msg)
     29{
     30    let cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
     31    if (!cmpHealth)
     32        return;
     33    let healthRatio = cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints();
     34
     35    let oldSelection = this.currentSelection
     36    if (healthRatio > 0)
     37    {
     38        this.currentSelection = "healthy";
     39        for (let key in this.template.VariantSelection)
     40        {
     41            if (+this.template.VariantSelection[key] < healthRatio)
     42                continue;
     43            if (this.currentSelection == "healthy" ||
     44                +this.template.VariantSelection[key] < +this.template.VariantSelection[this.currentSelection])
     45                this.currentSelection = key;
     46        }
     47    }
     48    else
     49        this.currentSelection = "death"
     50
     51    if (oldSelection == this.currentSelection)
     52        return;
     53    let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
     54    if (cmpVisual)
     55        cmpVisual.SetVariantSelection("health", this.currentSelection);
     56       
     57};
     58
     59Engine.RegisterComponentType(IID_HealthVisualization, "HealthVisualization", HealthVisualization);
     60
  • binaries/data/mods/public/simulation/components/interfaces/HealthVisualization.js

     
     1Engine.RegisterInterface("HealthVisualization");
     2
  • binaries/data/mods/public/simulation/templates/template_unit_mechanical_ship_fire.xml

     
    3030    <Max>500</Max>
    3131    <RegenRate>-3</RegenRate>
    3232  </Health>
     33  <HealthVisualization>
     34    <VariantSelection>
     35      <LightDamage>0.85</LightDamage>
     36      <MediumDamage>0.65</MediumDamage>
     37      <HeavyDamage>0.35</HeavyDamage>
     38    </VariantSelection>
     39  </HealthVisualization>
    3340  <Identity>
    3441    <GenericName>Fire Ship</GenericName>
    3542    <Classes datatype="tokens">Warship Fireship Melee</Classes>