skylib_fluffos_v3/
skylib_fluffos_v3/bin/
skylib_fluffos_v3/bin/db/
skylib_fluffos_v3/fluffos-2.9-ds2.04/
skylib_fluffos_v3/fluffos-2.9-ds2.04/ChangeLog.old/
skylib_fluffos_v3/fluffos-2.9-ds2.04/Win32/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/simuls/
skylib_fluffos_v3/fluffos-2.9-ds2.04/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/clone/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/command/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/data/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/etc/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/master/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/log/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/compiler/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/efuns/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/operators/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/u/
skylib_fluffos_v3/fluffos-2.9-ds2.04/tmp/
skylib_fluffos_v3/fluffos-2.9-ds2.04/windows/
skylib_fluffos_v3/mudlib/
skylib_fluffos_v3/mudlib/cmds/
skylib_fluffos_v3/mudlib/cmds/admin/
skylib_fluffos_v3/mudlib/cmds/guild-race/
skylib_fluffos_v3/mudlib/cmds/living/broken/
skylib_fluffos_v3/mudlib/cmds/player/group_cmds/
skylib_fluffos_v3/mudlib/cmds/playtester/
skylib_fluffos_v3/mudlib/d/admin/
skylib_fluffos_v3/mudlib/d/admin/room/
skylib_fluffos_v3/mudlib/d/admin/room/we_care/
skylib_fluffos_v3/mudlib/d/admin/save/
skylib_fluffos_v3/mudlib/d/admin/text/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/buildings/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/map/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/roads/
skylib_fluffos_v3/mudlib/d/learning/chars/
skylib_fluffos_v3/mudlib/d/learning/functions/
skylib_fluffos_v3/mudlib/d/learning/handlers/
skylib_fluffos_v3/mudlib/d/learning/help_topics/
skylib_fluffos_v3/mudlib/d/learning/help_topics/npcs/
skylib_fluffos_v3/mudlib/d/learning/help_topics/objects/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/RCS/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/crowd/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/situations/
skylib_fluffos_v3/mudlib/d/learning/save/
skylib_fluffos_v3/mudlib/d/learning/school/
skylib_fluffos_v3/mudlib/d/learning/school/add_sc/
skylib_fluffos_v3/mudlib/d/learning/school/characters/
skylib_fluffos_v3/mudlib/d/learning/school/general/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/basic_commands/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/edtutor/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/unix_tutor/
skylib_fluffos_v3/mudlib/d/learning/school/items/
skylib_fluffos_v3/mudlib/d/learning/school/npc_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/room_basic/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/situations/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/terrain_tutor/
skylib_fluffos_v3/mudlib/d/learning/text/
skylib_fluffos_v3/mudlib/d/liaison/
skylib_fluffos_v3/mudlib/d/mudlib/
skylib_fluffos_v3/mudlib/d/mudlib/changes/
skylib_fluffos_v3/mudlib/d/playtesters/
skylib_fluffos_v3/mudlib/d/playtesters/effects/
skylib_fluffos_v3/mudlib/d/playtesters/handlers/
skylib_fluffos_v3/mudlib/d/playtesters/items/
skylib_fluffos_v3/mudlib/d/sage/
skylib_fluffos_v3/mudlib/doc/
skylib_fluffos_v3/mudlib/doc/creator/
skylib_fluffos_v3/mudlib/doc/driver/
skylib_fluffos_v3/mudlib/doc/driver/efuns/arrays/
skylib_fluffos_v3/mudlib/doc/driver/efuns/buffers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/calls/
skylib_fluffos_v3/mudlib/doc/driver/efuns/compile/
skylib_fluffos_v3/mudlib/doc/driver/efuns/filesystem/
skylib_fluffos_v3/mudlib/doc/driver/efuns/floats/
skylib_fluffos_v3/mudlib/doc/driver/efuns/functions/
skylib_fluffos_v3/mudlib/doc/driver/efuns/general/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mappings/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mixed/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mudlib/
skylib_fluffos_v3/mudlib/doc/driver/efuns/numbers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/parsing/
skylib_fluffos_v3/mudlib/doc/login/
skylib_fluffos_v3/mudlib/doc/lpc/basic_manual/
skylib_fluffos_v3/mudlib/doc/lpc/intermediate/
skylib_fluffos_v3/mudlib/doc/new/add_command/
skylib_fluffos_v3/mudlib/doc/new/events/
skylib_fluffos_v3/mudlib/doc/new/handlers/
skylib_fluffos_v3/mudlib/doc/new/living/race/
skylib_fluffos_v3/mudlib/doc/new/living/spells/
skylib_fluffos_v3/mudlib/doc/new/object/
skylib_fluffos_v3/mudlib/doc/new/player/
skylib_fluffos_v3/mudlib/doc/new/room/guild/
skylib_fluffos_v3/mudlib/doc/new/room/outside/
skylib_fluffos_v3/mudlib/doc/new/room/storeroom/
skylib_fluffos_v3/mudlib/doc/object/
skylib_fluffos_v3/mudlib/doc/playtesters/
skylib_fluffos_v3/mudlib/doc/policy/
skylib_fluffos_v3/mudlib/doc/weapons/
skylib_fluffos_v3/mudlib/global/
skylib_fluffos_v3/mudlib/global/creator/
skylib_fluffos_v3/mudlib/handlers/
skylib_fluffos_v3/mudlib/include/casino/
skylib_fluffos_v3/mudlib/include/cmds/
skylib_fluffos_v3/mudlib/include/effects/
skylib_fluffos_v3/mudlib/include/npc/
skylib_fluffos_v3/mudlib/include/room/
skylib_fluffos_v3/mudlib/include/shops/
skylib_fluffos_v3/mudlib/net/daemon/
skylib_fluffos_v3/mudlib/net/daemon/chars/
skylib_fluffos_v3/mudlib/net/inherit/
skylib_fluffos_v3/mudlib/net/obj/
skylib_fluffos_v3/mudlib/net/obj/BACKUPS/
skylib_fluffos_v3/mudlib/obj/amulets/
skylib_fluffos_v3/mudlib/obj/armours/plate/
skylib_fluffos_v3/mudlib/obj/b_day/
skylib_fluffos_v3/mudlib/obj/clothes/transport/horse/
skylib_fluffos_v3/mudlib/obj/faith/symbols/
skylib_fluffos_v3/mudlib/obj/fungi/
skylib_fluffos_v3/mudlib/obj/gatherables/
skylib_fluffos_v3/mudlib/obj/instruments/
skylib_fluffos_v3/mudlib/obj/media/
skylib_fluffos_v3/mudlib/obj/misc/player_shop/
skylib_fluffos_v3/mudlib/obj/monster/godmother/
skylib_fluffos_v3/mudlib/obj/monster/transport/
skylib_fluffos_v3/mudlib/obj/rings/
skylib_fluffos_v3/mudlib/obj/scabbards/
skylib_fluffos_v3/mudlib/obj/spells/
skylib_fluffos_v3/mudlib/obj/stationery/
skylib_fluffos_v3/mudlib/obj/stationery/envelopes/
skylib_fluffos_v3/mudlib/obj/toys/
skylib_fluffos_v3/mudlib/obj/vessels/
skylib_fluffos_v3/mudlib/obj/weapons/axes/
skylib_fluffos_v3/mudlib/obj/weapons/chains/
skylib_fluffos_v3/mudlib/obj/weapons/maces/BACKUPS/
skylib_fluffos_v3/mudlib/save/autodoc/
skylib_fluffos_v3/mudlib/save/book_handler/
skylib_fluffos_v3/mudlib/save/books/history/calarien/
skylib_fluffos_v3/mudlib/save/mail/
skylib_fluffos_v3/mudlib/save/new_soul/data/
skylib_fluffos_v3/mudlib/save/parcels/
skylib_fluffos_v3/mudlib/save/playerinfo/
skylib_fluffos_v3/mudlib/save/players/d/
skylib_fluffos_v3/mudlib/save/players/s/
skylib_fluffos_v3/mudlib/save/random_names/
skylib_fluffos_v3/mudlib/save/random_names/data/
skylib_fluffos_v3/mudlib/save/terrains/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_desert/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_grassy_field/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_mountain/
skylib_fluffos_v3/mudlib/save/todo_lists/
skylib_fluffos_v3/mudlib/secure/
skylib_fluffos_v3/mudlib/secure/cmds/admin/
skylib_fluffos_v3/mudlib/secure/cmds/lord/
skylib_fluffos_v3/mudlib/secure/config/
skylib_fluffos_v3/mudlib/secure/handlers/autodoc/
skylib_fluffos_v3/mudlib/secure/handlers/intermud/
skylib_fluffos_v3/mudlib/secure/include/global/
skylib_fluffos_v3/mudlib/secure/save/
skylib_fluffos_v3/mudlib/secure/save/handlers/
skylib_fluffos_v3/mudlib/secure/std/
skylib_fluffos_v3/mudlib/secure/std/classes/
skylib_fluffos_v3/mudlib/secure/std/modules/
skylib_fluffos_v3/mudlib/std/creator/
skylib_fluffos_v3/mudlib/std/dom/
skylib_fluffos_v3/mudlib/std/effects/
skylib_fluffos_v3/mudlib/std/effects/external/
skylib_fluffos_v3/mudlib/std/effects/fighting/
skylib_fluffos_v3/mudlib/std/effects/magic/
skylib_fluffos_v3/mudlib/std/effects/magic/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/other/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/priest/
skylib_fluffos_v3/mudlib/std/effects/room/
skylib_fluffos_v3/mudlib/std/environ/
skylib_fluffos_v3/mudlib/std/guilds/
skylib_fluffos_v3/mudlib/std/guilds/old/
skylib_fluffos_v3/mudlib/std/languages/
skylib_fluffos_v3/mudlib/std/liquids/
skylib_fluffos_v3/mudlib/std/npc/
skylib_fluffos_v3/mudlib/std/npc/goals/
skylib_fluffos_v3/mudlib/std/npc/goals/basic/
skylib_fluffos_v3/mudlib/std/npc/goals/misc/
skylib_fluffos_v3/mudlib/std/npc/plans/
skylib_fluffos_v3/mudlib/std/npc/plans/basic/
skylib_fluffos_v3/mudlib/std/npc/types/
skylib_fluffos_v3/mudlib/std/npc/types/helper/
skylib_fluffos_v3/mudlib/std/npcs/
skylib_fluffos_v3/mudlib/std/outsides/
skylib_fluffos_v3/mudlib/std/races/shadows/
skylib_fluffos_v3/mudlib/std/room/basic/BACKUPS/
skylib_fluffos_v3/mudlib/std/room/basic/topography/
skylib_fluffos_v3/mudlib/std/room/controller/
skylib_fluffos_v3/mudlib/std/room/inherit/topography/
skylib_fluffos_v3/mudlib/std/room/topography/area/
skylib_fluffos_v3/mudlib/std/room/topography/iroom/
skylib_fluffos_v3/mudlib/std/room/topography/milestone/
skylib_fluffos_v3/mudlib/std/shadows/curses/
skylib_fluffos_v3/mudlib/std/shadows/disease/
skylib_fluffos_v3/mudlib/std/shadows/fighting/
skylib_fluffos_v3/mudlib/std/shadows/healing/
skylib_fluffos_v3/mudlib/std/shadows/magic/
skylib_fluffos_v3/mudlib/std/shadows/poison/
skylib_fluffos_v3/mudlib/std/shadows/room/
skylib_fluffos_v3/mudlib/std/shops/controllers/
skylib_fluffos_v3/mudlib/std/shops/objs/
skylib_fluffos_v3/mudlib/std/shops/player_shop/
skylib_fluffos_v3/mudlib/std/socket/
skylib_fluffos_v3/mudlib/std/soul/d/
skylib_fluffos_v3/mudlib/std/soul/e/
skylib_fluffos_v3/mudlib/std/soul/i/
skylib_fluffos_v3/mudlib/std/soul/j/
skylib_fluffos_v3/mudlib/std/soul/k/
skylib_fluffos_v3/mudlib/std/soul/l/
skylib_fluffos_v3/mudlib/std/soul/n/
skylib_fluffos_v3/mudlib/std/soul/o/
skylib_fluffos_v3/mudlib/std/soul/q/
skylib_fluffos_v3/mudlib/std/soul/r/
skylib_fluffos_v3/mudlib/std/soul/u/
skylib_fluffos_v3/mudlib/std/soul/v/
skylib_fluffos_v3/mudlib/std/soul/y/
skylib_fluffos_v3/mudlib/std/soul/z/
skylib_fluffos_v3/mudlib/std/stationery/
skylib_fluffos_v3/mudlib/w/
skylib_fluffos_v3/mudlib/w/default/
skylib_fluffos_v3/mudlib/w/default/armour/
skylib_fluffos_v3/mudlib/w/default/clothes/
skylib_fluffos_v3/mudlib/w/default/item/
skylib_fluffos_v3/mudlib/w/default/npc/
skylib_fluffos_v3/mudlib/w/default/room/
skylib_fluffos_v3/mudlib/w/default/weapon/
skylib_fluffos_v3/mudlib/www/
skylib_fluffos_v3/mudlib/www/java/
skylib_fluffos_v3/mudlib/www/secure/
skylib_fluffos_v3/mudlib/www/secure/lpc/advanced/
skylib_fluffos_v3/mudlib/www/secure/lpc/intermediate/
skylib_fluffos_v3/win32/
/**
 * This class keeps track of whether things are open or closed,
 * locked or unlocked.  Trap functions that are triggered when
 * an object is opened or unlocked are also handled.  When
 * you need an object that is locked you should remember to
 * use set_key() and set_difficulty().  When cloning an object
 * and moving other objects inside it you should remember to
 * make sure the object is open before moving things into it,
 * and then close it if neccessary.
 *
 * @author Gototh
 */
