nightmare3_fluffos_v2/
nightmare3_fluffos_v2/bin/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/ChangeLog.old/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/Win32/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/compat/simuls/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/clone/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/command/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/data/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/etc/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/include/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/inherit/master/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/log/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/compiler/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/efuns/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/single/tests/operators/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/testsuite/u/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/tmp/
nightmare3_fluffos_v2/fluffos-2.9-ds2.08/windows/
nightmare3_fluffos_v2/lib/cmds/ambassador/
nightmare3_fluffos_v2/lib/cmds/database/
nightmare3_fluffos_v2/lib/cmds/hm/
nightmare3_fluffos_v2/lib/cmds/soul/
nightmare3_fluffos_v2/lib/daemon/cfg/
nightmare3_fluffos_v2/lib/daemon/cfg/mon_races/
nightmare3_fluffos_v2/lib/daemon/cfg/races/
nightmare3_fluffos_v2/lib/daemon/include/
nightmare3_fluffos_v2/lib/daemon/save/
nightmare3_fluffos_v2/lib/daemon/services/
nightmare3_fluffos_v2/lib/daemon/soul/
nightmare3_fluffos_v2/lib/doc/
nightmare3_fluffos_v2/lib/doc/TestPlans/
nightmare3_fluffos_v2/lib/doc/approval/
nightmare3_fluffos_v2/lib/doc/approval/QC/
nightmare3_fluffos_v2/lib/doc/approval/balance/
nightmare3_fluffos_v2/lib/doc/build/
nightmare3_fluffos_v2/lib/doc/build/armours/
nightmare3_fluffos_v2/lib/doc/build/economy/
nightmare3_fluffos_v2/lib/doc/build/etc/
nightmare3_fluffos_v2/lib/doc/build/monster/
nightmare3_fluffos_v2/lib/doc/build/room/
nightmare3_fluffos_v2/lib/doc/build/virtual/
nightmare3_fluffos_v2/lib/doc/build/weapon/
nightmare3_fluffos_v2/lib/doc/classes/
nightmare3_fluffos_v2/lib/doc/efun/
nightmare3_fluffos_v2/lib/doc/etc/
nightmare3_fluffos_v2/lib/doc/help/creator/
nightmare3_fluffos_v2/lib/doc/help/hm/
nightmare3_fluffos_v2/lib/doc/law/
nightmare3_fluffos_v2/lib/doc/lpc/basic/
nightmare3_fluffos_v2/lib/doc/lpc/data_types/
nightmare3_fluffos_v2/lib/doc/lpc/etc/
nightmare3_fluffos_v2/lib/doc/lpc/intermediate/
nightmare3_fluffos_v2/lib/doc/lpc/types/
nightmare3_fluffos_v2/lib/doc/mudlib/
nightmare3_fluffos_v2/lib/doc/mudlib/features/
nightmare3_fluffos_v2/lib/domains/Examples/etc/
nightmare3_fluffos_v2/lib/domains/Examples/room/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaA/
nightmare3_fluffos_v2/lib/domains/Examples/virtual/exaB/
nightmare3_fluffos_v2/lib/domains/Examples/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/
nightmare3_fluffos_v2/lib/domains/Praxis/adm/
nightmare3_fluffos_v2/lib/domains/Praxis/attic/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/
nightmare3_fluffos_v2/lib/domains/Praxis/cemetary/mon/
nightmare3_fluffos_v2/lib/domains/Praxis/data/
nightmare3_fluffos_v2/lib/domains/Praxis/death/
nightmare3_fluffos_v2/lib/domains/Praxis/mountains/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/armour/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/magic/
nightmare3_fluffos_v2/lib/domains/Praxis/obj/weapon/
nightmare3_fluffos_v2/lib/domains/Praxis/orc_valley/
nightmare3_fluffos_v2/lib/domains/Praxis/quests/
nightmare3_fluffos_v2/lib/domains/Praxis/standardOld/
nightmare3_fluffos_v2/lib/include/
nightmare3_fluffos_v2/lib/log/
nightmare3_fluffos_v2/lib/log/errors/
nightmare3_fluffos_v2/lib/log/reports/
nightmare3_fluffos_v2/lib/log/watch/
nightmare3_fluffos_v2/lib/news/
nightmare3_fluffos_v2/lib/secure/cfg/
nightmare3_fluffos_v2/lib/secure/cmds/ambassador/
nightmare3_fluffos_v2/lib/secure/cmds/mortal/
nightmare3_fluffos_v2/lib/secure/save/users/d/
nightmare3_fluffos_v2/lib/secure/std/
nightmare3_fluffos_v2/lib/std/hm/
nightmare3_fluffos_v2/lib/std/living/
nightmare3_fluffos_v2/lib/std/room/
nightmare3_fluffos_v2/lib/std/user/
nightmare3_fluffos_v2/lib/std/virtual/
nightmare3_fluffos_v2/lib/www/
nightmare3_fluffos_v2/lib/www/errors/
nightmare3_fluffos_v2/lib/www/gateways/
nightmare3_fluffos_v2/win32/
/*    /std/storage.c
 *    from Nightmare IV
 *    the standard object for storing things
 *    created by Descartes of Borg 940212
 */

