/* The Evasion Version 2.0 Script
by Outerbeast */
#include "anti_rush"

#include "beast/checkpoint_spawner"
#include "beast/monster_protector"
#include "beast/game_hudsprite"

#include "opfor/nvision"
#include "opfor/weapon_knife"

const bool blAntiRushEnabled = false; // You can change this to have AntiRush mode enabled or disabled
const bool blDoorCrush = true; // Set to false if you wan't want doors to crush players
const float flSurvivalVoteAllow = g_EngineFuncs.CVarGetFloat( "mp_survival_voteallow" );

void MapInit()
{
	// Enable SC PointCheckPoint Support
	RegisterCheckPointSpawnerEntity();
	RegisterGameHudSpriteEntity();
	// Enable Nightvision Support
	NightVision::Enable();
	// Register Opposing Force knife weapon
	RegisterKnife();
	// Register AntiRush(if AntiRush mode is enabled)
    ANTI_RUSH::EntityRegister( blAntiRushEnabled );
	// Global CVars
	g_EngineFuncs.CVarSetFloat( "mp_hevsuit_voice", 0 );

	if( g_Engine.mapname == "evasion_1" )
	{
		g_SurvivalMode.SetStartOn( false );

		if( flSurvivalVoteAllow > 0 )
			g_EngineFuncs.CVarSetFloat( "mp_survival_voteallow", 0 );
	}
}

void MapActivate()
{
	g_EngineFuncs.ServerPrint( "The Evasion Version 2.0 by Forsete - Download this campaign from scmapdb.com\n" );
	MONSTERPROTECTOR::Activate( 2.0f );
	// I can't be assed to go through each bsp and adding damage manually to every func_door just to prevent trolling
    CBaseEntity@ pEntity;
    while( ( @pEntity = g_EntityFuncs.FindEntityByClassname( pEntity, "func_door*" ) ) !is null )
	{
		if( blDoorCrush && pEntity.pev.dmg == 0.0f )
			pEntity.pev.dmg = 50000.0f;
	}
}
// Trigger Script for Survival Mode
void TurnOnSurvival(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
	g_EngineFuncs.CVarSetFloat( "mp_survival_voteallow", flSurvivalVoteAllow ); // Revert to the original cvar setting as per server

	if( g_SurvivalMode.IsEnabled() && g_SurvivalMode.MapSupportEnabled() && !g_SurvivalMode.IsActive() )
		g_SurvivalMode.Activate( true );
}
