Author Topic: LIB_ELEVATOR for ds 3.8.6  (Read 907 times)

Offline toninno

  • Acquaintance
  • *
  • Posts: 16
    • View Profile
LIB_ELEVATOR for ds 3.8.6
« on: February 19, 2015, 01:50:12 PM »
my modifications are provided under gpl/public domain/wtfpl whichever you like :)
Code: [Select]
diff -Naur a/lib/domains/campus/chamber/elevator.c b/lib/domains/campus/chamber/elevator.c
--- a/lib/domains/campus/chamber/elevator.c 2009-12-30 09:54:38.000000000 +0000
+++ b/lib/domains/campus/chamber/elevator.c 2015-02-18 15:01:45.000000000 +0000
@@ -1,3 +1,7 @@
+so I wanted to note here that this file isn't intended to work with my implementation of LIB_ELEVATOR.
+Also, this file isn't referenced from the mudlib
+Also, I think the previos LIB_ELEVATOR wasn't a working elevator implementation.
+
 #include <lib.h>
 
 inherit LIB_ELEVATOR;
diff -Naur a/lib/domains/town/room/basement.c b/lib/domains/town/room/basement.c
--- a/lib/domains/town/room/basement.c 2009-12-30 09:54:56.000000000 +0000
+++ b/lib/domains/town/room/basement.c 2015-02-18 21:35:55.000000000 +0000
@@ -19,9 +19,11 @@
     SetExits( ([
                 "west" : "/domains/town/room/elevator",
                 ]) );
-    //AddStuff( ({"/domains/town/npc/leo"}) );
+    //this one will add the buttons automatically:
+    load_object("/domains/town/room/elevator");
+    //I suggest to set the coordinates in all rooms connected to an elevator in order for the mapping to work properly
+    SetCoordinates("-1,1,-1");
 }
 void init(){
     ::init();
-    if(!present("button",this_object())) AddItem(new("/domains/town/obj/basement_button"));
 }
diff -Naur a/lib/domains/town/room/church.c b/lib/domains/town/room/church.c
--- a/lib/domains/town/room/church.c 2009-12-30 09:54:56.000000000 +0000
+++ b/lib/domains/town/room/church.c 2015-02-18 21:34:23.000000000 +0000
@@ -38,11 +38,14 @@
     SetEnters( ([
                 "elevator" : "/domains/town/room/elevator",
                 ]) );
-    AddItem(new("/domains/town/obj/church_button"));
     SetExits( ([
                 "south" : "/domains/town/room/road1",
                 "west" : "/domains/town/room/elevator",
                 ]) );
