ds2.9a12/bin/
ds2.9a12/extra/
ds2.9a12/extra/crat/
ds2.9a12/extra/creremote/
ds2.9a12/extra/mingw/
ds2.9a12/extra/wolfpaw/
ds2.9a12/fluffos-2.14-ds13/
ds2.9a12/fluffos-2.14-ds13/Win32/
ds2.9a12/fluffos-2.14-ds13/compat/
ds2.9a12/fluffos-2.14-ds13/compat/simuls/
ds2.9a12/fluffos-2.14-ds13/include/
ds2.9a12/fluffos-2.14-ds13/testsuite/
ds2.9a12/fluffos-2.14-ds13/testsuite/clone/
ds2.9a12/fluffos-2.14-ds13/testsuite/command/
ds2.9a12/fluffos-2.14-ds13/testsuite/data/
ds2.9a12/fluffos-2.14-ds13/testsuite/etc/
ds2.9a12/fluffos-2.14-ds13/testsuite/include/
ds2.9a12/fluffos-2.14-ds13/testsuite/inherit/
ds2.9a12/fluffos-2.14-ds13/testsuite/inherit/master/
ds2.9a12/fluffos-2.14-ds13/testsuite/log/
ds2.9a12/fluffos-2.14-ds13/testsuite/single/
ds2.9a12/fluffos-2.14-ds13/testsuite/single/tests/compiler/
ds2.9a12/fluffos-2.14-ds13/testsuite/single/tests/efuns/
ds2.9a12/fluffos-2.14-ds13/testsuite/single/tests/operators/
ds2.9a12/fluffos-2.14-ds13/testsuite/u/
ds2.9a12/lib/cmds/admins/
ds2.9a12/lib/cmds/common/
ds2.9a12/lib/cmds/creators/include/
ds2.9a12/lib/daemon/services/
ds2.9a12/lib/daemon/tmp/
ds2.9a12/lib/doc/
ds2.9a12/lib/doc/bguide/
ds2.9a12/lib/doc/efun/all/
ds2.9a12/lib/doc/efun/arrays/
ds2.9a12/lib/doc/efun/buffers/
ds2.9a12/lib/doc/efun/compile/
ds2.9a12/lib/doc/efun/floats/
ds2.9a12/lib/doc/efun/functions/
ds2.9a12/lib/doc/efun/general/
ds2.9a12/lib/doc/efun/mixed/
ds2.9a12/lib/doc/efun/numbers/
ds2.9a12/lib/doc/efun/parsing/
ds2.9a12/lib/doc/hbook/
ds2.9a12/lib/doc/help/classes/
ds2.9a12/lib/doc/help/races/
ds2.9a12/lib/doc/lfun/
ds2.9a12/lib/doc/lfun/all/
ds2.9a12/lib/doc/lfun/lib/abilities/
ds2.9a12/lib/doc/lfun/lib/armor/
ds2.9a12/lib/doc/lfun/lib/bank/
ds2.9a12/lib/doc/lfun/lib/bot/
ds2.9a12/lib/doc/lfun/lib/clay/
ds2.9a12/lib/doc/lfun/lib/clean/
ds2.9a12/lib/doc/lfun/lib/clerk/
ds2.9a12/lib/doc/lfun/lib/client/
ds2.9a12/lib/doc/lfun/lib/combat/
ds2.9a12/lib/doc/lfun/lib/connect/
ds2.9a12/lib/doc/lfun/lib/container/
ds2.9a12/lib/doc/lfun/lib/corpse/
ds2.9a12/lib/doc/lfun/lib/creator/
ds2.9a12/lib/doc/lfun/lib/daemon/
ds2.9a12/lib/doc/lfun/lib/damage/
ds2.9a12/lib/doc/lfun/lib/deterioration/
ds2.9a12/lib/doc/lfun/lib/donate/
ds2.9a12/lib/doc/lfun/lib/door/
ds2.9a12/lib/doc/lfun/lib/equip/
ds2.9a12/lib/doc/lfun/lib/file/
ds2.9a12/lib/doc/lfun/lib/fish/
ds2.9a12/lib/doc/lfun/lib/fishing/
ds2.9a12/lib/doc/lfun/lib/flashlight/
ds2.9a12/lib/doc/lfun/lib/follow/
ds2.9a12/lib/doc/lfun/lib/ftp_client/
ds2.9a12/lib/doc/lfun/lib/ftp_data_connection/
ds2.9a12/lib/doc/lfun/lib/fuel/
ds2.9a12/lib/doc/lfun/lib/furnace/
ds2.9a12/lib/doc/lfun/lib/genetics/
ds2.9a12/lib/doc/lfun/lib/holder/
ds2.9a12/lib/doc/lfun/lib/id/
ds2.9a12/lib/doc/lfun/lib/interactive/
ds2.9a12/lib/doc/lfun/lib/lamp/
ds2.9a12/lib/doc/lfun/lib/leader/
ds2.9a12/lib/doc/lfun/lib/light/
ds2.9a12/lib/doc/lfun/lib/limb/
ds2.9a12/lib/doc/lfun/lib/living/
ds2.9a12/lib/doc/lfun/lib/load/
ds2.9a12/lib/doc/lfun/lib/look/
ds2.9a12/lib/doc/lfun/lib/manipulate/
ds2.9a12/lib/doc/lfun/lib/meal/
ds2.9a12/lib/doc/lfun/lib/messages/
ds2.9a12/lib/doc/lfun/lib/player/
ds2.9a12/lib/doc/lfun/lib/poison/
ds2.9a12/lib/doc/lfun/lib/position/
ds2.9a12/lib/doc/lfun/lib/post_office/
ds2.9a12/lib/doc/lfun/lib/potion/
ds2.9a12/lib/doc/lfun/lib/room/
ds2.9a12/lib/doc/lfun/lib/server/
ds2.9a12/lib/doc/lfun/lib/spell/
ds2.9a12/lib/doc/lfun/lib/torch/
ds2.9a12/lib/doc/lfun/lib/vendor/
ds2.9a12/lib/doc/lfun/lib/virt_sky/
ds2.9a12/lib/doc/lfun/lib/weapon/
ds2.9a12/lib/doc/lfun/lib/worn_storage/
ds2.9a12/lib/doc/lpc/basic/
ds2.9a12/lib/doc/lpc/concepts/
ds2.9a12/lib/doc/lpc/constructs/
ds2.9a12/lib/doc/lpc/etc/
ds2.9a12/lib/doc/lpc/intermediate/
ds2.9a12/lib/doc/lpc/types/
ds2.9a12/lib/doc/misc/
ds2.9a12/lib/doc/old/
ds2.9a12/lib/domains/
ds2.9a12/lib/domains/Praxis/adm/
ds2.9a12/lib/domains/Praxis/attic/
ds2.9a12/lib/domains/Praxis/cemetery/mon/
ds2.9a12/lib/domains/Praxis/data/
ds2.9a12/lib/domains/Praxis/death/
ds2.9a12/lib/domains/Praxis/mountains/
ds2.9a12/lib/domains/Praxis/obj/armour/
ds2.9a12/lib/domains/Praxis/obj/magic/
ds2.9a12/lib/domains/Praxis/obj/weapon/
ds2.9a12/lib/domains/Praxis/orc_valley/
ds2.9a12/lib/domains/Ylsrim/
ds2.9a12/lib/domains/Ylsrim/adm/
ds2.9a12/lib/domains/Ylsrim/armor/
ds2.9a12/lib/domains/Ylsrim/broken/
ds2.9a12/lib/domains/Ylsrim/fish/
ds2.9a12/lib/domains/Ylsrim/meal/
ds2.9a12/lib/domains/Ylsrim/npc/
ds2.9a12/lib/domains/Ylsrim/obj/
ds2.9a12/lib/domains/Ylsrim/virtual/
ds2.9a12/lib/domains/Ylsrim/weapon/
ds2.9a12/lib/domains/campus/adm/
ds2.9a12/lib/domains/campus/etc/
ds2.9a12/lib/domains/campus/meals/
ds2.9a12/lib/domains/campus/save/
ds2.9a12/lib/domains/campus/txt/ai/charles/
ds2.9a12/lib/domains/campus/txt/ai/charles/bak2/
ds2.9a12/lib/domains/campus/txt/ai/charles/bak2/bak1/
ds2.9a12/lib/domains/campus/txt/ai/charly/
ds2.9a12/lib/domains/campus/txt/ai/charly/bak/
ds2.9a12/lib/domains/campus/txt/jenny/
ds2.9a12/lib/domains/cave/doors/
ds2.9a12/lib/domains/cave/etc/
ds2.9a12/lib/domains/cave/meals/
ds2.9a12/lib/domains/cave/weap/
ds2.9a12/lib/domains/default/creator/
ds2.9a12/lib/domains/default/doors/
ds2.9a12/lib/domains/default/etc/
ds2.9a12/lib/domains/default/vehicles/
ds2.9a12/lib/domains/default/virtual/
ds2.9a12/lib/domains/default/weap/
ds2.9a12/lib/domains/town/txt/shame/
ds2.9a12/lib/domains/town/virtual/
ds2.9a12/lib/domains/town/virtual/bottom/
ds2.9a12/lib/domains/town/virtual/space/
ds2.9a12/lib/estates/
ds2.9a12/lib/ftp/
ds2.9a12/lib/lib/comp/
ds2.9a12/lib/lib/daemons/
ds2.9a12/lib/lib/daemons/include/
ds2.9a12/lib/lib/lvs/
ds2.9a12/lib/lib/user/
ds2.9a12/lib/lib/virtual/
ds2.9a12/lib/log/
ds2.9a12/lib/log/adm/
ds2.9a12/lib/log/archive/
ds2.9a12/lib/log/chan/
ds2.9a12/lib/log/errors/
ds2.9a12/lib/log/law/adm/
ds2.9a12/lib/log/law/email/
ds2.9a12/lib/log/law/names/
ds2.9a12/lib/log/law/sites-misc/
ds2.9a12/lib/log/law/sites-register/
ds2.9a12/lib/log/law/sites-tempban/
ds2.9a12/lib/log/law/sites-watch/
ds2.9a12/lib/log/open/
ds2.9a12/lib/log/reports/
ds2.9a12/lib/log/router/
ds2.9a12/lib/log/secure/
ds2.9a12/lib/log/watch/
ds2.9a12/lib/obj/book_source/
ds2.9a12/lib/obj/include/
ds2.9a12/lib/powers/prayers/
ds2.9a12/lib/powers/spells/
ds2.9a12/lib/realms/template/adm/
ds2.9a12/lib/realms/template/area/armor/
ds2.9a12/lib/realms/template/area/npc/
ds2.9a12/lib/realms/template/area/obj/
ds2.9a12/lib/realms/template/area/room/
ds2.9a12/lib/realms/template/area/weap/
ds2.9a12/lib/realms/template/bak/
ds2.9a12/lib/realms/template/cmds/
ds2.9a12/lib/save/kills/o/
ds2.9a12/lib/secure/cfg/classes/
ds2.9a12/lib/secure/cmds/builders/
ds2.9a12/lib/secure/cmds/creators/include/
ds2.9a12/lib/secure/cmds/players/
ds2.9a12/lib/secure/cmds/players/include/
ds2.9a12/lib/secure/daemon/imc2server/
ds2.9a12/lib/secure/daemon/include/
ds2.9a12/lib/secure/lib/
ds2.9a12/lib/secure/lib/include/
ds2.9a12/lib/secure/lib/net/include/
ds2.9a12/lib/secure/lib/std/
ds2.9a12/lib/secure/log/adm/
ds2.9a12/lib/secure/log/bak/
ds2.9a12/lib/secure/log/intermud/
ds2.9a12/lib/secure/log/network/
ds2.9a12/lib/secure/modules/
ds2.9a12/lib/secure/npc/
ds2.9a12/lib/secure/obj/include/
ds2.9a12/lib/secure/room/
ds2.9a12/lib/secure/save/
ds2.9a12/lib/secure/save/backup/
ds2.9a12/lib/secure/save/boards/
ds2.9a12/lib/secure/tmp/
ds2.9a12/lib/secure/upgrades/files/
ds2.9a12/lib/secure/verbs/creators/
ds2.9a12/lib/std/board/
ds2.9a12/lib/std/lib/
ds2.9a12/lib/tmp/
ds2.9a12/lib/verbs/admins/include/
ds2.9a12/lib/verbs/builders/
ds2.9a12/lib/verbs/common/
ds2.9a12/lib/verbs/common/include/
ds2.9a12/lib/verbs/creators/
ds2.9a12/lib/verbs/creators/include/
ds2.9a12/lib/verbs/rooms/
ds2.9a12/lib/verbs/rooms/include/
ds2.9a12/lib/www/client/
ds2.9a12/lib/www/errors/
ds2.9a12/lib/www/images/
ds2.9a12/lib/www/lpmuds/downloads_files/
ds2.9a12/lib/www/lpmuds/intermud_files/
ds2.9a12/lib/www/lpmuds/links_files/
ds2.9a12/win32/
#include <lib.h>
#include <daemons.h>
#include "/lib/include/stargate.h"