#include <move_failures.h>

#define MAX_INVENT 40
#define C_CLOSED 1
#define C_TRANS 2
#define C_OPAQUE 1

#define LOCKED        1
#define CLOSED        2
#define CLOSED_LOCKED 3

int do_lock(object *obs);
int do_unlock(object *obs);

private int _locked;
private int _closed;

private string _pick_skill;

private nosave int _unlockable;
private nosave int _stuck;
private nosave int _trans;
private nosave int _difficulty;
private nosave int _autolock;

private nosave string _trap_open_func;
private nosave string _trap_lock_func;

private nosave object _trap_open_ob;
private nosave object _trap_lock_ob;

private nosave mixed _key;

/**
 * @ignore yes
 */
void create() {
  _difficulty = 5;
  _pick_skill = "covert.lockpick.doors";
} /* create() */

/**
 * This sets the object as being open.  Note that to find out
 * if an object is open we use query_closed() which will return
 * 0 if the object is open.
 *
 * @see set_closed()
 * @see query_closed()
 */

void set_open() {
  if(_closed)
    if(environment())
      event(({environment(), TO}), "open", TP);
    else if(TO->query_my_room())
      event(({ TO->query_my_room(), TO}), "open", TP);

  _closed = 0;
  _locked = 0;
} /* set_open() */

