pdirt/data/
pdirt/data/HELP/
pdirt/data/HELP/0/
pdirt/data/HELP/F/
pdirt/data/HELP/G/
pdirt/data/HELP/H/
pdirt/data/HELP/J/
pdirt/data/HELP/K/
pdirt/data/HELP/O/
pdirt/data/HELP/Q/
pdirt/data/HELP/R/
pdirt/data/HELP/U/
pdirt/data/HELP/V/
pdirt/data/HELP/Y/
pdirt/data/HELP/Z/
pdirt/data/MESSAGES/
pdirt/data/POWERINFO/
pdirt/data/WIZ_ZONES/
pdirt/drv/
pdirt/drv/bin/
pdirt/drv/compiler/converter/
pdirt/drv/compiler/libs/
pdirt/drv/compiler/scripts/
pdirt/drv/include/AberChat/
pdirt/drv/include/InterMud/
pdirt/drv/include/machine/
pdirt/drv/src/InterMud/
pdirt/drv/src/Players/
pdirt/drv/utils/UAFPort/
pdirt/drv/utils/dnsresolv/
pdirt/drv/utils/gdbm/
#define OBJSYS_C

#include "kernel.h"
#include <stdlib.h>
#include <string.h>
#ifdef RS6000
#include <strings.h>
#endif
#include "oflagnames.h"
#include "objsys.h"
#include "sendsys.h"
#include "lflags.h"
#include "pflags.h"
#include "sflags.h"
#include "mflags.h"
#include "oflags.h"
#include "cflags.h"
#include "mobile.h"
#include "quests.h"
#include "mudmacros.h"
#include "bprintf.h"
#include "rooms.h"
#include "log.h"
#include "fight.h"
#include "parse.h"
#include "commands.h"
#include "clone.h"
#include "quest.h"
#include "special.h"
#include "verbs.h"
#include "tables.h"
#include "zones.h"

#define MAX_ARMOR	50	/* Take a WIIIILD guess. :P */

int	       value_class(CLASS_DATA *cl, int plx, Boolean silent);
static Boolean classmatch(int ob,CLASS_DATA *cl);
static void    dropall(CLASS_DATA *cl);
static void    getall(CLASS_DATA *cl);
static void    getallfr(CLASS_DATA *cl);
static void    trywear(int a, Boolean print_stuff);

static CLASS_DATA class_data[] = {
  { "clothing",   1 << OFL_WEARABLE,  -2},
  { "weapons",    1 << OFL_WEAPON,    -1},
  { "containers", 1 << OFL_CONTAINER, -1},
  { "food",       1 << OFL_FOOD,      -1},
  { "keys",       1 << OFL_KEY,       -1},
  { "all",        0,                  -1},
  { NULL,         0,                  -1}};

#define is_wearable(O) (otstbit(O, OFL_WEARABLE) || \
			otstbit(O, OFL_WEARONHANDS) || otstbit(O, OFL_WEARONBODY) || \
			otstbit(O, OFL_WEARONHEAD) || otstbit(O, OFL_WEARONBACK) || \
			otstbit(O, OFL_WEARONLEGS) || otstbit(O, OFL_WEARONFACE) || \
			otstbit(O, OFL_WEARONFEET) || otstbit(O, OFL_WEARONNECK) || \
			otstbit(O, OFL_WEARONARMS))

/* Check if player has an object that enhances magic */
int has_magic_object(int plx)
{  int count = 0;
  int i,o,i2,o2;

  for (i = 0; i < pnumobs(plx); i++) 
  {
    o = pobj_nr(i, plx);

    if (iscarrby(o, plx) && otstbit(o,OFL_ENHMAGIC))
       count++;

    else if (otstbit(o,OFL_CONTAINER))		/* COunt objects in container */
    {   for (i2 = 0; i < onumobs(o); i++)
        {   o2 = oobj_nr(i2,o);
       
            if (otstbit(o2,OFL_ENHMAGIC) && oloc(o2) == o)
               count++;
         }
     }
  }
  return count;
}

Boolean has_anti_spell_obj(int plx)
{   
  int i,o;

  for (i = 0; i < pnumobs(plx); i++) 
  {
    o = pobj_nr(i, plx);

    if (iscarrby(o, plx) && otstbit(o,OFL_BLMAGIC))
       return True;
    else if (iswornby(o,plx) && otstbit(o,OFL_WBLMAGIC))
       return True;
  }
  return False; 
}

Boolean ispit(register int o)
{
  register int i = 0;
  register int j;
  
  while ((j = pits[i++]) != o && j != -1);
  return (j >= 0);
}

void giveall(int plx)
{  int o;
   int_set *inv;

   if (plx == -1)
   {  bprintf("Give all to whom?\n");
      return;
   }
   if (plx == mynum)
   {  bprintf("Cheap skate!\n");
      return;
   }
   if (pvis(plx) > pvis(mynum))
   {  bprintf("Give all to whom?\n");
      return;
   }
   if (ploc(plx) != ploc(mynum) && plev(mynum) < LVL_APPREN)
   {  bprintf("They aren't here.\n");
      return;
   }
   inv = pinv(mynum);

   for (o = first_obj(inv); o != SET_END; o = next_obj(inv))
   {  if (dogive(o,plx) == -1)
         return;
   }
}

A_COMMAND(givecom)
{
  int a, c;
  
  if (EMPTY(item1)) {
    bprintf("Give what to who?\n");
    return;
  }
  if (ltstflg(ploc(mynum),LFL_JAIL) && (plev(mynum) < LVL_DEMI) )
  {  bprintf("You can't give items to people in this room.\n");
     return;
  }
  if (psitting(mynum) > 1)
  {  bprintf("You're too far from the awake world to do that.\n");
     return;
  }

  if (strcasecmp(item1,"all") == 0)
  {   giveall(pl2);
      return;
  }
  else if (strcasecmp(item2,"all") == 0)
  {   giveall(pl1);
      return;
  }
  else if (pl1 != -1 && ob2 != -1)
  {   a = pl1;
      if (a == mynum)
      {   bprintf("Cheap skate!\n");
          return;
      }
      if (pvis(a) > plev(mynum))
      {   bprintf("Give what to whom?\n");
          return;
      }
      if (EMPTY(item2))
      {  bprintf("Give what to %s?\n",pname(a));
         return;
      }
      if ((c = ob2) == -1)
      {  bprintf("You don't have any %s.\n",item2);
         return;
      }
  }
  else if (pl2 != -1 && ob1 != -1)
  {   a = pl2;
      if (a == mynum)
      {   bprintf("Cheap skate!\n");
          return;
      }
      if (pvis(a) > plev(mynum))
      {   bprintf("Give what to whom?\n");
          return;
      }
      if (EMPTY(item1))
      {  bprintf("Give what to %s?\n",pname(a));
         return;
      }
      if ((c = ob1) == -1)
      {  bprintf("You don't have any %s.\n",item1);
         return;
      }
  }
  else if ((pl1 != -1 && ob2 == -1) || (pl2 != -1 && ob1 == -1))
  {  bprintf("You don't have it.\n");
     return;
  }
  else if ((ob1 != -1 && pl2 == -1) || (ob2 != -1 && pl1 == -1))
  {  bprintf("Who's that?\n");
     return;
  }
  else
  {  bprintf("Give what to whom?\n");
     return;
  }
  (void)dogive(c,a);
}

int dogive(int ob, int pl)
{
  int o, p;
  
  o = 0;
  p = 0;
  if (plev(mynum) < LVL_APPREN && ploc(pl) != ploc(mynum)) {
    bprintf("They aren't here.\n");
    return -1;
  }
  if (!iscarrby(ob, mynum)) {
    bprintf("You don't have any %s.\n", oname(ob));
    return -1;
  }
  if (!cancarry(pl)) {
    bprintf("They can't carry it.\n");
    return -1;
  }
  if (pl >= max_players && mtstflg(pl, MFL_QFOOD) && otstbit(ob, OFL_FOOD)) {
    bprintf("%s thanks you.\n", pname(pl));
    sendf(ploc(mynum), "%s has left the game.\n", pname(pl));
    setpscore(pl, pscore(pl) + 50);
    dumpstuff(pl, ploc(pl));
    setpfighting(pl,-1);
    strcpy(pname(pl), "");
    eat(ob);
    return -1;
  }

/* Special events give */
  if (ublock[pl].spec_case != NULL)  /* Check player */
  {   param_s.plx = mynum;
      param_s.ob  = ob;
      param_s.loc = ploc(mynum);
      param_s.pl  = pl;
      param_s.ret = 1;
      ublock[pl].spec_case(E_ONGIVE);
      if (param_s.ret != 1)
        return -1;
  }
  if (obj_fun(ob) != NULL)            /* check object */
  {  param_s.plx = mynum;
     param_s.ob  = ob;
     param_s.loc = ploc(ob);
     param_s.pl  = pl;
     param_s.ret = 1;
     obj_fun(ob)(E_ONGIVE);
     if (param_s.ret != 1)
       return -1;
  }
/* End special events give */
  setoloc(ob, pl, CARRIED_BY);
  sendf(pl, "%s gives you the %s.\n", see_name(pl, mynum), oname(ob));
  send_msg(ploc(pl), 0, LVL_MIN, LVL_MAX, pl, mynum,
	   "\001p%s\003 gives \001p%s\003 the %s.\n",
	   pname(mynum), pname(pl), oname(ob));
  bprintf("%s: Ok.\n",oname(ob));
  return 1;
}