/**
 * 2006-03-28, jonez
 *  - based on a suggestion from rhk, changed so that one cannot enter the
 *    gate unless status is "outbound". this makes the object closer to the
 *    (theoretical) math and also to what happens on the show.
 */

/**
 * based on portal.c by Brodbane - March 2006
 *
 * $Id: stargate.c,v 1.1 2006/04/05 05:48:39 jam Exp $
 *
 * The desired functionality is much like a "star gate": users dialed
 * letters or full words that lined up with destinations.  A portal opens to
 * that destination briefly.  To define destinations you must setup a
 * constant below then add it to the switch statement in the cmdDial
 * function.  This object is crude and basic, but gets the job done.
 *
 * 2006-03-22, jonez
 *   - original version of this file is from Daelas@Moraelinost
 * 2006-03-23, jonez
 *   - altered so code uses existing verbs (touch, enter) where possible. last add_action is for dial command.
 *   - added single mapping called "database" and made the "dial" command use it.
 *   - dial command no longer uses switch/case, making adding a new destination simpler
 *   - made use of SetPreventGet() / SetPreventPut()
 *   - made use of new stargate daemon
 *   - made use of LIB_STARGATE
 *   - made use of STARGATE_D
 *
 * IDEAS:
 *  - create a daemon that holds the stargate network [DONE]
 *  - allow for stargate failure
 *  - add dhd object
 *  - change the code so that it uses a single mapping of names and
 *    destinations, perhaps in a database file. currently an update to the
 *    object requires an update for all the objects. [DONE]
 *  - dhd skill (thanks plato)
 *  - delay when dialing gate. destination dhd lights up?
 *  - player should not be able to dial earth if earth is already connected elsewhere (need daemon) [DONE]
 *  - make use of existing verbs (enter, touch) instead of doing our own thing. [DONE]
 *  - daemon should contain a class that maps the various gates to each other. see lib/include/door.h [DONE]
 *  - shout "off world activation" into the gateroom when the gate engages.
 *  - track status as "incoming" or "outgoing".. you can only "enter" an outgoing gate (rhk) [DONE]
 *  - if room is empty, shut down the gate (rhk)
 *  - change callout time when someone goes through the gate (rhk)
 */

