/************************************************************************
 * _doenrtance#.zes Entity Script
 * 
 * Author: GD
 * Date:   6 July 2002
 *
 * Desc:   A script for any Outside Dungeon Entrance - that is a dungeon
 *		   from the outside leading in.
 *
 * Usage:  Place in the Landscape Designer.
 *
 *         Use SetString() to place the identifier of the door you want this one
 *         to lead to into the first string of this entity, i.e:
 * 
 *		      SetString("thisdoor", 0, "targetdoor");
 *
 *		   Then it should automatically take you to the target door when you go
 *         Through this one.
 *
 * Sprites: _MiscBuildings1.spt
 *         
 ***********************************************************************/
#include <entity>
#include <general>
#include <animation>
new doorsprite[20];	
new width;			// Used to store the widht and height of the door
new height;
new param;			// Will hold the parameter passed to this script
new x;
new y;

//----------------------------------------
// Name: main()
//----------------------------------------
main()
{
   if (FirstRun())
   {
      // Get the parameter passed to this script from the sprite code
      param = GetParam("this");
      AllocateStrings("this", 1, 20);
      SetDirection("this", north);
      SetType("this", doorType);
           
      // Add Frames to Animation depending on what the parameter is
      if ( param == 'a' )       // Entrance to green dungeon
      {
         doorsprite = "_doentrancea";
      }
      else if ( param == 'b' )    // Entrance to first dark word temple
      {
         doorsprite = "_doentranceb";
      }
     
      // Record the width and height of the main sprite for later use
      width  = GetWidth(doorsprite);
      height = GetHeight(doorsprite);
      SetImage("this", doorsprite);
      x = GetX("this");
      y = GetY("this");
   
      SetOpenFlag("this", true);
      SetInteractingFlag("this", false);
   }

   // Draw the door 
   PutSprite(doorsprite, x, y, 1);

   // Create a collsion rectangle around the whole door
   SetCollisionRect("this", 0, false, x, y, x + width, y + height);

   /* Create another collision rectangle inside the door for checking if the 
      player is standing in the doorway */
   SetCollisionRect("this", 1, false, x, y, x + width, y + 2);

   // Check if the Player is standing in the doorway
   if ( CollideAll("this", "player1") )
   {
      SetInteractingFlag("this", true);     						// Set the Interacting Flag to true     
      CallFunction("_doorlib", true, "MoveToOtherDoor", "NULL");	// Maybe move to another door
   }
   else
      SetInteractingFlag("this", false);  
}

