#include "../point_checkpoint"
#include "armor_system"
#include "spawn_enemy"
#include "upgrade_system"
#include "ins2_register"


CScheduledFunction@ INTERVAL_TEST;
CScheduledFunction@ INTERVAL_WAVE;
CScheduledFunction@ INTERVAL_BEGIN;
CScheduledFunction@ INTERVAL_TEXT;


int TIME_BEGIN_COUNTDOWN = 20;
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("event_spawn_wave_enemies", 0.25, -1);
        @INTERVAL_TEXT = g_Scheduler.SetInterval("tick_display_wave", 1, -1);
 
        @INTERVAL_BEGIN = g_Scheduler.SetInterval("tick_enable_button_begin", 1, -1);
        
        g_Hooks.RegisterHook( Hooks::Player::PlayerSpawn, OnPlayerRespawn );
        g_Hooks.RegisterHook( Hooks::Player::PlayerTakeDamage, OnPlayerTakeDamage );
        /////g_SoundSystem.PrecacheSound( "killing_combine/player_killed.wav" );


      
	// Weapons
	RegisterAll();



        g_Game.PrecacheModel( "models/hunger/hungercrab.mdl" );
        g_Game.PrecacheModel( "models/hunger/nursezombie.mdl" );
        g_Game.PrecacheModel( "models/hunger/chicken.mdl" );
        g_Game.PrecacheModel( "models/hunger/hungerhound.mdl" );
        g_Game.PrecacheModel( "models/hunger/thehand.mdl" );
        g_Game.PrecacheModel( "models/hunger/bullsquid.mdl" );
        g_Game.PrecacheModel( "models/hunger/hungergonome.mdl" );
        g_Game.PrecacheModel( "models/hunger/zork.mdl" );
        g_Game.PrecacheModel( "models/hunger/hungerslave.mdl" );
        g_Game.PrecacheModel( "models/hunger/zombiebull.mdl" );
        g_Game.PrecacheModel( "models/hunger/hungerbarney.mdl" );
        g_Game.PrecacheModel( "models/hunger/hungerotis.mdl" );
        g_Game.PrecacheModel( "models/hunger/zgrunt.mdl" );







}






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 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);


       }


}