//-------------------------------------------------------------------
//
//  This code is copyright 2001 by G5 Software.
//  Any unauthorized usage, either in part or in whole of this code
//  is strictly prohibited. Violators WILL be prosecuted to the
//  maximum extent allowed by law.
//
//-------------------------------------------------------------------

class CLifeSystem
{
  string ExplosionId = "";

  void CLifeSystem(
      float  _InitialHP,
      string _ExplosionId
    )
  {
    MaxHitpoints = _InitialHP;
    NowHitpoints = _InitialHP;
    ExplosionId  = _ExplosionId;
  }

  void OnObjectLoaded()
  {
    HitpointsWasChanged(NowHitpoints);
  }

  void OnToDamage(
      float _Damage
    )
  {
    NowHitpoints = NowHitpoints - _Damage;

    if (NowHitpoints <= 0.0)
    {
      NowHitpoints = 0.0;
      DetonateObject(ExplosionId);
    }

    HitpointsWasChanged(NowHitpoints);
  }

  void HitpointsWasChanged(
      float _NowHitpoints
    )
  {
  }

  bool m_Isexploded = false;

  void DetonateObject(
      string _ExplosionId
    )
  {
    if (m_Isexploded)
      return;
    m_Isexploded = true;

    CreateExplosion(_ExplosionId, ObjectPosition);
    DestroyComponent();
  }

  void DestroyComponent()
  {
    // Destroy object (with little delay for effect?)
    Core_PostEventTo(
        SOID_MissionController,
        "DestroyGameObject",
        Core_GetIdentificator()
      );
  }

  void OnCollisionOccured(
      float _fPower
    )
  {
    OnToDamage(_fPower * 5.0);
  }
}

class CUnitLifeSystem
{
  void CUnitLifeSystem(
      string _LifeSystem
    )
  {
    CreateComponent("LifeSystem", "LifeSystem", _LifeSystem);
    SetComponentPositionable("LifeSystem", "Mesh");
  }
}