#include <std.h>
#include "storage.h"

inherit CONTAINER;

private int __CanClose, __CanLock;
private string __Key;
static private int __Closed, __Locked;

void init() {
    ::init();
    add_action("Get", "get");
    add_action("Put", "put");
    add_action("Open", "open");
    add_action("Close", "close");
    add_action("Lock", "lock");
    add_action("Unlock", "unlock");
}

void create() {
    container::create();
    __CanClose = 0;
    __Closed = 0;
}

static int Put(string str) {
    object ob;
    string what, where;
    int tmp;

    if(!str) return 0;
    if(effective_light(this_player()) < -1) 
      return notify_fail("It is too dark.\n");
    if(sscanf(lower_case(str), "%s in %s", what, where) != 2) return 0;
    if(present(where, environment(this_player())) != this_object() &&
      present(where, this_player()) != this_object()) return 0;
    if(!(ob = present(what, this_player()))) return 0;
    if(ob == this_object()) {
        message("my_action", "You cannot change the laws of physics.",
          this_player());
        return 1;
    }
    if(!((int)ob->allow_put(this_player()))) return 1;
    if(!((int)ob->allow_drop(this_player()))) return 1;
    if(tmp = (int)ob->move(this_object())) {
        if(query_closed()) 
          message("my_action", sprintf("The %s is closed.", query_name()),
            this_player());
        else message("my_action", "You cannot fit it in there.",this_player());
        return 1;
    }
    message("my_action", sprintf("You put %s into %s.", 
      (string)ob->query_short(), query_short()), this_player());
    message("other_action", sprintf("%s puts %s into %s.",
      (string)this_player()->query_cap_name(), (string)ob->query_short(),
      query_short()), environment(this_player()), ({this_player()}));
    return 1;
}

static int Get(string str) { 
    object *things;
    object ob;
    string what, where;
    int tmp, i;

    if(!str) return 0;
    if(effective_light(this_player()) < 1)
      return notify_fail("It is too dark.\n");
    if(sscanf(lower_case(str), "%s from %s", what, where) != 2) return 0;
    if(present(where, environment(this_player())) != this_object() &&
      present(where, this_player()) != this_object()) return 0;
    if(what == "all")
      i = sizeof(things = all_inventory(this_object()));
    else if(!(ob = present(what, this_object()))) {
        message("my_action", "There is no such thing in there!",this_player());
        return 1;
    }
    else {
        i = 1;
        things = ({ ob });
    }
    if(query_closed()) {
        message("my_action", sprintf("%s is closed.", 
          capitalize(query_short())), this_player());
        return 1;
    }
    while(i--) {
        if(!((int)things[i]->allow_get(this_player()))) continue;
        message("my_action", sprintf("You get %s from %s.",
          (string)things[i]->query_short(), query_short()), this_player());
        message("other_action", sprintf("%s gets %s from %s.", 
          (string)this_player()->query_cap_name(), (string)things[i]->query_short(),
          query_short()), environment(this_player()), ({this_player()}));
        if((int)things[i]->move(this_player())) {
            message("my_action", "You cannot carry that!", this_player());
            things[i]->move(environment(this_player()));
            message("other_action", sprintf("%s drops %s.", 
              (string)this_player()->query_cap_name(), (string)things[i]->query_short()),
              environment(this_player()), ({ this_player() }));
        }
    }
    return 1;
}

