act_move.c

src/act_move.c · 261.7 KB

From the archive cotn-4.0.tar.gz

Download the archive   « Back to the archive contents

/***************************************************************************
 *  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.                                               *
 *                                                                         *
 *  Dystopia Mud improvements copyright (C) 2000, 2001 by Brian Graversen  *
 *                                                                         *
 *  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.                                                  *
 ***************************************************************************/
/***************************************************************************
 *                                 _/                            _/        *
 *      _/_/_/  _/_/      _/_/_/  _/    _/_/    _/    _/    _/_/_/         *
 *     _/    _/    _/  _/        _/  _/    _/  _/    _/  _/    _/          *
 *    _/    _/    _/  _/        _/  _/    _/  _/    _/  _/    _/           *
 *   _/    _/    _/    _/_/_/  _/    _/_/      _/_/_/    _/_/_/            *
 ***************************************************************************
 * Mindcloud Copyright 2001-2003 by Jeff Boschee (Zarius),                 *
 * Additional credits are in the help file CODECREDITS                     *
 * All Rights Reserved.                                                    *
 ***************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"


void horn args((CHAR_DATA * ch));

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));
int count_imms args((CHAR_DATA * ch));
bool check_track args((CHAR_DATA * ch, int direction));
void add_tracks args((CHAR_DATA * ch, int direction));
void drow_hate args((CHAR_DATA * ch));


void move_char(CHAR_DATA * ch, int door)
{
        CHAR_DATA *fch;
        CHAR_DATA *fch_next;
        CHAR_DATA *mount;
        ROOM_INDEX_DATA *in_room;
        ROOM_INDEX_DATA *to_room;
        OBJ_DATA *obj;
        EXIT_DATA *pexit;
        DESCRIPTOR_DATA *d;
        char      buf[MAX_STRING_LENGTH];
        char      poly[MAX_STRING_LENGTH];
        char      mount2[MAX_INPUT_LENGTH];
        char      leave[20];
        int       revdoor;
        bool      bad_wall = FALSE;

        if (door < 0 || door > 5)

        {
                bug("Do_move: bad door %d.", door);
                return;
        }
        /*
         * Exit trigger, if activated, bail out. Only PCs are triggered.
         */
        if (!IS_NPC(ch)
            && (p_exit_trigger(ch, door, PRG_MPROG)
                || p_exit_trigger(ch, door, PRG_OPROG)
                || p_exit_trigger(ch, door, PRG_RPROG)))
                return;

        in_room = ch->in_room;

        if (!in_room)
        {
                bug("Move_char : ch not in any room.", 0);
                return;
        }

        if ((pexit = in_room->exit[door]) == NULL
            || (to_room = pexit->to_room) == NULL)
        {
                send_to_char("Alas, you cannot go that way.\n\r", ch);
                return;
        }
        if (!IS_NPC(ch) && IS_CLASS(ch, CLASS_DROID)
            && IS_SET(ch->newbits, NEW_CUBEFORM))
        {
                if (!IS_SET
                    (ch->pcdata->powers[DROID_IMPLANTS], IMPLANT_LARVAFEET)
                    || ch->fighting)
                {
                        send_to_char
                                ("Battlestations don't go anywhere, they stand still and fight.\n\r",
                                 ch);
                        return;
                }
                WAIT_STATE(ch, 4);
                send_to_char("Chrss..chrss...chrrrr...shh...\n\r", ch);
        }

        if (door == DIR_NORTH
            && ((obj = get_obj_list(ch, "walln", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "walls", to_room->contents)) != NULL))
                bad_wall = TRUE;

        if (door == DIR_SOUTH
            && ((obj = get_obj_list(ch, "walls", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "walln", to_room->contents)) != NULL))
                bad_wall = TRUE;

        if (door == DIR_EAST
            && ((obj = get_obj_list(ch, "walle", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "wallw", to_room->contents)) != NULL))
                bad_wall = TRUE;

        if (door == DIR_WEST
            && ((obj = get_obj_list(ch, "wallw", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "walle", to_room->contents)) != NULL))
                bad_wall = TRUE;

        if (door == DIR_UP
            && ((obj = get_obj_list(ch, "wallu", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "walld", to_room->contents)) != NULL))
                bad_wall = TRUE;

        if (door == DIR_DOWN
            && ((obj = get_obj_list(ch, "walld", ch->in_room->contents)) !=
                NULL
                || (obj =
                    get_obj_list(ch, "wallu", to_room->contents)) != NULL))
                bad_wall = TRUE;
        if (bad_wall)
        {
                send_to_char("You are unable to pass the wall.\n\r", ch);
                return;
        }

        if (IS_SET(pexit->exit_info, EX_CLOSED)
            && (!IS_AFFECTED(ch, AFF_PASS_DOOR)
                || IS_SET(pexit->exit_info, EX_NOPASS))
            && !IS_AFFECTED(ch, AFF_ETHEREAL) && !IS_IMMORTAL(ch)
            && !IS_AFFECTED(ch, AFF_SHADOWPLANE))

        {
                if (!IS_NPC(ch) && IS_CLASS(ch, CLASS_WEREWOLF) &&
                    ch->power[DISC_WERE_BOAR] > 0
                    && !IS_SET(pexit->exit_info, EX_PRISMATIC_WALL))
                {
                        act("You smash open the $d.", ch, NULL,
                            pexit->keyword, TO_CHAR);
                        act("$n smashes open the $d.", ch, NULL,
                            pexit->keyword, TO_ROOM);
                        REMOVE_BIT(pexit->exit_info, EX_CLOSED);
                }
                else
                {
                        act("The $d is closed.", ch, NULL, pexit->keyword,
                            TO_CHAR);
                        return;
                }
        }

        if (IS_SET(pexit->exit_info, EX_PRISMATIC_WALL)
            && IS_SET(pexit->exit_info, EX_CLOSED))
        {
                stc("The prismatic wall prevents movement through this closed exit.\n\r", ch);
                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_NPC(ch) && (mount = ch->mount) != NULL
            && IS_SET(ch->mounted, IS_MOUNT))
        {
                send_to_char
                        ("You better wait for instructions from your rider.\n\r",
                         ch);
                return;
        }

        if (room_is_private(to_room))
        {
                if (IS_NPC(ch) || ch->trust < MAX_LEVEL)
                {
                        send_to_char("That room is private right now.\n\r",
                                     ch);
                        return;
                }
                else
                        send_to_char
                                ("That room is private (Access granted).\n\r",
                                 ch);
        }

        if ((IS_LEG_L(ch, BROKEN_LEG) || IS_LEG_L(ch, LOST_LEG)) &&
            (IS_LEG_R(ch, BROKEN_LEG) || IS_LEG_R(ch, LOST_LEG)) &&
            (IS_ARM_L(ch, BROKEN_ARM) || IS_ARM_L(ch, LOST_ARM) ||
             get_eq_char(ch, WEAR_HOLD) != NULL) &&
            (IS_ARM_R(ch, BROKEN_ARM) || IS_ARM_R(ch, LOST_ARM) ||
             get_eq_char(ch, WEAR_WIELD) != NULL))
        {
                send_to_char
                        ("You need at least one free arm to drag yourself with.\n\r",
                         ch);
                return;
        }
        else if (IS_BODY(ch, BROKEN_SPINE) &&
                 (IS_ARM_L(ch, BROKEN_ARM) || IS_ARM_L(ch, LOST_ARM) ||
                  get_eq_char(ch, WEAR_HOLD) != NULL) &&
                 (IS_ARM_R(ch, BROKEN_ARM) || IS_ARM_R(ch, LOST_ARM) ||
                  get_eq_char(ch, WEAR_WIELD) != NULL))
        {
                send_to_char("You cannot move with a broken spine.\n\r", ch);
                return;
        }

        if (!IS_NPC(ch))
        {
                int       move;

                if (in_room->sector_type == SECT_AIR
                    || to_room->sector_type == SECT_AIR)
                {
                        if (!IS_AFFECTED(ch, AFF_FLYING) &&
                            (!IS_NPC(ch) && (!IS_CLASS(ch, CLASS_DROW) ||
                                             !IS_SET(ch->pcdata->powers[1], DPOWER_LEVITATION)))
                            && (!IS_NPC(ch) && !IS_VAMPAFF(ch, VAM_FLYING)
                                && (!IS_NPC(ch)
                                    && !IS_DEMAFF(ch, DEM_UNFOLDED)))
                            && !((mount = ch->mount) != NULL
                                 && IS_SET(ch->mounted, IS_RIDING)
                                 && IS_AFFECTED(mount, AFF_FLYING)))
                        {
                                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)
                {
                        //OBJ_DATA *obj;
                        bool      found;

                        /*
                         * Look for a boat.
                         */
                        found = FALSE;
                        if (!IS_NPC(ch) && IS_CLASS(ch, CLASS_VAMPIRE))
                        {
                                if (IS_VAMPAFF(ch, VAM_FLYING))
                                        found = TRUE;
                                else if (IS_POLYAFF(ch, POLY_SERPENT))
                                        found = TRUE;
                                else if (IS_AFFECTED(ch, AFF_SHADOWPLANE))
                                        found = TRUE;
                                else if ((mount = ch->mount) != NULL
                                         && IS_SET(ch->mounted, IS_RIDING)
                                         && IS_AFFECTED(mount, AFF_FLYING))
                                        found = TRUE;
                                else
                                {
                                        send_to_char
                                                ("You are unable to cross running water.\n\r",
                                                 ch);
                                        return;
                                }
                        }
                        if (IS_AFFECTED(ch, AFF_FLYING))
                                found = TRUE;
                        else if (!IS_NPC(ch) && IS_DEMAFF(ch, DEM_UNFOLDED))
                                found = TRUE;
                        else if (!IS_NPC(ch) && (IS_CLASS(ch, CLASS_DROW) && IS_SET(ch->pcdata->powers[1], DPOWER_LEVITATION)))
                                found = TRUE;
                        if (!found)
                        {
                                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;
                                }
                        }
                }
                else if (!IS_AFFECTED(ch, AFF_FLYING)
                         && IS_POLYAFF(ch, POLY_FISH))
                {
                        bool      from_ok = FALSE;
                        bool      to_ok = FALSE;

                        if (in_room->sector_type == SECT_WATER_NOSWIM)
                                from_ok = TRUE;
                        if (in_room->sector_type == SECT_WATER_SWIM)
                                from_ok = TRUE;
                        if (to_room->sector_type == SECT_WATER_NOSWIM)
                                to_ok = TRUE;
                        if (to_room->sector_type == SECT_WATER_SWIM)
                                to_ok = TRUE;
                        if (!from_ok || !to_ok)
                        {
                                send_to_char("You cannot cross land.\n\r",
                                             ch);
                                return;
                        }
                }

                move = movement_loss[UMIN(SECT_MAX - 1, in_room->sector_type)]
                        +
                        movement_loss[UMIN
                                      (SECT_MAX - 1, to_room->sector_type)];

                if (IS_HERO(ch))
                        move = 0;

                if (ch->move <= 0)
                {
                        send_to_char("You are too Exhausted.\n\r", ch);
                        return;
                }

                if (IS_SET(ch->mounted, IS_RIDING)
                    && (ch->move < move || ch->move < 1))
                {
                        send_to_char("You are too exhausted.\n\r", ch);
                        return;
                }

                if (IS_SET(pexit->exit_info, EX_IRON_WALL)
                    && !IS_AFFECTED(ch, AFF_PASS_DOOR))
                {
                        send_to_char
                                ("A towering wall of iron blocks your path.\n\r",
                                 ch);
                        act("$n's path is blocked by the wall of iron.", ch,
                            NULL, NULL, TO_ROOM);
                        return;
                }

                if (IS_SET(pexit->exit_info, EX_MUSHROOM_WALL))
                {
                        send_to_char("The mushrooms block your path.\n\r",
                                     ch);
                        return;
                }

                if (IS_SET(pexit->exit_info, EX_ICE_WALL)
                    && ch->power[DISC_DAEM_GELU] < 5)
                {
                        send_to_char
                                ("A huge wall of ice blocks your way.\n\r",
                                 ch);
                        return;
                }

                if (IS_SET(pexit->exit_info, EX_FIRE_WALL) && ch->class == 0)
                {
                        act("$n bursts through the wall of fire.", ch, NULL,
                            NULL, TO_ROOM);
                        send_to_char
                                ("You jump through the flames and are unaffected.\n\r",
                                 ch);
                }

                else if (IS_SET(pexit->exit_info, EX_FIRE_WALL)
                         && ch->class != 0 && !IS_NPC(ch) && ch->level > 2)
                {
                        act("$n bursts through the wall of fire.", ch, NULL,
                            NULL, TO_ROOM);
                        send_to_char("You jump through the flames.\n\r", ch);
                        ch->hit -= dice(6, 50);
                        stc("The flames sear your flesh.\n\r", ch);
                }

                if (IS_SET(pexit->exit_info, EX_SWORD_WALL) && ch->class == 0)
                {
                        act("$n bursts through the wall of swords.", ch, NULL,
                            NULL, TO_ROOM);
                        send_to_char
                                ("You jump through the swords and are unaffected.\n\r",
                                 ch);
                }

                else if (IS_SET(pexit->exit_info, EX_SWORD_WALL)
                         && ch->class != 0 && !IS_NPC(ch) && ch->level > 2)
                {
                        act("$n jumps through the wall of swords.", ch, NULL,
                            NULL, TO_ROOM);
                        send_to_char("You jump through the swords.\n\r", ch);
                        send_to_char("Aaaaaaaaarghhhhhhh! That hurt!\n\r",
                                     ch);
                        ch->hit -= dice(6, 70);
                }

                if (IS_SET(pexit->exit_info, EX_ASH_WALL))
                {
                        send_to_char
                                ("You scream in agony as the wall of ash rips apart your life force.\n\r",
                                 ch);
                        act("$n screams in agony as the wall of ash rips $s life force apart.", ch, NULL, NULL, TO_ROOM);
                        ch->hit /= 2;
                        ch->move /= 2;
                }
	if(IS_SET(pexit->exit_info, EX_SHIN_WALL) && !IS_CLASS(ch,CLASS_SHINOBI)){
		stc("The shurikens tear through your flesh!\n\r",ch);
		act("$n's flesh is torn by the shuriken wall!",ch,NULL,NULL,TO_ROOM);
		ch->hit *= .9;
	}
                WAIT_STATE(ch, 1);
                if (!IS_SET(ch->mounted, IS_RIDING))
                        ch->move -= move;
        }

        /*
         * Check for mount message - KaVir 
         */
        if ((mount = ch->mount) != NULL && ch->mounted == IS_RIDING)
        {
                if (IS_NPC(mount))
                        xprintf(mount2, " on %s.", mount->short_descr);
                else
                        xprintf(mount2, " on %s.", mount->name);
        }
        else
                xprintf(mount2, ".");

        if (IS_HEAD(ch, LOST_HEAD) || IS_EXTRA(ch, EXTRA_OSWITCH))
                xprintf(leave, "rolls");
        else if (IS_AFFECTED(ch, AFF_ETHEREAL))
                xprintf(leave, "floats");
        else if (ch->in_room->sector_type == SECT_WATER_SWIM)
                xprintf(leave, "swims");
        else if (IS_SET(ch->polyaff, POLY_SERPENT))
                xprintf(leave, "slithers");
        else if (IS_SET(ch->polyaff, POLY_WOLF))
                xprintf(leave, "stalks");
        else if (IS_SET(ch->polyaff, POLY_FROG))
                xprintf(leave, "hops");
        else if (IS_SET(ch->polyaff, POLY_FISH))
                xprintf(leave, "swims");
        else if (!IS_NPC(ch) && IS_DEMAFF(ch, DEM_UNFOLDED))
                xprintf(leave, "flies");
        else if (IS_BODY(ch, BROKEN_SPINE))
                xprintf(leave, "drags $mself");
        else if (IS_LEG_L(ch, LOST_LEG) && IS_LEG_R(ch, LOST_LEG))
                xprintf(leave, "drags $mself");
        else if ((IS_LEG_L(ch, BROKEN_LEG) || IS_LEG_L(ch, LOST_LEG)
                  || IS_LEG_L(ch, LOST_FOOT)) && (IS_LEG_R(ch, BROKEN_LEG)
                                                  || IS_LEG_R(ch, LOST_LEG)
                                                  || IS_LEG_R(ch, LOST_FOOT)))
                xprintf(leave, "crawls");
        else if (ch->hit < (ch->max_hit / 4))
                xprintf(leave, "crawls");
        else if ((IS_LEG_R(ch, LOST_LEG) || IS_LEG_R(ch, LOST_FOOT)) &&
                 (!IS_LEG_L(ch, BROKEN_LEG) && !IS_LEG_L(ch, LOST_LEG) &&
                  !IS_LEG_L(ch, LOST_FOOT)))
                xprintf(leave, "hops");
        else if ((IS_LEG_L(ch, LOST_LEG) || IS_LEG_L(ch, LOST_FOOT)) &&
                 (!IS_LEG_R(ch, BROKEN_LEG) && !IS_LEG_R(ch, LOST_LEG) &&
                  !IS_LEG_R(ch, LOST_FOOT)))
                xprintf(leave, "hops");
        else if ((IS_LEG_L(ch, BROKEN_LEG) || IS_LEG_L(ch, LOST_FOOT)) &&
                 (!IS_LEG_R(ch, BROKEN_LEG) && !IS_LEG_R(ch, LOST_LEG) &&
                  !IS_LEG_R(ch, LOST_FOOT)))
                xprintf(leave, "limps");
        else if ((IS_LEG_R(ch, BROKEN_LEG) || IS_LEG_R(ch, LOST_FOOT)) &&
                 (!IS_LEG_L(ch, BROKEN_LEG) && !IS_LEG_L(ch, LOST_LEG) &&
                  !IS_LEG_L(ch, LOST_FOOT)))
                xprintf(leave, "limps");
        else if (ch->hit < (ch->max_hit / 3))
                xprintf(leave, "limps");
        else if (ch->hit < (ch->max_hit / 2))
                xprintf(leave, "staggers");
        else if (!IS_NPC(ch))
        {

                if (ch->pcdata->condition[COND_DRUNK] > 10)
                        xprintf(leave, "staggers");
                else
                        xprintf(leave, "walks");
        }
        else
                xprintf(leave, "walks");

        if (!IS_NPC(ch) && ch->stance[0] != -1)
                do_stance(ch, "");
        for (d = descriptor_list; d != NULL; d = d->next)
        {
                CHAR_DATA *victim;

                if ((victim = d->character) == NULL)
                        continue;

                if (ch->in_room == NULL || victim->in_room == NULL)
                        continue;

                if (ch == victim || ch->in_room != victim->in_room)
                        continue;

                if (d->connected != CON_PLAYING || !can_see(ch, victim))
                        continue;

                if (!IS_NPC(ch) && !IS_AFFECTED(ch, AFF_SNEAK)
                    && IS_AFFECTED(ch, AFF_POLYMORPH) && (IS_NPC(ch)
                                                          || !IS_SET(ch->act,
                                                                     PLR_WIZINVIS))
                    && can_see(victim, ch))
                {
                        if (((mount = ch->mount) != NULL
                             && ch->mounted == IS_RIDING
                             && IS_AFFECTED(mount, AFF_FLYING))
                            || IS_AFFECTED(ch, AFF_FLYING) || (!IS_NPC(ch)
                                                               &&
                                                               IS_VAMPAFF(ch,
                                                                          VAM_FLYING)))
                                xprintf(poly, "%s flies $T%s", ch->morph,
                                        mount2);
                        else if ((mount = ch->mount) != NULL
                                 && ch->mounted == IS_RIDING)
                                xprintf(poly, "%s rides $T%s", ch->morph,
                                        mount2);
                        else
                                xprintf(poly, "%s %s $T%s", ch->morph, leave,
                                        mount2);
                        act(poly, victim, NULL, dir_name[door], TO_CHAR);
                }
                else if (!IS_AFFECTED(ch, AFF_SNEAK)
                         && (IS_NPC(ch) || !IS_SET(ch->act, PLR_WIZINVIS))
                         && can_see(victim, ch))
                {
                        if (((mount = ch->mount) != NULL
                             && ch->mounted == IS_RIDING
                             && IS_AFFECTED(mount, AFF_FLYING))
                            || IS_AFFECTED(ch, AFF_FLYING) || (!IS_NPC(ch)
                                                               &&
                                                               IS_VAMPAFF(ch,
                                                                          VAM_FLYING)))
                                xprintf(poly, "$n flies %s%s", dir_name[door],
                                        mount2);
                        else if ((mount = ch->mount) != NULL
                                 && ch->mounted == IS_RIDING)
                                xprintf(poly, "$n rides %s%s", dir_name[door],
                                        mount2);
                        else
                                xprintf(poly, "$n %s %s%s", leave,
                                        dir_name[door], mount2);
                        act(poly, ch, NULL, victim, TO_VICT);
                }
        }
        char_from_room(ch);
        char_to_room(ch, to_room);
        if (door == 0)
        {
                revdoor = 2;
                xprintf(buf, "the south");
        }
        else if (door == 1)
        {
                revdoor = 3;
                xprintf(buf, "the west");
        }
        else if (door == 2)
        {
                revdoor = 0;
                xprintf(buf, "the north");
        }
        else if (door == 3)
        {
                revdoor = 1;
                xprintf(buf, "the east");
        }
        else if (door == 4)
        {
                revdoor = 5;
                xprintf(buf, "below");
        }
        else
        {
                revdoor = 4;
                xprintf(buf, "above");
        }

        for (d = descriptor_list; d != NULL; d = d->next)
        {
                CHAR_DATA *victim;

                if ((victim = d->character) == NULL)
                        continue;

                if (ch->in_room == NULL || victim->in_room == NULL)
                        continue;

                if (ch == victim || ch->in_room != victim->in_room)
                        continue;

                if (d->connected != CON_PLAYING || !can_see(ch, victim))
                        continue;

                if (!IS_NPC(ch) && !IS_AFFECTED(ch, AFF_SNEAK)
                    && IS_AFFECTED(ch, AFF_POLYMORPH) && (IS_NPC(ch)
                                                          || !IS_SET(ch->act,
                                                                     PLR_WIZINVIS))
                    && can_see(victim, ch))
                {
                        if (((mount = ch->mount) != NULL
                             && ch->mounted == IS_RIDING
                             && IS_AFFECTED(mount, AFF_FLYING))
                            || IS_AFFECTED(ch, AFF_FLYING) || (!IS_NPC(ch)
                                                               &&
                                                               IS_VAMPAFF(ch,
                                                                          VAM_FLYING)))
                                xprintf(poly, "%s flies in from %s%s",
                                        ch->morph, buf, mount2);
                        else if ((mount = ch->mount) != NULL
                                 && ch->mounted == IS_RIDING)
                                xprintf(poly, "%s rides in from %s%s",
                                        ch->morph, buf, mount2);
                        else
                                xprintf(poly, "%s %s in from %s%s", ch->morph,
                                        leave, buf, mount2);
                        act(poly, ch, NULL, victim, TO_VICT);
                }
                else if (!IS_AFFECTED(ch, AFF_SNEAK) && can_see(victim, ch)
                         && (IS_NPC(ch) || !IS_SET(ch->act, PLR_WIZINVIS)))
                {
                        if (((mount = ch->mount) != NULL
                             && ch->mounted == IS_RIDING
                             && IS_AFFECTED(mount, AFF_FLYING))
                            || IS_AFFECTED(ch, AFF_FLYING) || (!IS_NPC(ch)
                                                               &&
                                                               IS_VAMPAFF(ch,
                                                                          VAM_FLYING)))
                                xprintf(poly, "$n flies in from %s%s", buf,
                                        mount2);
                        else if ((mount = ch->mount) != NULL
                                 && ch->mounted == IS_RIDING)
                                xprintf(poly, "$n rides in from %s%s", buf,
                                        mount2);
                        else
                                xprintf(poly, "$n %s in from %s%s", leave,
                                        buf, mount2);
                        act(poly, ch, NULL, victim, TO_VICT);
                }
        }

        do_look(ch, "auto");

        for (fch = in_room->people; fch != NULL; fch = fch_next)
        {
                fch_next = fch->next_in_room;
                if ((mount = fch->mount) != NULL && mount == ch
                    && IS_SET(fch->mounted, IS_MOUNT))
                {
                        act("$N digs $S heels into you.", fch, NULL, ch,
                            TO_CHAR);
                        char_from_room(fch);
                        char_to_room(fch, ch->in_room);
                }

                if (fch->master == ch && fch->position == POS_STANDING
                    && fch->in_room != ch->in_room)
                {
                        act("You follow $N.", fch, NULL, ch, TO_CHAR);
                        move_char(fch, door);
                }
        }
        /*
         * If someone is following the char, these triggers get activated
         * for the followers before the char, but it's safer this way...
         */
        if (IS_NPC(ch) && HAS_TRIGGER_MOB(ch, TRIG_ENTRY))
                p_percent_trigger(ch, NULL, NULL, NULL, NULL, NULL,
                                  TRIG_ENTRY);
        if (!IS_NPC(ch))
        {
                p_greet_trigger(ch, PRG_MPROG);
                p_greet_trigger(ch, PRG_OPROG);
                p_greet_trigger(ch, PRG_RPROG);
        }
        room_text(ch, ">enter<");
        return;
}

