dsIIr4/bin/
dsIIr4/extra/creremote/
dsIIr4/extra/wolfpaw/
dsIIr4/lib/cmds/admins/
dsIIr4/lib/cmds/common/
dsIIr4/lib/cmds/creators/include/
dsIIr4/lib/cmds/creators/include/SCCS/
dsIIr4/lib/daemon/services/
dsIIr4/lib/doc/
dsIIr4/lib/domains/Ylsrim/
dsIIr4/lib/domains/Ylsrim/adm/
dsIIr4/lib/domains/Ylsrim/armor/
dsIIr4/lib/domains/Ylsrim/broken/
dsIIr4/lib/domains/Ylsrim/fish/
dsIIr4/lib/domains/Ylsrim/meal/
dsIIr4/lib/domains/Ylsrim/npc/
dsIIr4/lib/domains/Ylsrim/virtual/
dsIIr4/lib/domains/Ylsrim/weapon/
dsIIr4/lib/domains/campus/adm/
dsIIr4/lib/domains/campus/etc/
dsIIr4/lib/domains/campus/meals/
dsIIr4/lib/domains/campus/npc/
dsIIr4/lib/domains/campus/save/
dsIIr4/lib/domains/campus/txt/
dsIIr4/lib/domains/campus/txt/ai/charles/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/bak1/
dsIIr4/lib/domains/campus/txt/ai/charly/
dsIIr4/lib/domains/campus/txt/ai/charly/bak/
dsIIr4/lib/domains/campus/txt/jenny/
dsIIr4/lib/domains/default/creator/
dsIIr4/lib/domains/default/doors/
dsIIr4/lib/domains/default/etc/
dsIIr4/lib/domains/default/virtual/
dsIIr4/lib/domains/default/weap/
dsIIr4/lib/domains/town/virtual/
dsIIr4/lib/lib/comp/
dsIIr4/lib/lib/lvs/
dsIIr4/lib/lib/user/
dsIIr4/lib/lib/virtual/
dsIIr4/lib/log/
dsIIr4/lib/obj/book_source/
dsIIr4/lib/obj/include/
dsIIr4/lib/realms/template/
dsIIr4/lib/realms/template/adm/
dsIIr4/lib/realms/template/area/armor/
dsIIr4/lib/realms/template/area/npc/
dsIIr4/lib/realms/template/area/obj/
dsIIr4/lib/realms/template/area/room/
dsIIr4/lib/realms/template/area/weap/
dsIIr4/lib/realms/template/bak/
dsIIr4/lib/realms/template/cmds/
dsIIr4/lib/save/
dsIIr4/lib/save/kills/o/
dsIIr4/lib/secure/cfg/classes/
dsIIr4/lib/secure/cmds/creators/include/
dsIIr4/lib/secure/cmds/players/
dsIIr4/lib/secure/cmds/players/include/
dsIIr4/lib/secure/daemon/include/
dsIIr4/lib/secure/lib/
dsIIr4/lib/secure/lib/include/
dsIIr4/lib/secure/lib/net/include/
dsIIr4/lib/secure/lib/std/
dsIIr4/lib/secure/modules/
dsIIr4/lib/secure/npc/
dsIIr4/lib/secure/obj/include/
dsIIr4/lib/secure/room/
dsIIr4/lib/secure/save/
dsIIr4/lib/secure/save/boards/
dsIIr4/lib/secure/save/players/g/
dsIIr4/lib/secure/tmp/
dsIIr4/lib/secure/verbs/creators/
dsIIr4/lib/shadows/
dsIIr4/lib/spells/
dsIIr4/lib/std/board/
dsIIr4/lib/std/lib/
dsIIr4/lib/tmp/
dsIIr4/lib/verbs/admins/include/
dsIIr4/lib/verbs/common/
dsIIr4/lib/verbs/common/include/
dsIIr4/lib/verbs/creators/include/
dsIIr4/lib/verbs/players/include/SCCS/
dsIIr4/lib/verbs/rooms/
dsIIr4/lib/verbs/rooms/include/
dsIIr4/lib/www/
dsIIr4/v22.2b14-dsouls2/
dsIIr4/v22.2b14-dsouls2/ChangeLog.old/
dsIIr4/v22.2b14-dsouls2/Win32/
dsIIr4/v22.2b14-dsouls2/compat/
dsIIr4/v22.2b14-dsouls2/compat/simuls/
dsIIr4/v22.2b14-dsouls2/include/
dsIIr4/v22.2b14-dsouls2/mudlib/
dsIIr4/v22.2b14-dsouls2/testsuite/
dsIIr4/v22.2b14-dsouls2/testsuite/clone/
dsIIr4/v22.2b14-dsouls2/testsuite/command/
dsIIr4/v22.2b14-dsouls2/testsuite/data/
dsIIr4/v22.2b14-dsouls2/testsuite/etc/
dsIIr4/v22.2b14-dsouls2/testsuite/include/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/master/
dsIIr4/v22.2b14-dsouls2/testsuite/log/
dsIIr4/v22.2b14-dsouls2/testsuite/single/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/compiler/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/efuns/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/operators/
dsIIr4/v22.2b14-dsouls2/testsuite/u/
dsIIr4/v22.2b14-dsouls2/tmp/
dsIIr4/win32/
#include <lib.h>
#include <vendor_types.h>
inherit LIB_ITEM;
inherit LIB_PRESS;

