/***********************************************
 * _prupeeweapon1 - A weapon that transforms rupees into bombs.
 * 
 * Author: Saber Mage
 * Date:   29 Febuary 2003
 *
 * Desc:   Script to allow the player to use bombs reducing
 *		   the quantity of rupees instead of bombs. This script needs the 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 Rupee Bombs! Like having a bomb shop right with you!");
        SetString("this", 1, "Rupee Bombs");
        SetOwnedFlag("this", true);		// Rupee 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("rupees") < 1)
	{
		// no bombs
		PlaySound("_error.wav", 240);
		// Return control back to player entity
    	SetState("player1", standing);
		return 0;
	}
	else
	{
		// Decrease rupee amount by 1
		IncCounterValue("rupees", -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
    SetState("player1", standing);
}