void do_north(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }

        in_room = ch->in_room;
        move_char(ch, DIR_NORTH);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_NORTH);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
        drow_hate(ch);

        return;
}

void do_east(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }


        in_room = ch->in_room;
        move_char(ch, DIR_EAST);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_EAST);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
        drow_hate(ch);
        return;
}

void do_south(CHAR_DATA * ch, char *argument)
{

        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }


        in_room = ch->in_room;
        move_char(ch, DIR_SOUTH);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_SOUTH);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
        drow_hate(ch);
        return;
}

void do_west(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }



        in_room = ch->in_room;
        move_char(ch, DIR_WEST);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_WEST);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
        drow_hate(ch);
        return;
}

void do_up(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }


        in_room = ch->in_room;
        move_char(ch, DIR_UP);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_UP);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
/*
    if (!IS_NPC(ch) && ch->in_room != in_room) add_tracks( ch, DIR_DOWN );
*/
        drow_hate(ch);
        return;
}

void do_down(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *in_room;

        if (IS_AFFECTED(ch, AFF_WEBBED))
        {
                send_to_char
                        ("You are unable to move with all this sticky webbing on.\n\r",
                         ch);
                return;
        }
        if (IS_AFFECTED2(ch, AFF2_THORNS))
        {
                send_to_char
                        ("Not while being rooted to the ground by brambles and thorns.\n\r",
                         ch);
                return;
        }


        in_room = ch->in_room;
        move_char(ch, DIR_DOWN);
        if (!IS_NPC(ch) && ch->in_room != in_room)
        {
                ROOM_INDEX_DATA *old_room;

                old_room = ch->in_room;
                char_from_room(ch);
                char_to_room(ch, in_room);
                add_tracks(ch, DIR_DOWN);
                char_from_room(ch);
                char_to_room(ch, old_room);
        }
/*
    if (!IS_NPC(ch) && ch->in_room != in_room) add_tracks( ch, DIR_UP );
*/
        drow_hate(ch);
        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;
                }
                act("I see no $T here.", ch, NULL, arg, TO_CHAR);
                return -1;
        }

        if ((pexit = ch->in_room->exit[door]) == NULL)
        {
                act("I see no door $T here.", ch, NULL, arg, TO_CHAR);
                return -1;
        }

        if (!IS_SET(pexit->exit_info, EX_ISDOOR))
        {
                send_to_char("You can't do that.\n\r", ch);
                return -1;
        }

        return door;
}

