//===================================================
// Z O M B I E   T O R R E N T   2
// SLOT MACHINE SYSTEM
//
// Coded by Zedek the Plague Doctor
// Inspired by Marco's slot machines for KF
//===================================================

#library "slotcards"
#include "zcommon.acs"
#import "zt2functions.acs"

#define MAX_SLOTS 150

//=====================================================
// DO NOT DIRECTLY MODIFY THESE VARIABLES
//=====================================================
int totalCards;

// Display name
str cardDisplayName[MAX_SLOTS];
// What case in the script this card uses
int cardCaseID[MAX_SLOTS];
// The icon that this card uses
str cardIcon[MAX_SLOTS];
// Script that this card uses
int cardScript[MAX_SLOTS];
// CARD TYPE
// 0: Good card
// 1: Bad card
// 2: Fucking lulzy card (Really good)
// 3: Awful card (Really bad)
int cardType[MAX_SLOTS];
// What happens when you get this card
int cardDescription[MAX_SLOTS];
// Sound that this slot plays
str cardSound[MAX_SLOTS];

// -- "PERK" ICONS ------------------------------------
int effectTotal;
str effectIcon[MAX_SLOTS];
str effectItem[MAX_SLOTS];

// Height of the effect icons
#define EFFECT_HEIGHT 32.0
#define EFFECT_STARTX 0.05
#define EFFECT_STARTY 0.5
#define EFFECT_BASEID 750

// How many columns to show on-screen (Make this CVAR)
#define EFFECT_COLUMNS 2

// FOR THE RANDOM WEAPON SLOT
#define TOTAL_WEAPONS 4
#define RANDOM_ACTOR 0
#define RANDOM_STRING 1
str randomWeapons[TOTAL_WEAPONS][2] = {
	{"Flamethrower","the \cKFlamethrower"},
	{"DWChainsaw","a huge \cKChainsaw"},
	{"SS-2 Ravager","the \cKSS-2 Ravager"},
	{"AA12 Shotgun","an \cKAA-12 Shotgun"},
};

//=====================================================================
// v v v DO NOT CHANGE THESE FUNCTIONS v v v
//=====================================================================
// Initial trader add for a weapon
function void AddSlotCard(str cName,int cID,str cIcon,int cScript,int cType,str cDescription,str cSound)
{
	cardDisplayName[totalCards] = cName;
	cardCaseID[totalCards] = cID;
	cardIcon[totalCards] = cIcon;
	cardScript[totalCards] = cScript;
	cardType[totalCards] = cType;
	cardDescription[totalCards] = cDescription;
	cardSound[totalCards] = cSound;
	// Increase how many tracks we have
	totalCards ++;
}

// Add an effect icon to show on the screen
function void AddEffect(str eIcon,str eItem)
{
	effectIcon[effectTotal] = eIcon;
	effectItem[effectTotal] = eItem;
	effectTotal ++;
}

// Clear all of the previous cards and get ready to add our own
function void ClearSlotCards(void) {totalCards = 0;}

//=====================================================================
// ^ ^ ^ DO NOT CHANGE THESE FUNCTIONS ^ ^ ^
//=====================================================================

// Let's print some HUD junk on the screen
script 474 ENTER CLIENTSIDE
{
	int l;
	int row;
	int column;
	int iSize;
	
	// Permanently loop
	while (1)
	{
		row = 0;
		column = 0;
		
		iSize = EFFECT_HEIGHT+(GetCVar("cl_effectpadding")*1.0);
		
		for (l=0; l<effectTotal; l++)
		{
			SetFont("SMALLFONT");
			HUDMessageUnscaledSlot(0,0,"",0,0,EFFECT_BASEID+l,1.0);
			
			// Do we have the item that belongs to this effect?
			if (CheckInventory(effectItem[l]))
			{
				SetFont(effectIcon[l]);
				HUDMessageUnscaledSlot(32.0+(column*iSize),128.0+(row*iSize),"a",0,0,EFFECT_BASEID+l,1.0);
				
				column ++;
				if (column >= GetCVar("cl_effectcolumns"))
				{
					column = 0;
					row ++;
				}
			}
			
			SetFont("SMALLFONT");
		}
		
		delay(1);
	}
}

