kbkmud/player/
/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
*	ROM 2.4 is copyright 1993-1996 Russ Taylor			   *
*	ROM has been brought to you by the ROM consortium		   *
*	    Russ Taylor (rtaylor@pacinfo.com)				   *
*	    Gabrielle Taylor (gtaylor@pacinfo.com)			   *
*	    Brian Moore (rom@rom.efn.org)				   *
*	By using this code, you have agreed to follow the terms of the	   *
*	ROM license, in the file Tartarus/doc/rom.license                  *
***************************************************************************/

/***************************************************************************
*       Tartarus code is copyright (C) 1997-1998 by Daniel Graham          *
*	In using this code you agree to comply with the Tartarus license   *
*       found in the file /Tartarus/doc/tartarus.doc                       *
***************************************************************************/

#include "include.h"

char *	const	dir_name	[]		=
{
    "north", "east", "south", "west", "up", "down"
};

const	sh_int	rev_dir		[]		=
{
    2, 3, 0, 1, 5, 4
};

const	sh_int	movement_loss	[SECT_MAX]	=
{
    1, 2, 2, 3, 4, 6, 4, 1, 6, 10, 6
};



/*
 * Local functions.
 */
int	find_door		args( ( CHAR_DATA *ch, char *arg ) );
bool	has_key			args( ( CHAR_DATA *ch, int key ) );
void 	murder_entry_trigger	args( (CHAR_DATA *ch) );
void 	move_prog_hydra		args( (CHAR_DATA *ch) );
void 	move_prog_bones		args( (CHAR_DATA *ch) );
void 	mob_entry_wraith	args( (CHAR_DATA *ch) );
bool    check_slick		args( (CHAR_DATA *ch) );
bool	pay_howmuch		args( (CHAR_DATA *ch) );
void 	EsiraenPiranhaCheck	args( (CHAR_DATA *ch) );

void move_char( CHAR_DATA *ch, int door, bool follow )
{
    CHAR_DATA *fch, *fch_next, *tch, *tch_next, *snaremaker, *moveprog;
    ROOM_INDEX_DATA *in_room, *to_room;
    EXIT_DATA *pexit;
    OBJ_DATA *obj;
    AFFECT_DATA snareaf;
    ROOM_AFFECT_DATA *snareaffect,*dragaf;
    bool snaretripped;
    int odir, centcount, c, invnum, move;
    char buf[MAX_STRING_LENGTH], buf2[MSL];
    bool room_has_pc;
    snaremaker=NULL;

    if ( door < 0 || door > 5 )
    {
	bug( "Do_move: bad door %d.", door );
	return;
    }

     if(!ch->in_room)
        return;

        invnum = ch->in_room->vnum;

    if (is_centurion(ch))
		return;

    if (!IS_NPC(ch))
    {
	if(is_affected(ch,gsn_chameleon))
	    affect_strip(ch,gsn_chameleon);

      	if (is_affected(ch, gsn_confuse) && number_percent()>60)
      	{
       	    act("You feel very confused.", ch,NULL,NULL,TO_CHAR);
            act("$n looks confused.", ch,NULL,NULL,TO_ROOM);
            door = number_range(0,5);
      	}
    }

    in_room = ch->in_room;
    if ( ( pexit   = in_room->exit[door] ) == NULL
    ||	 pexit->u1.vnum == 0
    ||   ( to_room = pexit->u1.to_room   ) == NULL
    ||	 !can_see_room(ch,pexit->u1.to_room))
    {
	send_to_char( "Alas, you cannot go that way.\n\r", ch );
	return;
    }
	
	if (is_affected_room(to_room,skill_lookup("hurricane")) && !IS_IMMORTAL(ch)) {
		ROOM_AFFECT_DATA *hurr = room_affect_find(to_room->affected,skill_lookup("hurricane"));
		CHAR_DATA *hurr_owner;
		
		act("A billowing wind knocks you down, preventing you from heading that way!",ch,0,0,TO_CHAR);
		act("A billowing wind knocks $n down!",ch,0,0,TO_ROOM);
		
		if ((hurr_owner = find_char_by_name(hurr->owner_name)) != NULL)
			damage_newer(hurr_owner,ch,hurr->level * 2 + number_range(1,5),TYPE_UNDEFINED,DAM_WIND,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"fall",PLURAL,DAM_POSSESSIVE,NULL,FALSE);
		else
			damage_newer(ch,ch,hurr->level * 2 + number_range(1,5),TYPE_UNDEFINED,DAM_WIND,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"fall",PLURAL,DAM_POSSESSIVE,NULL,FALSE);
		WAIT_STATE(ch,2*PULSE_VIOLENCE);
		return;
	}
	
	if (is_affected_room(ch->in_room,skill_lookup("hurricane")) && !IS_IMMORTAL(ch)) {
		ROOM_AFFECT_DATA *hurr = room_affect_find(ch->in_room->affected,skill_lookup("hurricane"));
		CHAR_DATA *hurr_owner;
		
		
		act("A billowing wind knocks you down, preventing you from heading that way!",ch,0,0,TO_CHAR);
		act("A billowing wind knocks $n down!",ch,0,0,TO_ROOM);
		
		if ((hurr_owner = find_char_by_name(hurr->owner_name)) != NULL)
			damage_newer(hurr_owner,ch,hurr->level + number_range(1,5),TYPE_UNDEFINED,DAM_WIND,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"fall",PLURAL,DAM_POSSESSIVE,NULL,FALSE);
		else
			damage_newer(ch,ch,hurr->level + number_range(1,5),TYPE_UNDEFINED,DAM_WIND,TRUE,HIT_UNBLOCKABLE,HIT_NOADD,HIT_NOMULT,"fall",PLURAL,DAM_POSSESSIVE,NULL,FALSE);
		WAIT_STATE(ch,2*PULSE_VIOLENCE);
		return;
	}

    if (IS_NPC(ch) && ch->pIndexData->vnum == MOB_VNUM_ENFORCER && !is_protected_city(to_room->area))
	return;
   
   if (in_room->sector_type!=SECT_UNDERWATER && to_room->sector_type==SECT_UNDERWATER && !is_affected(ch,gsn_water_breathing) && !is_affected(ch,gsn_drowning) && !IS_IMMORTAL(ch))
    {
	AFFECT_DATA applyAffect;
	send_to_char( "You take a deep breath and plunge below the water's surface.\n\r",ch);
	act( "$n takes a deep breath and plunges below the water's surface.",ch,0,0,TO_ROOM);
	init_affect(&applyAffect);
	applyAffect.aftype = AFT_INVIS;
	applyAffect.where = TO_AFFECTS;
	applyAffect.type = gsn_drowning;
	applyAffect.level = 1;
	applyAffect.duration = -1;
	affect_to_char(ch,&applyAffect);
    }

     if (in_room->sector_type==SECT_UNDERWATER && to_room->sector_type !=SECT_UNDERWATER && is_affected(ch,gsn_drowning) && !is_affected(ch,gsn_water_breathing))
    {
	send_to_char( "You gasp for air as you surface.\n\r",ch);
	affect_strip(ch,gsn_drowning);
    }

    if (IS_ROOM_AFFECTED(in_room,AFF_ROOM_RANDOMIZER))
    {
     	int d0;
     	int i;

     	for(i=0; i< 1000; i++)
     	{
     	    d0 = number_range(0,5);
     	    if ( ( pexit   = in_room->exit[d0] ) == NULL
     	    ||   ( to_room = pexit->u1.to_room   ) == NULL
     	    ||    !can_see_room(ch,pexit->u1.to_room))
     		continue;

     	    door = d0;
     	    break;
     	}
    }

    /* Centurions! */
    if ((centcount = room_centurions(ch)) > 0) 
    {
	if (!IS_IMMORTAL(ch) && !isNewbie(ch)) 
	{
		if (!IS_NPC(ch) && ch->ghost == 0) {
		    for (c = 0; c < centcount; c++) {
			if (ch->pcdata->empire == EMPIRE_ANATH) {
				act("An Imperial Centurion is infuriated and blocks your path!",ch,NULL,NULL,TO_CHAR);
				act("An Imperial Centurion is infuriated and blocks $n's path!",ch,NULL,NULL,TO_ROOM);
				return;
			}
			if (ch->pcdata->empire >= EMPIRE_BLOOD ||
				(ch->pcdata->empire < EMPIRE_BLOOD && ch->pcdata->empire_pay >= pay_howmuch(ch)))
			{
				act("An Imperial Centurion steps aside and allows you to pass.",ch,NULL,NULL,TO_CHAR);
				act("An Imperial Centurion steps aside and allows $n to pass.",ch,NULL,NULL,TO_ROOM);
				break;
			} else {
				if (ch->pcdata->empire_prev && ch->ghost==0) {
				odir = ch->pcdata->empire_prev;
				if (odir == ch->in_room->exit[door]->u1.to_room->vnum)
				{
					act("You turn away from the Centurion and return the way you came.",ch,NULL,NULL,TO_CHAR);
					act("$n turns away from the Centurion and returns the way $e came.",ch,NULL,NULL,TO_ROOM);
					break;
				} else {
					act("An Imperial Centurion blocks the way.",ch,NULL,NULL,TO_CHAR);
					return;
				}
				}
			}
		}
		ch->pcdata->empire_pay = 0;
	}
	}
    } // End centurion check.

    if (IS_SET(pexit->exit_info, EX_CLOSED)
    &&  (!IS_AFFECTED(ch, AFF_PASS_DOOR) || IS_SET(pexit->exit_info,EX_NOPASS))
    &&   !IS_TRUSTED(ch,ANGEL))
    {
	act( "You can't go that way.", ch, NULL, pexit->keyword, TO_CHAR );
	return;
    }

    if ( IS_AFFECTED(ch, AFF_CHARM)
    &&   ch->master != NULL
    &&   in_room == ch->master->in_room )
    {
	send_to_char( "What?  And leave your beloved master?\n\r", ch );
	return;
    }

    if ( !is_room_owner(ch,to_room) && room_is_private( to_room ) )
    {
	send_to_char( "That room is private right now.\n\r", ch );
	return;
    }

    if(!IS_NPC(ch) && isNewbie(ch) && IS_EXPLORE(to_room))
    {
	send_to_char("You are too young to go there.\n\r",ch);
	return;
    }

    if(!IS_NPC(ch) && ch->ghost>0 && IS_EXPLORE(to_room))
	ch->ghost=0;

    if ( !IS_NPC(ch) )
    {

	if ( in_room->sector_type == SECT_AIR
	||   to_room->sector_type == SECT_AIR )
	{
	    if ( !IS_AFFECTED(ch, AFF_FLYING) && !IS_IMMORTAL(ch))
	    {
		send_to_char( "You can't fly.\n\r", ch );
		return;
	    }
	}

	if (( in_room->sector_type == SECT_WATER_NOSWIM
	||    to_room->sector_type == SECT_WATER_NOSWIM )
  	&&    (!IS_AFFECTED(ch,AFF_FLYING) && !IS_AFFECTED(ch,AFF_WATERBREATHING)) )
	{
	    OBJ_DATA *obj;
	    bool found;

	    /*
	     * Look for a boat.
	     */
	    found = FALSE;

	    if (IS_IMMORTAL(ch))
		found = TRUE;

	    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
	    {
		if ( obj->item_type == ITEM_BOAT )
		{
		    found = TRUE;
		    break;
		}
	    }
	    if ( !found )
	    {
		send_to_char( "You need a boat to go there.\n\r", ch );
		return;
	    }
	}

	if(ch->in_room->move_progs)
		for(moveprog = ch->in_room->people; moveprog; moveprog = moveprog->next_in_room)
			if(IS_SET(moveprog->progtypes, MPROG_MOVE))
				if(((moveprog->pIndexData->mprogs->move_prog) (ch,moveprog,ch->in_room,door)) == FALSE)
					return;
	

	move = movement_loss[UMIN(SECT_MAX-1, in_room->sector_type)] + movement_loss[UMIN(SECT_MAX-1, to_room->sector_type)];
	if (get_skill(ch,gsn_pathfinding) > 0 && isInWilderness(ch) && cabal_down_new(ch,CABAL_SYLVAN,FALSE))
		move *= ((100 - get_skill(ch,gsn_pathfinding))/100);
        move /= 2;

	/* conditional effects */
	if (IS_AFFECTED(ch,AFF_FLYING) || IS_AFFECTED(ch,AFF_HASTE))
	    move *= .75;

	if (IS_AFFECTED(ch,AFF_SLOW))
	    move *= 2;

	if (is_affected(ch,gsn_hobble))
	    move *= 10;

	if (is_affected(ch,gsn_bloody_shackles))
	    move *= 8;

	if ( ch->move < move )
	{
	    send_to_char( "You are too exhausted.\n\r", ch );
	    return;
	}
	int wait_state = 1;
	if (get_skill(ch,gsn_pathfinding) > 0 && (ch->in_room->sector_type==SECT_FOREST || ch->in_room->sector_type==SECT_HILLS || ch->in_room->sector_type==SECT_MOUNTAIN) && cabal_down_new(ch,CABAL_SYLVAN,FALSE))
		wait_state = 1*((100-get_skill(ch,gsn_pathfinding))/100);
	if (is_affected(ch,gsn_hobble))
		wait_state = 3;
	WAIT_STATE(ch,wait_state);
		

	ch->move -= move;
    }

    if (is_affected(ch,gsn_forest_blending))
	un_forest_blend(ch);

	if(is_affected(ch,gsn_dragsnare))
		affect_strip(ch,gsn_dragsnare);

    if ( IS_AFFECTED(ch, AFF_CAMOUFLAGE) && !is_affected(ch,gsn_creep))
    {
	un_camouflage(ch, NULL);
    }

    un_earthfade(ch,NULL);

    if ( IS_AFFECTED(ch, AFF_HIDE) && to_room->sector_type != SECT_CITY && to_room->sector_type != SECT_ROAD && to_room->sector_type != SECT_INSIDE && !is_affected(ch,gsn_creep))
    {
	un_hide(ch,NULL);
    }

    if (ch->invis_level < LEVEL_HERO
    &&   !is_affected(ch,gsn_creep)
    && (!IS_AFFECTED(ch, AFF_SNEAK) && get_skill(ch,skill_lookup("shadowstep")) <= 90))
    {
	un_hide(ch, NULL);
   	if (is_affected(ch,gsn_door_bash))
            act("$n goes crashing through the door $T.",ch,0,dir_name[door],TO_ROOM);
    	else
	{
	    if (IS_AFFECTED(ch,AFF_FLYING) && ch->in_room->sector_type != SECT_UNDERWATER)
		act( "$n flies $T.", ch, NULL, dir_name[door], TO_ROOM);
	    else if (in_room->sector_type != SECT_UNDERWATER && to_room->sector_type == SECT_UNDERWATER)
		act( "$n plunges into the water $Tward.", ch, NULL, dir_name[door], TO_ROOM);
	    else if (in_room->sector_type == SECT_UNDERWATER && to_room->sector_type != SECT_UNDERWATER)
		act( "$n disappears $Tward, beyond the water's surface.", ch, NULL, dir_name[door], TO_ROOM); 
	    else if (in_room->sector_type == SECT_UNDERWATER && to_room->sector_type == SECT_UNDERWATER)
		act( "$n swims $T.", ch, NULL, dir_name[door], TO_ROOM );
	    else
	        act( "$n leaves $T.", ch, NULL, dir_name[door], TO_ROOM );
	}
    } else {
	act( "IMM: $n sneaks $T.", ch, NULL, dir_name[door], TO_IMMINROOM );
    }

    if ( (to_room->sector_type != SECT_FOREST) && (to_room->sector_type != SECT_MOUNTAIN) && (to_room->sector_type != SECT_HILLS ) )
    {
	un_camouflage(ch, NULL);
    }

    /* tracking stuff...very inefficient tracking method but basic. */
    if (!IS_NPC(ch))
    {
	ch->pcdata->track_dir[ch->in_room->vnum] = door + 1;
	if (ch->in_room)
	    ch->pcdata->empire_prev = ch->in_room->vnum;
    }
    
    char_from_room( ch );
    char_to_room( ch, to_room );

    snaretripped=FALSE;

    if ( !IS_AFFECTED(ch, AFF_SNEAK)
    &&   ch->invis_level < LEVEL_HERO
    &&   !is_affected(ch,gsn_creep)
    && get_skill(ch,skill_lookup("shadowstep")) <= 90)
    {
    	if (is_affected(ch,gsn_door_bash))
            act("The $T door bursts open and $n comes crashing in!",ch,0,dir_name[door],TO_ROOM);
    	else
	{
	    if (IS_AFFECTED(ch,AFF_FLYING) && ch->in_room->sector_type != SECT_UNDERWATER)
		act( "$n flies into the room.", ch, NULL, NULL, TO_ROOM);
	    else if (in_room->sector_type != SECT_UNDERWATER && to_room->sector_type == SECT_UNDERWATER)
		act( "$n plunges into the water from above the surface.", ch, NULL, NULL, TO_ROOM);
	    else if (in_room->sector_type == SECT_UNDERWATER && to_room->sector_type != SECT_UNDERWATER)
		act( "$n emerges from below the water's surface.", ch, NULL, NULL, TO_ROOM); 
	    else if (in_room->sector_type == SECT_UNDERWATER && to_room->sector_type == SECT_UNDERWATER)
		act( "$n swims in.", ch, NULL, NULL, TO_ROOM );
	    else
	    	act( "$n has arrived.", ch, NULL, NULL, TO_ROOM );
	}
    } else {
	act( "IMM: $n sneaks in.", ch, NULL, NULL, TO_IMMINROOM );
    }

    do_look( ch, "auto" );

    if (is_affected_room(to_room, gsn_snare) && !IS_NPC(ch))
    {
	for(snareaffect = to_room->affected; snareaffect!=NULL; snareaffect = snareaffect->next)
		if(snareaffect->type == gsn_snare)
			break;
	snaremaker = find_char_by_name(snareaffect->owner_name);
	if(snareaffect && snaremaker!=NULL && snaremaker!=ch && !is_safe(ch,snaremaker) && !is_same_group(ch,snaremaker) &&
		!is_same_cabal(ch,snaremaker) && (!IS_IMMORTAL(ch) || IS_IMMORTAL(snaremaker)))
	{
	act("A tangled mass of vines descends upon you, entangling you and rendering you immobile!",ch,0,0,TO_CHAR);
	act("A tangled mass of vines descends upon $n, entangling $m and rendering $m immobile!",ch,0,0,TO_ROOM);
	init_affect(&snareaf);
      	snareaf.where     = TO_CHAR;
	snareaf.type      = gsn_snare;
	snareaf.aftype	  = AFT_SKILL;
      	snareaf.level     = ch->level;
      	snareaf.duration  = 1;
      	snareaf.location  = APPLY_NONE;
      	snareaf.modifier  = 0;
      	snareaf.bitvector = 0;
      	affect_to_char( ch, &snareaf );
	snaretripped = TRUE;
	sprintf(buf2,"%sYou hear a loud cracking noise as %s stumbles into your snares.%s\n\r",
		get_char_color(snaremaker,"green"),ch->name,END_COLOR(snaremaker));
	send_to_char(buf2,snaremaker);
	}
    } // End snare check.

	if(is_affected_room(to_room, gsn_dragsnare) && !IS_NPC(ch))
	{
		for(dragaf = to_room->affected; dragaf != NULL; dragaf = dragaf->next) {
			if(dragaf->type == gsn_dragsnare)
				break;
		}
		CHAR_DATA *owner = find_char_by_name(dragaf->owner_name);
		if(is_affected(owner,gsn_dragsnare)) {
			if(!IS_AFFECTED(ch,AFF_FLYING)) {
				send_to_char("You feel someone step into your snare and give it a sharp pull!\n\r",owner);
				send_to_char("You feel a pull on your foot and suddenly you're somewhere else!\n\r",ch);
				char_from_room(ch);
				char_to_room(ch,owner->in_room);
				WAIT_STATE(ch,PULSE_VIOLENCE);
				affect_strip_room(in_room,gsn_dragsnare);
				affect_strip(owner,gsn_dragsnare);
				act("$N is dragged into the room on the end of your rope!",owner,0,ch,TO_CHAR);
				do_look(ch,"auto");
				return;
			}
		}
	}

    for (fch = to_room->people,room_has_pc = FALSE; fch != NULL; fch = fch_next)
    {
	fch_next = fch->next_in_room;
	if (!IS_NPC(fch))
		room_has_pc = TRUE;
    }

    for (fch = to_room->people; fch != NULL; fch = fch_next)
    {
	fch_next = fch->next_in_room;
	/* greet trigger for items carried by people in room */
	for (obj = fch->carrying; room_has_pc && obj != NULL; obj = obj->next_content)
	{
		if (IS_SET(obj->progtypes,IPROG_GREET))
			(obj->pIndexData->iprogs->greet_prog) (obj,ch);
	}
      	/* Greet trigger for mobs  */
      	if (room_has_pc && IS_SET(fch->progtypes,MPROG_GREET))
            (fch->pIndexData->mprogs->greet_prog) (fch,ch);
    }

    for (obj = ch->carrying; room_has_pc && obj != NULL; obj = obj->next_content)
    {
	if (IS_SET(obj->progtypes,IPROG_ENTRY))
	    (obj->pIndexData->iprogs->entry_prog) (obj);
    }

    if (in_room == to_room) /* no circular follows */
	return;

    for ( fch = in_room->people; fch != NULL; fch = fch_next )
    {
	fch_next = fch->next_in_room;

	if ( fch->master == ch && IS_AFFECTED(fch,AFF_CHARM)
	&&   fch->position < POS_STANDING)
	    do_stand(fch,"");

	if ( fch->master == ch && fch->position == POS_STANDING
	&&   can_see_room(fch,to_room))
	{

	    if (is_affected(ch,skill_lookup("drive")))
		continue;

	    if (IS_SET(ch->in_room->room_flags,ROOM_LAW)
	    &&  (IS_NPC(fch) && IS_SET(fch->act,ACT_AGGRESSIVE)))
	    {
		act("You can't bring $N into the city.", ch,NULL,fch,TO_CHAR);
		act("You aren't allowed in the city.", fch,NULL,NULL,TO_CHAR);
		continue;
	    }

	    act( "You follow $N.", fch, NULL, ch, TO_CHAR );
	    move_char( fch, door, TRUE );
	}
    }

    if(is_affected_room(to_room,gsn_snare) && snaretripped)
	affect_strip_room(to_room,gsn_snare);

    if (IS_SET(ch->progtypes,MPROG_ENTRY))
	(ch->pIndexData->mprogs->entry_prog) (ch);

    if (!IS_NPC(ch))
	ch->pcdata->track_dir[ch->in_room->vnum] = 0;

    for (tch = char_list; tch != NULL; tch = tch_next)
    {
	tch_next = tch->next;
    }

    /*
     * If someone is following the char, these triggers get activated
     * for the followers before the char, but it's safer this way...
     */

    murder_entry_trigger(ch); /* For the OFF_MURDER flag */
    //mob_entry_wraith(ch); /* For the drannor forest. Remove if not using the drannor areas */
    EsiraenPiranhaCheck(ch);

    for (tch = char_list; tch != NULL; tch = tch->next)
    {
	if (IS_NPC(ch))
		continue;
	if (tch->alarm == NULL)
		continue;
	if (tch->alarm != ch->in_room)
		continue;
	sprintf(buf,"%s has entered %s.\n\r",PERS(ch,tch),ch->in_room->name);
	send_to_char(buf,tch);
	tch->alarm = NULL;
    }

    if ( !IS_NPC( ch ) )
    {
	move_prog_bones(ch);
	move_prog_hydra(ch);
    }

    if (is_affected(ch,gsn_parting_blow)) 
	affect_strip(ch,gsn_parting_blow);

    if (is_affected(ch,gsn_blackjack)) 
	affect_strip(ch,gsn_blackjack);

    return;
}