A_COMMAND(stealcom)
{
  int a, c, e, f;
  char x[128];
  
  if (EMPTY(item1)) 
  {
    bprintf("Steal what?\n");
    return;
  }
  strcpy(x, item1);
  if (EMPTY(item2)) {
    bprintf("From who?\n");
    return;
  }
  if ((c = pl2) == -1) 
  {
    bprintf("Who is that?\n");
    return;
  }
  if (mynum == c) 
  {
    bprintf("A true kleptomaniac.\n");
    return;
  }
  if ((a = fobncb(x, c)) == -1) 
  {
    bprintf("They don't have it.\n");
    return;
  }
  if (plev(mynum) < LVL_APPREN && ploc(c) != ploc(mynum)) 
  {
    bprintf("They're not here!\n");
    return;
  }
  if (ocarrf(a) == WORN_BY) 
  {
    bprintf("They're wearing it.\n");
    return;
  }

#ifndef ALLOW_PL_STEAL
  if (c < max_players && !the_world->w_tournament && plev(mynum) < LVL_APPREN)
  {  bprintf("Thy shall not steal from thy fellow players.\n");
     return;
  }
#endif

  if (pwpn(c) == a) 
  {
    bprintf("They have it firmly to hand ... for KILLING people with!\n");
    return;
  }
  
  if (mtstflg(c, MFL_NOSTEAL)) 
  {
    sendf(ploc(c), "%s says 'How dare you steal from me, %s!'\n",
	  pname(c), pname(mynum));
    hit_player(c, mynum, -1);
    return;
  }
  
  if (mob_fun(pnum(c)) != NULL && c > max_players)
  {  param_s.plx = mynum;
     param_s.loc = ploc(mynum);
     param_s.pl  = c;
     param_s.ob  = a;
     param_s.misc= VERB_STEAL;
     param_s.ret = 1;
     mob_fun(pnum(c))(E_ONMISC);
     if (param_s.ret != 1)
       return;
  }
  
  if (!do_okay( mynum, c, PFL_NOSTEAL)) 
  {
    int i = randperc() % 3;
    switch (i) {
    case 0:
      bprintf("%s is too watchful.\n", he_or_she(c));
      return;
    case 1:
      bprintf("%s is too alert.\n", he_or_she(c));
      return;
    case 2:
      bprintf("%s is too crafty.\n", he_or_she(c));
      return;
    }
  }
  if (!cancarry(mynum)) 
  {
    bprintf("You can't carry any more.\n");
    return;
  }
  f = randperc();
  e = (10 + plev(mynum) - plev(c)) * 5;
  if (f < e || plev(mynum) >= LVL_APPREN) 
  {
    bprintf("Got it!\n");
    sendf(c, "%s steals the %s from you!\n",
	  see_name(c, mynum), oname(a));
#ifdef LOG_STEAL
    if (c < max_players)
      mudlog("STEAL: %s stole %s from %s",pname(mynum),x,pname(c));
#endif
    setoloc(a, mynum, CARRIED_BY);
    if ((f & 1) && (c >= max_players))
      hit_player(c, mynum, -1);
    return;
  }
  bprintf("Your attempt fails.\n");
}

Boolean is_rope(int obj)
{  return (otstbit(obj,OFL_ROPE));
}

Boolean is_shield(int obj)
{
  return (!strncasecmp(oname(obj),"shield",strlen(oname(obj))));
}

Boolean is_armor(int obj)
{
  return (!strncasecmp(oname(obj),"armor",strlen(oname(obj))) ||
          !strncasecmp(oname(obj),"armour",strlen(oname(obj))) ||
          !strncasecmp(oname(obj),"mail",strlen(oname(obj))));
}

Boolean is_mask(int obj)
{
  return (!strncasecmp(oname(obj),"mask",strlen(oname(obj))));
}

Boolean is_raft(int obj)
{  return in_table(obj,rafts);
}

Boolean is_boat(int obj)
{
  if (otstbit(obj, OFL_BOAT))
    return True;
  return False;
}

/* Does player pl wear a shield ?
 */
Boolean wears_shield(int pl)
{
  int i,o;
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iswornby(o, pl) && is_shield(o))
      return True;
  }
  
  return False;
}

/* Does player pl wear armor ?
 */
Boolean wears_armor(int pl)
{
  int i,o;
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iswornby(o, pl) && is_armor(o))
      return True;
  }
  return False;
}


Boolean wears_mask(int pl)
{
  int i,o;

  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i, pl);

    if (iswornby(o, pl) && is_mask(o))
      return True;
  }
  
  return False;
}

Boolean carries_raft(int pl)
{
  int i,o;
  
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iscarrby(o, pl) && is_raft(o))
      return True;
  }
  return False;
}

Boolean carries_boat(int pl)
{
  int i,o;
  
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iscarrby(o, pl) && is_boat(o))
      return True;
  }
  return False;
}

/* Does pl carry object type or a clone of it ?
 */
int carries_obj_type(int pl, int type)
{
  int i,o;
  
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iscarrby(o, pl) && onum(o) == type)
      return o;
  }
  return -1;
}

int has_container_obj(int pl)
{  
    int i,o;
    for (i=0; i < pnumobs(pl); i++)
    {  o = pobj_nr(i,pl);

       if (iscarrby(o , pl) && otstbit(o ,OFL_CONTAINER) )
          return o;
    }
    return -1;
}

/* Does pl wear object type or a clone of it ?
 */
int wears_obj_type(int pl, int type)
{
  int i,o;
  
  for (i = 0; i < pnumobs(pl); i++) {
    o = pobj_nr(i,pl);

    if (iswornby(o, pl) && onum(o) == type)
      return pobj_nr(i, pl);
  }
  return -1;
}

A_COMMAND(wearcom)
{
  int a;
  
  if ((a = ohereandget()) == -1) return;
  if (!iscarrby(a, mynum)) {
    bprintf("You don't have it.\n");
    return;
  }
  if (iswornby(a, mynum)) {
    bprintf("You're already wearing it.\n");
    return;
  }
  if (psitting(mynum)==2)
  { 
    bprintf("You roll around in your sleeping bag.\n");
    return;
  }
  if (psitting(mynum)==3)
  {  
     bprintf("You make some impressive Tai-Chi figures.\n");
     return;
  }
  
  trywear(a, True);
}

static void trywear(int a, Boolean print_stuff)
{
  int b;
  int_set *inv = pinv(mynum);
  int obj;

  if (obj_fun(a) != NULL)
  {  param_s.ob = a;
     param_s.plx = mynum;
     param_s.ret = 1;
     param_s.loc = ploc(a);
     obj_fun(a)(E_ONUSE);
     if (param_s.ret != 1)
       return;
  }
  
  if (!otstbit(a, OFL_WEARONHEAD) &&
      !otstbit(a, OFL_WEARONFACE) &&
      !otstbit(a, OFL_WEARONNECK) &&
      !otstbit(a, OFL_WEARONFACE) &&
      !otstbit(a, OFL_WEARONARMS) &&
      !otstbit(a, OFL_WEARONHANDS) &&
      !otstbit(a, OFL_WEARONBODY) &&
      !otstbit(a, OFL_WEARONLEGS) &&
      !otstbit(a, OFL_WEARONFEET) &&
      !otstbit(a, OFL_WEARONBACK) &&
      !otstbit(a, OFL_WEARABLE))
    {
      bprintf("Is this a new fashion?\n");
      return;
    }
  
  if (otstbit(a,OFL_EXCLUDEWEAR)) {
    for (obj = first_obj(inv); obj != SET_END; obj = next_obj(inv)) {
      if (otstbit(obj,OFL_EXCLUDEWEAR) && obj != a && isworn(obj)) {
	if ((otstbit(a,OFL_WEARONARMS) && otstbit(obj,OFL_WEARONARMS)) ||
	    (otstbit(a,OFL_WEARONHANDS)&& otstbit(obj,OFL_WEARONHANDS)) ||
	    (otstbit(a,OFL_WEARONBODY) && otstbit(obj,OFL_WEARONBODY)) ||
	    (otstbit(a,OFL_WEARONBACK) && otstbit(obj,OFL_WEARONBACK)) ||
	    (otstbit(a,OFL_WEARONLEGS) && otstbit(obj,OFL_WEARONLEGS)) ||
	    (otstbit(a,OFL_WEARONFEET) && otstbit(obj,OFL_WEARONFEET)) ||
	    (otstbit(a,OFL_WEARONNECK) && otstbit(obj,OFL_WEARONNECK)) ||
	    (otstbit(a,OFL_WEARONFACE) && otstbit(obj,OFL_WEARONFACE)) ||
	    (otstbit(a,OFL_WEARONHEAD) && otstbit(obj,OFL_WEARONHEAD))) {
	  if (!strcasecmp(oname(a),oname(obj)) && print_stuff) {
	    bprintf("You can't wear the two %ss at the same time.\n",
		    oname(a));
	    return;
	  } else if(print_stuff) {
	    bprintf("You can't wear the %s and the %s at the same time.\n",
		    oname(a),oname(obj));
	    return;
	  }
	  return;
	}
      }
    }
  }
  if((player_armor(mynum) + oarmor(a)) > MAX_ARMOR && otstbit(a, OFL_ARMOR)) {
    if(print_stuff)
      bprintf("You can't wear that with all that armor you're wearing.\n");
    return;
  } 
  if (oloc(a) != mynum)
  {   bprintf("Try taking it out of the container.\n");
      return;
  }
  b = WORN_BY;
  if (ocarrf(a) == WIELDED_BY)
    b = BOTH_BY;
  setcarrf(a, b);
  
  send_msg( ploc(mynum), 0, pvis(mynum), LVL_MAX, real_mynum, NOBODY,
	   "\001p%s\003 wears the %s.\n", pname(mynum), oname(a));
  
  bprintf("%s: Ok\n",oname(a));
}

A_COMMAND(removecom)
{
  int a;
  int b;
  
  if ((a = ohereandget()) == -1) return;
  if (!iswornby(a, mynum)) {
    bprintf("You're not wearing it.\n");
    return;
  }
  b = (ocarrf(a) == BOTH_BY) ? WIELDED_BY : CARRIED_BY;
  setcarrf(a, b);
  
  send_msg( ploc(mynum), 0, pvis(mynum), LVL_MAX, mynum, NOBODY,
	   "%s removes the %s.\n", pname(mynum), oname(a));
  
  bprintf("Ok\n");
}


/* VALUE command:
 *****************************************************************/

