//-------------------------------------------------------------------
//
//  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.
//
//-------------------------------------------------------------------

// Base bullets class (some default values)
class CBaseBulletClass extends CWorldPhysics
{
  bool   AutoTargeting  = false;
  float  ChangeDirSpeed = 0.0;
  bool   ExplodeOnPast  = false;
  float  LifeTime       = 0.0;
  string InverseTrackId = "";
  string ExplosionId    = "";
  string Renderable     = "";
}




// German bullets
class CGermanTankGunBullet extends CBaseBulletClass
{
  string Renderable  = "CGreenBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanTankBulletExplosion";
}

class CGermanAntiairGunBullet extends CBaseBulletClass
{
  string Renderable  = "CRedBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanAntiairBulletExplosion";
}

class CGermanAJeepGunBullet extends CBaseBulletClass
{
  string Renderable  = "CRedBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanAJeepBulletExplosion";
}

class CGermanGunTowerBullet extends CBaseBulletClass
{
  string Renderable  = "CBlueBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanGunTowerBulletExplosion";
}

class CGermanParatrooperBullet extends CBaseBulletClass
{
  string Renderable  = "CGreenBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanParatrooperBulletExplosion";
}

class CGermenArmedSHouseBullet extends CBaseBulletClass
{
  string Renderable  = "CRedBulletTraceEffect";
  string ExplosionId = "EXPLID_GermenArmedSHouseBulletExplosion";
}

class CGermenArmedDHouseBullet extends CBaseBulletClass
{
  string Renderable  = "CRedBulletTraceEffect";
  string ExplosionId = "EXPLID_GermenArmedDHouseBulletExplosion";
}

class CGermanArmedSandBagsBullet extends CBaseBulletClass
{
  string Renderable  = "CMagentaBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanArmedSandBagsBulletExplosion";
}

class CGermanPanzerFaustBullet extends CBaseBulletClass
{
  bool   ExplodeOnPast  = true;

  string Renderable     = "CHelicopterMissileMesh";
  string ExplosionId    = "EXPLID_GermanPanzerFaustExplosion";
  string InverseTrackId = "EFFECTID_PanzerFaustInverseTrackEffect";
}

class CGermanFlakGunBullet extends CBaseBulletClass
{
  bool   ExplodeOnPast  = true;
  string Renderable  = "CMagentaBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanFlakBulletExplosion";
}

class CGermanMobileFlakGunBullet extends CBaseBulletClass
{
  bool   ExplodeOnPast  = true;
  string Renderable  = "CMagentaBulletTraceEffect";
  string ExplosionId = "EXPLID_GermanMobileFlakBulletExplosion";
}



// Soviet bullets
class CSovietTankGunBullet extends CBaseBulletClass
{
  string Renderable  = "CYellowBulletTraceEffect";
  string ExplosionId = "EXPLID_SovietTankBulletExplosion";
}

class CSovietAJeepGunBullet extends CBaseBulletClass
{
  string Renderable  = "CYellowBulletTraceEffect";
  string ExplosionId = "EXPLID_SovietAJeepBulletExplosion";
}

class CSovietGunTowerBullet extends CBaseBulletClass
{
  string Renderable  = "CYellowBulletTraceEffect";
  string ExplosionId = "EXPLID_SovietGunTowerBulletExplosion";
}

class CSovietKatushaRocket extends CBaseBulletClass
{
  vector GravityVector  = g_Gravity;

  string Renderable     = "CHelicopterMissileMesh";
  string ExplosionId    = "EXPLID_SovietKatushaRocketExplosion";
  string InverseTrackId = "EFFECTID_RocketInverseTrack";
}

class CSovietAirBomb extends CBaseBulletClass
{
  vector GravityVector  = g_Gravity;
  string ExplosionId    = "EXPLID_SovietAirBombExplosion";
}




// Helicopter weapons
class CHelicopterMissileMesh
{
  final static string CID = "PatternObject";

  string MeshFile = "Models/W_Rocket.mesh";
  string SkinFile = "Models/W_Rocket.skin";
}

class CHelicopterGunBullet extends CBaseBulletClass
{
  string Renderable     = "CYellowBulletTraceEffect";
  string ExplosionId    = "EXPLID_HelicopterBulletExplosion";
}

class CHelicopterMissile extends CBaseBulletClass
{
  bool   AutoTargeting  = true;
  float  ChangeDirSpeed = 15;
  string Renderable     = "CHelicopterMissileMesh";
  string InverseTrackId = "EFFECTID_MissileInverseTrack";
  string ExplosionId    = "EXPLID_HelicopterMissileExplosion";
}

class CHelicopterRocket extends CBaseBulletClass
{
  string Renderable     = "CHelicopterMissileMesh";
  string InverseTrackId = "EFFECTID_MissileInverseTrack";
  string ExplosionId    = "EXPLID_HelicopterRocketExplosion";
}




// Bullets array
class CFireBallRockMesh
{
  final static string CID = "PatternObject";

  string MeshFile = "Models/W_Rock.mesh";
  string SkinFile = "Models/W_Rock.skin";
}

class CExplosionFireBall extends CBaseBulletClass
{
  vector GravityVector  = g_Gravity;