bool check_ice_slick(CHAR_DATA *ch)
{
    int chance;
    if (!IS_ROOM_AFFECTED(ch->in_room,AFF_ROOM_ICE_SLICK))
	return FALSE;
    chance = number_range(80,100);
    chance -= (get_curr_stat(ch,STAT_DEX) * 3.25);
    chance += get_carry_weight(ch) / 20;
    if (IS_AFFECTED(ch,AFF_HASTE))
	chance += 20;
    if (IS_AFFECTED(ch,AFF_SLOW))
	chance -= 15;
    chance = UMIN(chance, 90);
    //well flying things don't slip on the ground
    if (IS_AFFECTED(ch,AFF_FLYING))
	return FALSE;
    if (is_affected(ch,gsn_shield_of_frost))
	return FALSE;
    if (number_percent() > chance)
	return FALSE;    //they don't slip
    //they slip
    act("$n slips on the ice and falls to the ground!",ch,NULL,NULL,TO_ROOM);
    act("You slip on the ice and fall to the ground!",ch,NULL,NULL,TO_CHAR);
    damage_old(ch,ch,number_range(20,40),skill_lookup("ice slick"),DAM_BASH, TRUE);
    WAIT_STATE(ch, 1 * PULSE_VIOLENCE);
    return TRUE;
}

bool check_wall_thorns(CHAR_DATA *ch)
{
    if (IS_IMMORTAL(ch) || ch->cabal==CABAL_SYLVAN || ch->ghost > 0)
	return FALSE;

    if (!IS_ROOM_AFFECTED(ch->in_room,AFF_ROOM_WALL_THORNS))
	return FALSE;

    if (number_percent() < 40)
	return FALSE;

    act("A wall of thorns entraps $n, shredding $s unprotected skin!",ch,NULL,NULL,TO_ROOM);
    act("A wall of thorns entraps you, shredding any unprotected skin!",ch,NULL,NULL,TO_CHAR);
    damage_old(ch,ch,number_range(20,40),skill_lookup("wall of thorns"),DAM_BASH,TRUE);
    WAIT_STATE(ch, 1 * PULSE_VIOLENCE);
    return TRUE;
}

