//checked includes changed to match cerberus output
#include maps/mp/gametypes/_deathicons;
#include maps/mp/mp_vertigo_doors;
#include maps/mp/_compass;
#include maps/mp/mp_vertigo_amb;
#include maps/mp/_load;
#include maps/mp/mp_vertigo_fx;
#include maps/mp/_utility;

main() //checked matches cerberus output
{
	level.levelspawndvars = ::levelspawndvars;
	level.ragdoll_override = ::ragdoll_override;
	maps/mp/mp_vertigo_fx::main();
	maps/mp/_load::main();
	maps/mp/mp_vertigo_amb::main();
	maps/mp/_compass::setupminimap( "compass_map_mp_vertigo" );
	setdvar( "compassmaxrange", "2100" );
	game[ "strings" ][ "war_callsign_a" ] = &"MPUI_CALLSIGN_MAPNAME_A";
	game[ "strings" ][ "war_callsign_b" ] = &"MPUI_CALLSIGN_MAPNAME_B";
	game[ "strings" ][ "war_callsign_c" ] = &"MPUI_CALLSIGN_MAPNAME_C";
	game[ "strings" ][ "war_callsign_d" ] = &"MPUI_CALLSIGN_MAPNAME_D";
	game[ "strings" ][ "war_callsign_e" ] = &"MPUI_CALLSIGN_MAPNAME_E";
	game[ "strings_menu" ][ "war_callsign_a" ] = "@MPUI_CALLSIGN_MAPNAME_A";
	game[ "strings_menu" ][ "war_callsign_b" ] = "@MPUI_CALLSIGN_MAPNAME_B";
	game[ "strings_menu" ][ "war_callsign_c" ] = "@MPUI_CALLSIGN_MAPNAME_C";
	game[ "strings_menu" ][ "war_callsign_d" ] = "@MPUI_CALLSIGN_MAPNAME_D";
	game[ "strings_menu" ][ "war_callsign_e" ] = "@MPUI_CALLSIGN_MAPNAME_E";
	level thread waitforglassbreak();
	if ( getgametypesetting( "allowMapScripting" ) )
	{
		level maps/mp/mp_vertigo_doors::init();
	}
}

levelspawndvars( reset_dvars ) //checked matches cerberus output
{
	ss = level.spawnsystem;
	ss.enemy_influencer_radius = set_dvar_float_if_unset( "scr_spawn_enemy_influencer_radius", "2400", reset_dvars );
	ss.hq_objective_influencer_inner_radius = set_dvar_float_if_unset( "scr_spawn_hq_objective_influencer_inner_radius", "1400", reset_dvars );
}

waitforglassbreak() //checked matches cerberus output
{
	if ( glassexploderssetupcorrectly( 1000, 3 ) == 0 )
	{
		return;
	}
	if ( glassexploderssetupcorrectly( 1004, 3 ) == 0 )
	{
		return;
	}
	if ( glassexploderssetupcorrectly( 1007, 3 ) == 0 )
	{
		return;
	}
	for ( ;; )
	{
		level waittill( "glass_smash", origin );
		playglassexploder( origin, 1000, 3 );
		playglassexploder( origin, 1004, 3 );
		playglassexploder( origin, 1007, 3 );
	}
}

playglassexploder( origin, exploderbase, explodercount ) //checked changed to match cerberus output
{
	distancesq = distancesquared( origin, level.createfxexploders[ exploderbase ][ 0 ].v[ "origin" ] );
	if ( distancesq > 21000 )
	{
		return;
	}
	nearestpane = exploderbase;
	if ( distancesq > 5000 )
	{
		nearestpane = -1;
		distancesq = 5000;
	}
	nearestpanedistsq = distancesq;
	for ( glassexploderindex = 1; glassexploderindex < explodercount; glassexploderindex++ )
	{
		glassexploder = glassexploderindex + exploderbase;
		currentdistsq = distancesquared( origin, level.createfxexploders[ glassexploder ][ 0 ].v[ "origin" ] );
		if ( currentdistsq < nearestpanedistsq )
		{
			nearestpane = glassexploder;
			nearestpanedistsq = currentdistsq;
		}
	}
	if ( nearestpane != -1 )
	{
		exploder( nearestpane );
		level thread window_smash_wind_sound( origin );
	}
}

window_smash_wind_sound( origin ) //checked matches cerberus output
{
	wind_ent = spawn( "script_origin", origin );
	wind_ent playloopsound( "evt_window_wind", 1 );
	level waittill( "game_ended" );
	wind_ent stoploopsound( 0.5 );
	wind_ent delete();
}

glassexploderssetupcorrectly( exploderbase, explodercount ) //checked changed to match cerberus output
{
	for ( glassexploderindex = 0; glassexploderindex < explodercount; glassexploderindex++ )
	{
		glassexploder = glassexploderindex + exploderbase;
		if ( !isDefined( level.createfxexploders[ glassexploder ] ) )
		{
			/*
/#
			assertmsg( "Glass exploder " + glassexploder + " is undefined" );
#/
			*/
			return 0;
		}
		if ( isDefined( level.createfxexploders[ glassexploder ][ 0 ] ) || !isDefined( level.createfxexploders[ glassexploder ][ 0 ].v ) || !isDefined( level.createfxexploders[ glassexploder ][ 0 ].v[ "origin" ] ) )
		{
			/*
/#
			assertmsg( "Glass exploder " + glassexploder + " is undefined" );
#/
			*/
			return 0;
		}
	}
	return 1;
}

ragdoll_override( idamage, smeansofdeath, sweapon, shitloc, vdir, vattackerorigin, deathanimduration, einflictor, ragdoll_jib, body ) //checked matches cerberus output
{
	if ( smeansofdeath == "MOD_FALLING" )
	{
		deathanim = body getcorpseanim();
		startfrac = deathanimduration / 1000;
		if ( animhasnotetrack( deathanim, "start_ragdoll" ) )
		{
			times = getnotetracktimes( deathanim, "start_ragdoll" );
			if ( isDefined( times ) )
			{
				startfrac = times[ 0 ];
			}
		}
		self.body = body;
		if ( !isDefined( self.switching_teams ) )
		{
			thread maps/mp/gametypes/_deathicons::adddeathicon( body, self, self.team, 5 );
		}
		thread startragdollonground( startfrac );
		return 1;
	}
	return 0;
}

startragdollonground( deathanimduration ) //checked does not match cerberus output did not change
{
	timer = 0;
	while ( timer < deathanimduration )
	{
		if ( !isDefined( self ) || !isDefined( self.body ) )
		{
			return;
		}
		if ( self isonground() )
		{
			break;
		}
		else
		{
			wait 0.05;
			timer += 0.05;
		}
	}
	if ( !isDefined( self ) || !isDefined( self.body ) )
	{
		return;
	}
	self.body startragdoll();
}

