/***********************************************
 * _pbombweapon1 - Players bomb weapon
 * 
 * Author: GD
 * Date:   12 June 2002
 *
 * Desc:   Script to allow the player to use bombs as
 *		   a weapon, this script needs the actual bomb
 *		   script - _bombweapon1 to be included as well.
 * 
 * Usage:  Use in the players script
 *         
 ***********************************************/
#include <entity>
#include <general>
#include <counter>

main()
{
	if (FirstRun())
	{
		// Set the image which appears in the start menu
		SetImage("this", "_bombicon1");
		
		// Set this entity's basic type
      SetType("this", weaponType);
   
      // Create 2 string for the weapons descriptions
      AllocateStrings("this", 2, 64);	
      SetString("this", 0, "You Got Bombs!");
      SetString("this", 1, "Bombs");
      SetOwnedFlag("this", true);		// Bombs are always avaiable on the menu
	}
	
	SetActiveDist("this", -1);
}


//----------------------------------------
// Name: Init()
//----------------------------------------
public Init()
{
   /* This function should be called by the Player script every
      time just before the weapon is used */
      
	// Check the player actually has some bombs
	if (GetCounterValue("bombs") < 1)
	{
		// no bombs
		PlaySound("_error.wav", 240);
		return -1;
	}
	else
	{
		// Decrease bomb amount by 1
		IncCounterValue("bombs", -1);
	}

   // Play the sound of a bomb being laid
   PlaySound("_bombplaced.wav", 240);
   
   new EntName[20];
	new x = GetX("player1");
	new y = GetY("player1");
	new dir = GetDirection("player1");
	
	// Adjust the bombs position based on the player's direction
	if ( dir == north )
		y -= 12;
	else if ( dir == east )
		x += 12;
	else if ( dir == south )
		y += 12;
	else if ( dir == west )
		x -= 12;
			
	// We dont have to do much here - just create a bomb entity
	// in front of the player.
	CreateEntity("_bombweapon1", x, y, EntName);
	
	// Return control back to player entity
	return -1;
}