void do_north( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
	return;
    if (check_wall_thorns(ch))
	return;
    if (is_affected(ch,gsn_bloody_shackles))
    {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
    }
    move_char( ch, DIR_NORTH, FALSE );
    if (ch->in_room != original_room)
	if (check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
	if (check_wall_thorns(ch))
		return;
    return;
}



void do_east( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
        return;
    if (check_wall_thorns(ch))
        return;
    if (is_affected(ch,gsn_bloody_shackles))
        {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
        }
    move_char( ch, DIR_EAST, FALSE );
    if (ch->in_room != original_room)
        if (check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
        if (check_wall_thorns(ch))
                return;
    return;
}



void do_south( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
        return;
    if (check_wall_thorns(ch))
        return;
    if (is_affected(ch,gsn_bloody_shackles))
        {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
        }
    move_char( ch, DIR_SOUTH, FALSE );
    if (ch->in_room != original_room)
       if ( check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
        if (check_wall_thorns(ch))
                return;
    return;
}



void do_west( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
        return;
    if (check_wall_thorns(ch))
        return;
    if (is_affected(ch,gsn_bloody_shackles))
        {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
        }
    move_char( ch, DIR_WEST, FALSE );
    if (ch->in_room != original_room)
        if (check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
        if (check_wall_thorns(ch))
                return;
    return;
}



void do_up( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
        return;
    if (check_wall_thorns(ch))
        return;
    if (is_affected(ch,gsn_bloody_shackles))
        {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
        }
    move_char( ch, DIR_UP, FALSE );
    if (ch->in_room != original_room)
        if (check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
        if (check_wall_thorns(ch))
                return;
    return;
}



void do_down( CHAR_DATA *ch, char *argument )
{
    ROOM_INDEX_DATA *original_room;
    original_room = ch->in_room;
    if (check_ice_slick(ch))
        return;
    if (check_wall_thorns(ch))
        return;
    if (is_affected(ch,gsn_bloody_shackles))
        {
	damage_old(ch,ch,number_range(25,50),skill_lookup("bloody shackles"),DAM_BASH,TRUE);
        }
    move_char( ch, DIR_DOWN, FALSE );
    if (ch->in_room != original_room)
        if (check_ice_slick(ch))
		return;
    if (ch->in_room != original_room)
        if (check_wall_thorns(ch))
                return;
    return;
}



int find_door( CHAR_DATA *ch, char *arg )
{
    EXIT_DATA *pexit;
    int door;

	 if ( !str_cmp( arg, "n" ) || !str_cmp( arg, "north" ) ) door = 0;
    else if ( !str_cmp( arg, "e" ) || !str_cmp( arg, "east"  ) ) door = 1;
    else if ( !str_cmp( arg, "s" ) || !str_cmp( arg, "south" ) ) door = 2;
    else if ( !str_cmp( arg, "w" ) || !str_cmp( arg, "west"  ) ) door = 3;
    else if ( !str_cmp( arg, "u" ) || !str_cmp( arg, "up"    ) ) door = 4;
    else if ( !str_cmp( arg, "d" ) || !str_cmp( arg, "down"  ) ) door = 5;
    else
    {
	for ( door = 0; door <= 5; door++ )
	{
	    if ( ( pexit = ch->in_room->exit[door] ) != NULL
	    &&   IS_SET(pexit->exit_info, EX_ISDOOR)
	    &&   pexit->keyword != NULL
	    &&   is_name( arg, pexit->keyword ) )
		return door;
	}
	return -1;
    }

    if ( ( pexit = ch->in_room->exit[door] ) == NULL )
    {
	return -2;
    }

    if ( !IS_SET(pexit->exit_info, EX_ISDOOR) )
    {
	return -3;
    }

    return door;
}


void do_open( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int door;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Open what?\n\r", ch );
	return;
    }

	if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
		/* 'open door' */
		ROOM_INDEX_DATA *to_room;
		EXIT_DATA *pexit;
		EXIT_DATA *pexit_rev;

		pexit = ch->in_room->exit[door];
		if ( !IS_SET(pexit->exit_info, EX_CLOSED) )
		    { send_to_char( "It's already open.\n\r",      ch ); return; }
		if (  IS_SET(pexit->exit_info, EX_LOCKED) )
		    { send_to_char( "It's locked.\n\r",            ch ); return; }

		REMOVE_BIT(pexit->exit_info, EX_CLOSED);
		act( "$n opens the $d.", ch, NULL, pexit->keyword, TO_ROOM );
		send_to_char( "Ok.\n\r", ch );

		/* open the other side */
		if ( ( to_room   = pexit->u1.to_room            ) != NULL
		&&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != NULL
		&&   pexit_rev->u1.to_room == ch->in_room )
		{
		    CHAR_DATA *rch;

		    REMOVE_BIT( pexit_rev->exit_info, EX_CLOSED );
		    for ( rch = to_room->people; rch != NULL; rch = rch->next_in_room )
			act( "The $d opens.", rch, NULL, pexit_rev->keyword, TO_CHAR );
		}
        return;
    }

    if ( ( obj = get_obj_here( ch, arg ) ) != NULL )
    {
	 	/* open portal */
		if (obj->item_type == ITEM_PORTAL)
		{
		    if (!IS_SET(obj->value[1], EX_ISDOOR))
		    {
			send_to_char("You can't do that.\n\r",ch);
			return;
		    }

		    if (!IS_SET(obj->value[1], EX_CLOSED))
		    {
			send_to_char("It's already open.\n\r",ch);
			return;
		    }

		    if (IS_SET(obj->value[1], EX_LOCKED))
		    {
			send_to_char("It's locked.\n\r",ch);
			return;
		    }

		    REMOVE_BIT(obj->value[1], EX_CLOSED);
		    act("You open $p.",ch,obj,NULL,TO_CHAR);
		    act("$n opens $p.",ch,obj,NULL,TO_ROOM);
		    return;
	 	}

		/* 'open object' */
		if ( obj->item_type != ITEM_CONTAINER)
		    { send_to_char( "That's not a container.\n\r", ch ); return; }
		if ( !IS_SET(obj->value[1], CONT_CLOSED) )
		    { send_to_char( "It's already open.\n\r",      ch ); return; }
		if ( !IS_SET(obj->value[1], CONT_CLOSEABLE) )
		    { send_to_char( "You can't do that.\n\r",      ch ); return; }
		if ( IS_SET(obj->value[1], CONT_LOCKED) )
		    { send_to_char( "It's locked.\n\r",            ch ); return; }

		REMOVE_BIT(obj->value[1], CONT_CLOSED);
		act("You open $p.",ch,obj,NULL,TO_CHAR);
		act( "$n opens $p.", ch, obj, NULL, TO_ROOM );
		return;
    }
	
	if (door == -1) { act( "I see no $T here.", ch, NULL, arg, TO_CHAR ); return; }
	else if (door == -2) { act( "I see no door $T here.", ch, NULL, arg, TO_CHAR ); return; }
	else if (door == -3) { send_to_char( "You can't do that.\n\r", ch ); return; }

    return;
}



void do_close( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int door;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Close what?\n\r", ch );
	return;
    }

	if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
	/* 'close door' */
	ROOM_INDEX_DATA *to_room;
	EXIT_DATA *pexit;
	EXIT_DATA *pexit_rev;

	pexit	= ch->in_room->exit[door];
	if ( IS_SET(pexit->exit_info, EX_CLOSED) )
	    { send_to_char( "It's already closed.\n\r",    ch ); return; }

	SET_BIT(pexit->exit_info, EX_CLOSED);
	act( "$n closes the $d.", ch, NULL, pexit->keyword, TO_ROOM );
	send_to_char( "Ok.\n\r", ch );

	/* close the other side */
	if ( ( to_room   = pexit->u1.to_room            ) != NULL
	&&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != 0
	&&   pexit_rev->u1.to_room == ch->in_room )
	{
	    CHAR_DATA *rch;

	    SET_BIT( pexit_rev->exit_info, EX_CLOSED );
	    for ( rch = to_room->people; rch != NULL; rch = rch->next_in_room )
		act( "The $d closes.", rch, NULL, pexit_rev->keyword, TO_CHAR );
	}
        return;
    }

    if ( ( obj = get_obj_here( ch, arg ) ) != NULL )
    {
	/* portal stuff */
	if (obj->item_type == ITEM_PORTAL)
	{

	    if (!IS_SET(obj->value[1],EX_ISDOOR)
	    ||   IS_SET(obj->value[1],EX_NOCLOSE))
	    {
		send_to_char("You can't do that.\n\r",ch);
		return;
	    }

	    if (IS_SET(obj->value[1],EX_CLOSED))
	    {
		send_to_char("It's already closed.\n\r",ch);
		return;
	    }

	    SET_BIT(obj->value[1],EX_CLOSED);
	    act("You close $p.",ch,obj,NULL,TO_CHAR);
	    act("$n closes $p.",ch,obj,NULL,TO_ROOM);
	    return;
	}

	/* 'close object' */
	if ( obj->item_type != ITEM_CONTAINER )
	    { send_to_char( "That's not a container.\n\r", ch ); return; }
	if ( IS_SET(obj->value[1], CONT_CLOSED) )
	    { send_to_char( "It's already closed.\n\r",    ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_CLOSEABLE) )
	    { send_to_char( "You can't do that.\n\r",      ch ); return; }

	SET_BIT(obj->value[1], CONT_CLOSED);
	act("You close $p.",ch,obj,NULL,TO_CHAR);
	act( "$n closes $p.", ch, obj, NULL, TO_ROOM );
	return;
    }

	if (door == -1) { act( "I see no $T here.", ch, NULL, arg, TO_CHAR ); return; }
	else if (door == -2) { act( "I see no door $T here.", ch, NULL, arg, TO_CHAR ); return; }
	else if (door == -3) { send_to_char( "You can't do that.\n\r", ch ); return; }
    return;
}



bool has_key( CHAR_DATA *ch, int key )
{
    OBJ_DATA *obj;

    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
	if ( obj->pIndexData->vnum == key )
	    return TRUE;
    }

    return FALSE;
}



void do_lock( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int door;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Lock what?\n\r", ch );
	return;
    }

    if ( ( obj = get_obj_here( ch, arg ) ) != NULL )
    {
	/* portal stuff */
	if (obj->item_type == ITEM_PORTAL)
	{
	    if (!IS_SET(obj->value[1],EX_ISDOOR)
	    ||  IS_SET(obj->value[1],EX_NOCLOSE))
	    {
		send_to_char("You can't do that.\n\r",ch);
		return;
	    }
	    if (!IS_SET(obj->value[1],EX_CLOSED))
	    {
		send_to_char("It's not closed.\n\r",ch);
	 	return;
	    }

	    if (obj->value[4] < 0 || IS_SET(obj->value[1],EX_NOLOCK))
	    {
		send_to_char("It can't be locked.\n\r",ch);
		return;
	    }

	    if (!has_key(ch,obj->value[4]))
	    {
		send_to_char("You lack the key.\n\r",ch);
		return;
	    }

	    if (IS_SET(obj->value[1],EX_LOCKED))
	    {
		send_to_char("It's already locked.\n\r",ch);
		return;
	    }

	    SET_BIT(obj->value[1],EX_LOCKED);
	    act("You lock $p.",ch,obj,NULL,TO_CHAR);
	    act("$n locks $p.",ch,obj,NULL,TO_ROOM);
	    return;
	}

	/* 'lock object' */
	if ( obj->item_type != ITEM_CONTAINER )
	    { send_to_char( "That's not a container.\n\r", ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_CLOSED) )
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( obj->value[2] < 0 )
	    { send_to_char( "It can't be locked.\n\r",     ch ); return; }
	if ( !has_key( ch, obj->value[2] ) )
	    { send_to_char( "You lack the key.\n\r",       ch ); return; }
	if ( IS_SET(obj->value[1], CONT_LOCKED) )
	    { send_to_char( "It's already locked.\n\r",    ch ); return; }

	SET_BIT(obj->value[1], CONT_LOCKED);
	act("You lock $p.",ch,obj,NULL,TO_CHAR);
	act( "$n locks $p.", ch, obj, NULL, TO_ROOM );
	return;
    }

    if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
	/* 'lock door' */
	ROOM_INDEX_DATA *to_room;
	EXIT_DATA *pexit;
	EXIT_DATA *pexit_rev;

	pexit	= ch->in_room->exit[door];
	if ( !IS_SET(pexit->exit_info, EX_CLOSED) )
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( pexit->key < 0 )
	    { send_to_char( "It can't be locked.\n\r",     ch ); return; }
	if ( !has_key( ch, pexit->key) )
	    { send_to_char( "You lack the key.\n\r",       ch ); return; }
	if ( IS_SET(pexit->exit_info, EX_LOCKED) )
	    { send_to_char( "It's already locked.\n\r",    ch ); return; }

	SET_BIT(pexit->exit_info, EX_LOCKED);
	send_to_char( "*Click*\n\r", ch );
	act( "$n locks the $d.", ch, NULL, pexit->keyword, TO_ROOM );

	/* lock the other side */
	if ( ( to_room   = pexit->u1.to_room            ) != NULL
	&&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != 0
	&&   pexit_rev->u1.to_room == ch->in_room )
	{
	    SET_BIT( pexit_rev->exit_info, EX_LOCKED );
	}
    }

    return;
}



void do_unlock( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int door;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Unlock what?\n\r", ch );
	return;
    }

    if ( ( obj = get_obj_here( ch, arg ) ) != NULL )
    {
 	/* portal stuff */
	if (obj->item_type == ITEM_PORTAL)
	{
	    if (!IS_SET(obj->value[1],EX_ISDOOR))
	    {
		send_to_char("You can't do that.\n\r",ch);
		return;
	    }

	    if (!IS_SET(obj->value[1],EX_CLOSED))
	    {
		send_to_char("It's not closed.\n\r",ch);
		return;
	    }

	    if (obj->value[4] < 0)
	    {
		send_to_char("It can't be unlocked.\n\r",ch);
		return;
	    }

	    if (!has_key(ch,obj->value[4]))
	    {
		send_to_char("You lack the key.\n\r",ch);
		return;
	    }

	    if (!IS_SET(obj->value[1],EX_LOCKED))
	    {
		send_to_char("It's already unlocked.\n\r",ch);
		return;
	    }

	    REMOVE_BIT(obj->value[1],EX_LOCKED);
	    act("You unlock $p.",ch,obj,NULL,TO_CHAR);
	    act("$n unlocks $p.",ch,obj,NULL,TO_ROOM);
	    return;
	}

	/* 'unlock object' */
	if ( obj->item_type != ITEM_CONTAINER )
	    { send_to_char( "That's not a container.\n\r", ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_CLOSED) )
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( obj->value[2] < 0 )
	    { send_to_char( "It can't be unlocked.\n\r",   ch ); return; }
	if ( !has_key( ch, obj->value[2] ) )
	    { send_to_char( "You lack the key.\n\r",       ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_LOCKED) )
	    { send_to_char( "It's already unlocked.\n\r",  ch ); return; }

	REMOVE_BIT(obj->value[1], CONT_LOCKED);
	act("You unlock $p.",ch,obj,NULL,TO_CHAR);
	act( "$n unlocks $p.", ch, obj, NULL, TO_ROOM );
	return;
    }

    if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
	/* 'unlock door' */
	ROOM_INDEX_DATA *to_room;
	EXIT_DATA *pexit;
	EXIT_DATA *pexit_rev;

	pexit = ch->in_room->exit[door];
	if ( !IS_SET(pexit->exit_info, EX_CLOSED) )
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( pexit->key < 0 )
	    { send_to_char( "It can't be unlocked.\n\r",   ch ); return; }
	if ( !has_key( ch, pexit->key) )
	    { send_to_char( "You lack the key.\n\r",       ch ); return; }
	if ( !IS_SET(pexit->exit_info, EX_LOCKED) )
	    { send_to_char( "It's already unlocked.\n\r",  ch ); return; }

	REMOVE_BIT(pexit->exit_info, EX_LOCKED);
	send_to_char( "*Click*\n\r", ch );
	act( "$n unlocks the $d.", ch, NULL, pexit->keyword, TO_ROOM );

	/* unlock the other side */
	if ( ( to_room   = pexit->u1.to_room            ) != NULL
	&&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != NULL
	&&   pexit_rev->u1.to_room == ch->in_room )
	{
	    REMOVE_BIT( pexit_rev->exit_info, EX_LOCKED );
	}
    }

    return;
}