/* random room generation procedure */
ROOM_INDEX_DATA *get_random_room(CHAR_DATA * ch)
{
        ROOM_INDEX_DATA *room;

        for (;;)
        {
                room = get_room_index(number_range(0, 100000));
                if (room != NULL)
                        if (!IS_SET(room->room_flags, ROOM_PRIVATE)
                            && !IS_SET(room->room_flags, ROOM_SOLITARY)
                            && !IS_SET(room->room_flags, ROOM_SAFE))
                                break;
        }

        return room;
}

ROOM_INDEX_DATA *get_rand_room()
{
        ROOM_INDEX_DATA *room;

        for (;;)
        {
                room = get_room_index(number_range(1000, 85000));
                if (room != NULL)
                        if (!IS_SET(room->room_flags, ROOM_PRIVATE)
                            && !IS_SET(room->room_flags, ROOM_ASTRAL)
                            && !IS_SET(room->room_flags, ROOM_SOLITARY)
                            && !IS_SET(room->room_flags, ROOM_SAFE))
                                break;
        }

        return room;
}

ROOM_INDEX_DATA *get_treemeld_room()
{
        ROOM_INDEX_DATA *room;

        for (;;)
        {
                room = get_room_index(number_range(0, 100000));
                if (room != NULL && room->sector_type == SECT_FOREST)
                        break;
        }

        return room;
}