  string Renderable     = "CFireBallRockMesh";
  string InverseTrackId = "EFFECTID_FireBallInverseTrack";
  string ExplosionId    = "EXPLID_FireBallExplosion";
}

class CExplosionBlackFireBall extends CBaseBulletClass
{
  vector GravityVector  = g_Gravity;

  string Renderable     = "CFireBallRockMesh";
  string InverseTrackId = "EFFECTID_BlackFireBallInverseTrack";
  string ExplosionId    = "EXPLID_FireBallExplosion";
}




// Splashes
class CBaseSplashItemClass extends CBaseBulletClass
{
  vector GravityVector  = g_Gravity;
  float  LifeTime       = 2.0;
}

class CExplosionFireSplash extends CBaseSplashItemClass
{
  float  LifeTime       = 2.0;
  string InverseTrackId = "EFFECTID_BlackFireSplashInverseTrack";
}

class CExplosionSmokeSplash extends CBaseSplashItemClass
{
  float  LifeTime       = 0.0;
  string InverseTrackId = "EFFECTID_BlackFireBallInverseTrack";
}

class CBulletHitSplashItem extends CBaseSplashItemClass
{
  float  LifeTime       = 2.5;
  string Renderable     = "CSplashBulletTraceEffect";
}




// Bullets array
class CBulletsArray
{
  void CBulletsArray()
  {
    CreatePattern("CGermanTankGunBullet", "BULLETID_GermanTankGunBullet");
    CreatePattern("CGermanAntiairGunBullet", "BULLETID_GermanAntiairGunBullet");
    CreatePattern("CGermanAJeepGunBullet", "BULLETID_GermanAJeepGunBullet");
    CreatePattern("CGermanGunTowerBullet", "BULLETID_GermanGunTowerGunBullet");
    CreatePattern("CGermanParatrooperBullet", "BULLETID_GermanParatrooperBullet");
    CreatePattern("CGermenArmedSHouseBullet", "BULLETID_GermenArmedSHouseBullet");
    CreatePattern("CGermenArmedDHouseBullet", "BULLETID_GermenArmedDHouseBullet");
    CreatePattern("CGermanArmedSandBagsBullet", "BULLETID_GermanArmedSandBagsBullet");
    CreatePattern("CGermanPanzerFaustBullet", "BULLETID_GermanPanzerFaustBullet");
    CreatePattern("CGermanFlakGunBullet", "BULLETID_GermanFlakGunBullet");
    CreatePattern("CGermanMobileFlakGunBullet", "BULLETID_GermanMobileFlakGunBullet");

    CreatePattern("CSovietTankGunBullet", "BULLETID_SovietTankGunBullet");
    CreatePattern("CSovietAJeepGunBullet", "BULLETID_SovietAJeepGunBullet");
    CreatePattern("CSovietGunTowerBullet", "BULLETID_SovietGunTowerGunBullet");
    CreatePattern("CSovietKatushaRocket", "BULLETID_SovietKatushaRocket");
    CreatePattern("CSovietAirBomb", "BULLETID_SovietAirBomb");

    CreatePattern("CHelicopterGunBullet", "BULLETID_HelicopterGunBullet");
    CreatePattern("CHelicopterRocket", "BULLETID_HelicopterRocket");
    CreatePattern("CHelicopterMissile", "BULLETID_HelicopterMissile");

    CreatePattern("CExplosionFireBall", "BULLETID_ExplosionFireBall");
    CreatePattern("CExplosionBlackFireBall", "BULLETID_ExplosionBlackFireBall");

    CreatePattern("CExplosionFireSplash", "BULLETID_ExplosionFireSplash");
    CreatePattern("CExplosionSmokeSplash", "BULLETID_ExplosionSmokeSplash");

    CreatePattern("CBulletHitSplashItem", "BULLETID_BulletHitSplashItem");
  }

  void StartSovietAirBombing(
      int    _BombsQty,
      float  _Duration,
      vector _Position,
      float  _Radius
    )
  {
    for (int Bomb = 0; Bomb < _BombsQty; Bomb = Bomb + 1)
    {
      final float Alpha  = rand(Math_PI);
      final float Radius = rand(0.0, _Radius);

      matrix BulletPosition = matrix(
          1.0, 0.0, 0.0, Core_GetVectorX(_Position) + Radius * sin(Alpha),
          0.0, 1.0, 0.0, Core_GetVectorY(_Position) + Radius * cos(Alpha),
          0.0, 0.0, 1.0, Core_GetVectorZ(_Position),
          0.0, 0.0, 0.0, 1.0
        );

      if ((rand_int(4) == 0) &&
          (Bomb < (_BombsQty * 2 / 3)))
      {
        Core_ScheduleTask(
            "Sounds",
            OT_CallFunction,
            _Duration * (float(Bomb) / float(_BombsQty)),
            "CreateSound",
            "SOUNDID_AirBombPitchSound",
            BulletPosition
          );
      }

      Core_ScheduleTask(
          "Bullets",
          OT_CallFunction,
          _Duration * (float(Bomb) / float(_BombsQty)),
          "CreateBullet",
          "BULLETID_SovietAirBomb",
          BulletPosition,
          vector(0.0, 0.0, 0.0)
        );
    }
  }
}

