#library "NADEMODE"
#include "zcommon.acs"

// ----------------------------------------------------------------------------
//
// 'Rasputin' grenade mode switching script
//
// Written by KeksDose for Russian Overkill
// Please do use and modify this script as you wish, but please keep the source
// file with this comment section intact and credit me somewhere.
//
// ----------------------------------------------------------------------------

#LibDefine RASPUTIN_NORMALMODE	0
#LibDefine RASPUTIN_FLAMEMODE	1
#LibDefine RASPUTIN_FROSTMODE	2
#LibDefine RASPUTIN_TOXICMODE	3
#LibDefine RASPUTIN_MODECOUNT	3
#LibDefine RASPUTIN_SWITCHDELAY	81	// Should be the switching animation time

Int RasputinModes[RASPUTIN_MODECOUNT]	=
{
	RASPUTIN_FLAMEMODE,
	RASPUTIN_FROSTMODE,
	RASPUTIN_TOXICMODE
};

Int RasputinButtons[RASPUTIN_MODECOUNT]	=
{
	BT_MOVELEFT,
	BT_FORWARD,
	BT_MOVERIGHT
};

Str RasputinTriggers[RASPUTIN_MODECOUNT]	=
{
	"FlameModeTrigger",
	"FrostModeTrigger",
	"ToxicModeTrigger"
};

Str RasputinNormal = "NormalModeTrigger";

Function Bool Input_ButtonHeld(Int OldInput, Int NewInput, Int ButtonMask)
{
	If((OldInput & ButtonMask) &&
	   (NewInput & ButtonMask))
	{
		Return TRUE;
	}
	
	Return FALSE;
}

Function Bool Input_ButtonClicked(Int OldInput, Int NewInput, Int ButtonMask)
{
	If(!(OldInput & ButtonMask) &&
	    (NewInput & ButtonMask))
	{
		Return TRUE;
	}
	
	Return FALSE;
}

// Remember:
// FlameMode, FrostMode, ToxicMode

Script 714 (Void)
{
	Int OldInput = 0;
	Int NewInput = 0;
	Int WeaponMode = 0;
	
	While(CheckWeapon("Rasputin") == TRUE)
	{
		OldInput = GetPlayerInput(-1, INPUT_OLDBUTTONS);
		NewInput = GetPlayerInput(-1, INPUT_BUTTONS);
		
		If(Input_ButtonHeld(OldInput, NewInput, BT_ALTATTACK) == TRUE)
		{
			For(Int TestMode = 0; TestMode < RASPUTIN_MODECOUNT; TestMode++)
			{
				If(Input_ButtonClicked(OldInput, NewInput, RasputinButtons[TestMode]))
				{
					If(WeaponMode == RasputinModes[TestMode])
					{
						WeaponMode = RASPUTIN_NORMALMODE;
						
						GiveInventory(RasputinNormal, 1);
					}
					
					Else
					{
						WeaponMode = RasputinModes[TestMode];
						
						GiveInventory(RasputinTriggers[TestMode], 1);
					}
					
					Delay(Const:RASPUTIN_SWITCHDELAY);
				}
			}
		}
		
		Delay(Const:1);
	}
}