int value_class(CLASS_DATA *cl, int plx, Boolean silent)
{
  int obj, sum = 0;
  
  for (obj = 0; obj < numobs; obj++ ) {
    
    if (in_inventory(obj, plx) && classmatch(obj, cl)) {
      sum += ovalue(obj);
      if (!silent) {
	if (plev(plx) >= LVL_APPREN) bprintf("&+w[&*%-4d&+w]&*", obj);
	bprintf("%12.12s:%5d points\n",
		oname(obj), ovalue(obj));
      }
    }
  }
  return sum;
}

A_COMMAND(valuecom)
{
  CLASS_DATA *c;
  int a;
 
  if (brkword() == -1) {
    bprintf("Total value of all your possessions: %d points.\n",
	    value_class(findclass("all"), mynum, True));
  } else {
    do {
      if ((c = findclass(wordbuf)) != NULL) {
	bprintf("\n&+wTotal value:&+w%*d points.&*\n",
		plev(mynum) >= LVL_APPREN ? 11 : 6,
		value_class(c, mynum, False));
      } else if ((a = fobn(wordbuf)) == -1) {
	bprintf("%s: no such object\n", wordbuf);
      } else {
	if (plev(mynum) >= LVL_APPREN) 
            bprintf("&+w[&*%-4d&+w]&*", a);
	bprintf("%12.12s:%5d points\n", oname(a), ovalue(a));
      }
    } while (brkword() != -1);
  }
}
/*End, VALUE command
 ****************************************************************/


A_COMMAND(putcom)
{
  int a /*, i*/;
  char ar[128];
  int c;
  
  if ((a = ohereandget()) == -1)
    return;
  if (EMPTY(item2)) {
    bprintf("Where?\n");
    return;
  }

  if (psitting(mynum) > 1)
  {  bprintf("Somehow you can't seem to focus yourself on the job.\n");
     return;
  }
  if ((c = ob2) == -1) {
    bprintf( "I can't see any %s here.\n", item2);
    return;
  }
  /* Special event Code 
   * OB  : object where to put it in.
   * MISC: Object you wanna put
   * LOC : ploc(ob)
   * PLX : mynum
   * PL  : Not defined.
   * RET : Default (continue)
   */
   /* Setup param_s */
   param_s.ob  = c;             /* put a in/on c*/
   param_s.misc= a;
   param_s.plx = mynum;
   param_s.loc = oloc(c);
   param_s.pl  = -1;
   param_s.ret = 1;
   /* Check objects that take part in this action */
   if (obj_fun(c) != NULL) 
   {  obj_fun(c)(E_ONPUT);
      if (param_s.ret != 1)
         return;
   }
   if (obj_fun(a) != NULL)  /* No else, you never know where the code is placed */
   {   obj_fun(a)(E_ONPUT);
   
       if (param_s.ret != 1)
          return;
   }
   if (rom_fun(ploc(mynum)) != NULL)
   {   rom_fun(ploc(mynum))(E_ONPUT);
      if (param_s.ret != 1)
         return;
   }
    
  
  if (c == a) 
  {
    bprintf("What do you think this is, the goon show?\n");
    return;
  }
  if (otstbit(c, OFL_CONTAINER) == 0) 
  {
    bprintf("You can't do that.\n");
    return;
  }
  if (state(c) != 0) 
  {
    bprintf("It's not open.\n");
    return;
  }
  if (oflannel(a)) 
  {
    bprintf("You can't take that!\n");
    return;
  }
  if ((ishere(a)) && (dragget()))
    return;

  if (onum(a) == RuneSword_Obj) 
  {
    bprintf("You can't let go of it!\n");
    return;
  }
  if (onum(a) == Umbrella_Obj && state(a) == 1) 
  {
    bprintf("Close it first...\n");
    return;
  }
  if (otstbit(a, OFL_LIT)) 
  {
    bprintf("I'd try putting it out first!\n");
    return;
  }
  if (!willhold(c, a)) 
  {
    bprintf("It won't fit.\n");
    return;
  }

  setoloc(a, c, IN_CONTAINER);
  bprintf("Ok\n");
  
  send_msg(ploc(mynum), 0, LVL_MIN, LVL_MAX, mynum, NOBODY,
	   "\001D%s\003\001c puts the %s in the %s.\n\003",
	   pname(mynum), oname(a), oname(c));
  
  if (otstbit(a, OFL_GETFLIPS))
    setobjstate(a, 0);

   /* Check objects that take part in this action */
   if (obj_fun(c) != NULL) 
   {  obj_fun(c)(E_AFTERPUT);
      if (param_s.ret != 1)
         return;
   }
   if (obj_fun(a) != NULL)  /* No else, you never know where the code is placed */
      obj_fun(a)(E_AFTERPUT);
   
   if (param_s.ret != 1)
     return;
     
  if (ploc(mynum) == Tower_Treasure_Loc && state(Tower_Door) == 0
      && ishere(a)) 
  {
    setobjstate(Tower_Door, 1);
    strcpy(ar, "The door clicks shut....\n");
    sendf( Tower_Treasure_Loc, ar);
    sendf( oloc(Tower_Door2), ar);
  }
}

A_COMMAND(eatcom)
{
  int b;
  char s[100];
  
  if (brkword() == -1) {
    bprintf("Eat what?\n");
    return;
  }
  if (EQ(wordbuf, "water"))
    strcpy(wordbuf, "spring");
  if ((b = ob1 == -1 ? ob2 : ob1) == -1) {
    bprintf("It isn't here.\n");
    return;
  }
  if (obj_fun(onum(b)) != NULL)
  {  param_s.plx = mynum;
     param_s.ob  = b;
     param_s.loc = ploc(mynum);
     param_s.ret = 1;
     obj_fun(onum(b))(E_ONCONSUME);
     if (param_s.ret != 0)
       return;
  }

  if (otstbit(b, OFL_FOOD) || otstbit(b, OFL_BOOZE)) 
  {
      if (otstbit(b,OFL_POISON))
      {  bprintf("As you consume the %s, you feel the poison crawling in your\n"
                 "blood. Maybe this wasnt such a smart move.\n",oname(b));
         setpscore(mynum,pscore(mynum)- (pscore(mynum)/3));
         crapup("You died by a deadly poison.\n",CRAP_SAVE);
         return;
      }
      else if (pstr(mynum) >= maxstrength(mynum))
      {   bprintf("One more bite or drink and you will start to ruminate your dinner.\n");
          return;
      }
      else if (otstbit(b,OFL_BOOZE))
      {   bprintf("You greedily drink up the strong %s.\n",oname(b));
          send_msg(ploc(mynum),0,pvis(mynum),LVL_MAX,mynum,NOBODY,
                   "%s greedily drinks the %s.\n",pname(mynum),oname(b));
          setpdrunk(mynum, pdrunk(mynum) + 5);
          setpstr(mynum, pstr(mynum) + 14);
          ssetflg(mynum,SFL_DRUNK);
          eat(b);
          calibme();
          return;
      }   
      sprintf(s, "\001P%s\003 greedily devours the %s.\n", pname(mynum), oname(b));
      eat(b);
      bprintf("Delicious!\n");
      setpstr(mynum, pstr(mynum) + 12);
      calibme();
      sillycom(s);
  } 
  else 
  {
      bprintf("I think I've lost my appetite.\n");
      return;
  }
}

A_COMMAND(inventory)
{ int plr = mynum;
  Boolean awiz = (plev(mynum) >= LVL_APPREN);

  if (!awiz) 
  {
     if (psitting(mynum) == 2)
     {  bprintf("It's all gone!... phew... luckily it was just a bad dream.\n");
     } 
     else if (psitting(mynum) == 3)
     {  bprintf("Doing that will disturb your inner balance.\n");
     } 
     send_msg(ploc(mynum), 0, pvis(mynum), LVL_MAX, real_mynum, NOBODY,
	     "%s rummages through %s backpack.\n", 
	     pname(mynum), his_or_her(mynum));
  }
  else if (brkword() != -1)
  { plr = fpbns(wordbuf);
    if (plr < 0)
    {   bprintf("Show whose inventory?\n");
        return;
    }

    if (plr >= max_players && !can_manipulate(mynum,plr) && ploc(mynum) != ploc(plr) )
    {   bprintf("You cannot see their inventory.\n");
        return; 
    }
  }
  print_inventory(plr);
}


void listobject(int loc,int mode)
{
  aobjsat(loc, mode, 0);
}

void mlobjsat(int x, int m)
{
  aobjsat(x, CARRIED_BY, m);
}



/* All OBJectS AT - list all objects at the destination given.
 */