/**
 * This sets the object as being closed.  If you are moving
 * objects into the object, make sure that you do not set
 * the object as closed and then try to move the objects in.
 * Move the objects in and then close the object.
 *
 * @see set_open()
 * @see query_closed()
 */

void set_closed() {
  if(!_closed)
    if(environment())
      event(({environment(), TO}), "close", TP);
    else if(TO->query_my_room())
      event(({ TO->query_my_room(), TO }), "close", TP);

  _closed = 1;
} /* set_closed() */

/**
 * This function tells you whether an object is open or closed.
 * It returns 1 if the object is closed, and 0 if the object is open.
 *
 * @return Return 1 if closed, 0 if open.
 * @see set_open()
 * @see set_closed()
 */
int query_closed() { return _closed; }

/**
 * This function tells you whether an object is open or closed.
 * It returns 1 if the object is open and 0 if the object is closed.
 *
 * @return Return 1 if open, 0 if closed.
 * @see set_open()
 * @see set_closed()
 */
int query_open() { return !_closed; }

/**
 * This sets the object as being locked.  Remember to set the
 * object as being closed before using this.  In most cases you
 * should probably use set_key() to set the key which opens the
 * lock and use set_difficulty() to set the skill level required
 * to pick the lock.
 *
 * @see set_open()
 * @see set_closed()
 * @see set_key()
 * @see set_difficulty()
 */