int PushTheButton();
string color,gagnant,my_door,other_door,removed_door;

void create(){
    ::create();
    SetKeyName("button pedestal");
    SetId( ({"pedestal","altar"}) );
    SetAdjectives( ({"cylindrical","round","waist-high"}) );
    SetShort("a pedestal with a red button on it");
    SetLong("This is a cylindrical pedestal, about waist-high, "
      "of mysterious composition. A button is "
      "on it.");
    SetItems( ([
	({"button","red button"})  : "A red button."
      ]) );
    SetMass(20);
    SetDollarCost(10);
    SetVendorType(VT_TREASURE);
    SetPress( ([
	({"button","red button"}) : (: PushTheButton :)
      ]) );
}
mixed CanGet(object ob) { return "The pedestal does not budge.";}

int ResetGame(){
    object *objects;
    object *contents;
    string prize;
    prize = "/domains/campus/armor/silverring";
    objects = ({});
    objects+=({ find_object("/domains/campus/room/red_room2") });
    objects+=({ find_object("/domains/campus/room/green_room2") });
    objects+=({ find_object("/domains/campus/room/blue_room2") });

    objects = ({ find_object("/domains/campus/doors/red_door") });
    objects +=({ find_object("/domains/campus/doors/green_door") });
    objects +=({ find_object("/domains/campus/doors/blue_door") });

    foreach(object ding in objects){
	if(ding) ding->SetClosed(1);
	if(ding) ding->SetLocked(1);
    }


    if(sscanf(gagnant,"%s door",color)>0){
	string where;
	where="/domains/campus/room/"+color+"_room2";
	new(prize)->eventMove(find_object(where));
    }
}


int PushTheButton(){
    int genrand;
    gagnant = "";
    genrand = random(256);
    send_messages("press", "$agent_name $agent_verb the button.",
      this_player(), 0, environment(this_player()));
    if(!genrand || genrand == 0){
	tell_room(environment(),"A voice from the pedestal says: "
	  "Whoops! There's been a minor glitch, but "
	  "it's nothing to worry about. Please "
	  "try again.");
	return 1;
    }
    tell_room(environment(),"A voice from the pedestal says: "
      "PRECOG: genrand is: "+genrand);
    genrand = genrand % 3;
    if(genrand == 0) gagnant = "red door";
    if(genrand == 1) gagnant = "green door";
    if(genrand == 2) gagnant = "blue door";
    tell_room(environment(),"A voice from the pedestal says: "
      "PRECOG: gagnant is: "+gagnant+".\n"
      "PRECOG: genrand modulus is: "+genrand);
    remove_action("doStay","stay");
    remove_action("doSwitch","switch");
    add_action("choose","choose");
    tell_room(environment(),"A voice from the pedestal says: "
      "You must now choose one door from these "
      "three. Behind one is a prize. Behind the "
      "other two, nothing. To choose the "
      "red door, for example: choose red door");
    ResetGame();
    return 1;
}

