#include "../point_checkpoint"
#include "spawn_ammo"
#include "spawn_enemy"




CScheduledFunction@ INTERVAL_TEST;
CScheduledFunction@ INTERVAL_WAVE;
CScheduledFunction@ INTERVAL_KILL_REMAIN;


CScheduledFunction@ INTERVAL_BEGIN;

int TIME_BEGIN_COUNTDOWN = 40;
bool ENABLE_BEGIN_COUNTDOWN = true;
HUDTextParams FORMAT_TEXT_INTERVAL_BEGIN;

void MapInit()
{	

	// Map support is enabled here by default.
	// So you don't have to add "mp_survival_supported 1" to the map config
        RegisterPointCheckPointEntity();
	g_SurvivalMode.EnableMapSupport();



        ////@INTERVAL_TEST = g_Scheduler.SetInterval("test_calculate", 1, -1);

        @INTERVAL_WAVE = g_Scheduler.SetInterval("tick_display_wave", 1, -1);

        @INTERVAL_BEGIN = g_Scheduler.SetInterval("tick_enable_button_begin", 1, -1);

         @INTERVAL_KILL_REMAIN = g_Scheduler.SetInterval("tick_kill_remain", 1, -1);

        g_Hooks.RegisterHook( Hooks::Player::PlayerKilled, AutoOnPlayerKilled );

        


        ENABLE_AMMO_SPAWN = false;
        ENABLE_BUYING_ROOM = false;


        g_SoundSystem.PrecacheSound( "killing_combine/player_killed.wav" );
        g_SoundSystem.PrecacheSound( "killing_combine/hgrunt/die1.wav" );
        g_SoundSystem.PrecacheSound(  "killing_combine/hgrunt/die2.wav" );
        g_SoundSystem.PrecacheSound(  "killing_combine/hgrunt/die3.wav" );
        g_Game.PrecacheGeneric("sprites/white.spr");





}






void ActivateSurvival( CBaseEntity@ pActivator, CBaseEntity@ pCaller,
	USE_TYPE useType, float flValue )
{
	g_SurvivalMode.Activate();
}

void DisableSurvival( CBaseEntity@ pActivator, CBaseEntity@ pCaller, 
	USE_TYPE useType, float flValue )
{
    g_SurvivalMode.Disable();
}




/////Test Code


void abc(CBaseEntity@ activator, CBaseEntity@ pcaller, USE_TYPE usetype, float flValue)
{
     
     CBaseEntity@ mapcommand = null;
     @mapcommand = g_EntityFuncs.FindEntityByTargetname(mapcommand, "targ_command");

     g_EntityFuncs.FireTargets("light_gen", mapcommand, mapcommand, USE_SET);
     

}



//Set this entity as commander to the map
void assigncommander(CBaseEntity@ activator, CBaseEntity@ pcaller, USE_TYPE usetype, float flValue)
{
     CBaseEntity@ mapcommand = null;
     @mapcommand = g_EntityFuncs.FindEntityByTargetname(mapcommand, "targ_command");

}




HookReturnCode AutoOnPlayerKilled( CBasePlayer@ pPlayer, CBaseEntity@ pAttacker, int iGib )
{

          bool GET_SUR_MODE = g_SurvivalMode.IsActive();                


           if(GET_SUR_MODE)
           {
           g_SoundSystem.PlaySound(pPlayer.edict(), CHAN_STREAM, "killing_combine/player_killed.wav", 1, ATTN_NONE, 0, PITCH_NORM);
           }
   

   return HOOK_CONTINUE;
}




void button_buy(CBaseEntity@ activator, CBaseEntity@ pcaller, USE_TYPE usetype, float flValue)
{

   
  


}


void tick_enable_button_begin()
{

   if(ENABLE_BEGIN_COUNTDOWN)
     {





              if(TIME_BEGIN_COUNTDOWN > 0)
                  {

                  FORMAT_TEXT_INTERVAL_BEGIN.x = -1;
	          FORMAT_TEXT_INTERVAL_BEGIN.y = 0.25;
	          FORMAT_TEXT_INTERVAL_BEGIN.channel = 3;
	          FORMAT_TEXT_INTERVAL_BEGIN.fadeinTime = 0;
                  FORMAT_TEXT_INTERVAL_BEGIN.fadeoutTime = 1;
	         FORMAT_TEXT_INTERVAL_BEGIN.r1 = 255;
	          FORMAT_TEXT_INTERVAL_BEGIN.g1 = 255;
	          FORMAT_TEXT_INTERVAL_BEGIN.b1 = 255;
	          FORMAT_TEXT_INTERVAL_BEGIN.a1 = 200;
	          FORMAT_TEXT_INTERVAL_BEGIN.holdTime = 2;



                     TIME_BEGIN_COUNTDOWN -= 1;

                     g_PlayerFuncs.HudMessageAll(FORMAT_TEXT_INTERVAL_BEGIN, "Button Will Unlock In:" + "\n" + TIME_BEGIN_COUNTDOWN + "s");

                 }



                 else
                 {
                     CBaseEntity@ mapcommand = null;
                     @mapcommand = g_EntityFuncs.FindEntityByTargetname(mapcommand, "targ_map_command");

                     g_EntityFuncs.FireTargets("trig_set_targ_button", mapcommand, mapcommand, USE_SET);

                     ENABLE_BEGIN_COUNTDOWN = false;

                 }


           ////g_PlayerFuncs.ShowMessageAll(1111);


       }


}