void set_locked() {
  if(_closed) {
    if(!_locked)
      if(environment())
        event(({environment(), TO}), "lock", TP);
      else if(TO->query_my_room())
        event(({TO->query_my_room(), TO}), "lock", TP);

    _locked = 1;
  }
} /* set_locked() */

/**
 * This sets the object as being unlocked.
 *
 * @see set_locked()
 */

void set_unlocked() {
  if(_locked)
    if(environment())
      event(({environment(), TO}), "unlock", TP);
    else if(TO->query_my_room())
      event(({TO->query_my_room(), TO}), "unlock", TP);

  _locked = 0;
} /* set_unlocked() */

/**
 * This tells us whether an object is locked.  It returns 1 if
 * the object is locked and 0 is the object is unlocked.
 *
 * @see set_locked()
 * @see set_unlocked()
 * @return Return 1 if locked and 0 if unlocked.
 */
int query_locked() { return _locked; }

/**
 * This tells us whether an object is unlocked.  It returns 1 if
 * the object is unlocked and 0 is the object is locked.
 *
 * @see set_locked()
 * @see set_unlocked()
 * @return Return 1 if unlocked and 0 if locked.
 */
int query_unlocked() { return !_locked; }

/**
 * This sets the object so that it will lock automatically when closed.
 */
