foundation2_fluffos_v1/
foundation2_fluffos_v1/bin/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/ChangeLog.old/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/Win32/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/compat/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/compat/simuls/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/include/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/clone/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/command/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/data/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/etc/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/include/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/inherit/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/inherit/master/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/log/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/compiler/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/efuns/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/single/tests/operators/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/testsuite/u/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/tmp/
foundation2_fluffos_v1/fluffos-2.9-ds2.13/windows/
foundation2_fluffos_v1/lib/cfg/
foundation2_fluffos_v1/lib/cmds/adm/
foundation2_fluffos_v1/lib/daemon/save/
foundation2_fluffos_v1/lib/daemon/services/
foundation2_fluffos_v1/lib/daemon/soul/
foundation2_fluffos_v1/lib/doc/build/
foundation2_fluffos_v1/lib/doc/classes/
foundation2_fluffos_v1/lib/doc/driver/
foundation2_fluffos_v1/lib/doc/driver/applies/
foundation2_fluffos_v1/lib/doc/driver/applies/interactive/
foundation2_fluffos_v1/lib/doc/driver/concepts/
foundation2_fluffos_v1/lib/doc/driver/driver/
foundation2_fluffos_v1/lib/doc/driver/efuns/arrays/
foundation2_fluffos_v1/lib/doc/driver/efuns/buffers/
foundation2_fluffos_v1/lib/doc/driver/efuns/calls/
foundation2_fluffos_v1/lib/doc/driver/efuns/compile/
foundation2_fluffos_v1/lib/doc/driver/efuns/filesystem/
foundation2_fluffos_v1/lib/doc/driver/efuns/floats/
foundation2_fluffos_v1/lib/doc/driver/efuns/functions/
foundation2_fluffos_v1/lib/doc/driver/efuns/general/
foundation2_fluffos_v1/lib/doc/driver/efuns/mappings/
foundation2_fluffos_v1/lib/doc/driver/efuns/numbers/
foundation2_fluffos_v1/lib/doc/driver/efuns/parsing/
foundation2_fluffos_v1/lib/doc/driver/lpc/constructs/
foundation2_fluffos_v1/lib/doc/driver/lpc/types/
foundation2_fluffos_v1/lib/doc/driver/platforms/
foundation2_fluffos_v1/lib/doc/efun/
foundation2_fluffos_v1/lib/doc/etc/
foundation2_fluffos_v1/lib/doc/faq/
foundation2_fluffos_v1/lib/doc/help/creator/
foundation2_fluffos_v1/lib/doc/help/player/
foundation2_fluffos_v1/lib/doc/lpc/basic/
foundation2_fluffos_v1/lib/doc/lpc/data_types/
foundation2_fluffos_v1/lib/doc/lpc/etc/
foundation2_fluffos_v1/lib/doc/lpc/intermediate/
foundation2_fluffos_v1/lib/doc/lpc/types/
foundation2_fluffos_v1/lib/doc/mudlib/
foundation2_fluffos_v1/lib/doc/mudlib/Features/
foundation2_fluffos_v1/lib/domains/Examples/armour/
foundation2_fluffos_v1/lib/domains/Examples/etc/
foundation2_fluffos_v1/lib/domains/Examples/npc/
foundation2_fluffos_v1/lib/domains/Examples/room/
foundation2_fluffos_v1/lib/domains/Examples/virtual/
foundation2_fluffos_v1/lib/domains/Examples/virtual/exaA/
foundation2_fluffos_v1/lib/domains/Examples/virtual/exaB/
foundation2_fluffos_v1/lib/domains/Examples/weapon/
foundation2_fluffos_v1/lib/domains/School/doc/
foundation2_fluffos_v1/lib/domains/School/room/
foundation2_fluffos_v1/lib/domains/School/room/Classes/
foundation2_fluffos_v1/lib/domains/School/room/Offices/
foundation2_fluffos_v1/lib/domains/Standard/
foundation2_fluffos_v1/lib/domains/Standard/pools/
foundation2_fluffos_v1/lib/domains/Standard/std/
foundation2_fluffos_v1/lib/domains/Standard/xtra/
foundation2_fluffos_v1/lib/include/
foundation2_fluffos_v1/lib/lib/obj/
foundation2_fluffos_v1/lib/news/
foundation2_fluffos_v1/lib/save/
foundation2_fluffos_v1/lib/secure/cfg/
foundation2_fluffos_v1/lib/secure/cmds/player/
foundation2_fluffos_v1/lib/secure/lib/
foundation2_fluffos_v1/old/
foundation2_fluffos_v1/win32/
/*    /lib/door.c
 *    from the Foundation II LPC Library
 *    the standard door, window, rock object
 *    created by Descartes of Borg 950410
 *    with many thanks to Balack@Phoenix and Deathblade@ZorkMUD for their ideas
 */

#include <lib.h>
#include "door.h"

inherit LIB_DAEMON;

private int Closed, Locked;
private mapping Sides;

/*  ***************  /lib/door.c driver applies  ***************  */

static void create() {
    daemon::create();
    SetNoClean(1);
    Sides = ([]);
}

/*  ***************  /lib/door.c events  **************  */

/* eventOpen()
 * object by - The room from which the door is being open
 * object agent - The living thing responsible for it opening
 *
 * returns 1 on success, 0 on failure
 *
 * Used for actually opening the door
 * Before calling this, you should check if the door is locked and
 * check if it is already open so you can issue the appropriate messages
 */

