#library "MINEMODE"
#include "zcommon.acs"

// ----------------------------------------------------------------------------
//
// 'Gopnik' mine mode switching script
//
// Written by KeksDose for Russian Overkill
// Modified from 'Rasputin' grenade mode switching script by PillowBlaster
// 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 GOPNIK_NORMALMODE	0
#LibDefine GOPNIK_NUKEMODE		1
#LibDefine GOPNIK_TESLAMODE		2
#LibDefine GOPNIK_FARTMODE		3
#LibDefine GOPNIK_MODECOUNT		3
#LibDefine GOPNIK_SWITCHDELAY	25	// Should be the switching animation time

Int GopnikModes[GOPNIK_MODECOUNT]	=
{
	GOPNIK_NUKEMODE,
	GOPNIK_TESLAMODE,
	GOPNIK_FARTMODE
};

Int GopnikButtons[GOPNIK_MODECOUNT]	=
{
	BT_MOVELEFT,
	BT_FORWARD,
	BT_MOVERIGHT
};

Str GopnikTriggers[GOPNIK_MODECOUNT]	=
{
	"GopnikNukeModeTrigger",
	"GopnikTeslaModeTrigger",
	"GopnikFartModeTrigger"
};

Str GopnikNormal = "GopnikNormalModeTrigger";

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:
// NukeMode, TeslaMode, FartMode

Script 712 (Void)
{
	Int OldInput = 0;
	Int NewInput = 0;
	Int WeaponMode = 0;
	
	While(CheckWeapon("Gopnik") == TRUE)
	{
		OldInput = GetPlayerInput(-1, INPUT_OLDBUTTONS);
		NewInput = GetPlayerInput(-1, INPUT_BUTTONS);
		
		If(Input_ButtonHeld(OldInput, NewInput, BT_ALTATTACK) == TRUE)
		{
			For(Int TestMode = 0; TestMode < GOPNIK_MODECOUNT; TestMode++)
			{
				If(Input_ButtonClicked(OldInput, NewInput, GopnikButtons[TestMode]))
				{
					If(WeaponMode == GopnikModes[TestMode])
					{
						WeaponMode = GOPNIK_NORMALMODE;
						
						GiveInventory(GopnikNormal, 1);
					}
					
					Else
					{
						WeaponMode = GopnikModes[TestMode];
						
						GiveInventory(GopnikTriggers[TestMode], 1);
					}
					
					Delay(Const:GOPNIK_SWITCHDELAY);
				}
			}
		}
		
		Delay(Const:1);
	}
}
