Let's have some fun with doors!
advroom.c
inherit STD_ROOM_OB;
void create()
{
   ::create();
   set_short("Elven workshop");
   set_long("An elven workshop.\n\n"+
     "An elf blacksmith looks up at you from his work and smiles at you.  "+
     "Next to him, on the table, is a suit of armor he's working on.");

   set_slaughter("blacksmith",
     "A bloody elven workshop.\n\n"+
     "An elf blacksmith used to work here, but now the workshop is in "+
     "disarray.  A murder has recently been committed here!  Blood stains "+
     "cover the table.");

   add_item("table","The table is a simple workbench used for polishing "+
     "weapons and armor.  A suit of armor is on the table.");
   add_item("armor","A suit of armor occupies the blacksmith's table.  "+
     "An inscription has been written on the suit.");
   add_item("inscription", "The inscription on the suit says:\n\n"+
     "  %^RED%^To my son, Feanor, on his 120th birthday.%^RESET%^");

   add_exit("east",  __DIR__+"villagesquare");
   add_exit("north", __DIR__+"blocked", "pre_north");
   add_exit("south", __DIR__+"secret");
   add_exit("west",  __DIR__+"locked");

   set_door("south", 1);
   hide_exit("south");

   set_door("west", 0, 1, "blacksmithkey");

   set_dcsecret(20);
   set_dclock(25);
   set_dcopen(0);
}

void reset()
{
   ::reset();
   if(!present("blacksmith"))
     new("/wizards/grey/mon/blacksmith")->move(this_object());
}

int pre_north()
{
   if(present("blacksmith"))
   {
     write("You try to go north, but the blacksmith stops you!");
     return 0;
   } else {
     write("With that meddling blacksmith out of the way, you "+
     "easily stride into the northern room.");
     return 1;
}

This room contains 4 kinds of exits. Let's examine each of them.

The east exit - a standard exit
The east exit is the regulard kind of exit we've seen in the previous room discussions. This is an "open", "obvious" and "unblocked" exit.

The north exit - a blocked exit
The north exit is "open" and "obvious", but a 3rd argument was included in the add_exit function. This says to call the named function (in this example: "pre_north", but it can be any name you want) before moving the player through the exit. If the function returns a 0 (zero), the player will not be allowed to use the exit. If the function returns a 1 (one), the exit functions normally. You can use this functionality to block exits, provide "sound effects", trigger alarms, or anything else you can think of.

The south exit - a secret exit
The south exit is "open" and "unblocked", but it is not listed in the room's "obvious exits" list. We made this a secret door with the hide_exit("south"); function call. We made this an open door with the set_door("south", 1); function call. If we change the "1" to a "0" in that set_door call, the door will be closed rather than open.

Here's how secret doors work. According to the D&D rules, elves and half-elves have a chance of noticing a secret door whenever they enter a room. Everybody else has to type "search". In both cases, the player's "search" skill is compared against the DC (Difficulty Class) of the secret door. This is determined by the set_dcsecret(20); function call. If you don't use this call, a default value of 20 will be used. The higher the DC, the harder the door will be to find. See the Players Handbook for more information on door DCs.

If a secret door is discovered, the exit will be listed as an "obvious" exit for that player from that point forward. The player's savefile contains a listing of secret exits to be remembered forever. Each player must discover the secret exit before the exit may be used.

The west exit - a locked door
The west exit is a locked door. Here's how the set_door function call works.

The 1st argument to set_door is the exit direction.
The 2nd argument is whether or not the door is open (0 or 1).
The 3rd argument is whether or not the door is locked (0 or 1).
The 4th argument is the name of the lock's key.

So in this example: set_door("west", 0, 1, "blacksmithkey"); means...
The west door is open, locked, and can be unlocked with a key named "blacksmithkey".

Of course, a lock can be picked by a Rogue with the proper skill. The Rogue's skill is compared against the lock's DC. You set this by:
set_dclock(25);

The default DC for locks is 25, so 25 will be used if you forget to add this function call to your room. See the Players' Handbook for more information on lock DCs.

There's one other DC setting concerning doors. Doors are really intended to be used within dungeons. Age, moisture, and/or poor construction methods cause doors to get "jammed" or "stuck" over time. It may take several hard shoves until the player can open the door. This is determined by the general DC for the door, as set by set_dcopen(0);

Use a DC of zero, as in this example, for a door in town that doesn't get "stuck". A common DC to use in a dungeon is 13. A DC 13 can be opened by just about any character, although a weaker character may have to attempt it several times. A DC 25 can only be opened by the strongest of characters. Again, consult the Players' Handbook. A default value of 13 is used if you forget to use this function call.

One final note. DCs apply to all doors in the room. So if you have 2 secret doors, you can't make one easier to find than the other.

In our next discussion, we'll learn about traps, chests, and how to make keys for doors and/or chests.


This page may be viewed from any browser, not just one from Redmond.
Last Modified: Feb 4, 2001
Page written by Dave Shay (how to contact me).
Page content copyright ©2000-2001 by Dave Shay. Do not copy without express permission.
Dungeons & Dragons is a registered trademark of TSR, Inc., a subsidiary of Wizards of the Coast.
D&D rules, races, classes, features, etc. used in accordance with the TSR, Inc. Internet Policy.