void do_pick( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *gch;
    OBJ_DATA *obj;
    int door;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Pick what?\n\r", ch );
	return;
    }

    WAIT_STATE( ch, skill_table[gsn_pick_lock].beats );

    /* look for guards */
    for ( gch = ch->in_room->people; gch; gch = gch->next_in_room )
    {
	if ( IS_NPC(gch) && IS_AWAKE(gch) && ch->level + 5 < gch->level )
	{
	    act( "$N is standing too close to the lock.",
		ch, NULL, gch, TO_CHAR );
	    return;
	}
    }

    if ( !IS_NPC(ch) && number_percent( ) > get_skill(ch,gsn_pick_lock))
    {
	send_to_char( "You failed.\n\r", ch);
	check_improve(ch,gsn_pick_lock,FALSE,2);
	return;
    }

    if ( ( obj = get_obj_here( ch, arg ) ) != NULL )
    {
	/* portal stuff */
	if (obj->item_type == ITEM_PORTAL)
	{
	    if (!IS_SET(obj->value[1],EX_ISDOOR))
	    {
		send_to_char("You can't do that.\n\r",ch);
		return;
	    }

	    if (!IS_SET(obj->value[1],EX_CLOSED))
	    {
		send_to_char("It's not closed.\n\r",ch);
		return;
	    }

	    if (obj->value[4] < 0)
	    {
		send_to_char("It can't be unlocked.\n\r",ch);
		return;
	    }

	    if (IS_SET(obj->value[1],EX_PICKPROOF))
	    {
		send_to_char("You failed.\n\r",ch);
		return;
	    }

	    REMOVE_BIT(obj->value[1],EX_LOCKED);
	    act("You pick the lock on $p.",ch,obj,NULL,TO_CHAR);
	    act("$n picks the lock on $p.",ch,obj,NULL,TO_ROOM);
	    check_improve(ch,gsn_pick_lock,TRUE,2);
	    return;
	}





	/* 'pick object' */
	if ( obj->item_type != ITEM_CONTAINER )
	    { send_to_char( "That's not a container.\n\r", ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_CLOSED) )
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( obj->value[2] < 0 )
	    { send_to_char( "It can't be unlocked.\n\r",   ch ); return; }
	if ( !IS_SET(obj->value[1], CONT_LOCKED) )
	    { send_to_char( "It's already unlocked.\n\r",  ch ); return; }
	if ( IS_SET(obj->value[1], CONT_PICKPROOF) )
	    { send_to_char( "You failed.\n\r",             ch ); return; }

	REMOVE_BIT(obj->value[1], CONT_LOCKED);
        act("You pick the lock on $p.",ch,obj,NULL,TO_CHAR);
        act("$n picks the lock on $p.",ch,obj,NULL,TO_ROOM);
	check_improve(ch,gsn_pick_lock,TRUE,2);
	return;
    }

    if ( ( door = find_door( ch, arg ) ) >= 0 )
    {
	/* 'pick door' */
	ROOM_INDEX_DATA *to_room;
	EXIT_DATA *pexit;
	EXIT_DATA *pexit_rev;

	pexit = ch->in_room->exit[door];
	if ( !IS_SET(pexit->exit_info, EX_CLOSED) && !IS_IMMORTAL(ch))
	    { send_to_char( "It's not closed.\n\r",        ch ); return; }
	if ( pexit->key < 0 && !IS_IMMORTAL(ch))
	    { send_to_char( "It can't be picked.\n\r",     ch ); return; }
	if ( !IS_SET(pexit->exit_info, EX_LOCKED) )
	    { send_to_char( "It's already unlocked.\n\r",  ch ); return; }
	if ( IS_SET(pexit->exit_info, EX_PICKPROOF) && !IS_IMMORTAL(ch))
	    { send_to_char( "You failed.\n\r",             ch ); return; }

	REMOVE_BIT(pexit->exit_info, EX_LOCKED);
	send_to_char( "*Click*\n\r", ch );
	act( "$n picks the $d.", ch, NULL, pexit->keyword, TO_ROOM );
	check_improve(ch,gsn_pick_lock,TRUE,2);

	/* pick the other side */
	if ( ( to_room   = pexit->u1.to_room            ) != NULL
	&&   ( pexit_rev = to_room->exit[rev_dir[door]] ) != NULL
	&&   pexit_rev->u1.to_room == ch->in_room )
	{
	    REMOVE_BIT( pexit_rev->exit_info, EX_LOCKED );
	}
    }

    return;
}