void set_autolock(int number) { _autolock = number; }

/**
 * This tells us whether an object will lock automatically when closed.
 *
 * @see set_autolock()
 * @return 1 for true 0 for false;
 */
int query_autolock() { return _autolock; }

/**
 * This method makes the object unlockable.
 * @param 1 for unlockable, 0 for lockable
 */
void set_unlockable(int number) { _unlockable = number; }

/**
 * This tells us whether the object can be locked or not.
 * @see set_autolock()
 * @return 1 for true 0 for false;
 */
int query_unlockable() { return _unlockable; }

/**
 * This sets the property of the key that will unlock the object. This can
 * be a string, or a function pointer which will evaluate to a string.
 *
 * @see set_locked()
 * @param val The property the key must have to unlock the object.
 */
void set_key( mixed val ) {
  if( stringp(val) || functionp(val) )
    _key = val;
} /* set_key() */

/**
 * This returns the property of the key that will unlock the
 * object.
 *
 * @see set_key()
 */
string query_key() {
  if( stringp(_key) )
    return _key;
  if( functionp(_key) )
    return evaluate( _key );
  return 0;
} /* query_key() */

/**
 * This sets the skill that will be used when attempting to
 * pick the lock.  By default it is set to "covert.lockpick.safes"
 * so it need only be changed if you want to check a different
 * skill.
 *
 * @see query_pick_skill()
 * @see set_difficulty()
 * @param str The skill to use when picking the lock.
 */