varargs int eventOpen(object by, object agent) {
    string *sides;
    int i;

    if( !GetClosed() || GetLocked() ) return 0;
    i = sizeof(sides = keys(Sides));
    while(i--) {
	object *obs;
	int j;

	j = sizeof(obs = GetRooms(sides[i]));
	while(j--) {
	    if( obs[j] && obs[j] != by )
              message("environment", capitalize(GetShort(sides[i])) +
                " opens.", obs[j]);
	}
    }
    SetClosed(0);
    return 1;
}

/* eventClose()
 * object by - the room from which the door is being closed
 * object agent - the living things responsible for the closing
 *
 * returns 1 on success, 0 on failure
 *
 * Check to be certain the door is not already closed before calling so
 * you may issue the appropriate message
 */

varargs int eventClose(object by, object agent) {
    string *sides;
    int i;

    if( GetClosed() ) return 0;
    i = sizeof(sides = keys(Sides));
    while(i--) {
	object *obs;
	int j;

	j = sizeof(obs = GetRooms(sides[i]));
	while(j--) 
	  if( obs[j] && obs[j] != by )
            message("environment", capitalize(GetShort(sides[i])) +
              " closes.", obs[j]);
    }
    SetClosed(1);
    return 1;
}

/* eventLock()
 * object by - the room from which the door is being locked
 * object agent - the living thing responsible for the door locking
 *
 * returns 1 on success, 0 on failure
 *
 * Check to make sure the door is closed and unlocked before calling this
 * Also check to see that the door is lockable from this side
 * object by is required here
 */

varargs int eventLock(object by, object agent) {
    string *sides;
    int i;

    if( !by || !GetClosed() || GetLocked() ) return 0;
    if( !(i = sizeof(sides = keys(Sides))) ) return 0;
    while(i--) {
	if( member_array(by, Sides[sides[i]]["rooms"]) != -1) {
	    if( !GetLockable(sides[i]) ) return 0;
	    else return SetLocked(1); 
	}
    }
    return 0;
}

/* eventUnlock()
 * object by - the room from which the door is being unlocked
 * object agent - the living thing responsible for the door unlocking
 *
 * returns 1 on success, 0 on failure
 *
 * Check to make sure the door is closed and locked before calling this
 * Also check to see that the door is lockable from this side
 * object by is required here
 */

varargs int eventUnlock(object by, object agent) {
    string *sides;
    int i;

    if( !by || !GetClosed() || !GetLocked() ) return 0;
    if( !(i = sizeof(sides = keys(Sides))) ) return 0;
    while(i--) {
	if( member_array(by, Sides[sides[i]]["rooms"]) != -1) {
	    if( !GetLockable(sides[i]) ) return 0;
	    else return !SetLocked(0); 
	}
    }
    return 0;
}

/* eventRegisterSide()
 * string side - directional exit identifying which side of the door this room
 *               exits in
 *
 * returns 1 on success, 0 on failure
 *
 * never should be called manually
 * this is called by SetDoor() in exits.c to tell the door there is a room
 * which is observing it
 */
 
int eventRegisterSide(string side) {
    int i;

    if( !Sides[side] ) return 0;
    Sides[side]["rooms"] = 
      distinct_array(Sides[side]["rooms"] + ({ previous_object() }));
    previous_object()->AddItem(GetId(side), (: GetLong($(side)) :));
    return 1;
}

/*  **************  /lib/door.c data functions  **************  */

static int SetClosed(int x) { return (Closed = x); }

int GetClosed() { return Closed; }

static int SetLocked(int x) { return (Locked = x); }

int GetLocked() { return Locked; }

mapping SetSide(string side, mapping mp) {
    Sides[side] = mp;
    Sides[side]["rooms"] = ({});
    return mp;
}

int SetLockable(string side, int x) {
    if( !Sides[side] ) Sides[side] = ([ "rooms" : ({}) ]);
    return (Sides[side]["lockable"] = x); 
}

int GetLockable(string side) { return Sides[side]["lockable"]; }

string SetId(string side, string id) { 
    if( !Sides[side] ) Sides[side] = ([ "rooms" : ({}) ]);
    else return (Sides[side]["id"] = id);
}

string GetId(string side) { return Sides[side]["id"]; }

mixed SetShort(string side, mixed short) {
    if( !Sides[side] ) Sides[side] = ([ "rooms" : ({}) ]);
    else return (Sides[side]["short"] = short);
}

string GetShort(string side) {
    if( stringp(Sides[side]["short"]) ) return Sides[side]["short"];
    else return (string)evaluate(Sides[side]["short"], side);
}

mixed SetLong(string side, mixed long) {
    if( !Sides[side] ) Sides[side] = ([ "rooms" : ({}) ]);
    else return (Sides[side]["long"] = long); 
}

string GetLong(string side) {
    string tmp;

    if( GetClosed() ) tmp = "It is closed.";
    else tmp = "It is open.";
    if( stringp(Sides[side]["long"]) ) return Sides[side]["long"] + "\n" + tmp;
    else return (string)evaluate(Sides[side]["long"], side);
}

string *SetKeys(string side, string *cles) {
    if( !Sides[side] ) Sides[side] = ([ "rooms" : ({}) ]);
    else return (Sides[side]["keys"] = cles); 
}

string *GetKeys(string side) { return Sides[side]["keys"]; }

object *GetRooms(string side) { return Sides[side]["rooms"]; }