ROOM_INDEX_DATA *get_rand_room_by_sect(int sect)
{
        ROOM_INDEX_DATA *room;

        for (;;)
        {
                room = get_room_index(number_range(0, 100000));
                if (room != NULL && room->sector_type == sect)
                        break;
        }

        return room;
}

/* Designed for the portal spell, but can also have other uses...KaVir
 * V0 = Where the portal will take you.
 * V1 = Number of uses (0 is infinate).
 * V2 = if 2, cannot be entered.
 * V3 = The room the portal is currently in.
 */
void do_enter(CHAR_DATA * ch, char *argument)
{
        ROOM_INDEX_DATA *pRoomIndex;
        ROOM_INDEX_DATA *location;
        char      arg[MAX_INPUT_LENGTH];
        char      poly[MAX_INPUT_LENGTH];
        OBJ_DATA *obj;
        OBJ_DATA *portal;
        OBJ_DATA *portal_next;
        CHAR_DATA *mount;
        CHAR_DATA *gch;
        CHAR_DATA *gch_next;
        bool      found;

        argument = one_argument(argument, arg);

        if (ch->in_room != NULL)
        {
                if (IS_SET(ch->in_room->room_flags, ROOM_ASTRAL))
                {
                        send_to_char
                                ("The portal cannot function in an astral room.\n\r",
                                 ch);
                        return;
                }
        }

        if (arg[0] == '\0')
        {
                send_to_char("Enter what?\n\r", ch);
                return;
        }
        obj = get_obj_list(ch, arg, ch->in_room->contents);
        if (obj == NULL)
        {
                act("I see no $T here.", ch, NULL, arg, TO_CHAR);
                return;
        }
        if (obj->item_type != ITEM_PORTAL && obj->item_type != ITEM_WGATE)
        {
                act("You cannot enter that.", ch, NULL, arg, TO_CHAR);
                return;
        }
        if (IS_AFFECTED(ch, AFF_SHADOWPLANE)
            && !IS_SET(obj->extra_flags, ITEM_SHADOWPLANE))
        {
                send_to_char("You are too insubstantual.\n\r", ch);
                return;
        }
        else if (!IS_AFFECTED(ch, AFF_SHADOWPLANE) &&
                 IS_SET(obj->extra_flags, ITEM_SHADOWPLANE))
        {
                send_to_char("It is too insubstantual.\n\r", ch);
                return;
        }

        if (obj->item_type == ITEM_PORTAL)
        {
                if (obj->value[2] == 2 || obj->value[2] == 3)
                {
                        act("It seems to be closed.", ch, NULL, arg, TO_CHAR);
                        return;
                }

                pRoomIndex = get_room_index(obj->value[0]);
                location = ch->in_room;
                if (pRoomIndex == NULL)
                {
                        act("You are unable to enter.", ch, NULL, arg,
                            TO_CHAR);
                        return;
                }
                act("You step into $p.", ch, obj, NULL, TO_CHAR);
                if (!IS_NPC(ch) && IS_AFFECTED(ch, AFF_POLYMORPH))
                        xprintf(poly, "%s steps into $p.", ch->morph);
                else
                        xprintf(poly, "$n steps into $p.");
                act(poly, ch, obj, NULL, TO_ROOM);
                char_from_room(ch);
                char_to_room(ch, pRoomIndex);
                if (!IS_NPC(ch) && IS_AFFECTED(ch, AFF_POLYMORPH))
                        xprintf(poly, "%s steps out of $p.", ch->morph);
                else
                        xprintf(poly, "$n steps out of $p.");
                act(poly, ch, obj, NULL, TO_ROOM);
                char_from_room(ch);
                char_to_room(ch, location);
                if (obj->value[1] != 0)
                {
                        obj->value[1] = obj->value[1] - 1;
                        if (obj->value[1] < 1)
                        {
                                act("$p vanishes.", ch, obj, NULL, TO_CHAR);
                                act("$p vanishes.", ch, obj, NULL, TO_ROOM);
                                extract_obj(obj);
                        }
                }
                char_from_room(ch);
                char_to_room(ch, pRoomIndex);
                found = FALSE;
                for (portal = ch->in_room->contents; portal != NULL;
                     portal = portal_next)
                {
                        portal_next = portal->next_content;
                        if ((obj->value[0] == portal->value[3])
                            && (obj->value[3] == portal->value[0]))
                        {
                                found = TRUE;

                                if (IS_AFFECTED(ch, AFF_SHADOWPLANE) &&
                                    !IS_SET(portal->extra_flags,
                                            ITEM_SHADOWPLANE))
                                {
                                        REMOVE_BIT(ch->affected_by,
                                                   AFF_SHADOWPLANE);
                                        break;
                                }
                                else if (!IS_AFFECTED(ch, AFF_SHADOWPLANE) &&
                                         IS_SET(portal->extra_flags,
                                                ITEM_SHADOWPLANE))
                                {
                                        SET_BIT(ch->affected_by,
                                                AFF_SHADOWPLANE);
                                        break;
                                }
                                if (portal->value[1] != 0)
                                {
                                        portal->value[1] =
                                                portal->value[1] - 1;
                                        if (portal->value[1] < 1)
                                        {
                                                act("$p vanishes.", ch,
                                                    portal, NULL, TO_CHAR);
                                                act("$p vanishes.", ch,
                                                    portal, NULL, TO_ROOM);
                                                extract_obj(portal);
                                        }
                                }
                        }
                }
                do_look(ch, "auto");
                if ((mount = ch->mount) != NULL)
                {
                        char_from_room(mount);
                        char_to_room(mount, ch->in_room);
                }

                for (gch = location->people; gch; gch = gch_next)
                {
                        gch_next = gch->next_in_room;

                        if (gch->master == ch && gch->position == POS_STANDING
                            && gch->in_room != ch->in_room)
                        {
                                act("You follow $N.", gch, NULL, ch, TO_CHAR);
                                do_enter(gch, arg);
                        }
                }
                return;
        }
        else
        {
                pRoomIndex = get_room_index(obj->value[0]);
                location = ch->in_room;

                if (pRoomIndex == NULL)
                {
                        act("You are unable to enter.", ch, NULL, arg,
                            TO_CHAR);
                        return;
                }
                act("You step into $p.", ch, obj, NULL, TO_CHAR);
                if (!IS_NPC(ch) && IS_AFFECTED(ch, AFF_POLYMORPH))
                        xprintf(poly, "%s steps into $p.", ch->morph);
                else
                        xprintf(poly, "$n steps into $p.");
                act(poly, ch, obj, NULL, TO_ROOM);
                char_from_room(ch);
                char_to_room(ch, pRoomIndex);
                if (!IS_NPC(ch) && IS_AFFECTED(ch, AFF_POLYMORPH))
                        xprintf(poly, "%s steps out of $p.", ch->morph);
                else
                        xprintf(poly, "$n steps out of $p.");
                act(poly, ch, obj, NULL, TO_ROOM);

                for (portal = ch->in_room->contents; portal != NULL;
                     portal = portal_next)
                {
                        portal_next = portal->next_content;
                        if ((obj->value[0] == portal->value[3])
                            && (obj->value[3] == portal->value[0]))
                        {
                                found = TRUE;

                                if (IS_AFFECTED(ch, AFF_SHADOWPLANE) &&
                                    !IS_SET(portal->extra_flags,
                                            ITEM_SHADOWPLANE))
                                {
                                        REMOVE_BIT(ch->affected_by,
                                                   AFF_SHADOWPLANE);
                                        break;
                                }
                                else if (!IS_AFFECTED(ch, AFF_SHADOWPLANE) &&
                                         IS_SET(portal->extra_flags,
                                                ITEM_SHADOWPLANE))
                                {
                                        SET_BIT(ch->affected_by,
                                                AFF_SHADOWPLANE);
                                        break;
                                }
                        }
                }
                do_look(ch, "auto");
                if ((mount = ch->mount) == NULL)
                        return;
                char_from_room(mount);
                char_to_room(mount, ch->in_room);
                //mob progs
                /*
                 * If someone is following the char, these triggers get activated
                 * for the followers before the char, but it's safer this way...
                 */
                if (IS_NPC(ch) && HAS_TRIGGER_MOB(ch, TRIG_ENTRY))
                        p_percent_trigger(ch, NULL, NULL, NULL, NULL, NULL,
                                          TRIG_ENTRY);
                if (!IS_NPC(ch))
                {
                        p_greet_trigger(ch, PRG_MPROG);
                        p_greet_trigger(ch, PRG_OPROG);
                        p_greet_trigger(ch, PRG_RPROG);
                }
                return;
        }
}


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 ((obj = get_obj_here(ch, NULL, arg)) != NULL)
        {
                /*
                 * 'open object' 
                 */
                if (obj->item_type != ITEM_CONTAINER
                    && obj->item_type != ITEM_BOOK)
                {
                        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)
                    && obj->item_type != ITEM_BOOK)
                {
                        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);
                send_to_char("Ok.\n\r", ch);
                act("$n opens $p.", ch, obj, NULL, TO_ROOM);
                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->to_room) != NULL
                    && (pexit_rev = to_room->exit[rev_dir[door]]) != NULL
                    && pexit_rev->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;
}

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 ((obj = get_obj_here(ch, NULL, arg)) != NULL)
        {
                /*
                 * 'close object' 
                 */
                if (obj->item_type != ITEM_CONTAINER
                    && obj->item_type != ITEM_BOOK)
                {
                        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)
                    && obj->item_type != ITEM_BOOK)
                {
                        send_to_char("You can't do that.\n\r", ch);
                        return;
                }

                SET_BIT(obj->value[1], CONT_CLOSED);
                if (obj->item_type == ITEM_BOOK)
                        obj->value[2] = 0;
                send_to_char("Ok.\n\r", ch);
                act("$n closes $p.", ch, obj, NULL, TO_ROOM);
                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->to_room) != NULL
                    && (pexit_rev = to_room->exit[rev_dir[door]]) != 0
                    && pexit_rev->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;
}