void init(){
    if(gagnant != "" && my_door !=""){
	add_action("doStay","stay");
	add_action("doSwitch","switch");
    }
    if(gagnant != "" && my_door == ""){
	add_action("choose","choose");
    }
}

int choose(string str){
    if(!str || str == ""){
	tell_room(environment(),"A voice from the pedestal says: "
	  "Please try choosing a door, ok?");
    }
    else if(str == "door"){
	tell_room(environment(),"A voice from the pedestal says: "
	  "You'll need to be more specific.");
    }
    else if(str == "red door" || str == "blue door" ||str == "green door"){
	tell_room(environment(),"A voice from the pedestal says: "
	  "You choose the "+str+".");
	this_object()->MontyMagic(str);
    }
    else {
	tell_room(environment(),"A voice from the pedestal says: "
	  "I don't understand that.");
    }
    reap_dummies();
    reap_other("/domains/campus/armor/silverring");
    return 1;
}

int MontyMagic(string str){
    int genrand,which;
    string *choices;
    choices = ({});
    if(str != "red door") choices += ({ "red door" });
    if(str != "green door") choices += ({ "green door" });
    if(str != "blue door") choices += ({ "blue door" });
    genrand = random(256);
    if( choices[1] == gagnant) which = 0;
    else if( choices[0] == gagnant) which = 1;
    else which = genrand % 2;;
    removed_door = choices[which];
    choices -= ({ choices[which] });
    other_door = choices[0];
    my_door = str;
    choices += ({ str });
    if(sscanf(removed_door,"%s door",color)>0) color = color;
    find_object("/domains/campus/doors/"+color+"_door")->SetLocked(0);
    find_object("/domains/campus/doors/"+color+"_door")->SetClosed(0);
    tell_room(environment(),"A voice from the pedestal says: "
      "I have opened the "+removed_door+"! \n"
      "You may enter the "+color+" room and see that it is empty.\n"
      "Only the "+choices[0]+" and "+choices[1]+" remain.\n\n"
      "Would you like to switch to the "+other_door+"? \n"
      "Or would you rather stay with the "+str+"?\n\n"
      "To switch, type: switch\n"
      "To stay, type: stay");
    remove_action("choose","choose");
    add_action("doStay","stay");
    add_action("doSwitch","switch");
    return 1;

}

int CheckWin(string str){
    if(sscanf(str,"%s door",color)>0) color = color;
    if(str == gagnant) {
	this_object()->WinFun();
	return 1;
    }
    find_object("/domains/campus/doors/"+color+"_door")->SetLocked(0);
    find_object("/domains/campus/doors/"+color+"_door")->SetClosed(0);
    tell_room(environment(),"A voice from the pedestal says: "
      "YOU LOOOOOSE!\n"
      "You may enter the "+color+" room to get your big "
      "load of NOTHING. Haaa haa!");
    return 1;
}

int doStay(){
    tell_room(environment(),"A voice from the pedestal says: "
      "Oh, how loyal!");
    remove_action("doStay","stay");
    remove_action("doSwitch","switch");
    CheckWin(my_door);
    return 1;
}

int doSwitch(){
    tell_room(environment(),"A voice from the pedestal says: "
      "Why you're inconstant as a feather!");
    remove_action("doStay","stay");
    remove_action("doSwitch","switch");
    my_door = other_door;
    CheckWin(my_door);
    return 1;
}

int WinFun(){
    find_object("/domains/campus/doors/"+color+"_door")->SetLocked(0);
    find_object("/domains/campus/doors/"+color+"_door")->SetClosed(0);
    tell_room(environment(),"A voice from the pedestal says: "
      "You win, kid. Congrats!\n"
      "You may enter the "+color+" room and claim your prize.\n\n"
      "Push the pedestal button to reset the game.");
    return 1;
}