inherit LIB_ITEM;

static private string origin;
static private int connect_time;

string displayLong();
string displayShort();

void create(){ 
    item::create();

    SetKeyName("stargate");
    SetId(({"stargate", "gate", "portal", "ring"}));
    SetAdjectives(({"stargate"}));
    SetShort( (: displayShort :) );

    SetLong( (: displayLong :) );

    AddItem( "inner ring", "The second ring - the inner ring - is placed "
      "inside the larger ring and seems to be able to move.");
    SetMass(1000);
    SetBaseCost("silver",50);
    SetPreventGet("The gate is pure naquadah and cannot be moved.");
    SetPreventPut("The gate is pure naquadah and cannot be moved!");
    SetTouch("You feel the stargate beneath your hand humming with energy.");
}

void init(){
    ::init();
    add_action( "cmdDial", "dial" );
    add_action( "cmdEnter", "enter");
}


void SetOrigin(string o, string d){
    if (o == "" || d == "") return;    
    origin = lower_case(o);
    if(!sizeof(STARGATE_D->GetStargate(origin))){
        STARGATE_D->SetStargate(origin, d);
    }
}

string GetOrigin(){
    return origin;
}

void eventConnect(string destination){
    int ret;

    destination = lower_case(destination);

    if (origin == destination){
        write("You attempt to dial the gate, but the last chevron does not engage");
        say(this_player()->GetName() + " tries to dial the gate but the last chevron does not engage");
        return;
    }

    ret = STARGATE_D->eventConnect(origin, destination);
    if (ret){
        string d = STARGATE_D->GetDestination(destination);
        write("The ancient rings lock into place and a portal forms in an explosion of energy.");
        say("The ancient rings lock into place and a portal forms in an explosion of energy.");
        tell_room(d, "The ancient rings lock into place and a portal forms in an explosion of energy");
        call_out("eventDisconnect", 10+random(5));
        connect_time = time();
        return;
    }

    write("You attempt to dial the stargate, but nothing happens.");
    say(this_player()->GetName() + " tries to dial the gate but fails.");

    return;
}