void aobjsat(int loc, int mode, int marg)
{
  int ostack[64], ostackp = 0;
  
  char b[80], *s;
  
  int col;
  Boolean wwl;    /* worn, wielded or lit ?*/
  Boolean d, show_contents, empty = True;
  int obj;
  int stp;
  int_set *inv = mode == IN_ROOM ? linv(loc) :
    mode == IN_CONTAINER ? oinv(loc) : pinv(loc);
  
  
  for (col = 0; col < marg; col++)  bprintf(" ");
  
  for (obj = first_obj(inv); obj != SET_END; obj = next_obj(inv)) {
    
    show_contents = False;
    
    s = b;
    
    if ((mode == CARRIED_BY && iscarrby(obj, loc))
	|| (mode == IN_CONTAINER && iscontin(obj, loc))) {
      
      empty = False;
      show_contents = True;
      
      if ((d = (otstbit(obj, OFL_DESTROYED)))) {
	*s++ = '(';
      }
      
      strcpy(s, oname(obj));
      s += strlen(oname(obj));
      
      if (d) {
	*s++ = ')';
      }
      
      *s++ = ' ';
      
      wwl = False;
      
      if (mode == CARRIED_BY) {
	if (iswornby(obj, loc)) {
	  strcpy(s,"<worn ");
	  s += strlen(s);
	  wwl = True;
	}
	
	if (pwpn(loc) == obj
	    && ocarrf(obj) == WIELDED_BY) {
	  if (wwl) *s++ = ',';
	  else {
	    *s++ = '<';
	    wwl = True;
	  }
	  strcpy(s,"wielded");
	  s += strlen(s);
	}
	
	if (otstbit(obj, OFL_LIT)) 
        {
	  if (wwl) *s++ = ',';
	  else {
	    *s++ = '<';
	    wwl = True;
	  }
	  strcpy(s,"lit");
	  s += strlen(s);
	}
        if (otstbit(obj,OFL_MAGICLIT))
        { 
           if (wwl) 
              *s++ = ',';
           else
           {  *s++ = '<';
              wwl = True;
           }
           strcpy(s,"glowing");
           s+=strlen(s);
        }
	if (wwl) *s++ = '>';
      }
      
      *s = 0;
      
      if (s - b + 1 + col > 79) {
	bprintf("\n");
	for (col = 0; col < marg; col++) bprintf(" ");
      }
      
      bprintf( "%s ", b);
      col += strlen(b) + 1;
      
      if (otstbit(obj, OFL_CONTAINER) && show_contents &&
	  (!otstbit(obj, OFL_OPENABLE) || state(obj) == 0)) {
	ostack[ostackp++] = obj;
      }
    }
  }
  
  
  if (empty)  bprintf("Nothing");
  
  bprintf("\n");
  
  for (stp = 0; stp < ostackp; stp++) {
    for (col = 0; col < marg; col++)  bprintf(" ");
    
    obj = ostack[stp];
    
    bprintf("    The %s contains:\n", oname(obj));
    /*		pbfr();*/
    aobjsat(obj, IN_CONTAINER, marg + 8);
  }
}




/* Is o1 contained in o2 ?
 */
Boolean iscontin(int o1, int o2)
{
  if (ocarrf(o1) != IN_CONTAINER || oloc(o1) != o2)
    return False;
  
  if (plev(mynum) < LVL_APPREN && otstbit(o1, OFL_DESTROYED))
    return False;
  
  return True;
}


/* The room where an object, or its container or its carrier, are at.
 */
int obj_loc(int obj)
{
  for (; ocarrf(obj) == IN_CONTAINER; obj = oloc(obj))
    ;
  return ocarrf(obj) >= CARRIED_BY ? ploc(oloc(obj)) : oloc(obj);
}



/* The 'Find Object By Name' system.
 *
 * Name can be either 1) <object-number>
 *                 or 2) <object-name>
 *                 or 3) <object-name><number-in-sequence-with-that-name>
 */
static int fobnsys(char *name, int ctrl, int ct_inf, int_set *inv);

int fobn(char *word)
{
  int x;
  
  /* Look for all available objects (=in room or inventory)
   */
  if ((x = fobna(word)) != -1) return x;
  
  /* we didn't find any available object...look for *any* object
   */
  return fobnsys(word, 0, 0, NULL);
}

/* Look for available objects */
int fobna(char *word)
{
  int i;
  
  return (i = fobnc(word)) >= 0 ? i : fobnh(word);
}

/* Look for objects contained in ct */
int fobnin(char *word, int ct)
{
  return fobnsys(word, 5, ct, oinv(ct));
}

/* look for objects carried by me */
int fobnc(char *word)
{
  return fobncb(word, mynum);
}

/* look for objects carried by 'by' */
int fobncb(char *word, int by)
{
  return fobnsys(word, 3, by, pinv(by));
}

/* Look for objects that's here */
int fobnh(char *word)
{
  return fobnsys(word, 4, ploc(mynum), linv(ploc(mynum)));
}

/* Look for a obj. that's here and not scenery (can be taken) */
int fobn_can_take(char *word)
{
  return fobnsys(word, 6, ploc(mynum), linv(ploc(mynum)));
}


static int fobnsys(char *name, int ctrl, int ct_inf, int_set *inv)
{
  char b[ONAME_LEN + 1], *p = b;
  int i, obj, num;
  char *n;
  
  if (name == NULL || strlen(name) > ONAME_LEN || name[0] == '\0')  
      return -1;
  
  while (*name != '\0' && isalpha(*name)) *p++ = *name++;
  *p = '\0';
  
  if (isdigit(*name)) {
    num = atoi(name);
    
    while (isdigit(*++name));
    if (*name != '\0') return -1;
  }
  else if (*name != '\0') {
    return -1;
  }
  else num = 1;
  
  if (num < 0 || num >= numobs) return -1;
 
  if (*b == '\0') {
    switch(ctrl) {
    case 0: return num;
    case 3: return iscarrby(num, ct_inf) ? num : -1;
    case 4: return ishere(num) ? num : -1;
    case 5: return iscontin(num, ct_inf) ? num : -1;
    case 6: return ishere(num) && !oflannel(num) ? num : -1;
    default: return -1;
    }
  }
  
  if (ctrl == 0) {    /* Look for first object with this name*/
    
    for (obj = 0; obj < numobs; obj++) {
      n = EQ(b, oname(obj))    ? oname(obj) :
	EQ(b, oaltname(obj)) ? oaltname(obj) : NULL;
      
      if (n != NULL && --num == 0) {
	cur_player->wd_it = n;
	return obj;
      }
    }
    return -1;
  }
  
  for (i = 0; i < set_size(inv); i++) {
    
    obj = int_number(i, inv);
    
    n = EQ(b, oname(obj))    ? oname(obj) :
      EQ(b, oaltname(obj)) ? oaltname(obj) : NULL;
    
    if (n != NULL) {
      cur_player->wd_it = n;
      
      switch (ctrl) {
      case 3: /* Look for objects carried by ct_inf */
	if (iscarrby(obj, ct_inf) && --num == 0)
	  return obj;
	break;
      case 4: /* Look for objects that's here */
	if (ishere(obj) && --num == 0)
	  return obj;
	break;
      case 5: /* look for objects contained in ct_inf*/
	if (iscontin(obj, ct_inf) && --num == 0)
	  return obj;
	break;
      case 6: /* objects that are here and gettable */
	if (ishere(obj) && !oflannel(obj) && --num ==0)
	  return obj;
	break;
      default: 	return -1;
      }
    }
  }
  return -1;
}


/* Find an object's in-game index from its ID.
 * Return -1 if not found.
 */
int find_object_by_id(long int id)
{
  long int x;
  
  if (id >= 0 && id < num_const_obs) return id;
  
  return (x = lookup_entry(id, &id_table)) == NOT_IN_TABLE
    || x < 0 || x >= numobs ? -1 : x;
}




int get1objfrom(int ob,int container)
{
/*  char *s;*/
  char bf[81];

  if ((otstbit(ob, OFL_NEWBIE)) && (plev(mynum) > LVL_SEVEN)  && 
      (plev(mynum) < LVL_EMERITUS))
  {
      bprintf("A strange force prevents you from picking it up.\n");
      return -1;
  }
 
  if (oflannel(ob)) 
  { int i = fobn_can_take(oaltname(ob));
    
    if (i == -1) 
       i = fobn_can_take(oname(ob));
    
    if (i == -1) 
    {
      bprintf("You can't take that!\n");
      return -1;
    } 
    else 
      ob = i;
  }
  
  if (container == -1 || !iscarrby(container, mynum)) 
  {
    if (dragget())
      return -1;
  }
 
  if (!cancarry(mynum)) 
   {
    bprintf("You can't carry any more.\n");
    return -1;
  }
  /* Some stuff that go off DURING the get process (not much, but hey
   * you have to make it work the same dont ya?)
   */
  if (obj_fun(ob) != NULL)
  {  param_s.plx = mynum;
     param_s.ob  = ob;
     param_s.loc = container;
     param_s.ret = 1;
     param_s.misc= DURING_GET;
     obj_fun(ob)(E_ONGET);
     if (param_s.ret != 1)
       return param_s.ret;
     /* Fall through */
     ob = param_s.ob;  /* IF object to take is changed, change it here as well */
  }  

  setoloc(ob, mynum, CARRIED_BY);
  if (container == -1) {
    *bf = '\0';
  } else {
    sprintf(bf, " from the %s", oname(container));
  }
  send_msg(ploc(mynum), 0, LVL_MIN, LVL_MAX, mynum, NOBODY,
	   "\001p%s\003 takes the %s%s.\n", pname(mynum), oname(ob), bf);
  
  if (otstbit(ob, OFL_GETFLIPS))
    setobjstate(ob, 0);

  /* Check if the room will allow a get from that room */
  if (rom_fun(ploc(mynum)) != NULL)
  {  param_s.plx = mynum;
     param_s.ret = 1;
     param_s.ob  = ob;
     param_s.loc = ploc(mynum);
     rom_fun(ploc(mynum))(E_ONGET);
     if (param_s.ret != 1)
       return 0;
  }
  /* And finally the few that go off after an object has been picked up.
   * Might be usefull for burgler alarms ;)
   */
  if (obj_fun(ob) != NULL)
  {  param_s.plx = mynum;
     param_s.ob  = ob;
     param_s.loc = container;
     param_s.ret = 1;
     param_s.misc= AFTER_GET;
     obj_fun(ob)(E_ONGET);
     if (param_s.ret != 1)
       return param_s.ret;
  }  

  bprintf("Ok\n");
  return 0;
}