void set_pick_skill(string str) {
  _pick_skill = str;
} /* set_pick_skill() */

/**
 * This returns the name of the skill which is used when
 * determining if the object can be unlocked.
 *
 * @see set_pick_skill()
 */

string query_pick_skill() {
  return _pick_skill;
} /* query_pick_skill() */

/**
 * This sets how difficult the lock on an object is to pick.
 * By default it is set to 200.
 *
 * @see query_difficulty()
 * @param i The difficulty of the lock to pick.
 */

void set_difficulty(int i) {
  _difficulty = i;
} /* set_difficulty() */

/**
 * This returns the difficulty picking the lock on the object.
 * By default it is set to 200 unless it has been changed with
 * set_difficulty().
 *
 * @see set_difficulty()
 */

int query_difficulty() {
  return _difficulty;
} /* query_difficulty() */

/**
 * This can set an object as being stuck, or make it unstuck.
 * Stuck objects cannot be opened, closed, locked or unlocked.
 * Using set_stuck(1) will make the object stuck, and set_stuck(0)
 * will unstick it.
 *
 * @see query_stuck()
 * @param i Use 1 to make the object stuck, and 0 to unstick it.
 */

void set_stuck(int i) {
  _stuck = i;
} /* set_stuck() */

/**
 * This tells you whether an object is stuck or not.  It will
 * return 1 if the object is stuck, and 0 if the object is not
 * stuck.
 *
 * @see set_stuck()
 * @return Return 1 if the object is stuck, and 0 if it is not.
 */

int query_stuck() {
  return _stuck;
} /* query_stuck() */

/**
 * This sets the object as being transparent.
 * A transparent object is one in which you can see the
 * inventory even if it is closed.
 *
 * @see reset_transparent()
 * @see query_transparent()
 */

void set_transparent() {
  _trans = C_TRANS;
} /* set_transparent() */

/**
 * This method removes the current objects transparent
 * status.
 * A transparent object is one in which you can see the
 * inventory even if it is closed.  This is also
 * used for light propogration.
 *
 * @see set_transparent()
 * @see query_transparent()
 */

void reset_transparent() {
  _trans = 0;
} /* reset_transparent() */

/**
 * This method returns the current transparent
 * value of the object.
 * A transparent object is one in which you can see the
 * inventory even if it is closed.  This is also
 * used for light propogration.
 *
 * @see reset_transparent()
 * @see query_transparent()
 * @return 1 if the object is transparent
 */

int query_transparent() {
  return _trans;
} /* query_transparent() */

/**
 * This sets the function to be called when someone attempts to
 * open the object.  The function does not have to be in the
 * object's file, and can be specified using the 'ob' paramater.
 * In most cases the function will be stored in the same file,
 * so use TO in these cases.
 *
 * The function will be called with a single string parameter of "open" or
 * "close"
 *
 * @param ob The object in which the function is stored.
 * @param func The function to be called.
 * @see query_open_trap_func()
 * @see query_open_trap_ob()
 */

void set_open_trap(object ob, string func) {
  _trap_open_func =  func;
  _trap_open_ob = ob;
} /* set_open_trap() */

/**
 * This returns the name of the function to be called when
 * someone tries to open the object.
 *
 * @return The function to be called when the object is opened.
 * @see set_open_trap()
 * @see query_open_trap_ob()
 */

string query_open_trap_func() {
  return _trap_open_func;
} /* query_open_trap_func() */

/**
 * This returns the object on which the trap function is stored.
 * The trap function is called when someone tries to open the
 * the object.
 *
 * @return The function to be called when the object is opened.
 * @see set_open_trap()
 * @see query_open_trap_func()
 */

object query_open_trap_ob() {
  return _trap_open_ob;
} /* query_open_trap_ob() */