+    //this one will add the buttons automatically:
+    load_object("/domains/town/room/elevator");
+    //I suggest to set the coordinates in all rooms connected to an elevator in order for the mapping to work properly
+    SetCoordinates("-1,1,0");
 }
 
 void init(){
diff -Naur a/lib/domains/town/room/elevator.c b/lib/domains/town/room/elevator.c
--- a/lib/domains/town/room/elevator.c 2009-12-30 09:54:56.000000000 +0000
+++ b/lib/domains/town/room/elevator.c 2015-02-18 00:36:56.000000000 +0000
@@ -1,126 +1,15 @@
-#include <lib.h>
-inherit LIB_ROOM;
+inherit LIB_ELEVATOR;
 
-int doorcounter,callfloor,closed,floor,my_counter,moving;
-string floorname;
-static void create() {
-    room::create();
-    SetClimate("indoors");
-    SetAmbientLight(30);
+static void create()
+{
+    ::create("east");
     SetShort("Church Elevator");
-    SetLong("This is the elevator in the village church. The elevator door is on the east wall. Two buttons are set into the wall next to the door, labeled '1' and 'b'.");
-    floor=1;
-    moving = 0;
-    closed=1;
-    callfloor=0;
-    SetExits( ([
-                "east" : "/domains/town/room/church",
-                ]) );
-    SetItems(([
-                //new("/domains/town/obj/ebutton1") : 1,
-                //new("/domains/town/obj/ebutton2") : 1,
-                "elevator" : "A means of vertical indoors transportation.",
-                "wall" : "The buttons are on the wall.",
-                ({"elevator door","door"}) : "The door to the outside."
-                ]) );
-    AddItem(new("/domains/town/obj/ebutton2"));
-    AddItem(new("/domains/town/obj/ebutton1"));
-    set_heart_beat(1);
+    SetLong("This is the elevator in the village church. The elevator door is on the east wall. Two buttons are set into the wall next to the door, labeled '0' and 'b'.");
+    //you are supposed to provide exactly one integer key in each key list
+    SetFloors(([ ({0,"ground","church"}):"/domains/town/room/church",
+                 ({-1,"b","basement"}):"/domains/town/room/basement",
+             ]));
 }
 void init(){
     ::init();
-    set_heart_beat(1);
-}
-int CallMe(int i){
-    if(i == floor && moving == 0) {
-        this_object()->SetDoorClosed(0);
-        return 1;
-    }
-    else callfloor = i;
-    return 1;
-}
-int SetDoorClosed(int i){
-    if(i && i == closed) return i;
-    if(!i && closed == 0) return i;
-    if(i == 0 && closed == 0) return i;
-    if(i) closed = i;
-    else if( closed == 1 ) closed = 0;
-    else if( closed == 0 ) closed =1;
-    if(floor == 1) floorname = "/domains/town/room/church";
-    if(floor == 2) floorname = "/domains/town/room/basement";
-    if(closed < 1){
-        tell_room(this_object(),"The elevator door opens.");
-        tell_room(load_object(floorname),"The elevator door opens.");
-        doorcounter = 10;
-    }
-    if(closed > 0) {
-        tell_room(this_object(),"The elevator door closes.");
-        tell_room(load_object(floorname),"The elevator door closes.");
-        doorcounter = 0;
-    }
-    return closed;
-}
-int SetFloor(int i){
-    if(floor == i) return 0;
-    RemoveExit("east");
-    floor = i;
-    if(i == 1) AddExit("east", "/domains/town/room/church");
-    if(i == 2) AddExit("east", "/domains/town/room/basement");
-    return 1;
-}
-int CanReceive(object ob) {
-#if 1
-    if(living(ob) && closed > 0 && query_verb() != "goto" &&
-            query_verb() != "trans"  ){
-        message("info","The elevator door is closed.", ob);
-        return 0;
-    }
-#endif
-    return 1;
-}
-int CanRelease(object ob){
-    if(archp(ob)) {
-        tell_object(ob,"%^RED%^As archwizard, you are permitted to "
-                "exit the elevator at any time. Normal creators and "
-                "players cannot do this.%^RESET%^\n");
-    }
-    if(closed > 0 && query_verb() == "go" ){
-        message("info","The elevator door is closed.", ob);
-        return 0;
-    }
-    return 1;
-}
-varargs int eventRoll(int i){
-    if(!i) i = 10;
-    moving = 1;
-    SetDoorClosed(1);
-    my_counter = i;
-    return i;
-}
-void heart_beat(){
-    if(doorcounter > 0){
-        doorcounter--;
-        if(doorcounter  < 2) SetDoorClosed(1);
-    }
-
-    if(moving == 0 && closed == 1 && callfloor > 0){
-        tell_room(this_object(),"The elevator lurches into motion.");
-        eventRoll();
-    }
-
-    if(moving && moving > 0){
-        my_counter--;
-        if(my_counter % 5  == 0) {
-            tell_room(this_object(),"The elevator continues...");
-        }
-
-        if(my_counter < 2) {
-            my_counter = 0;
-            moving = 0;
-            SetFloor(callfloor);
-            tell_room(this_object(),"The elevator arrives at its destination.");
-            SetDoorClosed(0);
-            callfloor = 0;
-        }
-    }
 }
diff -Naur a/lib/lib/elevator_button.c b/lib/lib/elevator_button.c
--- a/lib/lib/elevator_button.c 2009-12-30 09:54:58.000000000 +0000
+++ b/lib/lib/elevator_button.c 2015-02-18 14:37:48.000000000 +0000
@@ -3,42 +3,29 @@
 inherit LIB_DUMMY; // These do not show up in desc, but you can look at them
 inherit LIB_PRESS; // Makes the item pressable
 
-object car, shaft;
-string button_id;
+string elevator;
+int level;
 
-int openDoor(object who) {
-    if(!car) return 0;
-    if(!who) who = this_player();
-    send_messages("press", "$agent_name $agent_verb the button.",
-            who, 0, environment(who));
-    car->SetDoor(1);
-    car->CallMe(1);
-
-}
-
-static void create() {
-    dummy::create();
-    SetKeyName("button");
-    SetAdjectives("elevator","button");
-    SetShort("a button");
-    SetLong("It is a button that you could probably press.");
-    SetPress((: openDoor :));
-}
-
-string SetButtonId(string str){
-    button_id = str;
-    return button_id;
+int OpenDoor(object who)
+{
+  object car;
+  send_messages("press", "$agent_name $agent_verb the button.",
+                who, 0, environment(who));
+  car=load_object(elevator);
+  car->CallMe(level);
 }
 
-string GetButtonId(){
-    return button_id;
+int SetLevel(int l)
+{
+  level=l;
 }
 
-object SetElevator(object ob){
-    car = ob;
-    return car;
+int SetMyElevator(string s)
+{
+  elevator=s;
 }
 
-object GetElevator(){
-    return car;
+static void create(string array id, mixed long, string array adj) {
+    dummy::create(id,long,adj);
+    SetPress((: OpenDoor :));
 }
diff -Naur a/lib/lib/elevator.c b/lib/lib/elevator.c
--- a/lib/lib/elevator.c 2009-12-30 09:54:58.000000000 +0000
+++ b/lib/lib/elevator.c 2015-02-18 17:32:25.000000000 +0000
@@ -1,71 +1,243 @@
 #include <lib.h>
-#include <position.h>
+inherit LIB_ROOM;
 
-inherit LIB_CHAMBER;
-
-mapping Floors;
-int elevator_speed;
-
-static void create() {
-    chamber::create();
-    SetKeyName("elevator");
-    SetId(({"box"}));
-    SetAdjectives(({"simple"}));
-    SetShort("a elevator");
-    SetLong("This is a large, boxlike conveyance for transporting "
-            "things and people along a defined vertical axis.");
-    SetRace("vehicle");
-    SetPosition(POSITION_NULL);
-    SetMelee(0);
-    SetNoClean(1);
-    SetMount(1);
-    SetMountStyle("driven");
-    SetVisibleRiders(0);
-    SetOpacity(100);
-    SetMaxHealthPoints(20);
-    SetMaxCarry(30000);
-}
-
-void init(){
-    ::init();
-}
-
-int eventMove(mixed foo){
-    int ret;
-    ret = ::eventMove(foo);
-    return ret;
-}
-
-mapping GetFloors(){
-    return copy(Floors);
-}
-
-mapping SetFloors(mapping floors){
-    object *buttons = ({});
-    buttons = filter(all_inventory(),
-            (: base_name($1) == LIB_ELEVATOR_BUTTON :));
-    if(sizeof(buttons)) buttons->eventDestruct();
-    Floors = floors;
-    foreach(mixed key, mixed val in Floors){
-        object button = new(LIB_ELEVATOR_BUTTON);
-        string tmpname = cardinal(atoi(key));
-        string *tmpid = ({ key, "button" });
-        if(!undefinedp(tmpname)) tmpid += ({ tmpname });
-        button->SetAdjectives( ({ key, "elevator" }) );
-        button->SetId( tmpid );
-        button->SetKeyName( "button" );
-        button->SetElevator(this_object());
-        //button->SetInvis(0);
+int doorcounter,callfloor,closed,floor,my_counter,moving;
+string floorname;
+mapping floors;
+string exit;
+
+int SetDoorClosed(int i);
+int SetFloor(int i);
+
+static void create(string xdir)
+{
+  room::create();
+  SetClimate("indoors");
+  SetAmbientLight(30);
+  SetShort("Generic Elevator");
+  SetLong("This is a generic elevator. You aren't supposed to see this in game. This file is supposed to be inherited from.");
+  floor=0;
+  moving=0;
+  closed=1;
+  callfloor=0;
+  exit=xdir;
+  SetItems(([
+             "elevator" : "A means of vertical indoors transportation.",
+             "wall" : "The buttons are on the wall.",
+             ({"elevator door","door"}) : "The door to the outside."
+          ]) );
+}
+
+void init()
+{
+  ::init();
+}
+
+int CallMe(int i)
+{
+  if(i == floor && moving == 0)
+  {
+    SetDoorClosed(0);
+    return 1;
+  }
+
+  SetDoorClosed(1);
+  callfloor=i;
+  set_heart_beat(1);
+
+  return 1;
+}
+
+string GetFloorName(int i)
+{
+  return floors[i];
+}
+
+void SetFloors(mapping m)
+{
+  mixed key;
+  mixed value;
+  floors=([ ]);
+
+  foreach(key,value in m)
+  {
+    string *keys=({ });
+    string w;
+    string letter="";
+    object room;
+    int numeric;
+    if(arrayp(key))
+    {
+      foreach(w in key)
+      {
+        keys=({ keys..., ""+w });//string or int
+        if(intp(w)) numeric=to_int(w);
+        if(stringp(w)&&(strlen(w)==1)&&(letter=="")) letter=w;
+      }
+    }
+    else
+    {
+      keys=({ ""+key });//int
+      numeric=key;
+    }
+    floors[numeric]=value;
+    room=load_object(value);
+    if(room)
+    {
+      object button;
+      string kn;
+      string sl;
+      string *id;
+      string *adj;
+      kn="button "+numeric;
+      id=copy(keys);
+      if(member_array("button",id)==-1) id=({ id...,"button" });
+      id=({ kn,id... });
+      adj=copy(keys);
+      adj+=({ "elevator" });
+        sl="It is a button that you could probably press. ";
+        if(letter!="") sl+="The letter \""+letter+"\" is printed on it.";
+        else sl+="The number \""+numeric+"\" is printed on it.";
+      button=new(LIB_ELEVATOR_BUTTON,id,sl,adj);
+      if(button)
+      {
+        button->SetLevel(numeric);
+        button->SetMyElevator(file_name(this_object()));
         AddItem(button);
-        //button->eventMove(this_object());
+      }
+
+      if(!present("button",room))
+      {
+        button=new(LIB_ELEVATOR_BUTTON,
+                   ({"button","button on the wall", "button next to the elevator", "button next to elevator","button next to an elevator" }),
+                   "It is a button that you could probably press.",
+                   ({"call", "elevator"})
+                  );
+        if(button)
+        {
+          button->SetLevel(numeric);
+          button->SetMyElevator(file_name(this_object()));
+          room->AddItem(button);
+        }
+      }
     }
-}
+  }
 
-int GetSpeed(){
-    return elevator_speed;
+  --floor;
+  SetFloor(floor+1);
 }
 
-int SetSpeed(int x){
-    return (elevator_speed = x);
-}
+int SetDoorClosed(int i)
+{
+  //so I assume you'll only call this with i=1 or i=0 -- somehow I haven't found a sinle case of the type bool used in DS
+  //i=bool_reverse(bool_reverse(i));//would be a workaround if the above assumption is wrong
+  if(i==closed)
+  {
+    if(!i) doorcounter=10;
+    return closed;
+  }
+
+  closed=i;
+
+  floorname=GetFloorName(floor);
+
+  if(closed)
+  {
+    tell_room(this_object(),"The elevator door closes.");
+    tell_room(load_object(floorname),"The elevator door closes.");
+    doorcounter=0;
+  }
+  else
+  {
+    tell_room(this_object(),"The elevator door opens.");
+    tell_room(load_object(floorname),"The elevator door opens.");
+    doorcounter=10;
+    set_heart_beat(1);
+  }
+
+  return closed;
+}
+
+int SetFloor(int i)
+{
+  if(floor==i) return 0;
+  RemoveExit(exit);
+  floor=i;
+  AddExit(exit, GetFloorName(i));
+  return 1;
+}
+
+int CanReceive(object ob)
+{
+  if(living(ob) && closed > 0 && query_verb() != "goto" && query_verb()!="trans")
+  {
+    message("info","The elevator door is closed.", ob);
+    return 0;
+  }
+
+  return 1;
+}
+
+int CanRelease(object ob)
+{
+  //XXX fixme does it mean I can <<insert verb here>> out of the elevator when the door is closed?
+  if((closed>0)&&(member_array(query_verb(),({"go","crawl","fly","boost"}))!=-1))
+  {
+    if(archp(ob))
+      tell_object(ob,"%^RED%^As archwizard, you are permitted to "
+                  "exit the elevator at any time. Normal creators and "
+                  "players cannot do this.%^RESET%^\n");
+    else
+      message("info","The elevator door is closed.", ob);
+
+    return 0;
+  }
+
+  //if(closed>0) debug(identify(this_player())+" escaped the elevator "+identify(this_object())+" by "+identify(query_verb())+"ing.");
+
+  return 1;
+}
+
+varargs int eventRoll(int i)
+{
+  if(!i) i=10*(floor-callfloor);
+  if(i<0) i=i*-1;
+  if(i<1) i=10;
+  moving=1;
+  SetDoorClosed(1);
+  my_counter=i;
+  return i;
+}
+
+void heart_beat()
+{
+  if(doorcounter > 0)
+  {
+    --doorcounter;
+    if(doorcounter<1)
+    {
+      SetDoorClosed(1);
+      set_heart_beat(0);
+    }
+  }
 
+  if((moving==0)&&(closed==1)&&(callfloor!=floor))
+  {
+    tell_room(this_object(),"The elevator lurches into motion.");
+    eventRoll();
+  }
+
+  if(moving && moving > 0)
+  {
+    my_counter--;
+    if(my_counter&&(my_counter%5==0)) tell_room(this_object(),"The elevator continues...");
+
+    if(my_counter<1)
+    {
+      moving = 0;
+      SetFloor(callfloor);
+      tell_room(this_object(),"The elevator arrives at its destination.");
+      SetDoorClosed(0);
+    }
+  }
+}