//Scripts of my old bike. Required to make the tank work.


#library "VEHICLECONTROL"
#include "zcommon.acs"



int playerprevioushealth;
int playerpreviousarmor;
int vehicleprevioushealth;




//FORWARD
script 421 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
   
if (buttons & BT_FORWARD)
{
   GiveInventory("Accelerate", 1);
   //giveinventory("HealthBonus", GetActorProperty(0, APROP_HEALTH));
   
   delay(1);
}
   delay(1);
   TakeInventory("Accelerate", 1);
 }
}


//BACKPEDAL
script 422 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_BACK)
{
    GiveInventory("BackPedal", 1);
	delay(2);
}

   delay(2);
   TakeInventory("BackPedal", 1);
 }
}


//LEFT
script 423 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_MOVELEFT)
{
    GiveInventory("TurnLeft", 1);
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("RollLeft", 1); }
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("GoSpecial", 1); }
}

   delay(1);
 }
}



//RIGHT
script 424 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_MOVERIGHT)
{
    GiveInventory("TurnRight", 1);
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("RollRight", 1); }
	//if (checkinventory("IsRunning2") == 1) { GiveInventory("GoSpecial", 1); }
}

   delay(1);
   TakeInventory("TurnRight", 1);
 }
}

//USE
script 426 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_USE)
{
    GiveInventory("PressedUse", 1);
}

   delay(1);
 }
}

//JUMP
script 427 ENTER
{
 int buttons;

 while (TRUE)
 {
   buttons = GetPlayerInput(-1, INPUT_BUTTONS);
   
if (buttons & BT_JUMP)
{
    GiveInventory("PressedJump", 1);
}

   delay(1);
 }
}





Script 428 (VOID) NET
{
 delay (90);
 TakeInventory("FiredTankMainGun", 1);
}


Script 429 (VOID) NET
{
 delay (1);
 UnMorphActor(0, 0);
}

Script 129 (VOID)//Check if player is online.
{
if	(GameType () > 0) 
	SetActorState(0,"IsOnline"); 
}

script 130 (VOID) NET
{
 vehicleprevioushealth = GetActorProperty(261, APROP_Health);
  delay(1);
}

script 131 (VOID) NET
{
 delay(1);
 playerprevioushealth = GetActorProperty( 0, APROP_Health);
 playerpreviousarmor = CheckInventory("Armor");
}


//Entering Heavy Machinegun
script 132 (VOID) NET
{
 delay(6);
 SetActorAngle (0, GetActorAngle (261));
 Thing_Move(0, 261, 1);
 GiveInventory("ArmorBonus", playerpreviousarmor);
 SetActorProperty(0, APROP_Health, playerprevioushealth);
 int thisgunmachinegunammo = CheckActorInventory(261, "HeavyMachinegunAmmo");
 GiveInventory("HeavyMachinegunAmmo", thisgunmachinegunammo);
 delay(1);
}



//leaving Heavy Machinegun
script 133 (VOID) NET
{
 delay (1);
 playerprevioushealth = GetActorProperty( 0, APROP_Health);
 playerpreviousarmor = CheckInventory("Armor");
 delay (1);
 int thisgunmachinegunammo = CheckInventory("HeavyMachinegunAmmo");
 GiveActorInventory(261, "HeavyMachinegunAmmo", thisgunmachinegunammo);
 TakeInventory("HeavyMachinegunAmmo", 400);
 Thing_Move(0, 264, 1);
 UnMorphActor(0, 0);
 delay (1);
 TakeInventory("Armor", 999);
 SetActorProperty(0, APROP_Health, playerprevioushealth);
 GiveInventory("ArmorBonus", playerpreviousarmor);
}



