{
	debug_warpTrench [0]
	debug_spam [0]
	debug_GodMode [0]

	saved_FirstTime [1]
	saved_levelload [1]

	// Zone Triggers
	//
	saved_AtCTrigger01 [0]
	saved_AtCTrigger02 [0]
	saved_AtCTrigger03 [0]
	saved_AtCTrigger04 [0]
	saved_AtCTrigger05 [0]
	saved_AtCTrigger06 [0]
	saved_AtCTrigger08 [0]
	saved_AtCTrigger09 [0]
	saved_AtCTrigger10 [0]
	saved_AtTTrigger01 [0]
	saved_AtPTrigger01 [0]
	saved_AtPTrigger02 [0]
	saved_AtBattle01 [0]
	saved_AtPhase2 [0]
	saved_AtPhase3 [0]
	saved_AtPhase4 [0]
	saved_AtGoUpstairs [0]

	// Scripting Controls
	//
	saved_BriefClear [0]
	saved_RunField [0]
	saved_CountWaves [0]
	saved_Wave1 [0]
	saved_Inside [0]

	// Do not save these
	//
	FirstShotFired [0]

	// Objective Counters
	//
		saved_NumObjectives [14]
		saved_CurObjective [0]

		saved_Clear1 [0]	saved_Complete1 [4]	saved_Obj1Updated [0]
		saved_Clear2 [0]	saved_Complete2 [11]	saved_Obj2Updated [0]
		saved_Clear3 [0]	saved_Complete3 [5]	saved_Obj3Updated [0]
	//
	AdvanceObjectives[ (hideLast)
	{
		if( saved_CurObjective < saved_NumObjectives )
		{
			NextObj = (saved_CurObjective+1);
			DropObj = (saved_CurObjective-2);

			ObjectiveComplete( saved_CurObjective );

			if( NextObj < saved_NumObjectives )
			{
				if( hideLast = 1 )
				{
					SetObjectiveActive( saved_CurObjective, false );
				}

				SetObjectiveActive( NextObj, true );

				if( Level.saved_CurObjective > 1 )
				{
					Level.SetObjectiveActive( NextObj, true );
					if( hideLast = 0 )
					{
						Level.SetObjectiveActive( DropObj, false );
					}
				}
		}
			saved_CurObjective = NextObj;
		}
	}]

	CountDead[ (who)
	{
		Spew("   --> CountDead()");

		if(	(who = "1flr01") or
			(who = "1flr02") or
			(who = "1flr03") or
			(who = "1flr04") )
			{
				Spew("        F1 guy detected");
				saved_Clear1 = saved_Clear1 + 1;
				Spew("        New Total:  " # saved_Clear1);
				CheckFloors();
				return;
			}

		if(	(who ="2flr01") or
			(who ="2flr02") or
			(who ="2flr03") or
			(who ="2flr04") or
			(who ="2flr05") or
			(who ="2flr06") or
			(who ="2flr07") or
			(who ="2flr08") or
			(who ="2flr09") or
			(who ="2flr10") or
			(who ="2flr11")	)
			{
				Spew("        F2 guy detected");
				saved_Clear2 = saved_Clear2 + 1;
				Spew("        New Total:  " # saved_Clear2);

				CheckFloors();
				return;
			}



		if(	(who="3flr01") or
			(who="3flr02") or
			(who="3flr03") or
			(who="3flr04") or
			(who="3flr05") )
			{
				Spew("        F3 guy detected");
				saved_Clear3 = saved_Clear3 + 1;
				Spew("        New Total:  " # saved_Clear3);

				CheckFloors();
				return;
			}
	}]

	CheckFloors[ ()
	{
		Spew("   --> CheackFloors()");

		wtf1 = saved_Complete1 + 0;
		wtf2 = saved_Complete2 + 0;
		wtf3 = saved_Complete3 + 0;

		Spew("          saved_Clear1:     " # saved_Clear1);
		Spew("          saved_Complete1:  " # saved_Complete1);
		Spew("          wtf1:       " # wtf1);
		Spew("        --------------------------");
		Spew("          saved_Clear2:     " # saved_Clear2);
		Spew("          saved_Complete2:  " # saved_Complete2);
		Spew("          wtf2:       " # wtf2);
		Spew("        --------------------------");
		Spew("          saved_Clear3:     " # saved_Clear3);
		Spew("          saved_Complete3:  " # saved_Complete3);
		Spew("          wtf3:       " # wtf3);

		if( saved_Clear1=wtf1)
		{
			if( saved_Obj1Updated = 0 )
			{
				saved_Obj1Updated = 1;
				Spew("<><><><><>  FLOOR 1 CLEARED <><><><><>");
				AdvanceObjectives(1);
			}
		}
		if( saved_Clear2=wtf2)
		{
			if( saved_Obj2Updated = 0 )
			{
				saved_Obj2Updated = 1;
				Spew("<><><><><>  FLOOR 2 CLEARED <><><><><>");
				AdvanceObjectives(1);
			}
		}
		if( saved_Clear3=wtf3)
		{
			if( saved_Obj3Updated = 0 )
			{
				saved_Obj3Updated = 1;
				Spew("<><><><><>  FLOOR 3 CLEARED <><><><><>");
				AdvanceObjectives(1);
			}
		}

		if( (saved_Obj1Updated=1) and (saved_Obj2Updated=1) and (saved_Obj3Updated=1) )
		{
			Spew("<><><><><>  YOU WIN, FUCKER!  <><><><><><>");
			AdvanceObjectives(0);
			Victory();
			GetEntity("trunr1").Delay(8,100);
		}
	}]

	Slaughter[ ()
	{
		saved_Wave1 = 0;

		DoSlaughter("wave1g1");
		DoSlaughter("wave1g2");

		DoSlaughter("wave1d1");
		DoSlaughter("wave1d2");
		DoSlaughter("wave1d3");
		DoSlaughter("wave1d4");

		DoSlaughter("wave1a");
		DoSlaughter("wave1b");
		DoSlaughter("wave1c");

		DoSlaughter("trunr1");
		DoSlaughter("trunr2");
		DoSlaughter("trunr3");
	}]

	DoSlaughter[( who )
	{
		obj = GetEntity(who);

		if( not obj.IsDead() )
		{
			obj.Kill();
		}
	}]

	Init[ ()
	{
		SetVis_RayLen(64);
		SetVis_RayWidth(192);

		if( FirstShotFired = 0 )
		{
			ListenForPlayerShot( true );
		}

		if(saved_FirstTime = 1)
		{
			player = GetPlayer();
			if( debug_GodMode = 1 )
			{
				player.SetInvulnerable( true );
			}
			else
			{
				player.SetInvulnerable( false );
			}
			player.SetNationality(3);	// Russian


			AddObjective( 201, 9331, 26329 );
			SetObjectiveActive( 0, true );

			AddObjective( 202, 9435, 18102 );
			SetObjectiveActive( 1, false );

			AddObjective( 203, 15268, 19840 );
			SetObjectiveActive( 2, false );

			AddObjective( 204, 23833, 21299 );
			SetObjectiveActive( 3, false );

			AddObjective( 205, 23833, 21299 );
			SetObjectiveActive( 4, false );

			AddObjective( 206, 23833, 21299 );
			SetObjectiveActive( 5, false );

			AddObjective( 207, 23833, 21299 );
			SetObjectiveActive( 6, false );

			player.GiveWeapon(60, 3);	// MosNag
			player.GiveWeapon(62, 3);	// SMosNag
			player.GiveWeapon(61, 8);	// RGD-33 Stick Grenade

			saved_FirstTime = 0;

			if( debug_warpTrench = 1 )
			{
				GetEntity("bat08").Kill();
				GetPlayer().SetPosition(10227,26483,576);
			}

			AutoSave();
		}
	}]

	OnLevelLoad[ ()
	{
		PlayAmbient(61);

		if( saved_levelload = 1 )
		{
			saved_levelload = 0;

			SetMessage(515,75,35);
			SetMessage2(542,75,65);
			SetMessage3(514,75,80);
		}
	}]

	EnterZone[ (zone)
	{
		if( zone="CTrigger01" )
		{
			if( saved_AtCTrigger01 = 0 )
			{
				saved_AtCTrigger01 = 1;
				GetPlayer().PlaySound(56,50);
			}
		}
		if( zone="CTrigger02")
		{
			if( saved_AtCTrigger02=0 )
			{
			saved_AtCTrigger02 = 1;

				dude = GetEntity("dude02");
				dude.TakeCover("RunCover02",0,"left");
			}
		}
		if( zone="CTrigger03" )
		{
			if( saved_AtCTrigger03 = 0 )
			{
				saved_AtCTrigger03 = 1;
				GetEntity("bat01").DoLeanCover("stand");
			}
		}
		if( zone="TTrigger01" )
		{
			if( saved_AtTTrigger01 = 0 )
			{
				saved_AtTTrigger01 = 1;
				troll = GetEntity("troll01");
				troll.MoveAttack( 7718, 18137 );
			}
		}
		if( zone="MePassOn" )
		{
			GetPlayer().SetPassable(true);
		}
		if( zone="MePassOff" )
		{
			GetPlayer().SetPassable(false);
		}
		if( zone="Battle01" )
		{
			if( saved_AtBattle01 = 0 )
			{
				saved_AtBattle01 = 1;
				GetPlayer().PlaySound(56,50);

				GetEntity("bat01").SetPosition(2434,21864,-1283);
				GetEntity("bat02").SetPosition(1520,21632,-1475);
				GetEntity("bat03").SetPosition(1905,21760,-1475);
				GetEntity("bat04").SetPosition(4134,21866,-1283);
				GetEntity("bat05").SetPosition(6528,21376,-1283);

				GetEntity("bat02").TakeCover("RunBattle01",0,"crouch");
				GetEntity("bat03").TakeCover("RunBattle02",0,"stand");
			}
		}
	if( zone="CTrigger04" )
		{
			if( saved_AtCTrigger04 = 0 )
			{
				saved_AtCTrigger04 = 1;
				GetEntity("fall01").TakeCover("FallBattle01",1,"standPatrol");
			}
		}
		if( zone="CTrigger05" )
		{
			if( saved_AtCTrigger05 = 0 )
			{
				saved_AtCTrigger05 = 1;
				GetEntity("bat06").TakeCover("RunCover03",0,"left");
			}
		}
		if( zone="CTrigger06" )
		{
			if( saved_AtCTrigger06 = 0 )
			{
				saved_AtCTrigger06 = 1;
				GetEntity("bat07").TakeCover("RunBattle03",0,"standPatrol");
			}
		}
		if( zone="CTrigger08")
		{
			if( saved_AtCTrigger08 = 0 )
			{
				PlayAmbient(61);
				saved_AtCTrigger08 = 1;
				GetEntity("fall02").TakeCover("FallBattle02",1,"standPatrol");
			}
		}
		if( zone="CTrigger09")
		{
			if( saved_AtCTrigger09 = 0 )
			{
				saved_AtCTrigger09 = 1;
				GetEntity("bat08").TakeCover("RunBattle04",0,"standPatrol");
			}
		}
		if( zone="CTrigger10")
		{
			if( saved_AtCTrigger10 = 0 )
			{
				saved_AtCTrigger10 = 1;
				PlayAmbient(62);
				GetEntity("henry").TakeCover("RunBattle05",0,"standPatrol");
			}
		}
		if( zone="Phase2")
		{
			if( saved_AtPhase2 = 0 )
			{
				saved_AtPhase2 = 1;

				GetPlayer().SetFrozen( true );

				pav = GetEntity("sarge");
				AdvanceObjectives(0);
				pav.BriefTrench();
			}
		}
		if( zone="Phase3" )
		{
			if( saved_AtPhase3 = 0 )
			{
				saved_AtPhase3 = 1;
				AdvanceObjectives(0);

				pav = GetEntity("sarge");
				pav.BriefRunField();

				for i = 61 to 104
				{
					SetCellBlocking(42,i,false);
				}
			}
		}
		if( zone="Phase4" )
		{
			if( saved_AtPhase4 = 0 )
			{
				saved_AtPhase4 = 1;
				saved_Wave1 = 1;

				GetEntity("wave1a").TakeCover("WP1a",0,"stand");
				GetEntity("wave1b").TakeCover("WP1b",0,"crouch");
				GetEntity("wave1c").TakeCover("WP1c",0,"stand");

				GetEntity("wave1g1").TakeGun();
				GetEntity("wave1g2").TakeGun();

				AdvanceObjectives(0);

				GetEntity("sarge").FollowPathCallback( 127, "GoPatrol", 0);
			}
		}
		if( zone="GoUpstairs")
		{
			if( saved_AtGoUpstairs = 0 )
			{
				//JEFF TEST
				SetVis_Default();

				saved_AtGoUpstairs = 1;
				saved_Inside = 1;

				if( saved_BriefClear = 0 )
				{
					saved_BriefClear = 1;
					GetPlayer().PlaySound( 59 ); // "Clear the building floor by floor"
				}

				pav = GetEntity("sarge");

				if( saved_Wave1 = 1)
				{
					// You rushed the building
					saved_Wave1 = 0;

					pav.SetState_Idle();
					pav.GoPath("Enter1", 0);
					pav.FollowPathCallback(2, "SetState_Patrol", 0);
					pav.FollowPathCallback(2, "SetAttackDistance", 4, 2);
					pav.FollowPathCallback(127, "FightUpstairs");
				}
				else
				{
					pav.FightUpstairs();
				}
			}
		}
		if( zone="WaitForMe" )
		{
			if( saved_AtPhase3=0 )
			{
				// Why did you try to run across the field before being briefed???
				// Too bad you're now dead!

				me = GetPlayer();
				yPos = me.GetPositionY();

				me.SetFrozen(true);
				me.PlaySound(47); // Impact Flesh
				me.PlaySound(9);  // German Pain
				me.Kill();
				me.SetPosition(10268,yPos,18);
				me.SetFrozen(false);
			}
		}
	}]

	ActorKilled[ (who,obj)
	{
		if( saved_RunField = 1 )
		{
			if (saved_Wave1 = 1)
			{
				saved_CountWaves = saved_CountWaves + 1;
				if( saved_CountWaves = 8 ){ GetEntity("trunr3").Delay(5,10); }
				if( saved_CountWaves = 15 ){ GetEntity("trunr1").Delay(5,10); }
			if( saved_CountWaves = 18 ){ GetEntity("trunr2").Delay(5,10); }

				if( saved_CountWaves = 19 )
				{
					saved_Wave1 = 0;
					if( saved_BriefClear = 0 )
					{
						saved_BriefClear = 1;
						GetPlayer().PlaySound( 59 ); // "Clear the building floor by floor"
					}

					pav = GetEntity("sarge");
					pav.SetState_Idle();
					pav.GoPath( "Enter1", 0 );
					pav.FollowPathCallback(127,"GoPatrol",1);
					pav.FollowPathCallback(127,"TurnToLocation",20384,19584);
				}
			}
		}

		if( saved_BriefClear = 1 )
		{
			Spew("### DEAD:  " # who # " ###");
			Spew("### AmIn:  " # saved_Inside # " ###");
			CountDead(who);
		}

		if( (who="roofer") )
		{
			Spew( "Roofer has been killed, enabling gravity." );
			obj.UseGravity( true );
			return;
		}
	}]

	OnPlayerShot[ ()
	{
		FirstShotFired = 1;

		Spew("@@@ First Shot Fired @@@");
		dude = GetEntity("dude01");
		dude.TakeCover("RunCover01",0,"left");
	}]

	Spew[ (msg)
	{
		if( debug_spam = 1 )
		{
			Log(msg);
		}
	}]
}