/**
 * This sets the function to be called when someone attempts to
 * unlock the object.  The function does not have to be in the
 * object's file, and can be specified using the 'ob' paramater.
 * In most cases the function will be stored in the same file,
 * so use TO in these cases.
 *
 * The function will be called with a single string parameter of "lock",
 * "unlock" or "pick"
 *
 * @param ob The object in which the function is stored.
 * @param func The function to be called.
 * @see query_lock_trap_func()
 * @see query_lock_trap_ob()
 */
void set_lock_trap(object ob, string func) {
  _trap_lock_func = func;
  _trap_lock_ob = ob;
} /* set_unlock_trap() */

/**
 * This returns the name of the function to be called when
 * some attempts to unlock the object.
 *
 * @return The function to be called when someone attempts
 * to unlock the object.
 * @see set_open_trap()
 * @see query_open_trap_ob()
 */

string query_lock_trap_func() {
  return _trap_lock_func;
} /* query_lock_trap_func() */

/**
 * This returns the object on which the trap function is stored.
 * The trap function is called when someone tries to unlock the
 * the object.
 *
 * @return The function to be called when the object is opened.
 * @see set_open_trap()
 * @see query_open_trap_func()
 */

object query_lock_trap_ob() {
  return _trap_lock_ob;
} /* query_lock_trap_ob() */

/**
 * This method returns the closed and locked status.  The status is
 * 0 if open and unlocked, 1 if locked, 2 if closed and 3 if closed
 * and locked.
 * @return closed and locked status
 */
int query_closed_locked_status() {
   if (_closed && _locked) {
      return CLOSED_LOCKED;
   }
   if (_closed) {
      return CLOSED;
   }
   if (_locked) {
      return LOCKED;
   }
   return 0;
} /* query_closed_locked_status() */

/**
 * @ignore yes
 */

void init() {
  add_command("open");
  add_command("close");
  if( _key ) {
      add_command("lock");
      add_command("unlock");
      add_command("lock", "with <indirect:object:me>", (: do_lock($1) :) );
      add_command("unlock", "with <indirect:object:me>", (: do_unlock($1) :) );
  }
} /* init() */

/**
 * @ignore yes
 */

string short_status() {
  return "";
} /* short_status() */

/**
 * @ignore yes
 */

string long_status() {
  // If it is stuck in one state don't bother telling us the state.
  if (query_stuck())
    return "";

  switch (query_closed_locked_status()) {
  case CLOSED_LOCKED :
    return "It is closed and locked.\n";
  case CLOSED :
    return "It is closed.\n";
  default :
    return "It is open.\n";
  }
} /* long_status() */

/**
 * @ignore yes
 */
int do_unlock(object *obs) {
  if(!_locked || _stuck || !_closed || !_key) {
    if(!_locked)
      TP->add_failed_mess(TO,
      "$D $V$0=isn't,aren't$V$ locked.\n", ({ }));
    else if(_stuck)
      TP->add_failed_mess(TO,
      "$D $V$0=is,are$V$ stuck.\n", ({ }));
    else if(!_closed)
      TP->add_failed_mess(TO,
      "$D $V$0=isn't,aren't$V$ closed.\n", ({ }));
    else if(!_key)
      TP->add_failed_mess(TO,
      "$D $V$0=doesn't,don't$V$ have a key.\n", ({ }));
    return 0;
  }

  if( query_key() != "by hand") {
    if(!sizeof(obs))
      obs = all_inventory(TP);

    obs = filter_array(obs, (: $1->query_property( $2 ) :), query_key() );

    if(sizeof(obs)) {
      obs[0]->use_key(TO);
    } else {
      return 0;
    }
  }

  if(_trap_lock_func && _trap_lock_ob) {
    if(!call_other(_trap_lock_ob, _trap_lock_func, "unlock")) {
      return 0;
    }
  }
  set_unlocked();
  return 1;
} /* do_unlock() */

/**
 * @ignore yes
 */