//Entering Tank
script 134 (VOID) NET
{
 delay(1);
 delay(5);
 SetActorAngle (0, GetActorAngle (261));
 Thing_Move(0, 261, 1);
 vehicleprevioushealth = GetActorProperty(261, APROP_Health);
 GiveInventory("StoredArmorInsideVehicle", playerpreviousarmor);
 GiveInventory("StoredHealthInsideVehicle", playerprevioushealth);
 SetActorProperty(0, APROP_Health, vehicleprevioushealth);
 int thisgunmachinegunammo = CheckActorInventory(261, "HeavyMachinegunAmmo");
 int thistankammo = CheckActorInventory(261, "TankAmmo");
 int thisvehicleHelicopterRocketAmmo = CheckActorInventory(261, "HelicopterRocketAmmo");
 int thisvehicleMechMortarAmmo = CheckActorInventory(261, "MechMortarAmmo");
 int thisvehicleMechLaserAmmo = CheckActorInventory(261, "MechLaserAmmo");
 int thisvehicleMechRocketAmmo = CheckActorInventory(261, "MechRocketAmmo");
 int vehiclepreviousbaseangle = CheckActorInventory(261, "TankBaseDirection");
 GiveInventory("HeavyMachinegunAmmo", thisgunmachinegunammo);
 GiveInventory("TankAmmo", thistankammo);
 GiveInventory("HelicopterRocketAmmo", thisvehicleHelicopterRocketAmmo);
 GiveInventory("MechMortarAmmo", thisvehicleMechMortarAmmo);
 GiveInventory("MechLaserAmmo", thisvehicleMechLaserAmmo);
 GiveInventory("MechRocketAmmo", thisvehicleMechRocketAmmo);
 SetUserVariable(0, "user_tankbasedirection", vehiclepreviousbaseangle);
 delay(1);
}

//leaving Tank
script 135 (VOID) NET
{
 int thisgunmachinegunammo = CheckInventory("HeavyMachinegunAmmo");
 int thistankammo = CheckInventory("TankAmmo");
 int thisvehicleHelicopterRocketAmmo = CheckInventory("HelicopterRocketAmmo");
 int thisvehicleMechMortarAmmo = CheckInventory("MechMortarAmmo");
 int thisvehicleMechLaserAmmo = CheckInventory("MechLaserAmmo");
 int thisvehicleMechRocketAmmo = CheckInventory("MechRocketAmmo");
 vehicleprevioushealth = GetActorProperty(0, APROP_Health);
 int vehiclepreviousbaseangle = GetUserVariable(0, "user_tankbasedirection");
 TakeInventory("HeavyMachinegunAmmo", 9999);
 TakeInventory("TankAmmo", 9999);
 TakeInventory("HelicopterRocketAmmo", 9999);
 TakeInventory("MechRocketAmmo", 9999);
 TakeInventory("MechLaserAmmo", 9999);
 TakeInventory("MechMortarAmmo", 9999);
 Thing_Move(0, 264, 1);
 UnMorphActor(0, 0);
 delay (1);
 int resetarmor = CheckInventory("StoredArmorInsideVehicle");
 int resethealth = CheckInventory("StoredHealthInsideVehicle");
 SetActorProperty(0, APROP_Health, resethealth);
 GiveInventory("ArmorBonus", resetarmor);
 SetActorProperty(261, APROP_Health, vehicleprevioushealth);
 GiveActorInventory(261, "HeavyMachinegunAmmo", thisgunmachinegunammo);
 GiveActorInventory(261, "TankAmmo", thistankammo);
 GiveActorInventory(261, "HelicopterRocketAmmo", thisvehicleHelicopterRocketAmmo);
 GiveActorInventory(261, "MechMortarAmmo", thisvehicleMechMortarAmmo);
 GiveActorInventory(261, "MechLaserAmmo", thisvehicleMechLaserAmmo);
 GiveActorInventory(261, "MechRocketAmmo", thisvehicleMechRocketAmmo);
 GiveActorInventory(261, "TankBaseDirection", vehiclepreviousbaseangle);
 SetActorProperty(261, APROP_Health, vehicleprevioushealth);
 TakeInventory("StoredHealthInsideVehicle", 9999);
 TakeInventory("StoredArmorInsideVehicle", 9999);
}



//Set Tank's new base angle after you leave it.
script 136 (VOID) NET
{
 delay (1);
 int thisvehiclecurrentbaseangle = CheckInventory("TankBaseDirection");
 delay (1);
 SpawnSpot("TankBaseStationed", 0, 0, thisvehiclecurrentbaseangle*256/360);
 delay (1);
}


//Set the current direction of a newly spawned tank.
script 137 (VOID) NET
{
 delay (1);
 int thisvehicleinitialbaseangle = GetActorAngle(0);
 int angleformulacalculation = thisvehicleinitialbaseangle >> 8;
 int angleformulacalculationlastpart = angleformulacalculation*360/256;
 delay (1);
 GiveInventory("TankBaseDirection", angleformulacalculationlastpart);
 delay (1);
}















#define C_TIDX		1000	//Default camera tid
#define MAX_RX		220	//Maximum radius (or distance from the player)
#define ADJUST_R	12	//Amount to adjust the camera by
#define VIEW_HEIGHTX	100.0	//The approximate height of the player's view


#define VIEW_HEIGHTXMECH	200.0	//The approximate height of the player's view
#define MAX_RXMECH		300	//Maximum radius (or distance from the player)