int getcom(void)
{
  CLASS_DATA *cl;
  int ob;
  int i;
  int container = -1;
  char bf[1024];

  int loc = ploc(mynum);
  int m;
  
  if (brkword() == -1) {
    bprintf("Get what?\n");
    return -1;
  }
  
  if (isdark()) {
    bprintf("It's dark!\n");
    return -1;
  }
  
  /* No get while sleeping or trancing */
  if (psitting(mynum) == 2)
  {  bprintf("You move your arms in a frantic attempt to kling onto something.\n");
     return -1;
  }
  if (psitting(mynum) == 3)
  {  bprintf("The trance doesn't allow you to do that.\n");
     return -1;
  }
  
  if ((cl = findclass(wordbuf)) != NULL) {
    getall(cl);
    return 0;
  }
  
  ob = fobnh(wordbuf);
  /* Hold */
  i = stp;
  strcpy(bf, wordbuf);
  
  if (brkword() != -1 && (EQ(wordbuf, "from") || EQ(wordbuf, "out"))) {
    if (brkword() == -1) {
      bprintf("From what?\n");
      return -1;
    }
    if ((container = fobna(wordbuf)) == -1) {
      bprintf("You can't take things from that!  It's not here!\n");
      return -1;
    }
    
    if (otstbit(container, OFL_LOCKABLE) &&
	state(container) == 2 && !ohany(1<<OFL_KEY)) {
      bprintf("The %s is locked, and you have no key.\n", oname(container));
      return -1;
    }
    
    if ((otstbit(container, OFL_OPENABLE) || otstbit(container, OFL_LOCKABLE))
	&& state(container) > 0) {
      bprintf("You open the %s.\n", oname(container));
      setobjstate(container, 0);
    }
    
    ob = fobnin(bf, container);
  }
  
  /* Small loop to check for Mflags: GrabHostile and NoGrab
   * Checks all players in the room, see if they are mobiles, and alive
   * the check for the flags, print message and do some stuff 
   */
  for (i=0 ; i <lnumchars(loc); i++)
  {   m = lmob_nr(i,loc);
      if (m >= max_players && m != mynum && alive(m) != -1 && 
          (container == -1 || oloc(container) == ploc(m)))
      {   if (mtstflg(m,MFL_GRABH))
          { bprintf("%s looks at you and shouts: 'You can't take that!'\n",pname(m));
            send_msg(ploc(mynum),MODE_NODEAF,pvis(mynum),LVL_MAX,mynum,NOBODY,
                     "%s looks at %s and shouts 'You can't take that!'\n",
                     pname(m),pname(mynum));
            setpfighting(m,mynum);
            setpfighting(mynum,m);
            return -1;
          } else if (mtstflg(m,MFL_NOGRAB))
          { bprintf("%s won't allow you near it.\n",pname(m));
            return -1;
          }
      }
  }
  stp = i;
  
  if (ob == -1) 
  { if (EQ(item1,"water") && ltstflg(ploc(mynum),LFL_ON_WATER))
    {   if (carries_obj_type(mynum,LimboWater) != -1)
        {   bprintf("Your hipflask if full.\n");
            return -1;
        }
        ob = clone_object(LimboWater,-1,NULL);
        if (ob < 0)
        {  bprintf("It's not here.\n"); 
           return -1;
        } 
        bprintf("You fill your hipflask with water.\n");
    }
    else
    {  bprintf("It's not here.\n"); 
       return -1;
    } 
  }
  
  param_s.plx = mynum;
  param_s.ob  = ob;
  param_s.loc = (container == -1) ? ploc(mynum) : container;
  param_s.ret = 1;
  param_s.misc= BEFORE_GET;

  if (obj_fun(ob) != NULL)
  {  obj_fun(ob)(E_ONGET);
     if (param_s.ret != 1)
       return param_s.ret;
     /* Fall through */
     ob = param_s.ob;  /* IF object to take is changed, change it here as well */
  } 
  
   
  return get1objfrom(ob,container);
}

static void getall(CLASS_DATA *cl)
{
  int x;
  
  if (brkword() != -1) {
    getallfr(cl);
    return;
  }
  
  for (x = lfirst_obj(ploc(mynum)); x != SET_END; x=lnext_obj(ploc(mynum))) {
    
    if (ishere(x) && !oflannel(x) && classmatch(x, cl)) {
      strcpy(strbuf, oname(x));
      stp = 0;
      bprintf("%s: ", oname(x));
      if (getcom() == -1)
	break;
    }
  }
}

static void getallfr(CLASS_DATA *cl)
{
  int container;
  int ob;
  char obj[100];
 
  if (EQ(wordbuf,"from")) 
  {
    if (brkword() == -1) {
      bprintf("From what?\n");
      return;
    }
    strcpy(obj,wordbuf);
  }
  else 
    strcpy(obj,wordbuf);

  if ((container = fobna(obj)) == -1) {
    bprintf("That isn't here.\n");
    return;
  }
      
  /* Do items */
 
  for (ob = ofirst_obj(container); ob != SET_END; ob = onext_obj(container)){
    
    if (iscontin(ob, container) && !oflannel(ob) && classmatch(ob, cl)) {
      sprintf(strbuf, "%s from %s", oname(ob), obj);
      stp = 0;
      bprintf("%s: ", oname(ob));
      if (getcom() == -1)
	break;
    }
  }
}

static void dropall(CLASS_DATA *cl)
{
  int ob;
  
  for (ob = pfirst_obj(mynum); ob != SET_END; ob = pnext_obj(mynum)) {
    
    if (iscarrby(ob, mynum) && classmatch(ob, cl)) {
      strcpy(strbuf, oname(ob));
      stp = 0;
      bprintf("%s: ", oname(ob));
      if (dropobj(-1) == -1)
	return;
    }
  }
}


/* Is the item in the same room as the player ?
 */
Boolean p_ishere(int plr,int item)
{
  if (plev(plr) < LVL_APPREN && otstbit(item, OFL_DESTROYED))
    return False;
  
  if (ocarrf(item) != IN_ROOM || oloc(item) != ploc(plr)
      || ploc(plr) == 0)
    return False;
  
  return True;
}


Boolean ishere(int item)
{
  return p_ishere(mynum,item);
}



Boolean iscarrby(int item, int user)
{
  if (item == -1)
    return False;

  if (user < max_players && plev(user) < LVL_APPREN  && otstbit(item, OFL_DESTROYED))
    return False;
  
  if (ocarrf(item) < CARRIED_BY)
    return False;
  
  if (oloc(item) != user)
    return False;
  
  return True;
}


/* Is the object in a players inventory ?
 * (also handles objects in a container in a container etc...)
 */
Boolean in_inventory(int obj, int player)
{ while (ocarrf(obj) == IN_CONTAINER)  obj = oloc(obj);
  
  return iscarrby(obj, player);
}

void donate_object(int o)
{   char *deny = "The gods do not care for your sacrifice.\n";
    int  i;

#if 0
    if (get_quest_of_zone(ozone(o)) >= 0)
    {   bprintf(deny);
        return;
    }
#endif
    if (otstbit(o,OFL_NODONATE))
    {   bprintf("The gods do not allow you to drop that object here.\n");
        return;
    }

    if (!otstbit(o,OFL_ARMOR) && !otstbit(o,OFL_WEAPON) && !otstbit(o,OFL_FOOD) &&
        !otstbit(o,OFL_BOOZE) && !otstbit(o,OFL_WEARABLE) && !otstbit(o,OFL_CONTAINER))
    {   bprintf(deny);
        return;
    }
    
    if (obj_fun(onum(o)) != NULL)
    {  param_s.plx = mynum;
       param_s.misc= D_DONATE;
       param_s.ret = 1;
       param_s.loc = ploc(mynum);
       obj_fun(onum(o))(E_ONDROP);
       if (param_s.ret != 1)
          return;
    } 
    

    if (otstbit(o,OFL_DONATED))
    {  bprintf("The gods thank you for returning the %s.\n",oname(o));
       send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
                "\001p%s\003 returns the %s.\n",pname(mynum),oname(o));
    }
    else
    {
       bprintf("The gods accept your sacrifice and thank you.\n");
       send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
                "\001p%s\003 donates the %s.\n",pname(mynum),oname(o));
       setpscore(mynum,pscore(mynum) + ovalue(o));
       osetbit(o,OFL_DONATED);
    }
    setoloc(o,ploc(mynum),IN_ROOM);

    if (otstbit(o,OFL_CONTAINER))
    {   for (i = ofirst_obj(o); i != SET_END; i = onext_obj(o))
	   if (iscontin(i, o)) 
           {
	       setoloc(i,mynum,CARRIED_BY);
           }
    }
}


A_COMMAND(dropcom)
{  dropobj(-1);
}

int dropobj(int obj)
{
  CLASS_DATA *cl;
  int a, i, l, j;
  if(obj == -1) {
    if (brkword() == -1) {
      bprintf("Drop what?\n");
      return -1;
    }
    if ((cl = findclass(wordbuf)) != NULL) {
      dropall(cl);
      return 0;
    }
    if ((a = fobnc(wordbuf)) == -1) {
      bprintf("You don't have it.\n");
      return -1;
    }
  } else a = obj;

  l = ploc(mynum);

  if (ltstflg(l, LFL_ON_WATER) && !is_boat(onum(a))) 
  { bprintf("The %s sinks into the sea.\n", oname(a));
    l = Sea_Pit;
  }

  /*******************
   * SPECIAL EVENTS
   * PLX = mynum
   * OB  = a
   * LOC = l
   * MISC= D_NORMAL
   * event = E_ONDROP
   *******************/
  if (obj_fun(onum(a)) != NULL)
  {  param_s.plx = mynum;
     param_s.ob = a;
     param_s.loc = l;
     param_s.ret = 1;
     param_s.misc = D_NORMAL;
     obj_fun(onum(a))(E_ONDROP);
     if (param_s.ret != 1)
        return 0;
  }
  
  if (rom_fun(l) != NULL)
  {  param_s.plx = mynum;
     param_s.ob = a;
     param_s.loc = l;
     param_s.ret = 1;
     param_s.misc= D_NORMAL;
     rom_fun(l)(E_ONDROP);
     if (param_s.ret != 1)
       return 0;
     /* Fall through */
     l = param_s.loc;
  }

  for (j = 0; (i = pits[j++]) != -1;)
    if (oloc(i) == l)
      break;

  if (i >= 0 && !in_table(i,exception_pits)) 
  {
    bprintf("The %s disappears into the bottomless pit.....\n", oname(a));
    send_msg(ploc(mynum), 0, LVL_MIN, LVL_MAX, mynum, NOBODY,
	     "\001p%s\003 drops the %s into the pit.\n",
	     pname(mynum), oname(a));
    dropinpit(a);
    return 0;
  }
  else if (i >= 0 && in_table(i,exception_pits) ) 
  {
    bprintf("The %s disappears into the bottomless pit....."
	    "and hits bottom.\n", oname(a));
    send_msg(ploc(mynum), 0, LVL_MIN, LVL_MAX, mynum, NOBODY,
	     "\001p%s\003 drops the %s into the pit.\n",
	     pname(mynum), oname(a));
    l = Down_Catacomb_Pits;
    setoloc(a, l, IN_ROOM);	/* to spherical room in CATACOMB section */
    sendf(l, "Something falls to the ground.\n");
    return 0;
  }
  else if (ltstflg(l,LFL_DONATION))
  {  donate_object(a);
     return 0;
  }
  
  setoloc(a, l, IN_ROOM);
  send_msg(ploc(mynum), 0, LVL_MIN, LVL_MAX, mynum, NOBODY,
	   "\001p%s\003 drops the %s.\n", pname(mynum), oname(a));
  if ((l = (ploc(mynum))))
    bprintf("Ok\n");
  return 0;
}

