/***********************************************
 * Changes:  
 *	04/07/03 [lukex]: New file.
 ***********************************************/
#include <entity>
#include <general>
#include <counter>

new magicNeeded = 0;		// magic needed to fire the weapon
		
	
main()
{
	if (FirstRun())
	{
		// Set this entity's basic type
		SetType("this", weaponType);
		// Create 2 string for the item descriptions
		AllocateStrings("this", 2, 100);
		SetString("this", 0,  "You got the lantern! Now you can see in the dark");		// For Chests
		SetString("this", 1,  "Lantern");	// For menu
		SetImage("this", "i_lantern");
		SetOwnedFlag("this", true);
		magicNeeded = 1;
		CallFunction("_weatherlib", false, "AbleLantern", "n", true);
	}
	SetActiveDist("this", -1); 

		
}

//----------------------------------------
// Name: Init()
//----------------------------------------
public Init()
{
	
    if (magicNeeded > 0)
    {
	    // Make sure we have enough magic to do this
	    if ( GetCounterValue( "magicMeter" ) < magicNeeded )
	    {
	    	// Player does have enough magic
	    	PlaySound("_error.wav", 240);
	    	SetState("player1", standing);
	    	return;	
	    }
	    else
	    {
	    	// Decrease magic level
	    	IncCounterTarget("magicMeter", -magicNeeded);	
	    }
    }
	   
		
    // Set the Position and Direction of this entity to match the player's
    SetX("this", GetX("player1"));
    SetY("this", GetY("player1"));
    SetDirection("this", GetDirection("player1"));
    PlaySound("_fireball.wav");
    
    CreateFlame();
}

CreateFlame()
{
	new entity[20];
	new x = GetX("player1");
	new y = GetY("player1");
	new dir = GetDirection("player1");
	
	if ( dir == north )
	{
		y -= 18;
	}
	else if ( dir == east )
	{
		x += 18;
	}
	else if ( dir == south )
	{
		y += 18;
	}
	else if ( dir == west )
	{
		x -= 18;
	}
	
	// Create a flame entity
   CreateEntity("_flame", x, y, entity);
	SetDirection(entity, dir);
}

//----------------------------------------
// Name: DrawWeapon()
//----------------------------------------
public DrawWeapon(keypressed)
{
	// Get the Correct Animation
	new dir = GetDirection("this");

   new x = GetX("this");
   new y = GetY("this");

	// Draw the Player animation
	if (isVisible("player1"))
	{
		// Draw the Player
		CallFunction("player1", false, "Stand", "nn", x, y);
   }

   SetState("player1", standing);
}