int eventDisconnect(){
    string endpoint = STARGATE_D->GetEndpoint(origin);
    string e = STARGATE_D->GetDestination(origin);
    string d = STARGATE_D->GetDestination(endpoint);
    if(d) tell_room(d, "The chevrons on the stargate disengage and the portal disappears.");
    if(e) tell_room(e, "The chevrons on the stargate disengage and the portal disappears.");
    connect_time = 0;
    return STARGATE_D->eventDisconnect(origin);
}

string status(){
    return STARGATE_D->GetStatus(origin);  
}

mixed cmdDial(string s){
    object ob;
    string flipside;
    if (s)
    {
        if(STARGATE_D->GetDestination(s)) 
            flipside = STARGATE_D->GetDestination(s);
        eventConnect(s);
        if(sizeof(flipside) && !ob) ob = load_object(flipside);
        if(!ob){
            write("The Stargate abruptly begins to shuts down.");
            eventDisconnect();
        }
        return 1;
    }

    return 0;

}

int cmdEnter(string what){
    string endpoint, destination;
    object who;

    if (what != "gate" && what != "stargate")
    {
        return 0;
    }

    if (status() != "outbound")
    {
        return 0;
    }

    who = this_player();
    endpoint = STARGATE_D->GetEndpoint(origin);
    destination = STARGATE_D->GetDestination(endpoint);
    who->eventPrint("You step through the event horizon of the stargate.");
    who->eventMoveLiving(destination, 
      "$N enters into the event horizon and disappears.", 
      "$N emerges from the event horizon.");
    return 1;
}