void dropinpit(int o)
{
  int i;

  if (obj_fun(onum(o)) != NULL)
  {  param_s.plx = mynum;
     param_s.misc= D_INPIT;
     param_s.ret = 1;
     param_s.loc = ploc(mynum);
     obj_fun(onum(o))(E_ONDROP);
  }
 
  if (!otstbit(o,OFL_DONATED)) 
  {  setpscore(mynum, pscore(mynum) + ovalue(o));
     calib_player(mynum);
  }
  osetbit(o, OFL_DESTROYED);
  setoloc(o, pit_loc, IN_ROOM);

  if (otstbit(o, OFL_CONTAINER)) 
  {
      for (i = ofirst_obj(o); i != SET_END; i = onext_obj(o))
	if (iscontin(i, o)) 
        {
	    dropinpit(i);
        }
  }
}

/* List the objects at the current players location.
 */
void list_objects(int not_show,Boolean f)
{ int i, a;

  for (i = 0; i < lnumobs(ploc(mynum)); i++)
  {   a = lobj_nr(i, ploc(mynum));

/*      
      if (ishere(a) && (not_show == MAX_OFLAG || ltstflg(ploc(mynum),not_show) == f))
*/
      if (ishere(a) && (otstbit(a,not_show) == f || not_show == MAX_OFLAG))
      {  if (state(a) > 3)
           continue;
         if (!EMPTY(olongt(a,state(a))))
         {  if (otstbit(a, OFL_DESTROYED))
               bprintf("&+w--&*");
            oplong(a);
            cur_player->wd_it = oname(a);
         } 
         else if (plev(mynum) > LVL_COUNSEL)
             bprintf("&+w[&+wmarker&+w]&* %s\n",oname(a));
      }
  }
}

void dumpitems()
{
  dumpstuff(mynum, ploc(mynum));
  if (gotanything(mynum))
  {  bprintf("Dumping rest of your equipment in a pit.\n");
     dumpstuff(mynum, pit_loc);
  }
}

void dumpstuff(int n, int loc)
{
  int b;
  for (b = pfirst_obj(n); b != SET_END; b = pnext_obj(n))
    if (iscarrby(b, n)) {
      if (ltstflg(loc,LFL_DONATION))
        donate_object(b);
      else if (loc == pit_loc)
	dropinpit(b);
      else
	setoloc(b, loc, IN_ROOM);
    }
}

/* Set a players weapon. Sets both the carry-flag of the weapon and the
 * 'pweapon' entry for that player in the world. A negative value removes
 * any current weapon. Return True if a new weapon got set for the player,
 * else False.
 */
Boolean set_weapon(int plr, int wpn)
{
  int owpn, i;
  
  /* Erase any weapon we were already wielding:
   */
  if ((owpn = pwpn(plr)) != -1 && oloc(owpn) == plr) {
    if (ocarrf(owpn) == BOTH_BY)
      setcarrf(owpn, WORN_BY);
    else if (ocarrf(owpn) == WIELDED_BY)
      setcarrf(owpn, CARRIED_BY);
  }
  
  if (wpn < 0 || odamage(wpn) == 0 || ocarrf(wpn) < CARRIED_BY
      || oloc(wpn) != plr) {
    
    setpwpn(plr, -1);
    return False;
  }
  
  i = WIELDED_BY;
  
  if (ocarrf(wpn) == WORN_BY)  i = BOTH_BY;
  
  setpwpn(plr, wpn);
  setcarrf(wpn, i);
  
  return True;
}


void oplong(int x)
{
  char *t = olongt(x, state(x));
  
  if (!EMPTY(t)) {
    bprintf("%s\n", t);
  }
}


int gotanything(int x)
{
  int ct;
  
  for (ct = 0; ct < pnumobs(x); ct++) {
    
    if (iscarrby( pobj_nr(ct, x), x))  return 1;
  }
  
  return 0;
}


CLASS_DATA *findclass(char *n)
{
  CLASS_DATA *cl;
  
  for (cl = class_data; cl->class_name != NULL; cl++) {
    if (EQ(cl->class_name,n)) return cl;
  }
  return NULL;
}

static Boolean classmatch(int ob, CLASS_DATA *cl)
{
  register short st;
  
  return (cl == NULL ||
	  ((st = cl->class_state) < 0 || ((st == state(ob)) &&
					  otstmask(ob,cl->class_mask))));
}


/* Can player 'plyr' carry any more objects now ?
 * Amount of objects a player can carried is determined by the level of the
 * player, plus some standard. I Raised the plus bit so players can carry
 * more. -Marty
 */
Boolean cancarry(int plyr)
{
  int i, a;
  int num = 0;
  
  if (plev(plyr) >= LVL_APPREN || plyr >= max_players)
    return True;
  
  for (i = 0; i < pnumobs(plyr); i++) {
    
    a = pobj_nr(i, plyr);
    
    if (iscarrby(a, plyr) && !iswornby(a, plyr)) num++;
  }
  
  return num < plev(plyr) + 10;
}


int iswornby( int ob, int plr)
{
  return isworn(ob) && iscarrby(ob, plr);
}

/* Is object 'ob' available ?
 */
Boolean isavl(int ob)
{
  return ishere(ob) || iscarrby(ob, mynum);
}


/* Try to reset an object, return True on success.
 */
Boolean reset_object(int o)
{
  int loc=0;
  
  osetbaseval(o, ovalue_reset(o));
  osetsize(o, osize_reset(o));
  osetvis(o, ovis_reset(o));
  osetdamage(o, odamage_reset(o));
  osetarmor(o, oarmor_reset(o));
  state(o) = state_reset(o);

  obits(o).b1 = obits_reset(o).b1;
  obits(o).b2 = obits_reset(o).b2;
  obits(0).b3 = obits_reset(o).b3;

  loc = 0;
  if (!opermanent(o)) {
    if (ocarrf_reset(o) == IN_ROOM) {
      if ((loc = find_loc_by_id(oloc_reset(o))) == 0) {
	destroy(o);
	return False;
      }
    }
    else
      if (ocarrf_reset(o) == IN_CONTAINER) {
	if ((loc = find_object_by_id(oloc_reset(o))) < 0) {
	  destroy(o);
	  return False;
	}
      }
      else
	if (ocarrf_reset(o) >= CARRIED_BY) {
	  if ((loc = find_mobile_by_id(oloc_reset(o))) < 0) {
	    destroy(o);
	    return False;
	  }
	}
  } else {
    loc = oloc_reset(o);
    if (ocarrf_reset(o) >= CARRIED_BY) loc += max_players;
  }
  
  setoloc(o, loc, ocarrf_reset(o));
  
  return True;
}



void setobjstate(int obj, int state)
{
  if (state >= 0 && state <= omaxstate(obj)
      && (olinked(obj) == -1 || state <= omaxstate(olinked(obj)))) {
    
    state(obj) = state;
    
    if (olinked(obj) != -1) {
      state( olinked(obj) ) = state;
    }
    
  } else {
    mudlog( "Attempt to set object %s[%d] to state %d",
	   oname(obj), obj, state);
  }
}


void destroy(int ob)
{
  osetbit(ob, OFL_DESTROYED);
  setoloc(ob, destroyed_loc, IN_ROOM);
}

void eat(int ob)
{
  if (!opermanent(ob) && otemporary(ob)) {
    destruct_object(ob, NULL);
  }
  else {
    osetbit(ob, OFL_DESTROYED);
    setoloc(ob, eaten_loc, IN_ROOM);
  }
}

void create(int ob)
{
  oclrbit(ob, OFL_DESTROYED);
}


/* SET Object LOCation.
 */
void setoloc(int obj, int loc, int c)
{
  /* First remove the object from wherever it is:
   */
  switch( ocarrf(obj) ) {
  case IN_ROOM:
    if (exists(oloc(obj))) remove_int(obj, linv(oloc(obj)));
    break;
  case IN_CONTAINER:
    if (oloc(obj) >= 0 && oloc(obj) < numobs)
      remove_int(obj, oinv(oloc(obj)));
    break;
  case WIELDED_BY:
  case BOTH_BY:
       setpwpn(oloc(obj),-1);
  case CARRIED_BY:
  case WORN_BY:
    if (oloc(obj) >= 0 && oloc(obj) < numchars)
      remove_int(obj, pinv(oloc(obj)));
    break;
  }
  
  /* Then add it to the right place:
   */
  switch(c) {
  case IN_ROOM:
    if (exists(loc)) add_int(obj, linv(loc));
    break;
  case IN_CONTAINER:
    if (loc >= 0 && loc < numobs) add_int(obj, oinv(loc));
    break;
  case CARRIED_BY:
  case WORN_BY:
  case WIELDED_BY:
  case BOTH_BY:
    if (loc >= 0 && loc < numchars) add_int(obj, pinv(loc));
    break;
  }
  
  oloc(obj) = loc;
  ocarrf(obj) = c;
  
  if (c >= WIELDED_BY) set_weapon(loc, obj);
}