// Controls the actual adding of cards
script 475 OPEN
{
	//--SLOT MACHINE CARDS-----
	// No Explosives Allowed
	AddSlotCard("No Explosives Allowed",0,"SLOTIC01",476,3,"You lost your grenades!","slot/win");
	// Quicksilver
	AddSlotCard("Quicksilver",1,"SLOTIC02",476,0,"Gotta go fast!","slot/win");
	// Supply Drop
	AddSlotCard("Supply Drop",2,"SLOTIC03",476,0,"Lock and load!","slot/win");
	// Godlike
	AddSlotCard("Godlike",3,"SLOTIC04",476,2,"IDDQD, have fun!","slot/win");
	// Demigod
	AddSlotCard("Demigod",4,"SLOTIC05",476,0,"Feel the blood in your veins!","slot/win");
	// I Like Turtles
	AddSlotCard("I Like Turtles",5,"SLOTIC06",476,1,"Slow and steady wins the race.","slot/win");
	// Alcohol-Incarnate
	AddSlotCard("Alcohol Incarnate",6,"SLOTIC07",476,3,"Nice hangover, bro!","slot/win");
	// P A I N
	AddSlotCard("P A I N",7,"SLOTIC08",476,3,"Now you know true pain!","slot/win");
	// Flying High
	AddSlotCard("Flying High",8,"SLOTIC09",476,0,"Do you believe you can fly?","slot/win");
	// Supply Drop II
	AddSlotCard("Supply Drop II",9,"SLOTIC10",476,2,"You test your luck...","slot/win");
	
	//--EFFECTS TO SHOW ON THE SCREEN-----
	// Quicksilver
	AddEffect("EFFECT01","PowerQuicksilver");
	// Godlike
	AddEffect("EFFECT02","PowerGodlike");
	// Demigod
	AddEffect("EFFECT03","PowerDemigod");
	// I Like Turtles
	AddEffect("EFFECT04","PowerTurtles");
	// Alcohol-Incarnate
	AddEffect("EFFECT05","PowerDrunk");
	// Flying High
	AddEffect("EFFECT06","PowerFlyingHigh");
}

// ZT2 base slot effects
script 476 (int slotEffect) NET
{
	switch (slotEffect)
	{
		// No Explosives Allowed
		case 0:
		{
			TakeInventory("Type97Primary",999);
			TakeInventory("DynamitePrimary",999);
			TakeInventory("FlamenadePrimary",999);
			break;
		}
		
		// Quicksilver
		case 1:
		{
			GiveInventory("PowerQuicksilver",1);
			break;
		}
		
		// Supply Drop
		case 2:
		{
			GiveInventory("Backpack",1);
			delay(1);
			GiveInventory("Backpack",1);
			delay(1);
			GiveInventory("Backpack",1);
			delay(1);
			GiveInventory("Backpack",1);
			break;
		}
		
		// Godlike
		case 3:
		{
			GiveInventory("PowerGodlike",1);
			break;
		}
		
		// Demigod
		case 4:
		{
			GiveInventory("PowerDemigod",1);
			break;
		}
		
		// I Like turtles
		case 5:
		{
			GiveInventory("PowerTurtles",1);
			break;
		}
		
		// Alcohol-Incarnate
		case 6:
		{
			GiveInventory("DrunkTimer",999);
			GiveInventory("PowerDrunk",1);
			break;
		}
		
		// P A I N
		case 7:
		{
			SetActorProperty(0,APROP_HEALTH,5);
			break;
		}
		
		// Flying High
		case 8:
		{
			GiveInventory("PowerFlyingHigh",1);
			break;
		}
		
		// Supply Drop II
		case 9:
		{
			delay(45);
			
			int RW = Random(0,TOTAL_WEAPONS-1);
			
			GiveInventory(randomWeapons[RW][RANDOM_ACTOR],1);
			Print(s:"\cJYou found ",s:randomWeapons[RW][RANDOM_STRING],s:"\cJ!");
		}
	}
}

// Controls drunk mode and some other things
script 477 ENTER
{
	int drunkRot;
	int drunkIntensity = 0.006;
	int actualAngle;
	
	while (1)
	{
		drunkRot ++;
		if (drunkRot >= 360)
			drunkRot = 0;
			
		actualAngle = drunkRot << 8;
			
		if (CheckInventory("PowerDrunk"))
		{
			SetActorPitch(0,GetActorPitch(0) + FixedMul(drunkIntensity,sin(actualAngle)) );
			SetActorAngle(0,GetActorAngle(0) + FixedMul(drunkIntensity,sin(actualAngle)) );
			TakeInventory("DrunkTimer",1);
			
			if (CheckInventory("DrunkTimer") <= 0)
				TakeInventory("PowerDrunk",1);
		}
		
		delay(1);
	}
}