static int Open(string str) {
    if(!str) return 0;
    if(!query_can_close()) return 0;
    if(present(str =lower_case(str), this_player()) != this_object() &&
      present(str, environment(this_player())) != this_object()) return 0;
    if(!query_closed()) {
        message("my_action", "It is already open!", this_player());
        return 1;
    }
    if(query_locked()) {
        message("my_action", "It is locked.", this_player());
        return 1;
    }
    set_closed(0);
    message("my_action", sprintf("You open %s.", query_short()),this_player());
    message("other_action", sprintf("%s opens %s.", 
      (string)this_player()->query_cap_name(), query_short()),
      environment(this_player()), ({ this_player() }));
    return 1;
}

int Close(string str) {
    if(!str || !query_can_close()) return 0;
    if(present(str =lower_case(str), this_player()) != this_object() &&
      present(str, environment(this_player())) != this_object()) return 0;
    if(query_closed()) {
        message("my_action", "It is already closed.", this_player());
        return 1;
    }
    set_closed(1);
    message("my_action", sprintf("You close %s.", query_short()),
      this_player());
    message("other_action", sprintf("%s closes %s.", 
      (string)this_player()->query_cap_name(), query_short()),
      environment(this_player()), ({ this_player() }));
    return 1;
}

int Lock(string str) {
    object ob;
    string what;

    if(!str || !query_can_close() || !query_can_lock()) return 0;
    if(__Key) {
        sscanf(str, "%s with %s", str, what);
        if(!what || !(ob = present(what, this_player())))
          return notify_fail("Lock it with what?\n");
        else if(ob != present(__Key, this_player()))
          return notify_fail("It does not work.\n");
    }
    if(present(str = lower_case(str), this_player()) != this_object() &&
      present(str, environment(this_player())) != this_object()) return 0;
    if(!query_closed()) {
        message("my_action", "It must be closed before you can lock it.",
          this_player());
        return 1;
    }
    if(query_locked()) {
        message("my_action", "It is already locked!", this_player());
        return 1;
    }
    message("my_action", sprintf("You lock %s.", query_short()),
      this_player());
    message("other_action", sprintf("%s locks %s.", 
      (string)this_player()->query_cap_name(), query_short()),
      environment(this_player()), ({ this_player() }));  
    set_locked(1);
    return 1;
}

static int Unlock(string str) {
    object ob;
    string what;

    if(!str || !query_can_close() || !query_can_lock()) return 0;
    if(__Key) {
        sscanf(str, "%s with %s", str, what);
        if(!what || !(ob = present(what, this_player())))
          return notify_fail("Unlock it with what?\n");
        else if(ob != present(__Key, this_player())) 
          return notify_fail("It does not work.\n");
    }
    if(!query_locked()) {
        message("my_action", "It is not locked.", this_player());
        return 1;
    }
    set_locked(0);
    message("my_action", sprintf("You unlock %s.", query_short()),
      this_player());
    message("other_action", sprintf("%s unlocks %s.", 
      (string)this_player()->query_cap_name(), query_short()),
      environment(this_player()), ({ this_player() }));
    return 1;
}

int pick_lock() {
    if(!query_can_lock()) return 0;
    set_locked(!query_locked());
    return 1;
}

varargs string query_long(string str) {
    string tmp;

    tmp = container::query_long(str);
    if(query_closed()) tmp +="\nIt is closed.";
    else tmp = sprintf("%s\nContents:\n%s%s", tmp, 
      describe_item_contents(({})), (str = describe_living_contents(({}))) != "" ?
      "\n"+str : "");
    return tmp;
}

varargs int receive_objects(object ob) {
    if(query_closed()) return 0;
    return container::receive_objects(ob);
}

void set_can_close(int x) { __CanClose = x; }

int query_can_close() { return __CanClose; }

void set_can_lock(int x) { __CanLock = x; }

int query_can_lock() { return __CanLock; }

void set_closed(int x) { __Closed = x; }

int query_closed() { return query_can_close() && __Closed; }

void set_locked(int x) { __Locked = x; }

int query_locked() { return query_can_lock() && __Locked; }

void set_key(string str) { __Key = str; }

string query_key() { return __Key; }