/* same as p_ohany, except only checks one oflag, no mask of the lower bits */
int p_ohanyflag(int plx, int flag)
{   int i, a;
    int lnum = lnumobs(ploc(plx));

    for (i = 0; i < lnum; i++)
    {  a = lobj_nr(i, ploc(plx));

       if (p_ishere(plx, a) && otstbit(a,flag))
           return a;
    }

    lnum = pnumobs(plx);

    for (i=0; i < lnum; i++)
    {   a = pobj_nr(i,plx);

        if (iscarrby(a,plx) && otstbit(a,flag))
          return a;
    }
    return -1;
}

/* is there an object, either carried by the player or in the same
 * room that satisfies certain criteria (determined by mask) ?
 */
Boolean p_ohany(int plr,int mask)
{
  int i, a;
  mask &= 0xffff;
  
  for (i = 0; i < lnumobs(ploc(plr)); i++) 
  {
    
    a = lobj_nr(i, ploc(plr));
    
    if (p_ishere(plr, a) && (obits(a).b1 & mask)) 
        return True;
  }
  
  for (i = 0; i < pnumobs(plr); i++) 
  {
    
    a = pobj_nr(i, plr);
    
    if (iscarrby(a, plr) && (obits(a).b1 & mask)) 
          return True;
  }
  
  return False;
}


Boolean ohany(int mask)
{
  return p_ohany(mynum,mask);
}

int ovalue(int ob)
{
  return (tscale() * obaseval(ob) / 9);
}


char *xdesloc(char *b, int loc, int cf)
{
  char k[256];
  char v[256];
  char buff[256];
  
  *buff = '\0';
  
  while (cf == IN_CONTAINER) {
    
    sprintf(v,"In the %s ", oname(loc));
    strcat(buff, v);
    cf = ocarrf(loc);
    loc = oloc(loc);
  }
  
  if (cf >= CARRIED_BY) {
    if (cf == CARRIED_BY) strcat(buff, "Carried");
    if (cf == WORN_BY)    strcat(buff, "Worn");
    if (cf == WIELDED_BY) strcat(buff, "Wielded");
    if (cf == BOTH_BY)    strcat(buff, "Worn & Wielded");
    sprintf(v," by %s ", see_name(mynum, loc));
    strcat(buff, v);
    loc = ploc(loc);
  }
  
  if (!exists(loc)) {
    if (plev(mynum) < LVL_GOD) return strcpy(b,"Out in the void");
    else {
      sprintf(b,"NOT IN UNIVERSE[%d]", loc);
      return b;
    }
  }
  
  if (*buff != '\0')  strcat(buff, "in ");
  
  if (plev(mynum) >= LVL_APPREN)
    sprintf(v, "| %s", xshowname(k,loc));
  else
    *v = '\0';
  
  strcat(buff, (const char*)sdesc(loc));
  
  sprintf(b,"%-40.40s%s", buff, v);
  
  return b;
}

void desloc(int loc, int cf)
{
  char b[512];
  
  bprintf("%s\n", xdesloc(b,loc,cf));
}

Boolean otstmask(int ob, int v)
{
  return tst_doublebit(&obits(ob),v); /*tstbits(obits(ob),v);*/
}


/* Will the container x hold object y ?
 */
Boolean willhold(int x, int y)
{
  int i, a, sum = 0;
  
  for (i = 0; i < onumobs(x); i++) {
    
    a = oobj_nr(i, x);
    
    if (iscontin(a, x)) sum += osize(a);
  }
  
  sum += osize(y);
  
  return sum <= osize(x);
}

int ohereandget(void)
{
  int obj;
  
  if (EMPTY(item1)) {
    bprintf("Tell me more?\n");
    return -1;
  }
  if ((obj = ob1) == -1) {
    bprintf("It isn't here.\n");
  }
  return obj;
}


/* plx drops the objects that he carries that are not worn or wielded,
 */
void drop_some_objects(int plx)
{
  int obj;
  
  for (obj = pfirst_obj(plx); obj != SET_END; obj = pnext_obj(plx)) {
    if (ocarrf(obj) == CARRIED_BY && oloc(obj) == plx) {
      setoloc(obj, ploc(plx), IN_ROOM);
    }
  }
}


char *xdesrm(char *b, int loc, int cf)
{
  char k[25];
  char v[30];
  
  if (plev(mynum) < LVL_APPREN && cf == IN_ROOM && loc == limbo_loc) {
    return strcpy(b,"Somewhere.....");
  }
  if (cf == IN_CONTAINER) {
    sprintf(b,"In the %s", oname(loc));
    return b;
  }
  if (cf >= CARRIED_BY) {
    if (!seeplayer(loc))
      return strcpy(b,"Somewhere.....");
    else {
      sprintf(b,"Carried by %s", pname(loc));
      return b;
    }
  }
  if (!exists(loc)) {
    if (plev(mynum) < LVL_ARCHWIZARD)
      return strcpy(b,"Out in the void");
    else {
      sprintf(b,"NOT IN UNIVERSE[%d]", loc);
      return b;
    }
  }
  if (plev(mynum) >= LVL_APPREN)
    sprintf(v, "| %s", xshowname(k,loc));
  else
    *v = 0;
  
  sprintf(b,"%-30s%s", sdesc(loc), v);
  return b;
}


void desrm(int loc, int cf)
{ char b[80];
  
  bprintf("%s\n", xdesrm(b,loc,cf));
}

void print_inventory(int who)
{
  
  int obj, len=0, xen, weapon=-1, found=0;
  char outline[256];
  int_set *inv = pinv(who);
 
  for (obj=first_obj(inv); obj!=SET_END; obj=next_obj(inv)) 
  {
    int started = 0;
    
    if (otstbit(obj, OFL_DESTROYED) && plev(mynum) < LVL_APPREN)
      continue;

    if (obj == pwpn(who) && iswielded(obj)) 
    {
      weapon = pwpn(who);
      continue;
    }

    sprintf (outline,"%s%s", otstbit(obj,OFL_DESTROYED) ? "(" : "",
             oname(obj));

    if (isworn(obj)) 
    {
      strcat (outline, " &+w<&+wworn&*");
      started = 1;
    }
    if (otstbit(obj, OFL_LIT)) 
    {
      if (!started)
        strcat (outline, " &+w<&*");
      else
        strcat (outline, ",");
      started = 1;
      strcat (outline, "&+wlit&*");
    }
    if (otstbit(obj,OFL_MAGICLIT))
    {
      if (!started)
        strcat (outline, " &+w<&*");
      else
        strcat (outline, ",");
      started = 1;
      strcat (outline, "&+wGlowing&+w");
    }
    if (started)
      strcat (outline, "&+w>&*");

    if (otstbit(obj,OFL_DESTROYED)) strcat(outline,")");
    
    xen = xstrlen(outline);
    if (!found) 
    {
      bprintf ("%s %s carrying:\n   %s", who == mynum ? "You" : he_or_she(who),
               who == mynum ? "are" : "is", outline);
      len = 3 + xen;
      found = 1;
    } 
    else if (len + xen+2 >= 75) 
    {
      bprintf (",\n   %s", outline);
      len = 3 + xen;
    } else {
      bprintf (", %s", outline);
      len += xen+2;
    }
  }
  
  if (found)
    bprintf ("\n");
  else if (who == mynum)
    bprintf ("You are not carrying anything.\n");
  
  if (found && (who == mynum || plev(mynum) >= LVL_APPREN)) 
  {
    int obj2;
    int_set *inv2;
    
    for (obj=first_obj(inv); obj!=SET_END; obj=next_obj(inv)) 
    {
      if (otstbit(obj, OFL_DESTROYED) && plev(mynum) < LVL_APPREN)
        continue;
      if (otstbit(obj, OFL_CONTAINER)) 
      {
        inv2 = oinv(obj);
        found = 0;
        for (obj2=first_obj(inv2); obj2!=SET_END; obj2=next_obj(inv2)) 
        { 
          if (oloc(obj2) != obj)   /* Dirty patch to container bug? */
            continue;
     
          if (otstbit(obj2, OFL_DESTROYED) && plev(mynum) < LVL_APPREN)
            continue;

          sprintf (outline, "%s%s%s", otstbit(obj2, OFL_DESTROYED) ? "(" : "",
                   oname(obj2), otstbit(obj2, OFL_DESTROYED) ? ")" : "");

          xen = xstrlen (outline);

          if (!found) 
          {
            bprintf ("   The %s contains:\n      %s", oname(obj), outline);
            len = 6 + xen;
            found = 1;
          } 
          else if (len + xen+2 >= 75) 
          {
            bprintf (",\n      %s", outline);
            len = 6 + xen;
          } 
          else 
          {
            bprintf (", %s", outline);
            len += xen+2;
          }
        }
        if (found)
          bprintf ("\n");
      }
    }
  }
  
  if (weapon != -1)
    bprintf("&+w%s %s %s %s drawn and ready for battle.&*\n",
            who == mynum ? "You" : pname(who), who == mynum ? "have" : "has",
            who == mynum ? "your" : his_or_her(who), oname(weapon));
}

