/*
 * Temple and new recall code for Age of Infinity MUD
 * (c)1999 by Theodryck (Joe Brimingham).  Please feel
 * free to use this code and distribute. All I require
 * is that the documentation remain intact.
 *
 * This code essentially allows players to chose various
 * places to set as their point of recall.  Must be type
 * ROOM_TEMPLE in order to choose as a temple though
 */

 /* Ability to recall to various places around the mud
  by Theodryck */

/* In merc.h add this to the pcdata struct */
int                       temple;

/* Declare the room type */
#define                    ROOM_TEMPLE        BV17

/*add the command to the DECLARE_DO_FUN section */
DECLARE_DO_FUN(    do_temple )       /* Theodryck of Age of Infinity MUD */

void do_temple( CHAR_DATA *ch, char * argument )
 {
      char              buf[MAX_STRING_LENGTH];

     if (!IS_SET(ch->in_room->room_flags, ROOM_TEMPLE) )
       {
        sprintf( buf, "You are not in a temple.\n\r" );
        send_to_char( buf, ch );
        return;
       }

      ch->pcdata->temple = ch->in_room->vnum;
      send_to_char( "You are now templed here." , ch );
      return;
  }

  /*
   * Next is my new version of do recall.
   * You may wish to change it in order to suit
   * the temple vnums of your areas.
   * -- Theo
   */
void do_recall( CHAR_DATA *ch, char *argument )
{
    CHAR_DATA       *victim;
    ROOM_INDEX_DATA *location;
    char             buf [ MAX_STRING_LENGTH ];
    int              place;

/* Wynter - just stopping silly ppl from crashing mud by making mobs recall */
    if ( IS_NPC ( ch ) )
	return;

    act( "$n prays for transportation!", ch, NULL, NULL, TO_ROOM );

    if ( IS_SET( ch->in_room->room_flags, ROOM_NO_RECALL )
	|| IS_AFFECTED( ch, AFF_CURSE ) )
    {
	send_to_char( "God has forsaken you.\n\r", ch );
	return;
    }


     if(ch->pcdata->temple != 0 )
      place = ch->pcdata->temple;
     else
      place = 3001;

     /*if(IS_SET(ch->act, PLR_BATTLE) ) Part of my battle code.  Ignore unless you choose to add it
      place = 24050;  */

    if ( !( location = get_room_index( place ) ) )
    {
	send_to_char( "You are completely lost.\n\r", ch );
	return;
    }

    if ( ch->in_room == location )
	return;

    if ( ( victim = ch->fighting ) )  /*Again, if using my battle code add: && (!IS_SET( ch->act, PLR_BATTLE ) ) */
    {
	int lose;

	if ( number_bits( 1 ) == 0 )
	{
	    WAIT_STATE( ch, 4 );
	    if ( ch->level < 100 )
	      lose = ( ch->level * ch->level * 50 );
	    else
	      lose = ( ch->level * ch->level * ch->level );

	    gain_exp( ch, 0 - lose );
	    sprintf( buf, "You failed!  You lose %d exps.\n\r", lose );
	    send_to_char( buf, ch );
	    return;
	}

	    if ( ch->level < 100 )
	      lose = ( ch->level * ch->level * 50 );
	    else
	      lose = ( ch->level * ch->level * ch->level );
	gain_exp( ch, 0 - lose );
	sprintf( buf, "You recall from combat!  You lose %d exps.\n\r", lose );
	send_to_char( buf, ch );
	stop_fighting( ch, TRUE );
    }


    ch->move /= 2;
    act( "$n disappears.", ch, NULL, NULL, TO_ROOM );
    char_from_room( ch );
    char_to_room( ch, location );
    act( "$n appears in the room.", ch, NULL, NULL, TO_ROOM );
    do_look( ch, "auto" );

    return;
}

/*And lastly the function to the command table in interp.c */
{ "temple",         do_temple,      POS_DEAD,        0,  LOG_NORMAL, 1 },

/*
 * And that's pretty much it.  Don't forget to add the fields
 * for temple in save.c.  You shouldn't have any problems with
 * doing that though.
 * Comments or suggestions?  Email me: theo@envy.com
 */