bool camera_mode2[8];		//Variable for turning the camera on or off.
	
Script 111(VOID)
{
setfont("TNHSA0");
	hudmessage(s:"A"; 
				HUDMSG_PLAIN, 0, CR_UNTRANSLATED, 0.5, 0.57, 1.0);
	delay(40 * 6);
}

Script 656(VOID)
{
setfont("CONFONT");
 int mgunammo = CheckInventory("HeavyMachinegunAmmo");
	hudmessage(d: mgunammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.38, 0.80, 0.06);
 int rocketammo = CheckInventory("MechRocketAmmo");
	hudmessage(d: rocketammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.65, 0.80, 0.06);
int laserammo = CheckInventory("MechLaserAmmo");
	hudmessage(d: laserammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.38, 0.94, 0.06);	
int mortarammo = CheckInventory("MechMortarAmmo");
	hudmessage(d: mortarammo; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.65, 0.94, 0.06);	
int mechhealth = GetActorProperty(0, APROP_HEALTH);
	hudmessage(d: mechhealth; HUDMSG_PLAIN, 0, CR_LIGHTBLUE, 0.50, 0.96, 0.06);		
	delay(2);
}
	
Script 877 (VOID)
{
	camera_mode2[PlayerNumber ()] = ON;
	ACS_ExecuteAlways (801, 0, PlayerNumber ());
}


Script 801 (int p_num)
{
	int r = MAX_RX;
	
	while (camera_mode2[p_num] == ON)
	{	
		int a = GetActorAngle (0);
		int p = GetActorPitch (0);
		int x = GetActorX (0);
		int y = GetActorY (0);
		int z = GetActorZ (0) + VIEW_HEIGHTX;
		int xyr = r * cos (p) >> 16;
		
		if (!ThingCountName ("chasecam3", C_TIDX+p_num))
		{
			while (!Spawn ("chasecam3", x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, C_TIDX+p_num, a >> 8) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			if (ThingCountName ("chasecam3", C_TIDX + p_num))
				ChangeCamera (C_TIDX + p_num, 0, 0);
			else
			{
				camera_mode2[p_num] = OFF;
				print (s:"Camera script failed to initialize.");
			}
		}





	        else
		{
			while (!SetActorPosition (C_TIDX+p_num, x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, 0) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			SetActorAngle (C_TIDX + p_num, a);
			SetActorPitch (C_TIDX + p_num, p);
			
			if (r < MAX_RX) 
                                r += ADJUST_R;
		}
		
		delay (1);
	}
}




Script 871 (VOID)
{
	camera_mode2[PlayerNumber ()] = OFF;
	Thing_Remove (C_TIDX + PlayerNumber ());
}

Script 820 (int p_num) DISCONNECT
{
       camera_mode2[p_num] = OFF;
       Thing_Remove (C_TIDX + p_num);
}







Script 887 (VOID)
{
	camera_mode2[PlayerNumber ()] = ON;
	ACS_ExecuteAlways (811, 0, PlayerNumber ());
}


Script 811 (int p_num)
{
	int r = MAX_RXMECH;
	
	while (camera_mode2[p_num] == ON)
	{	
		int a = GetActorAngle (0);
		int p = GetActorPitch (0);
		int x = GetActorX (0);
		int y = GetActorY (0);
		int z = GetActorZ (0) + VIEW_HEIGHTXMECH;
		int xyr = r * cos (p) >> 16;
		
		if (!ThingCountName ("chasecam3", C_TIDX+p_num))
		{
			while (!Spawn ("chasecam3", x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, C_TIDX+p_num, a >> 8) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			if (ThingCountName ("chasecam3", C_TIDX + p_num))
				ChangeCamera (C_TIDX + p_num, 0, 0);
			else
			{
				camera_mode2[p_num] = OFF;
				print (s:"Camera script failed to initialize.");
			}
		}





	        else
		{
			while (!SetActorPosition (C_TIDX+p_num, x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, 0) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			SetActorAngle (C_TIDX + p_num, a);
			SetActorPitch (C_TIDX + p_num, p);
			
			if (r < MAX_RXMECH) 
                                r += ADJUST_R;
		}
		
		delay (1);
	}
}




Script 881 (VOID)
{
	camera_mode2[PlayerNumber ()] = OFF;
	Thing_Remove (C_TIDX + PlayerNumber ());
}

Script 830 (int p_num) DISCONNECT
{
       camera_mode2[p_num] = OFF;
       Thing_Remove (C_TIDX + p_num);
}