void do_stand( CHAR_DATA *ch, char *argument )
{
    OBJ_DATA *obj = NULL;


    if (argument[0] != '\0')
    {
	if (ch->position == POS_FIGHTING)
	{
	    send_to_char("Maybe you should finish fighting first?\n\r",ch);
	    return;
	}
	obj = get_obj_list(ch,argument,ch->in_room->contents);
	if (obj == NULL)
	{
	    send_to_char("You don't see that here.\n\r",ch);
	    return;
	}
	if (obj->item_type != ITEM_FURNITURE
	||  (!IS_SET(obj->value[2],STAND_AT)
	&&   !IS_SET(obj->value[2],STAND_ON)
	&&   !IS_SET(obj->value[2],STAND_IN)))
	{
	    send_to_char("You can't seem to find a place to stand.\n\r",ch);
	    return;
	}
	if (ch->on != obj && count_users(obj) >= obj->value[0])
	{
	    act_new("There's no room to stand on $p.",
		ch,obj,NULL,TO_CHAR,POS_DEAD);
	    return;
	}
 	ch->on = obj;
    }

    switch ( ch->position )
    {
    case POS_SLEEPING:
	if ( IS_AFFECTED(ch, AFF_SLEEP) || is_affected(ch,gsn_blackjack) ||
is_affected(ch,gsn_pummel) || is_affected(ch,gsn_healing_sleep))
	    { send_to_char( "You can't wake up!\n\r", ch ); return; }

	if (obj == NULL)
	{
	    if (is_affected(ch,gsn_camp))
	    {
		send_to_char("You break camp feeling more refreshed.\n\r",ch);
		affect_strip(ch,gsn_camp);
	    }
	    send_to_char( "You wake and stand up.\n\r", ch );
	    act( "$n wakes and stands up.", ch, NULL, NULL, TO_ROOM );
	    ch->on = NULL;
	}
	else if (IS_SET(obj->value[2],STAND_AT))
	{
	   act_new("You wake and stand at $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
	   act("$n wakes and stands at $p.",ch,obj,NULL,TO_ROOM);
	}
	else if (IS_SET(obj->value[2],STAND_ON))
	{
	    act_new("You wake and stand on $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
	    act("$n wakes and stands on $p.",ch,obj,NULL,TO_ROOM);
	}
	else
	{
	    act_new("You wake and stand in $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
	    act("$n wakes and stands in $p.",ch,obj,NULL,TO_ROOM);
	}
	ch->position = POS_STANDING;
	break;

    case POS_RESTING: case POS_SITTING:
	if (obj == NULL)
	{
	    send_to_char( "You stand up.\n\r", ch );
	    act( "$n stands up.", ch, NULL, NULL, TO_ROOM );
	    ch->on = NULL;
	}
	else if (IS_SET(obj->value[2],STAND_AT))
	{
	    act("You stand at $p.",ch,obj,NULL,TO_CHAR);
	    act("$n stands at $p.",ch,obj,NULL,TO_ROOM);
	}
	else if (IS_SET(obj->value[2],STAND_ON))
	{
	    act("You stand on $p.",ch,obj,NULL,TO_CHAR);
	    act("$n stands on $p.",ch,obj,NULL,TO_ROOM);
	}
	else
	{
	    act("You stand in $p.",ch,obj,NULL,TO_CHAR);
	    act("$n stands on $p.",ch,obj,NULL,TO_ROOM);
	}
	ch->position = POS_STANDING;
	break;

    case POS_STANDING:
	send_to_char( "You are already standing.\n\r", ch );
	break;

    case POS_FIGHTING:
	send_to_char( "You are already fighting!\n\r", ch );
	break;
    }

    return;
}



void do_rest( CHAR_DATA *ch, char *argument )
{
    OBJ_DATA *obj = NULL;

    if (ch->position == POS_FIGHTING)
    {
	send_to_char("You are already fighting!\n\r",ch);
	return;
    }

            if (is_affected(ch, gsn_bloodthirst))
            {
                send_to_char("No way! You are still bloodthirsty!\n\r",ch);
                return;
            }


    /* okay, now that we know we can rest, find an object to rest on */
    if (argument[0] != '\0')
    {
	obj = get_obj_list(ch,argument,ch->in_room->contents);
	if (obj == NULL)
	{
	    send_to_char("You don't see that here.\n\r",ch);
	    return;
	}
    }
    else obj = ch->on;

    if (obj != NULL)
    {
        if (!IS_SET(obj->item_type,ITEM_FURNITURE)
    	||  (!IS_SET(obj->value[2],REST_ON)
    	&&   !IS_SET(obj->value[2],REST_IN)
    	&&   !IS_SET(obj->value[2],REST_AT)))
    	{
	    send_to_char("You can't rest on that.\n\r",ch);
	    return;
    	}

        if (obj != NULL && ch->on != obj && count_users(obj) >= obj->value[0])
        {
	    act_new("There's no more room on $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
	    return;
    	}

	if (obj->pIndexData->vnum == OBJ_VNUM_EMPERORTHRONE) {
        if (!IS_NPC(ch) && ch->pcdata->empire !=EMPIRE_EMPEROR)
        {
	act("$n is rejected by $p!",ch,obj,NULL,TO_ROOM);
        damage( ch, ch, ((ch->level)*200), TYPE_HIT, DAM_OTHER, TRUE );
        return;
        }
}
	ch->on = obj;
    }

    switch ( ch->position )
    {
    case POS_SLEEPING:
	if (IS_AFFECTED(ch,AFF_SLEEP) || is_affected(ch,gsn_blackjack) || is_affected(ch,gsn_pummel) || is_affected(ch,gsn_healing_sleep))
	{
	    send_to_char("You can't wake up!\n\r",ch);
	    return;
	}

	if (obj == NULL)
	{
	    if (is_affected(ch,gsn_camp))
	    {
		send_to_char("You break camp feeling more refreshed.\n\r",ch);
		affect_strip(ch,gsn_camp);
	    }
	    send_to_char( "You wake up and start resting.\n\r", ch );
	    act ("$n wakes up and starts resting.",ch,NULL,NULL,TO_ROOM);
	}
	else if (IS_SET(obj->value[2],REST_AT))
	{
	    act_new("You wake up and rest at $p.",
		    ch,obj,NULL,TO_CHAR,POS_SLEEPING);
	    act("$n wakes up and rests at $p.",ch,obj,NULL,TO_ROOM);
	}
        else if (IS_SET(obj->value[2],REST_ON))
        {
            act_new("You wake up and rest on $p.",
                    ch,obj,NULL,TO_CHAR,POS_SLEEPING);
            act("$n wakes up and rests on $p.",ch,obj,NULL,TO_ROOM);
        }
        else
        {
            act_new("You wake up and rest in $p.",
                    ch,obj,NULL,TO_CHAR,POS_SLEEPING);
            act("$n wakes up and rests in $p.",ch,obj,NULL,TO_ROOM);
        }
	ch->position = POS_RESTING;
	break;

    case POS_RESTING:
	send_to_char( "You are already resting.\n\r", ch );
	break;

    case POS_STANDING:
	if (obj == NULL)
	{
	    send_to_char( "You rest.\n\r", ch );
	    act( "$n sits down and rests.", ch, NULL, NULL, TO_ROOM );
	}
        else if (IS_SET(obj->value[2],REST_AT))
        {
	    act("You sit down at $p and rest.",ch,obj,NULL,TO_CHAR);
	    act("$n sits down at $p and rests.",ch,obj,NULL,TO_ROOM);
        }
        else if (IS_SET(obj->value[2],REST_ON))
        {
	    act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
	    act("$n sits on $p and rests.",ch,obj,NULL,TO_ROOM);
        }
        else
        {
	    act("You rest in $p.",ch,obj,NULL,TO_CHAR);
	    act("$n rests in $p.",ch,obj,NULL,TO_ROOM);
        }
	ch->position = POS_RESTING;
	break;

    case POS_SITTING:
	if (obj == NULL)
	{
	    send_to_char("You rest.\n\r",ch);
	    act("$n rests.",ch,NULL,NULL,TO_ROOM);
	}
        else if (IS_SET(obj->value[2],REST_AT))
        {
	    act("You rest at $p.",ch,obj,NULL,TO_CHAR);
	    act("$n rests at $p.",ch,obj,NULL,TO_ROOM);
        }
        else if (IS_SET(obj->value[2],REST_ON))
        {
	    act("You rest on $p.",ch,obj,NULL,TO_CHAR);
	    act("$n rests on $p.",ch,obj,NULL,TO_ROOM);
        }
        else
        {
	    act("You rest in $p.",ch,obj,NULL,TO_CHAR);
	    act("$n rests in $p.",ch,obj,NULL,TO_ROOM);
	}
	ch->position = POS_RESTING;
	break;
    }


    return;
}


void do_sit (CHAR_DATA *ch, char *argument )
{
    OBJ_DATA *obj = NULL;

    if (ch->position == POS_FIGHTING)
    {
	send_to_char("Maybe you should finish this fight first?\n\r",ch);
	return;
    }

            if (is_affected(ch, gsn_bloodthirst))
            {
                send_to_char("No way! You are still bloodthirsty!\n\r",ch);
                return;
            }


    /* okay, now that we know we can sit, find an object to sit on */
    if (argument[0] != '\0')
    {
	obj = get_obj_list(ch,argument,ch->in_room->contents);
	if (obj == NULL)
	{
	    send_to_char("You don't see that here.\n\r",ch);
	    return;
	}
    }
    else obj = ch->on;

    if (obj != NULL)
    {
	if (!IS_SET(obj->item_type,ITEM_FURNITURE)
	||  (!IS_SET(obj->value[2],SIT_ON)
	&&   !IS_SET(obj->value[2],SIT_IN)
	&&   !IS_SET(obj->value[2],SIT_AT)))
	{
	    send_to_char("You can't sit on that.\n\r",ch);
	    return;
	}

	if (obj != NULL && ch->on != obj && count_users(obj) >= obj->value[0])
	{
	    act_new("There's no more room on $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
	    return;
	}

	if (obj->pIndexData->vnum == OBJ_VNUM_EMPERORTHRONE) {
	if (!IS_NPC(ch) && (ch->pcdata->empire == 0 || ch->pcdata->empire !=EMPIRE_EMPEROR))
		{
		act("$n is rejected by $p!",ch,obj,NULL,TO_ROOM);
		damage( ch, ch, ((ch->level)*200), TYPE_HIT, DAM_OTHER, TRUE );
		return;
		}
	}
	ch->on = obj;
    }
    switch (ch->position)
    {
	case POS_SLEEPING:
	    if (IS_AFFECTED(ch,AFF_SLEEP) || is_affected(ch,gsn_blackjack) || is_affected(ch,gsn_pummel) || is_affected(ch,gsn_healing_sleep))
	    {
		send_to_char("You can't wake up!\n\r",ch);
		return;
	    }

            if (obj == NULL)
            {
            	send_to_char( "You wake and sit up.\n\r", ch );
            	act( "$n wakes and sits up.", ch, NULL, NULL, TO_ROOM );
            }
            else if (IS_SET(obj->value[2],SIT_AT))
            {
            	act_new("You wake and sit at $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
            	act("$n wakes and sits at $p.",ch,obj,NULL,TO_ROOM);
            }
            else if (IS_SET(obj->value[2],SIT_ON))
			{
			if (obj->pIndexData->vnum == 27)
			{
				if ((is_name("Graelik",ch->name)) || (is_name("Graelik",ch->original_name)))
				{
					act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
					act("$n wakes and sits on $p and rests.",ch,obj,NULL,TO_ROOM);
				}
				else
				{
					act("The mere touch of $p burns you to a crisp.",ch,obj,NULL,TO_CHAR);
					act("$n wakes and tries to sit on $p, but merely touching it burns them to a crisp.",ch,obj,NULL,TO_ROOM);
					raw_kill(ch,ch);
				}
			}
			else
				{
            		act_new("You wake and sit in $p.",ch,obj,NULL,TO_CHAR,POS_DEAD);
            		act("$n wakes and sits in $p.",ch,obj,NULL,TO_ROOM);
				}
			}
	    ch->position = POS_SITTING;
	    break;
	case POS_RESTING:
	    if (obj == NULL)
		send_to_char("You stop resting.\n\r",ch);
	    else if (IS_SET(obj->value[2],SIT_AT))
	    {
		act("You sit at $p.",ch,obj,NULL,TO_CHAR);
		act("$n sits at $p.",ch,obj,NULL,TO_ROOM);
	    }

	    else if (IS_SET(obj->value[2],SIT_ON))
	    {
			if (obj->pIndexData->vnum == 27)
			{
				if ((is_name("Graelik",ch->name)) || (is_name("Graelik",ch->original_name)))
				{
					act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
					act("$n sits on $p and rests.",ch,obj,NULL,TO_ROOM);
				}
				else
				{
					act("The mere touch of $p burns you to a crisp.",ch,obj,NULL,TO_CHAR);
					act("$n tries to sit on $p, but merely touching it burns them to a crisp.",ch,obj,NULL,TO_ROOM);
					raw_kill(ch,ch);
				}
			}
			else
			{
				act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
				act("$n sits on $p and rests.",ch,obj,NULL,TO_ROOM);
			}
	    }
	    ch->position = POS_SITTING;
	    break;
	case POS_SITTING:
	    send_to_char("You are already sitting down.\n\r",ch);
	    break;
	case POS_STANDING:
	    if (obj == NULL)
    	    {
		send_to_char("You sit down.\n\r",ch);
    	        act("$n sits down on the ground.",ch,NULL,NULL,TO_ROOM);
	    }
	    else if (IS_SET(obj->value[2],SIT_AT))
	    {
		act("You sit down at $p.",ch,obj,NULL,TO_CHAR);
		act("$n sits down at $p.",ch,obj,NULL,TO_ROOM);
	    }
	    else if (IS_SET(obj->value[2],SIT_ON))
	    {
			if (obj->pIndexData->vnum == 27)
			{
				if ((is_name("Graelik",ch->name)) || (is_name("Graelik",ch->original_name)))
				{
					act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
					act("$n sits on $p and rests.",ch,obj,NULL,TO_ROOM);
				}
				else
				{
					act("The mere touch of $p burns you to a crisp.",ch,obj,NULL,TO_CHAR);
					act("$n tries to sit on $p, but merely touching it burns them to a crisp.",ch,obj,NULL,TO_ROOM);
					raw_kill(ch,ch);
				}
			}
			else
			{
				act("You sit on $p and rest.",ch,obj,NULL,TO_CHAR);
				act("$n sits on $p and rests.",ch,obj,NULL,TO_ROOM);
			}
		}
	    else
	    {
		act("You sit down in $p.",ch,obj,NULL,TO_CHAR);
		act("$n sits down in $p.",ch,obj,NULL,TO_ROOM);
	    }
    	    ch->position = POS_SITTING;
    	    break;
    }
    return;
}


void do_sleep( CHAR_DATA *ch, char *argument )
{
    OBJ_DATA *obj = NULL;


    switch ( ch->position )
    {
    case POS_SLEEPING:
	send_to_char( "You are already sleeping.\n\r", ch );
	break;

    case POS_RESTING:
    case POS_SITTING:
    case POS_STANDING:

            if (is_affected(ch, gsn_bloodthirst))
            {
                send_to_char("No way! You are still bloodthirsty!\n\r",ch);
                return;
            }

	if (argument[0] == '\0' && ch->on == NULL)
	{
	    send_to_char( "You go to sleep.\n\r", ch );
	    act( "$n goes to sleep.", ch, NULL, NULL, TO_ROOM );
	    ch->position = POS_SLEEPING;
	}
	else  /* find an object and sleep on it */
	{
	    if (argument[0] == '\0')
		obj = ch->on;
	    else
	    	obj = get_obj_list( ch, argument,  ch->in_room->contents );

	    if (obj == NULL)
	    {
		send_to_char("You don't see that here.\n\r",ch);
		return;
	    }
		
		if (!IS_NPC(ch) && obj->pIndexData->vnum == OBJ_VNUM_EMPERORTHRONE && (ch->pcdata->empire == 0 || ch->pcdata->empire !=EMPIRE_EMPEROR))
		{
		act("$n is rejected by $p!",ch,obj,NULL,TO_ROOM);
		damage( ch, ch, ((ch->level)*200), TYPE_HIT, DAM_OTHER, TRUE );
		return;
		}

	    if (obj->item_type != ITEM_FURNITURE
	    ||  (!IS_SET(obj->value[2],SLEEP_ON)
	    &&   !IS_SET(obj->value[2],SLEEP_IN)
	    &&	 !IS_SET(obj->value[2],SLEEP_AT)))
	    {
		send_to_char("You can't sleep on that!\n\r",ch);
		return;
	    }

	    if (ch->on != obj && count_users(obj) >= obj->value[0])
	    {
		act_new("There is no room on $p for you.",
		    ch,obj,NULL,TO_CHAR,POS_DEAD);
		return;
	    }

	    ch->on = obj;
	    if (IS_SET(obj->value[2],SLEEP_AT))
	    {
		act("You go to sleep at $p.",ch,obj,NULL,TO_CHAR);
		act("$n goes to sleep at $p.",ch,obj,NULL,TO_ROOM);
	    }
	    else if (IS_SET(obj->value[2],SLEEP_ON))
	    {
	        act("You go to sleep on $p.",ch,obj,NULL,TO_CHAR);
	        act("$n goes to sleep on $p.",ch,obj,NULL,TO_ROOM);
	    }
	    else
	    {
		act("You go to sleep in $p.",ch,obj,NULL,TO_CHAR);
		act("$n goes to sleep in $p.",ch,obj,NULL,TO_ROOM);
	    }
	    ch->position = POS_SLEEPING;
	}
	break;

    case POS_FIGHTING:
	send_to_char( "You are already fighting!\n\r", ch );
	break;
    }

    return;
}



void do_wake( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;

    one_argument( argument, arg );
    if ( arg[0] == '\0' )
	{ do_stand( ch, argument ); return; }


    if ( !IS_AWAKE(ch) )
	{ send_to_char( "You are asleep yourself!\n\r",       ch ); return; }

    if ( ( victim = get_char_room( ch, arg ) ) == NULL )
	{ send_to_char( "They aren't here.\n\r",              ch ); return; }

    if ( IS_AWAKE(victim) )
	{ act( "$N is already awake.", ch, NULL, victim, TO_CHAR ); return; }

    if ( IS_AFFECTED(victim, AFF_SLEEP) || is_affected(ch,gsn_blackjack))
	{ act( "You can't wake $M!",   ch, NULL, victim, TO_CHAR );  return; }

    act_new( "$n wakes you.", ch, NULL, victim, TO_VICT,POS_SLEEPING );
    do_stand(victim,"");
    return;
}


void do_sneak( CHAR_DATA *ch, char *argument )
{
    AFFECT_DATA af;

    int sn_fog, sn_fire;

    sn_fog = skill_lookup("faerie fog");
    sn_fire = skill_lookup("faerie fire");
    if (is_affected(ch,sn_fog) || is_affected(ch,sn_fire) || is_affected(ch,gsn_incandescense))
    {
	send_to_char("You can't hide while glowing.\n\r",ch);
	return;
    }

    send_to_char( "You attempt to move silently.\n\r", ch );
    if (IS_AFFECTED(ch,AFF_SNEAK))
	return;

    if ( number_percent( ) < get_skill(ch,gsn_sneak))
    {
	check_improve(ch,gsn_sneak,TRUE,3);
	init_affect(&af);
	af.where     = TO_AFFECTS;
	af.type      = gsn_sneak;
	af.aftype    = AFT_SKILL;
	af.level     = ch->level;
	af.duration  = ch->level;
	af.location  = APPLY_NONE;
	af.affect_list_msg = str_dup("grants quiet movement");
	af.modifier  = 0;
	af.bitvector = AFF_SNEAK;
	affect_to_char( ch, &af );
        send_to_char( "You begin sneaking.\n\r", ch);
    }
    else
	check_improve(ch,gsn_sneak,FALSE,3);

    return;
}

void do_acute_vision( CHAR_DATA *ch, char *argument )
{
    AFFECT_DATA  af;

    if (get_skill(ch,gsn_acute_vision) == 0
	|| ch->level < skill_table[gsn_acute_vision].skill_level[ch->class])
    {
	send_to_char("You don't know which bushes to look at.\n\r",ch);
	return;
    }

    if (is_affected(ch,gsn_acute_vision) )
    {
	send_to_char("Your eyes are already as sharp as they'll get.\n\r", ch);
	return;
    }

   if (ch->mana < 25)
   {
    send_to_char("You don't have the mana.\n\r", ch);
	return;
    }

    if (number_percent() > get_skill(ch,gsn_acute_vision))
    {
	send_to_char("Your vision sharpens but then dulls.\n\r",ch);
	check_improve(ch,gsn_acute_vision,FALSE,1);
    ch->mana -= 12;
	return;
    }

        init_affect(&af);
    af.where = TO_AFFECTS;
    af.type = gsn_acute_vision;
        af.aftype    = AFT_SKILL;
    af.location = 0;
    af.modifier = 0;
    af.level = ch->level;
    af.duration = ch->level;
	af.affect_list_msg = str_dup("grants the ability to detect camouflaged");
    af.bitvector = 0;
    affect_to_char(ch, &af);

    ch->mana -= 25;
    send_to_char( "Your vision sharpens.\n\r", ch);
    return;
    check_improve(ch,gsn_acute_vision,TRUE,1);
}

void do_camp(CHAR_DATA *ch, char *argument)
{
    AFFECT_DATA af;
    if ( (get_skill(ch,gsn_camp) == 0) || ch->level < skill_table[gsn_camp].skill_level[ch->class] )
    {
	send_to_char("You don't know how to effectively camp.\n\r",ch);
	return;
    }

    if (is_affected(ch,gsn_bloodthirst))
	return send_to_char("You can't camp while bloodthirsty.\n\r",ch);

    if (ch->position == POS_SLEEPING )
    {
	send_to_char("You are already asleep.",ch);
	return;
    }
    if ((ch->in_room->sector_type != SECT_FOREST) && (ch->in_room->sector_type != SECT_HILLS)
    && (ch->in_room->sector_type != SECT_MOUNTAIN) )
    {
	send_to_char("This land is not wild enough for you to camp out in.\n\r",ch);
	return;
    }

        init_affect(&af);
    af.where = TO_AFFECTS;
    af.location = 0;
    af.duration = -1;
    af.modifier = 0;
    af.level = ch->level;
    af.type = gsn_camp;
	af.affect_list_msg = str_dup("increased regeneration");
    af.aftype    = AFT_SKILL;
    af.bitvector = 0;
    affect_to_char(ch,&af);

    act("$n settles down and sets up camp.",ch,NULL,NULL,TO_ROOM);
    send_to_char("You settle down and set up camp.\n\r",ch);
    do_sleep(ch,"");
    return;
}


void do_camouflage( CHAR_DATA *ch, char *argument )
{
    int sn_fog, sn_fire;

    sn_fog = skill_lookup("faerie fog");
    sn_fire = skill_lookup("faerie fire");
    if (is_affected(ch,sn_fog) || is_affected(ch,sn_fire) || is_affected(ch, gsn_incandescense))
    {
	send_to_char("You can't camouflage while revealed.\n\r",ch);
	return;
    }

    if (IS_AFFECTED(ch, AFF_FAERIE_FIRE))
	return send_to_char("You can't camouflage while revealed.\n\r",ch);

    if ( (ch->in_room->sector_type != SECT_FOREST) && (ch->in_room->sector_type != SECT_MOUNTAIN) 
	&& (ch->in_room->sector_type != SECT_HILLS ) && (ch->in_room->sector_type != SECT_DESERT) 
	&& (ch->in_room->sector_type != SECT_FIELD ))
    {
	send_to_char("There is no cover here.\n\r", ch);
	act("$n tries to cover $mself on the single leaf on the ground.", ch, NULL, NULL, TO_ROOM);
	return;
    }

    send_to_char("You attempt to blend in with your surroundings.\n\r", ch);

    if ( number_percent( ) < get_skill(ch,gsn_camouflage) )
    {
	SET_BIT(ch->affected_by, AFF_CAMOUFLAGE);
	check_improve(ch, gsn_camouflage,TRUE,2);
	//WAIT_STATE(ch,8);
    }
    else
    {
	check_improve(ch,gsn_camouflage,FALSE,2);
	REMOVE_BIT(ch->affected_by,AFF_CAMOUFLAGE);
	WAIT_STATE(ch,8);
    }

    return;
}

/* Creep - Camo sneak -- Dioxide */

void do_creep(CHAR_DATA *ch, char *argument)
{
	int direction=0, chance, wait;
	AFFECT_DATA af;

	if ((chance = get_skill(ch,gsn_creep)) == 0)
	{
      	send_to_char("Creeping? What's that?\n\r",ch);
      	return;
	}

	if (!IS_AFFECTED(ch,AFF_CAMOUFLAGE))
	{
      	send_to_char("You must be blended in with your surroundings to creep.\n\r",ch);
      	return;
	}

	if (argument[0] == '\0') {
      	send_to_char("Creep in which direction?\n\r",ch);
      	return;
	}

	if ( !str_cmp( argument, "n" ) || !str_cmp( argument, "north" ) ) {
		direction = 0;
	} else if ( !str_cmp( argument, "e" ) || !str_cmp( argument, "east"  ) ) {
		direction = 1;
	} else if ( !str_cmp( argument, "s" ) || !str_cmp( argument, "south" ) ) {
		direction = 2;
	} else if ( !str_cmp( argument, "w" ) || !str_cmp( argument, "west"  ) ) {
		direction = 3;
	} else if ( !str_cmp( argument, "u" ) || !str_cmp( argument, "up"    ) ) {
		direction = 4;
	} else if ( !str_cmp( argument, "d" ) || !str_cmp( argument, "down"  ) ) {
		direction = 5;
	} else {
		act("You can't creep there.", ch, NULL, 0, TO_CHAR );
	}
        init_affect(&af);
	af.where     = TO_AFFECTS;
	af.type      = gsn_creep;
        af.aftype    = AFT_SKILL;
	af.bitvector = 0;
	af.modifier  = 0;
	af.location  = 0;
	af.duration  = 1;
	af.level     = ch->level;
	affect_join(ch, &af);
	move_char(ch, direction, FALSE);
	affect_strip(ch,gsn_creep);
	check_improve(ch, gsn_creep,TRUE,2);

	wait = 100 - chance;
	WAIT_STATE(ch,wait);
}

void do_hide( CHAR_DATA *ch, char *argument )
{
    int sn_fog, sn_fire;

    sn_fog = skill_lookup("faerie fog");
    sn_fire = skill_lookup("faerie fire");

    if (is_affected(ch,sn_fog) || is_affected(ch,sn_fire) || is_affected(ch, gsn_incandescense))
    {
	send_to_char("You can't hide while revealed.\n\r",ch);
	return;
    }

    if ((ch->in_room->sector_type != SECT_CITY) && (ch->in_room->sector_type != SECT_INSIDE) && (ch->in_room->sector_type != SECT_ROAD))
    {
	send_to_char("The shadows here are too natural to blend with.", ch);
	return;
    }

    send_to_char( "You attempt to hide.\n\r", ch );

    if ( IS_AFFECTED(ch, AFF_HIDE) )
        return;

    if ( number_percent( ) < get_skill(ch,gsn_hide))
    {
	SET_BIT(ch->affected_by, AFF_HIDE);
	check_improve(ch,gsn_hide,TRUE,3);
    }
    else
	check_improve(ch,gsn_hide,FALSE,3);

    return;
}

void un_camouflage( CHAR_DATA *ch, char *argument )
{
    if ( IS_AFFECTED(ch, AFF_CAMOUFLAGE) )
    {
	REMOVE_BIT( ch->affected_by, AFF_CAMOUFLAGE );
	act("$n steps out from their cover.",ch,NULL,NULL,TO_ROOM);
	send_to_char("You step out from your cover.\n\r",ch);
    }
    return;
}

void un_blackjack( CHAR_DATA *ch, char *argument )
{
    if ( is_affected(ch, gsn_blackjack) )
	affect_strip( ch, gsn_blackjack );
    return;
}

void un_garrotte( CHAR_DATA *ch, char *argument )
{
    if ( is_affected(ch, gsn_garrotte) )
	affect_strip( ch, gsn_garrotte );
    return;
}

void un_hide( CHAR_DATA *ch, char *argument )
{
    if ( IS_AFFECTED(ch, AFF_HIDE) )
    {
    REMOVE_BIT( ch->affected_by, AFF_HIDE		);
    act("$n steps out of the shadows.", ch, NULL, NULL, TO_ROOM);
    send_to_char("You step out of the shadows.\n\r", ch);
    }
    return;
}

void un_invis( CHAR_DATA *ch, char *argument )
{
    if ( IS_AFFECTED(ch, AFF_INVISIBLE))
    {
    affect_strip ( ch, gsn_invis);
    affect_strip ( ch, gsn_mass_invis);
    REMOVE_BIT   ( ch->affected_by, AFF_INVISIBLE	);
    act("$n fades into existence.\n\r", ch, NULL, NULL, TO_ROOM);
    send_to_char("You fade into existence.\n\r", ch);
    }
    return;
}
void un_sneak( CHAR_DATA *ch, char *argument )
{
    if ( ch->race == 3 || ch->race == 4 || ch->race == 5 )
	return;

    if ( IS_AFFECTED(ch, AFF_SNEAK))
    {
    affect_strip ( ch, gsn_sneak);
    REMOVE_BIT( ch->affected_by, AFF_SNEAK		);
    send_to_char("You trample around loudly again.\n\r", ch);
    }
    return;
}

void un_earthfade(CHAR_DATA *ch,char *argument)
{
	if (is_affected(ch,gsn_earthfade)) {

	affect_strip(ch,gsn_earthfade);

	act("$n slowly emerges from the ground.",ch,0,0,TO_ROOM);
	send_to_char("You slowly emerge from the ground.\n\r",ch);
	WAIT_STATE(ch,8);
	}

	return;
}

void un_duo(CHAR_DATA *ch,char *argument)
{
	if (is_affected(ch,gsn_duo))
	{
	affect_strip(ch,gsn_duo);
	act("$n pops back into existence.",ch,0,0,TO_ROOM);
	send_to_char("You step back into three dimensions.\n\r",ch);
	WAIT_STATE(ch,2);
	}
	return;
}

void do_visible( CHAR_DATA *ch, char *argument )
{
	un_earthfade(ch,NULL);
	un_camouflage(ch, NULL);
        un_hide(ch, NULL);
        un_invis(ch, NULL);
        un_sneak(ch, NULL);
	un_duo(ch,NULL);
        return;
}

void do_recall( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *victim;
    ROOM_INDEX_DATA *location;
    AFFECT_DATA af;

    if (IS_NPC(ch) && !IS_SET(ch->act,ACT_PET))
    {
	send_to_char("Only players can recall.\n\r",ch);
	return;
    }

    if (!isNewbie(ch) && ch->cabal != CABAL_RAGER)
    {
	send_to_char("Those who are not a NEWBIE cannot recall.\n\r",ch);
	return;
    }

    if (ch->level > 10 && ch->cabal == 4)
    {

        if (cabal_down(ch,CABAL_RAGER))
                return;

	if (is_affected(ch,gsn_recall))
	{
	send_to_char("You have already been granted recall by your Immortal recently.\n\r",ch);
	return;
	}

	if (ch->fighting != NULL || ch->position == POS_FIGHTING)
	{
	send_to_char("You are a Rager..you don't ask to be taken from battles!\n\r",ch);
	return;
 	}
	send_to_char("You pray to the Immortal of Ragers and recall!\n\r",ch);
    if ( IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL)
    ||   IS_AFFECTED(ch, AFF_CURSE))
    {
        send_to_char( "The gods have forsaken you.\n\r", ch );
	return;
    }
	act("$n calls to $s Immortal leader and vanishes!",ch,0,0,TO_ROOM);

	location = get_room_index(hometown_table[ch->hometown].recall);

	if (location == NULL)
		return send_to_char("Your temple has been destroyed...pray to the Gods for help!\n\r",ch);

	char_from_room(ch);
	char_to_room(ch,location);
	do_look(ch,"auto");
	init_affect(&af);
	af.where = TO_AFFECTS;
	af.aftype = AFT_POWER;
	af.type = gsn_recall;
	af.duration = 24;
	af.modifier = 0;
	af.bitvector = 0;
	af.location = 0;
	af.affect_list_msg = str_dup("unable to call upon your immortal to recall");
	af.level=ch->level;
	affect_to_char(ch,&af);
	return;
    }    

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

    location = get_room_index(hometown_table[ch->hometown].recall);

    if (location == NULL)
	return send_to_char("Your temple has been destroyed...pray to the Gods for help!\n\r",ch);

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

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

    if ( ( victim = ch->fighting ) != NULL )
    {
	int skill;

	skill = get_skill(ch,gsn_recall);

	if ( number_percent() < 80 * skill / 100 )
	{
	    check_improve(ch,gsn_recall,FALSE,6);
	    WAIT_STATE( ch, 4 );
	    sprintf( buf, "You failed!\n\r");
	    send_to_char( buf, ch );
	    return;
	}

	check_improve(ch,gsn_recall,TRUE,4);
	sprintf( buf, "You recall from combat! Pussy!\n\r" );
	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;
}



void do_train( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *mob;
    sh_int stat = - 1;
    char *pOutput = NULL;
    int cost;

    if ( IS_NPC(ch) )
	return;

    /*
     * Check for trainer.
     */
    for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
    {
	if ( IS_NPC(mob) && IS_SET(mob->act, ACT_TRAIN) )
	    break;
    }

    if ( mob == NULL )
    {
	send_to_char( "You can't do that here.\n\r", ch );
	return;
    }

    if ( argument[0] == '\0' )
    {
	sprintf( buf, "You have %d training sessions.\n\r", ch->train );
	send_to_char( buf, ch );
	argument = "foo";
    }

    cost = 1;

    if ( !str_cmp( argument, "str" ) )
    {
	stat        = STAT_STR;
	pOutput     = "strength";
    }

    else if ( !str_cmp( argument, "int" ) )
    {
	stat	    = STAT_INT;
	pOutput     = "intelligence";
    }

    else if ( !str_cmp( argument, "wis" ) )
    {
	stat	    = STAT_WIS;
	pOutput     = "wisdom";
    }

    else if ( !str_cmp( argument, "dex" ) )
    {
	stat  	    = STAT_DEX;
	pOutput     = "dexterity";
    }

    else if ( !str_cmp( argument, "con" ) )
    {
	stat	    = STAT_CON;
	pOutput     = "constitution";
    }

    else if ( !str_cmp(argument, "hp" ) )
	cost = 1;

    else if ( !str_cmp(argument, "mana" ) )
	cost = 1;

    else
    {
	strcpy( buf, "You can train:" );
	if ( ch->perm_stat[STAT_STR] < get_max_train(ch,STAT_STR))
	    strcat( buf, " str" );
	if ( ch->perm_stat[STAT_INT] < get_max_train(ch,STAT_INT))
	    strcat( buf, " int" );
	if ( ch->perm_stat[STAT_WIS] < get_max_train(ch,STAT_WIS))
	    strcat( buf, " wis" );
	if ( ch->perm_stat[STAT_DEX] < get_max_train(ch,STAT_DEX))
	    strcat( buf, " dex" );
	if ( ch->perm_stat[STAT_CON] < get_max_train(ch,STAT_CON))
	    strcat( buf, " con" );
    strcat( buf, " hp mana");

	if ( buf[strlen(buf)-1] != ':' )
	{
	    strcat( buf, ".\n\r" );
	    send_to_char( buf, ch );
	}
	else
	{
	    /*
	     * This message dedicated to Jordan ... you big stud!
	     */
	    act( "You have nothing left to train, you $T!",
		ch, NULL,
		ch->sex == SEX_MALE   ? "big stud" :
		ch->sex == SEX_FEMALE ? "hot babe" :
					"wild thing",
		TO_CHAR );
	}

	return;
    }

    if (!str_cmp("hp",argument))
    {
    	if ( cost > ch->train )
    	{
       	    send_to_char( "You don't have enough training sessions.\n\r", ch );
            return;
        }

	ch->train -= cost;
        ch->pcdata->perm_hit += 10;
        ch->max_hit += 10;
        ch->hit +=10;
        act( "Your durability increases!",ch,NULL,NULL,TO_CHAR);
        act( "$n's durability increases!",ch,NULL,NULL,TO_ROOM);
        return;
    }

    if (!str_cmp("mana",argument))
    {
        if ( cost > ch->train )
        {
            send_to_char( "You don't have enough training sessions.\n\r", ch );
            return;
        }

	ch->train -= cost;
        ch->pcdata->perm_mana += 10;
        ch->max_mana += 10;
        ch->mana += 10;
        act( "Your power increases!",ch,NULL,NULL,TO_CHAR);
        act( "$n's power increases!",ch,NULL,NULL,TO_ROOM);
        return;
    }

    if ( ch->perm_stat[stat]  >= get_max_train(ch,stat) )
    {
	act( "Your $T is already at maximum.", ch, NULL, pOutput, TO_CHAR );
	return;
    }

    if ( cost > ch->train )
    {
	send_to_char( "You don't have enough training sessions.\n\r", ch );
	return;
    }

    ch->train		-= cost;

    ch->perm_stat[stat]		+= 1;
    act( "Your $T increases!", ch, NULL, pOutput, TO_CHAR );
    act( "$n's $T increases!", ch, NULL, pOutput, TO_ROOM );
    return;
}



void do_shadowgate(CHAR_DATA *ch,char *argument)
{
	CHAR_DATA *victim;
	char arg1[MAX_INPUT_LENGTH];
	int level;

	one_argument(argument,arg1);

        if ( (get_skill(ch,gsn_shadowgate) == 0))
        {
        	send_to_char("Huh?\n\r",ch);
        	return;
        }

    	if (cabal_down(ch,CABAL_ANCIENT))
		return;

    if (affect_find(ch->affected,gsn_insect_swarm) != NULL)
    {
        send_to_char( "You attempt to transport yourself to safety but loose your concentration as you are bitten by yet another insect.\n\r", ch);
        return;
    }


       	if (ch->mana < 70)
                return send_to_char("You do not have the mana.\n\r",ch);

        if (number_percent() > ch->pcdata->learned[gsn_shadowgate] - 10)
        {
        	send_to_char("You fail to pass through the shadowplanes.\n\r",ch);
        	check_improve(ch,gsn_shadowgate,FALSE,1);
        	ch->mana -= 35;
        	return;
        }
	
	level = ch->level;
	victim = get_char_world(ch,arg1);

        if ( victim == NULL
        ||   victim == ch
        ||   victim->in_room == NULL
        ||   !can_see_room(ch,victim->in_room)
        ||   IS_SET(victim->in_room->room_flags, ROOM_NO_GATE)
        ||   IS_SET(victim->in_room->room_flags, ROOM_PRIVATE)
        ||   (victim->in_room->cabal != 0 && victim->in_room->cabal != ch->cabal)
        ||   IS_SET(victim->in_room->room_flags, ROOM_SOLITARY)
        ||   IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL)
        ||   victim->level >= level + 4
        ||   (!IS_NPC(victim) && !can_pk(ch,victim) && IS_SET(victim->act,PLR_NOSUMMON))
        ||   (!IS_NPC(victim) && saves_spell(level,victim,DAM_OTHER))
        ||   (!IS_NPC(victim) && victim->level > LEVEL_HERO)
        ||   (IS_NPC(victim) && IS_SET(victim->imm_flags,IMM_SUMMON))
        ||   (IS_NPC(victim) && saves_spell( level, victim,DAM_OTHER) ) )
        {
                send_to_char("You failed.\n\r",ch);
                WAIT_STATE(ch,12);
                return;
    	}

        ch->mana -= 70;

    	un_camouflage( ch, NULL);
    	un_earthfade(ch, NULL);
    	un_hide(ch, NULL);
    	un_sneak(ch, NULL);

        act("$n becomes enshrouded in darkness and disappears!",ch,0,0,TO_ROOM);
        char_from_room(ch);
        char_to_room(ch,victim->in_room);
        send_to_char("You step into the shadowplane and vanish.\n\r",ch);
        act("A vortex of shadows blasts into the room and $n step forth!",ch,0,0,TO_ROOM);
        do_look(ch,"auto");
	WAIT_STATE(ch,12);
        return;
}


void track_char(CHAR_DATA *ch, CHAR_DATA *tracking, int in_room)
{
    int track_dir;

    if( ch == NULL || ch->in_room == NULL || !IS_NPC(ch) || ch->pIndexData->vnum == MOB_VNUM_APRAT)
    	return;

    track_dir = tracking->pcdata->track_dir[in_room];
    track_dir -= 1;

    if (IS_AFFECTED(ch,AFF_CHARM))
	return;

    if (IS_SET(ch->off_flags,STATIC_TRACKING) || track_dir == -1)
    	return;

    if (IS_SET(ch->act,ACT_NO_TRACK)) return;

    // This was ending up as invalid memory. Checkin NULL first to be safe.
    if (ch->in_room->exit[track_dir]->u1.to_room->area == NULL)
	return;

    if (ch->in_room->exit[track_dir]->u1.to_room->area == ch->in_room->area)
    {
 	act("$n checks the ground for tracks.",ch,0,0,TO_ROOM);
	move_char(ch,track_dir,TRUE);
    }

    return;
}

void murder_entry_trigger(CHAR_DATA *ch)
{
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *rch;
    CHAR_DATA *rch_next;

    if (IS_NPC(ch))
	return;

    for (rch = ch->in_room->people; rch != NULL; rch = rch_next)
    {
	rch_next = rch->next_in_room;
	if (!IS_NPC(rch))	continue;
	if (!IS_SET(rch->off_flags,SPAM_MURDER)) 	continue;
	if (rch->fighting != NULL)	continue;
	if (!can_see(rch,ch))	continue;
	if (rch->last_fought != NULL)	continue;
	if (is_safe(rch,ch))	continue;
	if (rch->level < (ch->level - 5))	continue;

	sprintf(buf,"Help! I'm being attacked by %s!",rch->short_descr);
	do_myell(ch,buf);
	multi_hit(rch,ch,TYPE_UNDEFINED);
    }
    return;
}

void do_awareness(CHAR_DATA *ch,char *argument)
{
        int chance;
        AFFECT_DATA af;

        if (is_affected(ch,gsn_awareness))
        {
        send_to_char("You are already alert to the forests.\n\r",ch);
        return;
        }
        chance = get_skill(ch,gsn_awareness);
        if (chance == 0
        || ch->level < skill_table[gsn_awareness].skill_level[ch->class])
        {
        send_to_char("You don't know which part of the forests to be alert to.\n\r",ch);
        return;
        }
        if (ch->mana < 10)
        {
        send_to_char("You don't have the mana.\n\r",ch);
        return;
        }

        if (number_percent() > chance)
        {
        send_to_char("You try to watch your surroundings but become distracted.\n\r",ch);
        check_improve(ch,gsn_awareness,FALSE,1);
        ch->mana -= 5;
        return;
        }
        send_to_char("You start watching your surroundings more carefully.\n\r",ch);
        check_improve(ch,gsn_awareness,TRUE,1);
        ch->mana -= 10;
        init_affect(&af);
        af.where = TO_AFFECTS;
        af.location = 0;
        af.modifier = 0;
        af.type = gsn_awareness;
        af.aftype    = AFT_SKILL;
        af.bitvector = 0;
        af.level = ch->level;
		af.affect_list_msg = str_dup("grants the ability to detect camouflaged");
        af.duration = ch->level;
        affect_to_char(ch,&af);
        return;
}

/* Door bash for giants/trolls/centaurs */
void do_door_bash(CHAR_DATA *ch,char *argument)
{
    char arg[MAX_INPUT_LENGTH];
    int door;
    int chance;
    AFFECT_DATA af;

    one_argument(argument,arg);
    if (arg[0] == '\0')
    {
        send_to_char("Bash door which door?\n\r",ch);
        return;
    }
    chance = get_skill(ch,gsn_door_bash);
    if (chance == 0
    || ch->level < skill_table[gsn_door_bash].skill_level[ch->class])
    {
        send_to_char("You'd hurt yourself doing that.\n\r",ch);
        return;
    }
    if (ch->move < 5)
    {
        send_to_char("You are too exhausted.\n\r",ch);
	return;
    }

    if ( (door = find_door(ch,arg) ) >= 0)
    {
    ROOM_INDEX_DATA *to_room;
    EXIT_DATA *pexit;
    EXIT_DATA *pexit_rev;
    pexit = ch->in_room->exit[door];
    if (!IS_SET(pexit->exit_info,EX_CLOSED))
    {
        send_to_char("It's not closed.\n\r",ch);
        return;
    }

    if (!IS_SET(pexit->exit_info,EX_LOCKED))
    {
        send_to_char("It's already unlocked, why not just use the knob?\n\r",ch);
        return;
    }

    chance /= 4;
    chance += ch->level/5;
    chance += get_curr_stat(ch,STAT_STR)/2;

    if (!str_cmp(pc_race_table[ch->race].name,"cloud") ||
     !str_cmp(pc_race_table[ch->race].name,"storm") ||
     !str_cmp(pc_race_table[ch->race].name,"fire"))
	chance += 15;

    do_visible(ch,"");
    if (number_percent() > chance || IS_SET(pexit->exit_info,EX_NOBASH) )
    {
    act("$n flies into the $T door and rebounds with a great lack of dignity!",ch,0,dir_name[door],TO_ROOM);
    act("You fly into the door $T but simply bounce off it like a lump of rock!",ch,0,dir_name[door],TO_CHAR);
    damage_old(ch,ch,dice(3,5),gsn_door_bash,DAM_BASH,TRUE);
    check_improve(ch,gsn_door_bash,FALSE,1);
    WAIT_STATE(ch,12);
    return;
    }
    act("$n slams into the $T door and throws it open with a mighty crash!",ch,0,dir_name[door],TO_ROOM);
    act("You slam into the $T door and it cracks open with a deafening sound!",ch,0,dir_name[door],TO_CHAR);
    check_improve(ch,gsn_door_bash,TRUE,1);
    WAIT_STATE(ch,12);
    REMOVE_BIT(pexit->exit_info,EX_LOCKED);
    REMOVE_BIT(pexit->exit_info,EX_CLOSED);

    if ( ( (to_room = pexit->u1.to_room) != NULL)
    && ( pexit_rev = to_room->exit[rev_dir[door]] ) != NULL
    && pexit_rev->u1.to_room == ch->in_room)
        {
        REMOVE_BIT(pexit_rev->exit_info,EX_LOCKED);
        REMOVE_BIT(pexit_rev->exit_info,EX_CLOSED);
        }

    if (number_percent() < get_curr_stat(ch,STAT_DEX))
        return;

/*
 * Affect to char so in move_char you relay the right move message, then
 *  strip affect once moved.
 */
        init_affect(&af);
    af.where = TO_AFFECTS;
    af.type = gsn_door_bash;
        af.aftype    = AFT_SKILL;
    af.location = 0;
    af.modifier = 0;
    af.duration = -1;
    af.bitvector = 0;
    af.level = ch->level;
    affect_to_char(ch,&af);

    move_char(ch,door,FALSE);
    affect_strip(ch,gsn_door_bash);
    }

return;
}

void do_hometown(CHAR_DATA *ch, char *argument)
{
	int i;
	int cost;
	char arg[MAX_STRING_LENGTH];
	char arg2[MAX_STRING_LENGTH];
	char buf[MAX_STRING_LENGTH];
	int hometown;

	if (IS_NPC(ch))
		return;

	if (ch->in_room->vnum != ROOM_VNUM_HOMETOWNS)
	{
		send_to_char("You can't do that here.\n\r",ch);
		return;
	}

	argument = one_argument(argument,arg);
	one_argument(argument,arg2);

	cost = 50*(ch->level * ch->level);

	if (arg[0] == '\0')
	{
		send_to_char("Available hometowns to you are: \n\r",ch);
		for (i=0;i<MAX_HOMETOWN;i++)
		{
			if (can_live_in(ch,i)) {
				if (ch->hometown == i)
				{
					sprintf(buf,"%-18s (Current hometown)\n\r",hometown_table[i].name);
					send_to_char(buf,ch);
				}
				else
				{
					sprintf(buf,"%-18s %d gold.\n\r",hometown_table[i].name,cost);
					send_to_char(buf,ch);
				}
			}
		}
		return;
	}
	else
	{
		if (ch->gold < cost)
			return send_to_char("You don't have enough money.\n\r",ch);

		hometown = hometown_lookup(arg);

		if (hometown == ch->hometown)
		{
			send_to_char("That is your current hometown already.\n\r",ch);
			return;
		}
		else
		{
			if (!can_live_in(ch,hometown))
			{
				send_to_char("You cannot live there.\n\r",ch);
				return;
			}
			sprintf(buf,"Your hometown is now %s.\n\r",hometown_table[hometown].name);
			send_to_char(buf,ch);
			deduct_cost(ch,cost);
			ch->hometown = hometown;
			return;
		}
	}

	send_to_char("That city doesn't exist for choosing as a hometown. Type 'hometown' to see list.\n\r",ch);
	return;
}

void move_prog_bones(CHAR_DATA *ch)
{
    CHAR_DATA *bone1;
    CHAR_DATA *bone2;
    CHAR_DATA *bone3;
    CHAR_DATA *bone4;
    int num;
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *vch1;
    CHAR_DATA *vch2;
    CHAR_DATA *vch3;

    if (ch->in_room->vnum != 13868
    && ch->in_room->vnum != 13869
    && ch->in_room->vnum != 13871
    && ch->in_room->vnum != 13872
    && ch->in_room->vnum != 13884
    && ch->in_room->vnum != 13873)
        return;
    if (number_percent() > 20)
        return;
    bone1 = create_mobile(get_mob_index(MOB_VNUM_BONES));
    if (bone1 == NULL)
        return;

    act("The bones around you suddenly stir and rise up!",ch,0,0,TO_CHAR);
    act("The bones around you suddenly stir and rise up!",ch,0,0,TO_ROOM);

    switch(number_range(0,5))
    {
        case 1:
        sprintf(buf,"Die, thou who invades out rest!"); break;
        case 2:
        sprintf(buf,"%s, you shall pay for your desecration of our bones!",ch->name);
        break;
        case 3:
        sprintf(buf,"Flesh...flesh for us at last...");break;
        case 4:
        sprintf(buf,"I feel the warmth of life...give me your body so i may live!");
        break;
        case 5:
        sprintf(buf,"I sense your warm blood...let me feed...");
        break;
    }

    for (vch1 = ch->in_room->people; vch1 != NULL; vch1 = vch1->next_in_room)
    {
        if (is_same_group(vch1,ch) && number_bits(2) == 0)
            break;
    }
    if (vch1 == NULL)
        vch1 = ch;

    for (vch2 = ch->in_room->people; vch2 != NULL; vch2 = vch2->next_in_room)
    {
        if (is_same_group(vch2,ch) && number_bits(2) == 0)
            break;
    }
    if (vch2 == NULL)
        vch2 = ch;

    for (vch3 = ch->in_room->people; vch3 != NULL; vch3 = vch3->next_in_room)
    {
        if (is_same_group(vch3,ch) && number_bits(2) == 0)
            break;
    }
    if (vch3 == NULL)
        vch3 = ch;

    num = number_range(1,4);

    char_to_room(bone1,ch->in_room);

    do_say(bone1,buf);
    multi_hit(bone1,ch,TYPE_UNDEFINED);

    if (num >= 2)
    {
    bone2 = create_mobile(get_mob_index(MOB_VNUM_BONES));
    char_to_room(bone2,ch->in_room);
    act("$n rises up and attacks!",bone2,0,0,TO_ROOM);
    multi_hit(bone2,vch1,TYPE_UNDEFINED);
    }
    if (num >= 3)
    {
    bone3 = create_mobile(get_mob_index(MOB_VNUM_BONES));
    char_to_room(bone3,ch->in_room);
    act("$n rises up and attacks!",bone3,0,0,TO_ROOM);
    multi_hit(bone3,vch2,TYPE_UNDEFINED);
    }
    if (num >= 4)
    {
    bone4 = create_mobile(get_mob_index(MOB_VNUM_BONES));
    char_to_room(bone4,ch->in_room);
    act("$n rises up and attacks!",bone4,0,0,TO_ROOM);
    multi_hit(bone4,vch3,TYPE_UNDEFINED);
    }
    return;
}

void move_prog_hydra(CHAR_DATA *ch)
{
    CHAR_DATA *hydra;
    CHAR_DATA *vch;
    char buf[MAX_STRING_LENGTH];

    if (IS_NPC(ch))
        return;
    if (ch->in_room->vnum != 13874)
        return;

    for (hydra = char_list; hydra != NULL; hydra = hydra->next)
    {
        if (!IS_NPC(hydra)) continue;
        if (hydra->pIndexData->vnum == MOB_VNUM_HYDRA)
            break;
    }
    if (hydra != NULL)
        return;
    hydra = create_mobile(get_mob_index(MOB_VNUM_HYDRA));
    if (hydra == NULL)
        return;
    char_to_room(hydra,ch->in_room);

    act("The broken wood of the ships explodes as $n rises up in fury!",hydra,0,0,TO_ROOM);


    for (vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room)
    {
        if (is_same_group(vch,ch) && number_bits(2) == 0)
            break;
    }

    if (vch == NULL)
        vch = ch;

        sprintf(buf,"Help! %s is attacking me!",PERS(hydra,vch));
        do_myell(vch,buf);
        multi_hit(hydra,vch,TYPE_UNDEFINED);
        return;
}


void mob_entry_wraith(CHAR_DATA *ch)
{
    CHAR_DATA *wraith;

    if (IS_NPC(ch))
        return;
    if (str_cmp(ch->in_room->area->name,"mythforest.are")
    || number_percent() > 4)
        return;
    wraith = create_mobile(get_mob_index(13732));
    if (wraith == NULL)
        return;
    char_to_room(wraith,ch->in_room);
    act("A shimmering wraith rises from the damp forest ground in a swirling mist.",wraith,0,0,TO_ROOM);
    do_myell(ch,"Help! I'm being attacked by a mist wraith!");
    multi_hit(wraith,ch,TYPE_UNDEFINED);
    return;
}

void do_animal_call(CHAR_DATA *ch,char *argument)
{
    char arg[MAX_INPUT_LENGTH];
    MOB_INDEX_DATA *pMobIndex;
    CHAR_DATA *animal1;
    CHAR_DATA *mob;
    ROOM_INDEX_DATA *pRoomIndex;
    int chance, type;
    AFFECT_DATA af;

    one_argument(argument,arg);

    if ((chance = get_skill(ch,gsn_animal_call)) == 0
    || ch->level < skill_table[gsn_animal_call].skill_level[ch->class])
    {
        send_to_char("You don't know how to call upon animals for aid.\n\r",ch);
        return;
    }

    if (arg[0] == '\0')
    {
        send_to_char("Call out for which animal? (Falcon, Bear, Lion, Wolf)\n\r",ch);
        return;
    }

    if (!str_cmp(arg,"falcon"))
    {     
	type = MOB_VNUM_FALCON;
    }
    else if (!str_cmp(arg,"wolf"))
    {
	type = MOB_VNUM_WOLF;
    }
    else if (!str_cmp(arg,"bear"))  
    {
	type = MOB_VNUM_BEAR;
    }
    else if (!str_cmp(arg,"lion"))  
    {
	type = MOB_VNUM_LION;
    }
    else
    {
        send_to_char("call out for which animal? (Falcon, Bear, Lion, Wolf)\n\r",ch);
        return;
    }

    if (is_affected(ch,gsn_animal_call))
    {
        send_to_char("You aren't able to call upon anymore animals yet.\n\r",ch);
        return;
    }


    if (ch->mana < 50)
    {
        send_to_char("You don't have the mana.\n\r",ch);
        return;
    }

    for (mob = char_list; mob != NULL; mob = mob->next)
    {
        if (IS_NPC(mob) && IS_AFFECTED(mob,AFF_CHARM)
        && (mob->master == ch)
        && ( (mob->pIndexData->vnum == MOB_VNUM_FALCON)
        || (mob->pIndexData->vnum == MOB_VNUM_WOLF)
        || (mob->pIndexData->vnum == MOB_VNUM_BEAR)
        || (mob->pIndexData->vnum == MOB_VNUM_LION) ) )
        break;
    }

    if (mob != NULL)
    {
        send_to_char("You already have an animal you should care for.\n\r",ch);
        return;
    }

    if ( (ch->in_room->sector_type != SECT_FOREST) && (ch->in_room->sector_type != SECT_MOUNTAIN)
        && (ch->in_room->sector_type != SECT_HILLS ) && (ch->in_room->sector_type != SECT_DESERT)
        && (ch->in_room->sector_type != SECT_FIELD ))
    {
           send_to_char("You are not within the right environment to call an animal.\n\r",ch);
           return;
    }

    if (number_percent() > chance)
    {
    act("$n calls out to the wild but nothing responds.",ch,0,0,TO_ROOM);
    send_to_char("You call out to the wild but nothing responds.\n\r",ch);
    ch->mana -= 25;
    check_improve(ch,gsn_animal_call,FALSE,1);
    return;
    }

    pRoomIndex = ch->in_room;
    pMobIndex = get_mob_index(type);

    if (pMobIndex == NULL)
    {
        bug("Animal call: Bad mob vnum call %d.",type);
        send_to_char("You call out to the wild but nothing responds.\n\r",ch);
        act("$n calls out to the wild but nothing responds.",ch,0,0,TO_ROOM);
        ch->mana -= 25;
        return;
    }

    animal1 = create_mobile( pMobIndex );

    if (type == MOB_VNUM_FALCON)
    {
        animal1->max_hit = 3*ch->max_hit/4;
        animal1->hit = 3*ch->max_hit/4;
        animal1->damroll = (ch->level/2);
        animal1->hitroll = 10 * ch->level/3;
		animal1->numAttacks = 2;
    }

    else if (type == MOB_VNUM_WOLF)
    {
        animal1->max_hit = ch->max_hit/2;
        animal1->hit = ch->max_hit/2;
        animal1->damroll = (3 * ch->level / 4);
        animal1->hitroll = 5 * ch->level/3;
		animal1->numAttacks = 1;
    }


    else if (type == MOB_VNUM_BEAR)
    {
        animal1->max_hit = 2 * ch->max_hit;
        animal1->hit = 2 * ch->max_hit;
        animal1->damroll = (10+ch->level/3);
        animal1->hitroll = 5 * ch->level;
    }


    else if (type == MOB_VNUM_LION)
    {
        animal1->max_hit = ch->max_hit;
        animal1->hit = ch->max_hit;
        animal1->damroll = ch->level;
        animal1->hitroll = ch->level;
    }
    else
    {
    bug("Bad animal call: %d.",type);
    send_to_char("You call out to the wild but nothing responds.\n\r",ch);
    act("$n calls out to the wild but nothing comes.\n\r",ch,0,0,TO_ROOM);
    ch->mana -= 25;
    return;
    }

    char_to_room(animal1,pRoomIndex);
    animal1->level = ch->level;
    
    act("A beast of the wilds responds to $n's call!",ch,0,animal1,TO_ROOM);
    act("A beast of the wilds responds to your call!",ch,0,animal1,TO_CHAR);
    ch->mana -= 50;
    SET_BIT(animal1->affected_by,AFF_CHARM);
    animal1->leader = ch;
    animal1->master = ch;
    animal1->cabal  = ch->cabal;
    init_affect(&af);
    af.where 		= TO_AFFECTS;
    af.aftype 		= AFT_SKILL;
    af.type 		= gsn_animal_call;
    af.level 		= ch->level;
    af.duration 	= 12;
    af.location 	= 0;
    af.modifier 	= 0;
    af.bitvector	= 0;
	af.affect_list_msg = str_dup("unable to call upon the wilds");
    affect_to_char(ch,&af);
    return;
}

void do_forest_blending(CHAR_DATA *ch, char *argument)
{
        int chance;
        AFFECT_DATA af;

        chance = get_skill(ch,gsn_forest_blending);
        if (chance < 5
        || ch->level < skill_table[gsn_forest_blending].skill_level[ch->class])
        {
        	send_to_char("You don't know how to blend in with the forests.\n\r",ch);
        	return;
        }

        if (ch->in_room->sector_type != SECT_FOREST)
        {
        	send_to_char("You aren't within a suitable forest environment.\n\r",ch);
        	return;
        }

   	if (is_affected(ch,gsn_forest_blending))
	{
		send_to_char("You're already trying to blend in with your surroundings.\n\r",ch);
		return;
	}

	send_to_char("You attempt to blend in with the forests.\n\r",ch);

        if (number_percent() < chance)
        {
        	check_improve(ch,gsn_forest_blending,TRUE,1);
		init_affect(&af);
		af.where 	= TO_AFFECTS;
		af.aftype 	= AFT_SKILL;
		af.level 	= ch->level;
		af.modifier 	= 0;
		af.location 	= 0;
		af.bitvector 	= 0;
		af.duration 	= 5;
		af.affect_list_msg = str_dup("camouflaged in your surroundings");
		af.type = gsn_forest_blending;
		affect_to_char(ch,&af);
        }
        else
        {
                check_improve(ch,gsn_forest_blending,FALSE,1);
        affect_strip(ch,gsn_forest_blending);
        }

        WAIT_STATE(ch,6);
        return;
}

void un_forest_blend(CHAR_DATA *ch)
{
        if (!is_affected(ch,gsn_forest_blending))
                return;
        act("$n steps into the open from the surrounding forest.",ch,0,0,TO_ROOM);
        act("You step into the open from the surrounding forest.",ch,0,0,TO_CHAR);
        affect_strip(ch,gsn_forest_blending);
        return;
}

void do_cloak( CHAR_DATA *ch, char *argument )
{
	AFFECT_DATA af;
	char buf[MAX_STRING_LENGTH];
	char arg[MAX_STRING_LENGTH];

	argument = one_argument(argument,arg);

	if(is_affected(ch,gsn_cloak_form)) {
		affect_strip(ch,gsn_cloak_form);
		free_string(ch->name);
		ch->name=str_dup(ch->original_name);
	    	if(is_affected(ch, gsn_eye_of_the_predator)) {
			affect_strip(ch,gsn_eye_of_the_predator); 
	    	}
		if (str_cmp(arg,"auto") )
	    		send_to_char("You throw your cloak to the side, exposing yourself.\n\r",ch); 
				ch->cloaked = 0;
	    	return;
	}

	if (number_percent() < get_skill(ch,gsn_cloak_form))
	{
		init_affect(&af);
	  	af.where	= TO_AFFECTS;
		af.aftype	= AFT_POWER;
	  	af.type		= gsn_cloak_form;
	  	af.level	= ch->level;
	  	af.location	= APPLY_NONE;
	  	af.modifier	= 0;
	  	af.bitvector	= AFF_SNEAK;
	  	af.duration 	= -1;
		af.affect_list_msg = str_dup("grants silent movement and a shrouded disguise");
	  	affect_to_char( ch, &af );
		af.affect_list_msg = NULL;
	  	af.location 	= APPLY_HIT;
	  	af.modifier 	= ch->level*5;
	  	affect_to_char(ch,&af);
	  	af.location 	= APPLY_MOVE;
	  	af.modifier 	= ch->level*2;
	  	affect_to_char(ch,&af); 
	  	af.location 	= APPLY_MANA;
	  	af.modifier 	= ch->level*2;
	  	affect_to_char(ch,&af);
		af.location	= APPLY_DAMROLL;
		af.modifier	= 5;
		affect_to_char(ch,&af);
		af.location	= APPLY_HITROLL;
		af.modifier	= 5;
		affect_to_char(ch,&af);
	  	check_improve(ch,gsn_cloak_form,TRUE,6);
	  	send_to_char("You cloak your presence.\n\r",ch);
		free_string(ch->name);
		sprintf(buf, "cloaked figure");
		ch->name=str_dup(buf);
		ch->cloaked = 1;
		free_string(buf);
	  	return;
	}
	else
	{
	  	check_improve(ch,gsn_cloak_form, FALSE,3);
	  	send_to_char("You fail to cloak yourself.\n\r",ch);
	  	return;
	}
}

bool isInWilderness(CHAR_DATA *ch)
{
	if ((ch->in_room->sector_type == SECT_FIELD) || (ch->in_room->sector_type == SECT_FOREST) || (ch->in_room->sector_type == SECT_HILLS)
	|| (ch->in_room->sector_type == SECT_MOUNTAIN))
	{
		return TRUE;
	}
	return FALSE;
}

void EsiraenPiranhaCheck(CHAR_DATA *ch)
{
	CHAR_DATA *piranha;
	MOB_INDEX_DATA *pMob;


	if (IS_NPC(ch))
		return;

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

	if (isNewbie(ch))
		return;

	if (ch->invis_level > 51)
		return;

	if (str_cmp(ch->in_room->area->name, "Esiraen River") || number_percent() > 10)
		return;

	if (ch->in_room->vnum > 27515 || ch->in_room->vnum < 27500)
		return;

	pMob = get_mob_index(27501);
	if (!pMob || pMob->count > 12)
		return;

	piranha = create_mobile(pMob);
	if (piranha == NULL)
		return n_logf("EsiraenPiranhaCheck: could not create piranha mobile (vnum 27501)");

	char_to_room(piranha, ch->in_room);
	act("A vicious piranha appears out of nowhere and darts towards you!",ch,0,0,TO_CHAR);
	multi_hit(piranha,ch,TYPE_UNDEFINED);
	return;
}