int do_lock(object *obs) {
  if(_locked || _stuck || !_closed || !_key) {
    if(_locked)
      TP->add_failed_mess(TO,
      "$D $V$0=is,are$V$ already locked.\n", ({ }));
    else if(_stuck)
      TP->add_failed_mess(TO,
      "$D $V$0=is,are$V$ stuck.\n", ({ }));
    else if(!_closed)
      TP->add_failed_mess(TO,
      "$D $V$0=isn't,aren't$V$ closed.\n", ({ }));
    else if(!_key)
      TP->add_failed_mess(TO,
      "$D $V$0=doesn't,don't$V$ have a key.\n", ({ }));
    return 0;
  }

  if(!sizeof(obs))
    obs = all_inventory(TP);

  obs = filter_array(obs, (: $1->query_property( $2 ) :), _key);

  if(sizeof(obs)) {
    obs[0]->use_key(TO);
  } else {
    return 0;
  }
  if(_trap_lock_func && _trap_lock_ob) {
    if(!call_other(_trap_lock_ob, _trap_lock_func, "lock")) {
      return 0;
    }
  }
  set_locked();
  return 1;
} /* do_lock() */

/**
 * @ignore yes
 */

int pick_lock(object player) {
  if(_trap_lock_ob && !call_other(_trap_lock_ob, _trap_lock_func, "pick")) {
    return 0;
  }
  set_locked();
  return 1;
} /* pick_lock() */

/**
 * This is called when someone successfully unlocks the object.
 * If there is a trap, and the trap function returns true, the
 * object will not be opened.  If the trap function returns
 * false, the object will still be opened even if the trap is
 * sprung.
 *
 * @param player The player who is unlocking the object.
 *
 * @return Returns 1 if the object was unlocked, and 0 otherwise.
 */

int pick_unlock(object player) {
  if(_trap_lock_ob && !call_other(_trap_lock_ob, _trap_lock_func, "pick")) {
    return 0;
  }
  set_unlocked();
  return 1;
} /* pick_unlock() */

/**
 * @ignore yes
 */

int do_open() {
  if(!_closed) {
    TP->add_failed_mess(TO,
      "$D $V$0=is,are$V$ already open.\n", ({ }));
      return 0;
  }
  if(_stuck) {
    TP->add_failed_mess(TO,
      "$D $V$0=is,are$V$ stuck.\n", ({ }));
    return 0;
  }
  if(_locked && !do_unlock(0)) {
    TP->add_failed_mess(TO, "$D $V$0=is,are$V$ locked.\n", ({ }));
    return 0;
  }
  if(_trap_open_func && _trap_open_ob) {
    if(!call_other(_trap_open_ob, _trap_open_func, "open")) {
      return 0;
    }
  }
  set_open();
  return 1;
} /* do_open() */

/**
 * @ignore yes
 */

int do_close() {
  if(_closed) {
    TP->add_failed_mess(TO, "$D $V$0=is,are$V$ already closed.\n", ({ }));
    return 0;
  }
  if(_stuck) {
      TP->add_failed_mess(TO, "$D $V$0=is,are$V$ stuck.\n", ({ }));
    return 0;
  }
  if(_trap_open_func && _trap_open_ob) {
    if(!call_other(_trap_open_ob, _trap_open_func, "close")) {
      return 0;
    }
  }
  set_closed();
  if(_autolock)
    set_locked();
  return 1;
} /* do_close() */

/**
 * @ignore yes
 */

mixed *stats() {
  return ({
    ({"closed", query_closed()}),
    ({"transparent", query_transparent()}),
    ({"key", query_key()}),
    ({"difficulty", query_difficulty()}),
    ({"locked", query_locked()}),
    ({"stuck", query_stuck()}),
    ({"unlockable", query_unlockable()}),
    ({"open trapped", _trap_open_func != 0}),
    ({"lock trapped", _trap_lock_func != 0}),
    ({"pick skill", query_pick_skill()}),});
} /* stats() */