#include maps\mp\_utility;
main()
{
  precacheFX();
  ambientFX();
  level.scr_sound["flak88_explode"]	= "flak88_explode";

  if (getcvar("g_gametype") == "cnq" ) 
  {
    setupCallbacks();
    startSound();
  }
}

precacheFX()
{
	level._effect["flak_explosion"]		= loadfx("fx/explosions/flak88_explosion.efx");
	if(level.wwx_ambdustfx) level._effect["dust_wind"]		= loadfx ("fx/dust/dust_wind_brown_thick.efx");
	level._effect["radio_explosion"]	= loadfx("fx/props/radio_explosion.efx");
	level._effect["radio_sparks"]		= loadfx("fx/props/radio_sparks_smoke.efx");

}

ambientFX()
{
	if(level.wwx_ambdustfx)
{
	//original dust fx DO NOT DELETE
	maps\mp\_fx::loopfx("dust_wind", (2693,5237,-7), 3, (2693,5237,2));
	maps\mp\_fx::loopfx("dust_wind", (2758,6086,-7), 3, (2758,6086,2));
	maps\mp\_fx::loopfx("dust_wind", (3225,5742,-7), 3, (3225,5742,2));
	maps\mp\_fx::loopfx("dust_wind", (3007,7063,11), 3, (3007,7063,21));
	maps\mp\_fx::loopfx("dust_wind", (3700,8032,33), 3, (3700,8032,43));
	maps\mp\_fx::loopfx("dust_wind", (4310,7680,33), 3, (4310,7680,43));
	maps\mp\_fx::loopfx("dust_wind", (4318,6863,9), 3, (4318,6863,19));
	maps\mp\_fx::loopfx("dust_wind", (4323,6232,9), 3, (4323,6232,19));
	maps\mp\_fx::loopfx("dust_wind", (5695,7583,9), 3, (5695,7583,19));
	maps\mp\_fx::loopfx("dust_wind", (5485,6965,9), 3, (5485,6965,19));
	maps\mp\_fx::loopfx("dust_wind", (5387,6282,-54), 3, (5387,6282,-44));
	maps\mp\_fx::loopfx("dust_wind", (4888,5676,9), 3, (4888,5676,19));
	maps\mp\_fx::loopfx("dust_wind", (4878,5168,15), 3, (4878,5168,25));
	maps\mp\_fx::loopfx("dust_wind", (4875,4523,15), 3, (4875,4523,25));
	maps\mp\_fx::loopfx("dust_wind", (6537,6190,-17), 3, (6537,6190,-7));
	maps\mp\_fx::loopfx("dust_wind", (1952,8096,-7), 3, (1952,8096,2));
	maps\mp\_fx::loopfx("dust_wind", (1632, 6120,-7), 3, (1632,6120,2));
	maps\mp\_fx::loopfx("dust_wind", (848,5250,-7), 3, (848,5250,2));
	maps\mp\_fx::loopfx("dust_wind", (872,6080,-7), 3, (872,6080,2));
	maps\mp\_fx::loopfx("dust_wind", (1632,5288,-7), 3, (1632,5288,2));
	maps\mp\_fx::loopfx("dust_wind", (1056,6960,-7), 3, (1056,6960,2));
	maps\mp\_fx::loopfx("dust_wind", (1184,7816,-7), 3, (1184,7816,2));
	maps\mp\_fx::loopfx("dust_wind", (224,5048,-7), 3, (224,5048,2));
	maps\mp\_fx::loopfx("dust_wind", (7624,6536,-96), 3, (7624,6536,-89));
	maps\mp\_fx::loopfx("dust_wind", (7178, 6696, -96), 3, (7178, 6696, -89));	
}

}

startSound() 
{
  spawn_radios = getentarray("spawnobjective", "targetname");
  if (isdefined(spawn_radios))
    {
      for(i = 0; i < spawn_radios.size; i++)
        {
          if (spawn_radios[i].script_idnumber > getcvarint("scr_cnq_initialobjective"))
              spawn_radios[i] playLoopSound ("ge_radio");
          else
              spawn_radios[i] stoploopsound();
        }
    }
}

setupCallbacks()
{
  level.cnqCallbackSpawnObjectiveComplete = ::Callback_SpawnObjectiveComplete;
  level.cnqCallbackBonusObjectiveComplete = ::Callback_BonusObjectiveComplete;
}	

Callback_SpawnObjectiveComplete(objective, player)
{
  objective playsound ("radio_click");
  if (player.pers["team"] == "axis")
    objective playloopsound ("ge_radio");
  else
    objective stoploopsound();   
}

Callback_BonusObjectiveComplete(objective, player)
{
  playfx(level._effect["radio_explosion"], objective.origin);
  objective playsound ("radio_exp");
}


