#include "anti_rush"
#include "beast/checkpoint_spawner"

const bool blAntiRushEnable = 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()
{
    RegisterCheckPointSpawnerEntity();
    ANTI_RUSH::EntityRegister( blAntiRushEnable );

	if( g_Engine.mapname == "af1" )
	{
		g_SurvivalMode.SetStartOn( false );

		if( flSurvivalVoteAllow > 0 )
			g_EngineFuncs.CVarSetFloat( "mp_survival_voteallow", 0 );
	}
}

void MapActivate()
{
	g_EngineFuncs.ServerPrint( "Affliction - Download this campaign from scmapdb.com\n" );
	// 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;
	}
}

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 );
}
// Script conflicts means I have to copypaste this instead of loading directly from survival_generic.as -_-
void DisableSurvival(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
    g_SurvivalMode.Disable();
}