A_COMMAND(equipcom)
{ int who;
  int weapon = -1, light = -1, olight = 0, found = 0;
  int num_ofl = WEAR_LAST - WEAR_OFFSET + 1,
  wornset[WEAR_LAST - WEAR_OFFSET + 1][10];
  int i, j, obj;
  int_set *inv;
  char *armorstr[] = {
   "You can better run for your life than starting a fight.",
   "Only a good prayer would help you in your fight.",
   "Pretty well armoured, for a rookie...",
   "With a bit of luck you can take on some baddies.",
   "You are averagely armoured.",
   "The armour will protect you from many blows, but not all.",
   "With this armor you might consider taking on some real meanies.",
   "Just a little more and you may call yourself a true warrior",
   "You will bring it far in battles, but not all the way.",
   "You are extremely well equipped.",
   "Your armor won't even be penetrated by the mightiest oponent."
  };

  if (EMPTY(item1))
    who = mynum;
  else if (pl1 == -1) 
  { bprintf ("No one with that name is playing.\n");
    return;
  } 
  else if (plev(mynum) < LVL_APPREN && ploc(pl1) != ploc(mynum)) 
  { bprintf ("%s's not here!\n", he_or_she(pl1));
    return;
  } 
  else
    who = pl1;
  
  inv = pinv(who);
  
  for (i=0; i<num_ofl; i++)
    for (j=0; j<10; j++)
      wornset[i][j] = -1;
  
  for (obj = first_obj(inv); obj != SET_END; obj = next_obj(inv))
    if (obj == pwpn(who) && iswielded(obj)) 
    { weapon = obj;
      found = 1;
    } 
    else if (isworn(obj)) 
    { for (i=0; i<num_ofl && !otstbit(obj,WEAR_OFFSET+i); i++);
      if (i >= num_ofl)
        mudlog ("case slip in equipcom, no match for wear type [obj: %d]",obj);
      else 
      { for (j=0; j<10 && wornset[i][j]!=-1; j++);

        if (j<10)
          wornset[i][j] = obj;
        found = 1;
      }
    } 
    else if (light == -1 && (otstbit(obj, OFL_LIT) || otstbit(obj, OFL_MAGICLIT))) 
    { light = obj;
      found = 1;
    }
  
  if (!found) 
  { bprintf ("%s %s nothing equipped.&*\n",
             who == mynum ? "You" : pname(who),
             who == mynum ? "have" : "has");
    return;
  }
  bprintf ("&+w%s %s equipped:&*\n",
           who == mynum ? "You" : pname(who),
           who == mynum ? "have" : "has");
  
  if (weapon != -1) 
  { bprintf ("&+w<wielded>&*          : %s", oname(weapon));
    if (otstbit(weapon, OFL_LIT) || otstbit(weapon,OFL_MAGICLIT)) {
      bprintf (" (providing light)");
      olight = 1;
    }
    bprintf ("\n");
  }
  for (i=0; i<num_ofl; i++)
    for (j=0; j<10 && wornset[i][j]!=-1; j++) 
    {
      int valid = 1;
      
      switch (i + WEAR_OFFSET) {
      case OFL_WEARONHEAD:
        bprintf ("&+w<&*worn on head&+w>&*     : ");
        break;
      case OFL_WEARONFACE:
        bprintf ("&+w<&*worn over face&+w>&*   : ");
        break;
      case OFL_WEARONNECK:
        bprintf ("&+w<&*worn around neck&+w>&* : ");
        break;
      case OFL_WEARONARMS:
        bprintf ("&+w<&*worn on arms&+w>&*     : ");
        break;
      case OFL_WEARONHANDS:
        bprintf ("&+w<&*worn on hands&+w>&*    : ");
        break;
      case OFL_WEARONBODY:
        bprintf ("&+w<&+wworn on body&+w>&*     : ");
        break;
      case OFL_WEARONBACK:
        bprintf ("&+w<&+wworn over back&+w>&*   : ");
        break;
      case OFL_WEARONLEGS:
        bprintf ("&+w<&+wworn on legs&+w>&*     : ");
        break;
      case OFL_WEARONFEET:
        bprintf ("&+w<&+wworn on feet&+w>&*     : ");
        break;
      default:
        mudlog ("case slip in equipcom %s [%d]",oname(wornset[i][j]),wornset[i][j]);
        valid = 0;
      }
      if (valid) 
      {
        bprintf ("%s", oname(wornset[i][j]));
        if (otstbit(wornset[i][j], OFL_LIT)) 
        {
          bprintf (" &+w(providing light)&*");
          olight = 1;
        }
        if (otstbit(wornset[i][j],OFL_MAGICLIT))
        {  bprintf(" &+w(&+wmagically lit&+w)&*");
           olight = 1;
        }
        bprintf ("\n");
      }
    }
  if (light != -1 && !olight)
    bprintf ("&+w<providing light>&*  : %s\n", oname(light));

  i = player_armor(mynum) / 5;
  if (i > 10)
    i = 10;
  else if (i < 0)
    i = 0;
  bprintf("\nArmor Summary : %s\n",armorstr[i]);
}

A_COMMAND(lockcom)
{
  if (ob1 == -1)
  {  bprintf("Lock what?\n");
     return;
  }

  if (obj_fun(ob1) != NULL)
  {  param_s.ret = 1;
     param_s.ob = ob1;
     param_s.plx = mynum;
     param_s.loc = ploc(mynum);
     obj_fun(ob1)(E_ONLOCK);
     if (param_s.ret != 1)
       return;
  }
  if (!otstbit(ob1, OFL_LOCKABLE))
    bprintf("You can't lock that!\n");
  else if (state(ob1) > 1)
    bprintf("It's already locked.\n");
  else if (!ohany (1<<OFL_KEY))
    bprintf("You have no key.\n");
  else
  {  setobjstate(ob1, 2);

     if (oloc(ob1) == ploc(mynum))
        send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
              "\001p%s\003 locks the %s.\n",pname(mynum),oname(ob1));

     bprintf("OK.\n");
  }
}

A_COMMAND(unlockcom)
{
  if (ob1 == -1)
    {
      bprintf("What do you want to unlock?\n");
      return;
    }
  if (obj_fun(ob1) != NULL)
  {  param_s.ret = 1;
     param_s.ob  = ob1;
     param_s.plx = mynum;
     param_s.loc = ploc(ob1);
     obj_fun(ob1)(E_ONUNLOCK);
     if (param_s.ret != 1)
       return;
  }
  if (!otstbit(ob1, OFL_LOCKABLE))
     bprintf("You can't unlock that!\n");
  else if (state(ob1) == 1)
     bprintf("It's already unlocked.\n");
  else if (!ohany (1<<OFL_KEY))
     bprintf("You have no key.\n");
  else
  {  setobjstate(ob1, 1);

     if (oloc(ob1) == ploc(mynum))
        send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
              "\001p%s\003 unlocks the %s.\n",pname(mynum),oname(ob1));

     bprintf("Ok.\n");
  }
}

A_COMMAND(closecom)
{
  if (ob1 == -1)
    {
      bprintf("What would you like to close?\n");
      return;
    }
  if (obj_fun(ob1) != NULL)
  {  param_s.ob = ob1;
     param_s.ret= 1;
     param_s.plx= mynum;
     param_s.loc= ploc(mynum);
     obj_fun(ob1)(E_ONCLOSE);
     if (param_s.ret != 1)
       return;
  }
  
  if (!otstbit (ob1, OFL_OPENABLE))
     bprintf("You can't close that!\n");
  else if (state(ob1) > 0)
     bprintf("It's already closed.\n");
  else
  {  setobjstate(ob1, 1);
     bprintf("You close the %s.\n",oname(ob1));

     if (oloc(ob1) == ploc(mynum))
        send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
              "\001p%s\003 closes the %s.\n",pname(mynum),oname(ob1));
  }
}

A_COMMAND(opencom)
{
  char *cant_open ="You can't open that!\n";
  if (ob1 == -1)
    {
      bprintf("What would you like to open?\n");
      return;
    }
  
  if (obj_fun(onum(ob1)) != NULL)
  {   param_s.ob = ob1;
      param_s.ret= 1;
      param_s.plx= mynum;
      param_s.loc = ploc(mynum);
      obj_fun(ob1)(E_ONOPEN);
      if (param_s.ret != 1)
        return;
  }

  if (!otstbit (ob1, OFL_OPENABLE))
      bprintf(cant_open);
  else if (state(ob1) == 0)
      bprintf("It's already open.\n");
  else if (state(ob1) == 1)
  {   bprintf("You open the %s.\n", oname(ob1));
        
      if (oloc(ob1) == ploc(mynum))
          send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
              "\001p%s\003 opens the %s.\n",pname(mynum),oname(ob1));

      setobjstate(ob1, 0);
  }
  else if (state(ob1) == 2)
  {
     if (!ohany (1<<OFL_KEY))
        bprintf("It seems to be locked.\n");
     else
     {  bprintf("Ok.\n");

        if (oloc(ob1) == ploc(mynum))
          send_msg(ploc(mynum),MODE_NOBLIND,LVL_MIN,LVL_MAX,mynum,NOBODY,
              "\001p%s\003 opens the %s.\n",pname(mynum),oname(ob1));

        setobjstate(ob1, 0);
     }
  }
  else
     bprintf(cant_open);
}

A_COMMAND(wearall)
{ int reg[1024], arm[1024], reg_len = 0, arm_len = 0;
  int ob;
 
  if (psitting(mynum) == 2)
  {  bprintf("You roll around in your sleepingbag.\n");
     return;
  } 
  if (psitting(mynum) == 3)
  {  bprintf("You make some impressive Tai-Chi movements.\n");
     return;
  } 
  /* Can't this be something like obj_num? */
  for(ob = 0; ob < numobs; ob++)
    if(in_inventory(ob, mynum) && is_wearable(ob) && !iswornby(ob, mynum))
    { if(otstbit(ob, OFL_ARMOR)) 
         arm[arm_len++] = ob;
      else 
         reg[reg_len++] = ob;
    }
  
  /*  qsort(reg, reg_len, sizeof(int), cmp_reg_obj);
   *  qsort(arm, arm_len, sizeof(int), cmp_arm_obj);   :P Rex
   */ 
  for(ob = 0; ob < arm_len; ob++)
  {  if ((player_armor(mynum) + oarmor(ob)) > MAX_ARMOR)
     {   bprintf("Your armor is completely maxed out.\n");
         return;
     }
     trywear(arm[ob], False);
  }   
  for(ob = 0; ob < reg_len; ob++)
    trywear(reg[ob], False);
}

Boolean carrobjfrom(int plr, const int *table)
{   int i;

    for (i=0; table[i] != -1; i++)
        if (carries_obj_type(plr,table[i]) > -1)
           return True;

    return False;
}

Boolean wearsobjfrom(int plr,const int *table)
{   int i;

    for (i=0; table[i] != -1; i++)
        if (iswornby(table[i],plr))
           return True;

    return False;
}