User Tools

Site Tools

01 #include <mudlib.h>
02 #include <ansi.h>
03 #pragma strong_types
05 inherit ROOM;
07 void reset (int arg)
08 {
09   ::reset (arg);
11   if (!present("soldier")) 
12   {
13     place_objects("/players/orbital/projects/wiki/amob.c",2);
14     tell_room(this_object (),"Two guards arrive and take up station patrolling the area.\n");  
15   }
17   if (arg) return;
19   set_light (1);
20   set_indoor (1);
21   set_planet ("chapterhouse");
23   set_short ("A Simple Room");
24   set_long ("  This is a simple room on the planet Chapterhouse.  It has been created to show you\n\
25 the basics of room creation here on Dune.  We can see that we are indoors,\n\
26 thanks to the lamp in the corner of the room providing us with a little light!\n\
27 Someone has sneakily attached a lever to the floor.\n");
29   add_item ("lamp", "A fancy little desk lamp.");
30   add_item ("lever", "A small lever with a knob on the end that you could pull.");
32   add_exit ("out", "/d/Space/stryder/planets/chap_station");
33 }
35 void init ()
36 {
37   ::init ();
38   add_action ("pull", "pull");
39 }
41 int pull (string str)
42 {
43   if (!str || str != "lever")
44     return notify_fail ("What are you trying to pull?\n");
45   if (present("soldier"))
46     return notify_fail ("The guards seem to be blocking the way!\n");
48   write ("You pull the lever.  You feel healthier.\n");
49   say (sprintf ("%s pulls the lever.  %s looks healthier.\n",
50                  capitalize (this_player ()->query_real_name ()),
51                  capitalize (this_player ()->query_pronoun ())));
53   this_player ()->heal_self (50);
54   return 1;
55 }

The file above has definitely grown since it's first incarnation. However, since we already have line by line commentary for the majority of it, we are only going to look at lines 9 through 17, 45, and 46 for this tutorial.

Line 09 - Quick refresher, the :: operator calls the reset function in the room's parent file.

Line 11 - This line asks a question. The question is, 'are there no soldiers in the room'. If the answer is yes, we proceed to lines 13 and 14. If the answer is no, we continue on to line 17.

Line 13 - The answer to the question was yes, and there are no soldiers in the room. The place_objects function allows us to both create, and move an item in one line. Notice the two arguments passed to the function, the first, in quotations (“/players/orbital/projects/wiki/amob.c”) is the directory location of the object in question, in this case, a simple soldier. The second argument, the number 2, defines how many soldiers I would like to place in the room. Incidentally, place_objects will 'top up' an environment to have exactly the number specified of the given object. This means that if the if (!present (“soldier”)) line were omitted, every reset () call would make sure that two soldiers are in the room, never more.

Line 14 - The tell_room function broadcasts a simple message to anything living in the current room. If you happened to be standing in the room as it was reset, you would see the message about guards arriving and patrolling the area.

Line 17 - Another refresher from the basic room. The monster code we've just gone over happens when the room is first created, and approximately every hour after that. The code for the REST of the room is blocked by this line. We only need that code to be executed when the room is first created.

Moving right along…

Line 45 - Similar to line 11 above, this line is also asking a question. The question here though is the opposite, we ask 'are there any soldiers in the room'?. If the answer is yes, then we proceed to line 46, otherwise, we proceed to line 48.

Line 46 - In the 'less basic room' we determined that lines 43 and 44 were used to see if we were actually attempting to pull the lever correctly. We have passed that check now, and unfortunately for us, even though we've used the right syntax for the lever, if there are soldiers in the room, we are going to notify_fail that they are blocking us from using the lever.

talk/coding/mobroom.txt · Last modified: 2010/07/11 19:09 by mreh