int eventEnter(object who){
    string endpoint;

    if (!who) return 0;

    endpoint = STARGATE_D->GetEndpoint(origin);
    if (status() == "connected")
    {
        who->eventPrint("You step through the event horizon of the stargate.");
        who->eventMoveLiving(endpoint, 
          "$N enters into the event horizon and disappears.", 
          "$N emerges from the event horizon.");
    }
    return 1;
}

string displayLong(){
    string buf, stat;

    buf = "This is the Stargate of legend.  The Stargate was created "
    "from naquadah ore, similar to black quartz.  It is a perfectly "
    "circular device approximately ten meters in diameter and "
    "comprised of two sets of rings and nine chevrons placed "
    "equidistant along its outer circumference.";

    stat = status();

    if (stat == "outbound" || stat == "inbound")
    {
        buf += " There is an event horizon in the center of the ring that looks like shimmering water.";
    }
    else if (stat == "idle")
    {
        buf += " This gate is currently idle.";
    }
    return buf;
}

string displayShort(){
    string stat;
    stat = status();
    switch (stat)
    {
    case "inbound":
        return "an inbound stargate";
    case "outbound":
        return "an outbound stargate";
    case "idle":
        return "an idle stargate";
    default:
        return "a broken stargate";
    }
}

void heart_beat(){
    if(connect_time && (time() - connect_time ) > 60){
        eventDisconnect();
    }
}