LCOV - code coverage report
Current view: top level - simulation/components - DeathDamage.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 14 16 87.5 %
Date: 2023-04-02 12:52:40 Functions: 4 4 100.0 %

          Line data    Source code
       1             : function DeathDamage() {}
       2             : 
       3           1 : DeathDamage.prototype.Schema =
       4             :         "<a:help>When a unit or building is destroyed, it inflicts damage to nearby units.</a:help>" +
       5             :         "<a:example>" +
       6             :                 "<Shape>Circular</Shape>" +
       7             :                 "<Range>20</Range>" +
       8             :                 "<FriendlyFire>false</FriendlyFire>" +
       9             :                 "<Damage>" +
      10             :                         "<Hack>0.0</Hack>" +
      11             :                         "<Pierce>10.0</Pierce>" +
      12             :                         "<Crush>50.0</Crush>" +
      13             :                 "</Damage>" +
      14             :         "</a:example>" +
      15             :         "<element name='Shape' a:help='Shape of the splash damage, can be circular.'><text/></element>" +
      16             :         "<element name='Range' a:help='Size of the area affected by the splash.'><ref name='nonNegativeDecimal'/></element>" +
      17             :         "<element name='FriendlyFire' a:help='Whether the splash damage can hurt non enemy units.'><data type='boolean'/></element>" +
      18             :         AttackHelper.BuildAttackEffectsSchema();
      19             : 
      20           1 : DeathDamage.prototype.Init = function()
      21             : {
      22             : };
      23             : 
      24             : // We have no dynamic state to save.
      25           1 : DeathDamage.prototype.Serialize = null;
      26             : 
      27           1 : DeathDamage.prototype.GetDeathDamageEffects = function()
      28             : {
      29           4 :         return AttackHelper.GetAttackEffectsData("DeathDamage", this.template, this.entity);
      30             : };
      31             : 
      32           1 : DeathDamage.prototype.CauseDeathDamage = function()
      33             : {
      34           2 :         let cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
      35           2 :         if (!cmpPosition || !cmpPosition.IsInWorld())
      36           0 :                 return;
      37           2 :         let pos = cmpPosition.GetPosition2D();
      38             : 
      39           2 :         let cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
      40           2 :         let owner = cmpOwnership.GetOwner();
      41           2 :         if (owner == INVALID_PLAYER)
      42           0 :                 warn("Unit causing death damage does not have any owner.");
      43             : 
      44           2 :         AttackHelper.CauseDamageOverArea({
      45             :                 "type": "Death",
      46             :                 "attackData": this.GetDeathDamageEffects(),
      47             :                 "attacker": this.entity,
      48             :                 "attackerOwner": owner,
      49             :                 "origin": pos,
      50             :                 "radius": ApplyValueModificationsToEntity("DeathDamage/Range", +this.template.Range, this.entity),
      51             :                 "shape": this.template.Shape,
      52             :                 "friendlyFire": this.template.FriendlyFire == "true",
      53             :         });
      54             : };
      55             : 
      56           1 : Engine.RegisterComponentType(IID_DeathDamage, "DeathDamage", DeathDamage);

Generated by: LCOV version 1.14