void do_turn(CHAR_DATA * ch, char *argument)
{
        char      arg1[MAX_INPUT_LENGTH];
        char      arg2[MAX_INPUT_LENGTH];
        OBJ_DATA *obj;
        int       value = 0;

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

        if (arg1[0] == '\0' || arg2[0] == '\0')
        {
                send_to_char("Syntax: Turn <book> <forward/back>.\n\r", ch);
                return;
        }

        if (is_number(arg2))
                value = atoi(arg2);

        if ((obj = get_obj_here(ch, NULL, arg1)) == NULL)
        {
                send_to_char("You don't have that book.\n\r", ch);
                return;
        }

        if (obj->item_type != ITEM_BOOK)
        {
                send_to_char("That's not a book.\n\r", ch);
                return;
        }
        if (IS_SET(obj->value[1], CONT_CLOSED))
        {
                send_to_char("First you should open it.\n\r", ch);
                return;
        }

        if (!str_cmp(arg2, "f") || !str_cmp(arg2, "forward"))
        {
                if (obj->value[2] >= obj->value[3])
                {
                        send_to_char
                                ("But you are already at the end of the book.\n\r",
                                 ch);
                        return;
                }
                obj->value[2] += 1;
                act("You flip forward a page in $p.", ch, obj, NULL, TO_CHAR);
                act("$n flips forward a page in $p.", ch, obj, NULL, TO_ROOM);
        }
        else if (!str_cmp(arg2, "b") || !str_cmp(arg2, "backward"))
        {
                if (obj->value[2] <= 0)
                {
                        send_to_char
                                ("But you are already at the beginning of the book.\n\r",
                                 ch);
                        return;
                }
                obj->value[2] -= 1;
                act("You flip backward a page in $p.", ch, obj, NULL,
                    TO_CHAR);
                act("$n flips backward a page in $p.", ch, obj, NULL,
                    TO_ROOM);
        }
        else if (is_number(arg2) && value >= 0 && value <= obj->value[3])
        {
                if (value == obj->value[2])
                {
                        act("$p is already open at that page.", ch, obj, NULL,
                            TO_CHAR);
                        return;
                }
                else if (value < obj->value[2])
                {
                        act("You flip backwards through $p.", ch, obj, NULL,
                            TO_CHAR);
                        act("$n flips backwards through $p.", ch, obj, NULL,
                            TO_ROOM);
                }
                else
                {
                        act("You flip forwards through $p.", ch, obj, NULL,
                            TO_CHAR);
                        act("$n flips forwards through $p.", ch, obj, NULL,
                            TO_ROOM);
                }
                obj->value[2] = value;
        }
        else
                send_to_char
                        ("Do you wish to turn forward or backward a page?\n\r",
                         ch);
        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, NULL, arg)) != NULL)
        {
                /*
                 * '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);
                send_to_char("*Click*\n\r", ch);
                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->to_room) != NULL
                    && (pexit_rev = to_room->exit[rev_dir[door]]) != 0
                    && pexit_rev->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, NULL, arg)) != NULL)
        {
                /*
                 * '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);
                send_to_char("*Click*\n\r", ch);
                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->to_room) != NULL
                    && (pexit_rev = to_room->exit[rev_dir[door]]) != NULL
                    && pexit_rev->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() > ch->pcdata->learned[gsn_pick_lock])
        {
                send_to_char("You failed.\n\r", ch);
                return;
        }

        if ((obj = get_obj_here(ch, NULL, arg)) != NULL)
        {
                /*
                 * '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);
                send_to_char("*Click*\n\r", ch);
                act("$n picks $p.", ch, obj, NULL, TO_ROOM);
                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))
                {
                        send_to_char("It's not closed.\n\r", ch);
                        return;
                }
                if (pexit->key < 0)
                {
                        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))
                {
                        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);

                /*
                 * pick the other side 
                 */
                if ((to_room = pexit->to_room) != NULL
                    && (pexit_rev = to_room->exit[rev_dir[door]]) != NULL
                    && pexit_rev->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;

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

                send_to_char("You wake and stand up.\n\r", ch);
                act("$n wakes and stands up.", ch, NULL, NULL, TO_ROOM);
                ch->position = POS_STANDING;

                break;

        case POS_RESTING:
        case POS_SITTING:
                send_to_char("You stand up.\n\r", ch);
                act("$n stands up.", ch, NULL, NULL, TO_ROOM);
                ch->position = POS_STANDING;
                break;

        case POS_MEDITATING:
                send_to_char("You uncross your legs and stand up.\n\r", ch);
                act("$n uncrosses $s legs and stands up.", ch, NULL, 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;
        }
        //if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
        //p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );
        return;
}

/*
void do_rest( CHAR_DATA *ch, char *argument )
{
    switch ( ch->position )
    {
    case POS_SLEEPING:
	send_to_char( "You are already sleeping.\n\r", ch );
	break;

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

    case POS_MEDITATING:
    case POS_SITTING:
    case POS_STANDING:
	send_to_char( "You rest.\n\r", ch );
	act( "$n rests.", ch, NULL, NULL, TO_ROOM );
	ch->position = POS_RESTING;
	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 (IS_AFFECTED(ch, AFF_SLEEP)) /* magical sleep. can't rest. */
        {
                send_to_char("You are asleep and cannot wake up!\n\r", ch);
                return;
        }
        if (ch->position == POS_FIGHTING)
        {
                send_to_char("Maybe you should finish this fight first!\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("There's no more room on $p.", ch, obj, NULL,
                            TO_CHAR);
                        return;
                }
                ch->on = obj;
                if (HAS_TRIGGER_OBJ(obj, TRIG_SIT))
                        p_percent_trigger(NULL, obj, NULL, ch, NULL, NULL,
                                          TRIG_SIT);
        }

        switch (ch->position)
        {
        case POS_SLEEPING:
                send_to_char("You wake up and roll over to rest.\n\r", ch);
                act("$n wakes up, then rolls over to rest.", ch, NULL, NULL,
                    TO_ROOM);
                ch->position = POS_RESTING;
                do_look(ch, "auto");
                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 sit down and 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 )
{
    switch ( ch->position )
    {
    case POS_SLEEPING:
	send_to_char( "You are already sleeping.\n\r", ch );
	break;

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

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

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

    case POS_STANDING:
	send_to_char( "You sit down.\n\r", ch );
	act( "$n sits down.", ch, NULL, NULL, TO_ROOM );
	ch->position = POS_SITTING;
	break;

    case POS_FIGHTING:
	send_to_char( "You are already fighting!\n\r", ch );
	break;
    }
    //if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	//p_percent_trigger( NULL, OBJ, NULL, ch, NULL, NULL, TRIG_SIT );
    return;
}
*/

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

        if (IS_AFFECTED(ch, AFF_SLEEP)) /* magical sleep. can't rest. */
        {
                send_to_char("You are asleep and cannot wake up!\n\r", ch);
                return;
        }
        if (ch->position == POS_FIGHTING)
        {
                send_to_char("Maybe you should finish this fight first!\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("There's no more room on $p.", ch, obj, NULL,
                            TO_CHAR);
                        return;
                }
                ch->on = obj;
                if (HAS_TRIGGER_OBJ(obj, TRIG_SIT))
                {
                        p_percent_trigger(NULL, obj, NULL, ch, NULL, NULL,
                                          TRIG_SIT);
                }
        }

        switch (ch->position)
        {
        case POS_SLEEPING:
                send_to_char("You wake and sit up.\n\r", ch);
                act("$n wakes and sits up.", ch, NULL, NULL, TO_ROOM);
                ch->position = POS_SITTING;
                do_look(ch, "auto");
                break;
        case POS_SITTING:
                send_to_char("You are already sitting.\n\r", ch);
                break;
        case POS_STANDING:
                if (obj == NULL)
                {
                        send_to_char("You sit down.\n\r", ch);
                        act("$n sits down.", 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))
                {
                        act("You sit on $p.", ch, obj, NULL, TO_CHAR);
                        act("$n sits on $p.", ch, obj, NULL, TO_ROOM);
                }
                else
                {
                        act("You sit in $p.", ch, obj, NULL, TO_CHAR);
                        act("$n sits in $p.", ch, obj, NULL, TO_ROOM);
                }
                ch->position = POS_SITTING;
                break;
        case POS_RESTING:
                if (obj == NULL)
                {
                        send_to_char("You sit up.\n\r", ch);
                        act("$n sits up.", ch, NULL, NULL, TO_ROOM);
                }
                else if (IS_SET(obj->value[2], REST_AT))
                {
                        act("You sit up at $p.", ch, obj, NULL, TO_CHAR);
                        act("$n sits up 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_sleep(CHAR_DATA * ch, char *argument)
{
        OBJ_DATA *obj = NULL;

        switch (ch->position)
        {
        case POS_MORTAL:
                send_to_char
                        ("You give up on life, and go to sleep forever.\n\r",
                         ch);
                break;
        case POS_INCAP:
        case POS_STUNNED:
        case POS_DEAD:
                send_to_char("You are hurt far too badly for that.\n\r", ch);
                break;
        case POS_SLEEPING:
                send_to_char("You are already sleeping.\n\r", ch);
                break;
        case POS_RESTING:
        case POS_SITTING:
        case POS_STANDING:
                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 (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("There is no room on $p for you.", ch,
                                    obj, NULL, TO_CHAR);
                                return;
                        }

                        ch->on = obj;
                        if (HAS_TRIGGER_OBJ(obj, TRIG_SIT))
                                p_percent_trigger(NULL, obj, NULL, ch, NULL,
                                                  NULL, TRIG_SIT);
                        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("Yeah right! You'd get slaughtered!\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, NULL, arg)) == NULL)
        {
                send_to_char("They aren't here.\n\r", ch);
                return;
        }

        // Chars who are AWAKE by the macro's definition may still be unwakeable, and
        // will now get a better error msg. Someone who is mortally wounded isn't "already awake".

        if (victim->position < POS_SLEEPING)
        {
                act("$N can't be woken up.", ch, NULL, victim, TO_CHAR);
                return;
        }

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

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

        victim->position = POS_STANDING;
        victim->on = NULL;
        act("You wake $M.", ch, NULL, victim, TO_CHAR);
        act("$n wakes you.", ch, NULL, victim, TO_VICT);
        do_look(ch, "auto");
        return;
}


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

        if (IS_NPC(ch)
            || (!IS_CLASS(ch, CLASS_MAGE) && !IS_CLASS(ch, CLASS_MONK)
                && !IS_CLASS(ch, CLASS_FAE) && !IS_CLASS(ch, CLASS_NINJA)
                && !IS_CLASS(ch, CLASS_DROW) && !IS_CLASS(ch, CLASS_LICH)
		&& !IS_CLASS(ch, CLASS_ZOMBIE) && !IS_CLASS(ch, CLASS_SHINOBI)))
        {
                send_to_char
                        ("You are unable to attain the correct state of mind.\n\r",
                         ch);
                return;
        }


        obj = ch->on;
        if (obj != NULL)
        {
                send_to_char("You can't mediate on furniture.\n\r", ch);
                return;
        }



        if (IS_CLASS(ch, CLASS_FAE) && ch->power[DISC_FAE_ARCANE] < 2)
        {
                send_to_char("You don't know how to do that yet.\n\r", ch);
                return;
        }

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

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

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

        case POS_SITTING:
                send_to_char("You cross your legs and start meditating.\n\r",
                             ch);
                act("$n crosses $s legs and starts meditating.", ch, NULL,
                    NULL, TO_ROOM);
                ch->position = POS_MEDITATING;
                break;

        case POS_STANDING:
                send_to_char
                        ("You sit down, cross your legs and start meditating.\n\r",
                         ch);
                act("$n sits down, crosses $s legs and starts meditating.",
                    ch, NULL, NULL, TO_ROOM);
                ch->position = POS_MEDITATING;
                break;

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

        return;
}

void do_healing(CHAR_DATA * ch, char *argument)
{
        if (IS_NPC(ch)
            || (!IS_CLASS(ch, CLASS_VAMPIRE)
                && ch->power[DISC_VAMP_PROT] < 8))
        {
                send_to_char
                        ("You are unable to assume a state of healing.\n\r",
                         ch);
                return;
        }

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

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

        case POS_MEDITATING:
                send_to_char("You are already in a healing position.\n\r",
                             ch);
                break;

        case POS_SITTING:
                send_to_char
                        ("You close your eyes and become completely relaxed.\n\r",
                         ch);
                act("$n closes $m eyes and looks completely relaxed.", ch,
                    NULL, NULL, TO_ROOM);
                ch->position = POS_MEDITATING;
                break;

        case POS_STANDING:
                send_to_char
                        ("You close your eyes and become completely relaxed.\n\r",
                         ch);
                act("$n closes $m eyes and looks completely relaxed.", ch,
                    NULL, NULL, TO_ROOM);
                ch->position = POS_MEDITATING;
                break;

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

        return;
}

/*
void do_sleep( CHAR_DATA *ch, char *argument )
{
    switch ( ch->position )
    {
    case POS_SLEEPING:
	send_to_char( "You are already sleeping.\n\r", ch );
	break;

    case POS_SITTING:
    case POS_MEDITATING:
    case POS_RESTING:
    case POS_STANDING: 
	send_to_char( "You sleep.\n\r", ch );
	act( "$n sleeps.", ch, NULL, NULL, TO_ROOM );
	ch->position = POS_SLEEPING;
	break;

    case POS_FIGHTING:
	send_to_char( "You are already fighting!\n\r", ch );
	break;
    }
    //if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	//p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );
    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, NULL, 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))
	{ act( "You can't wake $M!",   ch, NULL, victim, TO_CHAR );  return; }

    if (victim->position < POS_SLEEPING)
	{ act( "$E doesn't respond!",   ch, NULL, victim, TO_CHAR );  return; }

    act( "You wake $M.", ch, NULL, victim, TO_CHAR );
    act( "$n wakes you.", ch, NULL, victim, TO_VICT );
    victim->position = POS_STANDING;
    return;
}
*/

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

        send_to_char("You attempt to move silently.\n\r", ch);
        affect_strip(ch, gsn_sneak);

        if (IS_NPC(ch) || number_percent() < ch->pcdata->learned[gsn_sneak])
        {
                af.type = gsn_sneak;
                af.duration = ch->level;
                af.location = APPLY_NONE;
                af.modifier = 0;
                af.bitvector = AFF_SNEAK;
                affect_to_char(ch, &af);
        }

        return;
}

void do_hide(CHAR_DATA * ch, char *argument)
{

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

        if (IS_AFFECTED(ch, AFF_HIDE))
                REMOVE_BIT(ch->affected_by, AFF_HIDE);

        if (IS_NPC(ch) || number_percent() < ch->pcdata->learned[gsn_hide])
                SET_BIT(ch->affected_by, AFF_HIDE);

        return;
}

/*
 * Contributed by Alander.
 */
void do_visible(CHAR_DATA * ch, char *argument)
{
        affect_strip(ch, gsn_invis);
        affect_strip(ch, gsn_mass_invis);
        affect_strip(ch, gsn_sneak);
        REMOVE_BIT(ch->affected_by, AFF_HIDE);
        REMOVE_BIT(ch->affected_by, AFF_INVISIBLE);
        REMOVE_BIT(ch->affected_by, AFF_SNEAK);
        send_to_char("Ok.\n\r", ch);
        return;
}



void do_unpolymorph(CHAR_DATA * ch, char *argument)
{
        if (!is_affected(ch, gsn_polymorph))
        {
                send_to_char("But you are not polymorphed!\n\r", ch);
                return;
        }
        act("$n's body begins to distort.", ch, NULL, NULL, TO_ROOM);
        affect_strip(ch, gsn_polymorph);
        act("$n resumes $s normal form.", ch, NULL, NULL, TO_ROOM);
        send_to_char("You resume your normal form.\n\r", ch);
        return;
}



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

        if (IS_NPC(ch))
                return;

        act("$n's body flickers with green energy.", ch, NULL, NULL, TO_ROOM);
        act("Your body flickers with green energy.", ch, NULL, NULL, TO_CHAR);

        if ((location = get_room_index(ch->home)) == NULL)
        {
                send_to_char("You are completely lost.\n\r", ch);
                return;
        }

        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("You are unable to recall.\n\r", ch);
                return;
        }

        if (IS_SET(ch->in_room->room_flags, ROOM_NO_CHANT))
        {
                send_to_char
                        ("You are unable to chant, its a no chant room.\n\r",
                         ch);
                return;
        }

        if (IS_SET(ch->flag2, AFF_TOTALBLIND))
        {
                stc("You are unable to recall.\n\r", ch);
                return;
        }

        if ((victim = ch->fighting) != NULL)
        {
                if (number_bits(1) == 0)
                {
                        WAIT_STATE(ch, 4);
                        xprintf(buf, "You failed!\n\r");
                        send_to_char(buf, ch);
                        return;
                }
                xprintf(buf, "You recall from combat!\n\r");
                send_to_char(buf, ch);
                stop_fighting(ch, TRUE);
        }

        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");
        if ((mount = ch->mount) == NULL)
                return;
        char_from_room(mount);
        char_to_room(mount, ch->in_room);
        return;
}

void do_crecall(CHAR_DATA * ch, char *argument)
{
        char      buf[MAX_STRING_LENGTH];
        CHAR_DATA *victim;
        CHAR_DATA *mount;
        ROOM_INDEX_DATA *location;

        if (IS_NPC(ch))
                return;

        if (ch->class == 0)
        {
                stc("Think about it...\n\r", ch);
                return;
        }

        act("$n's body flickers with red energy.", ch, NULL, NULL, TO_ROOM);
        act("Your body flickers with red energy.", ch, NULL, NULL, TO_CHAR);

        if (IS_CLASS(ch, CLASS_ANGEL))
                location = get_room_index(ROOM_VNUM_ANGEL_HOME);
        else if (IS_CLASS(ch, CLASS_LICH))
                location = get_room_index(ROOM_VNUM_LICH_HOME);
        else if (IS_CLASS(ch, CLASS_TANARRI))
                location = get_room_index(ROOM_VNUM_TAN_HOME);
        else if (IS_CLASS(ch, CLASS_CYBORG))
                location = get_room_index(ROOM_VNUM_DROID_HOME);
        else if (IS_CLASS(ch, CLASS_SAMURAI))
                location = get_room_index(ROOM_VNUM_SAM_HOME);
        else if (IS_CLASS(ch, CLASS_UNDEAD_KNIGHT))
                location = get_room_index(ROOM_VNUM_UK_HOME);
        else if (IS_CLASS(ch, CLASS_VAMPIRE))
                location = get_room_index(ROOM_VNUM_VAMP_HOME);
        else if (IS_CLASS(ch, CLASS_NINJA))
                location = get_room_index(ROOM_VNUM_NINJA_HOME);
        else if (IS_CLASS(ch, CLASS_MAGE))
                location = get_room_index(ROOM_VNUM_MAGE_HOME);
        else if (IS_CLASS(ch, CLASS_WEREWOLF))
                location = get_room_index(ROOM_VNUM_WW_HOME);
        else if (IS_CLASS(ch, CLASS_MONK))
                location = get_room_index(ROOM_VNUM_MONK_HOME);
        else if (IS_CLASS(ch, CLASS_THIEF))
                location = get_room_index(ROOM_VNUM_THIEF_HOME);
        else if (IS_CLASS(ch, CLASS_DRACONIAN))
                location = get_room_index(ROOM_VNUM_DRAC_HOME);
        else if (IS_CLASS(ch, CLASS_SKYBLADE))
                location = get_room_index(ROOM_VNUM_SKY_HOME);
        else if (IS_CLASS(ch, CLASS_GHOUL))
                location = get_room_index(ROOM_VNUM_GHOUL_HOME);
        else if (IS_CLASS(ch, CLASS_DEMON))
                location = get_room_index(ROOM_VNUM_DEMON_HOME);
        else if (IS_CLASS(ch, CLASS_JEDI))
                location = get_room_index(ROOM_VNUM_JEDI_HOME);
        else if (IS_CLASS(ch, CLASS_SHADOW))
                location = get_room_index(ROOM_VNUM_SHADOW_HOME);
        else if (IS_CLASS(ch, CLASS_SHAPESHIFTER))
                location = get_room_index(ROOM_VNUM_SHIFTER_HOME);
        else if (IS_CLASS(ch, CLASS_DROW))
                location = get_room_index(ROOM_VNUM_DROW_HOME);
        else if (IS_CLASS(ch, CLASS_PRIEST))
                location = get_room_index(ROOM_VNUM_PRIEST_HOME);
        else if (IS_CLASS(ch, CLASS_FAE))
                location = get_room_index(ROOM_VNUM_FAE_HOME);
        else if (IS_CLASS(ch, CLASS_DRONE))
                location = get_room_index(ROOM_VNUM_DRONE_HOME);
        else if (IS_CLASS(ch, CLASS_HOBBIT))
                location = get_room_index(ROOM_VNUM_HOBBIT_HOME);
        else if (IS_CLASS(ch, CLASS_GIANT))
                location = get_room_index(ROOM_VNUM_GIANT_HOME);
	else if (IS_CLASS(ch, CLASS_ELEMENTAL))
		location = get_room_index(ROOM_VNUM_ELEMENTAL_HOME);
        else if (IS_CLASS(ch, CLASS_PALADIN))
                location = get_room_index(ROOM_VNUM_PALADIN_HOME);
        else if (IS_CLASS(ch, CLASS_BLADE_MASTER))
                location = get_room_index(ROOM_VNUM_BLADE_HOME);

        else
        {
                send_to_char("Your crecall is broken, tell Zarius\n\r", ch);
                return;
        }


        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("You are unable to crecall.\n\r", ch);
                return;
        }

        if ((victim = ch->fighting) != NULL)
        {
                if (number_bits(1) == 0)
                {
                        WAIT_STATE(ch, 4);
                        xprintf(buf, "You failed!\n\r");
                        send_to_char(buf, ch);
                        return;
                }
                xprintf(buf, "You crecall from combat!\n\r");
                send_to_char(buf, ch);
                stop_fighting(ch, TRUE);
        }

        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");
        if ((mount = ch->mount) == NULL)
                return;
        char_from_room(mount);
        char_to_room(mount, ch->in_room);
        return;
}

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

        argument = one_argument(argument, arg);

        if (IS_NPC(ch))
                return;

        if (arg[0] == '\0' || str_cmp(arg, "here"))
        {
                send_to_char
                        ("If you wish this to be your room, you must type 'home here'.\n\r",
                         ch);
                return;
        }

        if (ch->in_room->vnum == ch->home)
        {
                send_to_char("But this is already your home!\n\r", ch);
                return;
        }

        if (IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL) ||
            IS_SET(ch->in_room->room_flags, ROOM_ASTRAL)
            || IS_SET(ch->in_room->area->areabits, AREA_BIT_NOHOME)
            || IS_SET(ch->in_room->room_flags, ROOM_SAFE))
        {
                send_to_char
                        ("You are unable to make this room your home.\n\r",
                         ch);
                return;
        }
        if (ch->in_room->vnum == 3001)
        {
                send_to_char
                        ("You are unable to make this room your home.\n\r",
                         ch);
                return;
        }
        ch->home = ch->in_room->vnum;
      

Showing the first 100 KB of 261.7 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571