ds2.1.1/bin/
ds2.1.1/extra/wolfpaw/
ds2.1.1/lib/cmds/admins/
ds2.1.1/lib/cmds/common/
ds2.1.1/lib/cmds/creators/include/
ds2.1.1/lib/cmds/creators/include/SCCS/
ds2.1.1/lib/daemon/services/
ds2.1.1/lib/doc/
ds2.1.1/lib/doc/efun/all/
ds2.1.1/lib/doc/efun/arrays/
ds2.1.1/lib/doc/efun/buffers/
ds2.1.1/lib/doc/efun/compile/
ds2.1.1/lib/doc/efun/floats/
ds2.1.1/lib/doc/efun/functions/
ds2.1.1/lib/doc/efun/general/
ds2.1.1/lib/doc/efun/mixed/
ds2.1.1/lib/doc/efun/numbers/
ds2.1.1/lib/doc/efun/parsing/
ds2.1.1/lib/doc/faq/
ds2.1.1/lib/doc/hbook/
ds2.1.1/lib/doc/help/classes/
ds2.1.1/lib/doc/lpc/basic/
ds2.1.1/lib/doc/lpc/concepts/
ds2.1.1/lib/doc/lpc/constructs/
ds2.1.1/lib/doc/lpc/etc/
ds2.1.1/lib/doc/lpc/intermediate/
ds2.1.1/lib/doc/lpc/types/
ds2.1.1/lib/doc/misc/
ds2.1.1/lib/doc/old/
ds2.1.1/lib/domains/Ylsrim/
ds2.1.1/lib/domains/Ylsrim/adm/
ds2.1.1/lib/domains/Ylsrim/armor/
ds2.1.1/lib/domains/Ylsrim/broken/
ds2.1.1/lib/domains/Ylsrim/fish/
ds2.1.1/lib/domains/Ylsrim/meal/
ds2.1.1/lib/domains/Ylsrim/npc/
ds2.1.1/lib/domains/Ylsrim/obj/
ds2.1.1/lib/domains/Ylsrim/virtual/
ds2.1.1/lib/domains/Ylsrim/weapon/
ds2.1.1/lib/domains/campus/adm/
ds2.1.1/lib/domains/campus/etc/
ds2.1.1/lib/domains/campus/meals/
ds2.1.1/lib/domains/campus/npc/
ds2.1.1/lib/domains/campus/txt/ai/charles/
ds2.1.1/lib/domains/campus/txt/ai/charles/bak2/
ds2.1.1/lib/domains/campus/txt/ai/charles/bak2/bak1/
ds2.1.1/lib/domains/campus/txt/ai/charly/
ds2.1.1/lib/domains/campus/txt/ai/charly/bak/
ds2.1.1/lib/domains/campus/txt/jenny/
ds2.1.1/lib/domains/default/creator/
ds2.1.1/lib/domains/default/doors/
ds2.1.1/lib/domains/default/etc/
ds2.1.1/lib/domains/default/weap/
ds2.1.1/lib/domains/town/doors/
ds2.1.1/lib/domains/town/txt/
ds2.1.1/lib/domains/town/txt/shame/
ds2.1.1/lib/domains/town/virtual/
ds2.1.1/lib/lib/comp/
ds2.1.1/lib/lib/lvs/
ds2.1.1/lib/lib/user/
ds2.1.1/lib/lib/virtual/
ds2.1.1/lib/log/
ds2.1.1/lib/obj/book_source/
ds2.1.1/lib/obj/include/
ds2.1.1/lib/realms/template/
ds2.1.1/lib/realms/template/area/armor/
ds2.1.1/lib/realms/template/area/npc/
ds2.1.1/lib/realms/template/area/obj/
ds2.1.1/lib/realms/template/area/room/
ds2.1.1/lib/realms/template/area/weap/
ds2.1.1/lib/realms/template/bak/
ds2.1.1/lib/realms/template/cmds/
ds2.1.1/lib/save/kills/o/
ds2.1.1/lib/secure/cfg/
ds2.1.1/lib/secure/cfg/classes/
ds2.1.1/lib/secure/cfg/races/SCCS/
ds2.1.1/lib/secure/cmds/creators/include/
ds2.1.1/lib/secure/cmds/players/
ds2.1.1/lib/secure/cmds/players/include/
ds2.1.1/lib/secure/daemon/include/
ds2.1.1/lib/secure/lib/
ds2.1.1/lib/secure/lib/include/
ds2.1.1/lib/secure/lib/net/
ds2.1.1/lib/secure/lib/net/include/
ds2.1.1/lib/secure/lib/std/
ds2.1.1/lib/secure/modules/
ds2.1.1/lib/secure/npc/
ds2.1.1/lib/secure/obj/include/
ds2.1.1/lib/secure/room/
ds2.1.1/lib/secure/save/
ds2.1.1/lib/secure/save/boards/
ds2.1.1/lib/secure/verbs/creators/
ds2.1.1/lib/shadows/
ds2.1.1/lib/spells/
ds2.1.1/lib/verbs/admins/include/
ds2.1.1/lib/verbs/common/
ds2.1.1/lib/verbs/common/include/
ds2.1.1/lib/verbs/creators/
ds2.1.1/lib/verbs/creators/include/
ds2.1.1/lib/verbs/players/include/SCCS/
ds2.1.1/lib/verbs/rooms/
ds2.1.1/lib/verbs/rooms/include/
ds2.1.1/lib/www/errors/
ds2.1.1/lib/www/images/
ds2.1.1/v22.2b14/
ds2.1.1/v22.2b14/ChangeLog.old/
ds2.1.1/v22.2b14/Win32/
ds2.1.1/v22.2b14/compat/
ds2.1.1/v22.2b14/compat/simuls/
ds2.1.1/v22.2b14/include/
ds2.1.1/v22.2b14/testsuite/
ds2.1.1/v22.2b14/testsuite/clone/
ds2.1.1/v22.2b14/testsuite/command/
ds2.1.1/v22.2b14/testsuite/data/
ds2.1.1/v22.2b14/testsuite/etc/
ds2.1.1/v22.2b14/testsuite/include/
ds2.1.1/v22.2b14/testsuite/inherit/
ds2.1.1/v22.2b14/testsuite/inherit/master/
ds2.1.1/v22.2b14/testsuite/log/
ds2.1.1/v22.2b14/testsuite/single/
ds2.1.1/v22.2b14/testsuite/single/tests/compiler/
ds2.1.1/v22.2b14/testsuite/single/tests/efuns/
ds2.1.1/v22.2b14/testsuite/single/tests/operators/
ds2.1.1/v22.2b14/testsuite/u/
ds2.1.1/v22.2b14/tmp/
ds2.1.1/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;

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));
	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.");

    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);
    //debug("endpoint=" + endpoint);
    //debug("destination=" + destination);
    who->eventPrint("You step through the event horizon of the stargate.");
    who->eventMoveLiving(destination, 
      "$N steps into the event horizon and disappears", 
      "$N steps out of 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 steps into the event horizon and disappears", 
	  "$N steps out of 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";
    }
}