Skip to content

Instantly share code, notes, and snippets.

@jalbright015
Created April 10, 2021 02:13
Show Gist options
  • Save jalbright015/7bec942334a14fd7dd4c1a43bca1e97f to your computer and use it in GitHub Desktop.
Save jalbright015/7bec942334a14fd7dd4c1a43bca1e97f to your computer and use it in GitHub Desktop.
// doors.c
// The standard door object. Any room (or other object if you like) that
// contains a door needs to inherit this file.
// Originally written by Rusty@TMI-2, 11-92.
// He lost his access in January 1993. Mobydick@TMI-2 went back and whipped
// the code into shape for the release.
// Originally part of room.c. Mobydick seperated in into two files, rooms
// and doors, on 2-17-93. This was done to save memory since most rooms do
// not contain doors and do not need this code.
//
// Removed the redundant functionality of set_desc_door()
// Lloyd@Astaria, 2004-09-30
// Prototypes for functions defined in room.c.
varargs void set (string foo, mixed data, string perms) ;
varargs mixed query (string foo, int flag) ;
int delete (string str) ;
void add (string foo, mixed data) ;
// Homegrown prototypes.
//void set_desc_door (string dir) ;
void initialize_link_door (string dir) ;
void delete_door (string dir) ;
// This function creates a door for a previously existing exit.
// If all you want is a door that opens and closes, this is enough.
// Ex. create_door("east", "west", "A simple wooden door");
//
varargs void create_door( string dir,
string linked_exit,
string door_desc,
string door_stat,
string lock)
{
set("doors/"+dir+"/linked", linked_exit);
set("doors/"+dir+"/lock", lock) ;
if (!door_desc) door_desc = "A door";
set("doors/"+dir+"/desc", door_desc);
set ("doors/"+dir+"/status", door_stat) ;
//set_desc_door(dir) ;
initialize_link_door(dir) ;
return;
}
// A function to set various door attributes.
// For value use "open" or "closed" or "locked"..
void set_status_door(string dir, string value)
{
set("doors/"+dir+"/status", value);
//set_desc_door(dir);
}
/*
void set_desc_door( string dir )
{
add( "item_desc", ([ dir + " door" :
query("doors/"+dir+"/desc") + ". It is "+
query("doors/"+dir+"/status") +".\n" ]) ) ;
return;
}
*/
// This function initializes a doorway linkage. When you create a new
// door with a link, this function queries the linked door and sets the
// status of this door to match the status of that door.
void initialize_link_door (string dir)
{
string ob_dir, ob_status, link ;
object ob;
link = this_object()->query("doors/"+dir+"/linked") ;
if (link && link!="none")
{
if (ob = find_object((string)query("exits/"+dir)))
{
ob_dir = (string)query("doors/"+dir+"/linked");
ob_status = (string)ob->query("doors/"+ob_dir+"/status") ;
set_status_door(dir, ob_status);
}
}
return;
}
// This function updates a doorway link. When called, it finds the door
// linked to this door and sets that door's status to match this door.
// The difference between initialize_link_door and update_link_door is that
// initialize causes this room's door to match the remote door, but update
// causes the remote door to match this room's door.
void update_link_door (string dir)
{
string link ;
string ob_dir;
string door_stat ;
string old_stat ;
object ob;
seteuid(getuid());
link = this_object()->query("doors/"+dir+"/linked") ;
if (link && link != "none")
{
if (ob = find_object((string)query("exits/"+dir)))
{
door_stat = (string)query("doors/"+dir+"/status") ;
ob_dir = (string)query("doors/"+dir+"/linked");
old_stat = (string)ob->query("doors/"+ob_dir+"/status") ;
ob->set_status_door(ob_dir, door_stat) ;
switch (door_stat)
{
case "open" :
{
tell_room (ob, "The "+ob_dir+" door swings open.\n") ;
break ;
}
case "locked" :
{
tell_room(ob,"You hear a clicking sound from the "+ob_dir+
" door.\n") ;
break ;
}
case "closed" :
{
if (old_stat=="locked")
{
tell_room (ob, "You hear a clicking sound from the "+
ob_dir+" door.\n") ;
}
else
tell_room (ob, "The "+ob_dir+" door swings shut.\n") ;
break ;
}
}
}
}
return;
}
// This deletes a door in this room. It does NOT delete the door
// in the linked room. Don't call this directly. Instead, call
// remove_door() below, which calls it in both places automagically
// for you.
// This also does not delete the exits.
void delete_door (string dir) {
delete ("doors/"+dir) ;
}
// This is for getting rid of a door you don't want no more.
// It calls delete_door() in both rooms, the near and the far.
varargs void remove_door (string dir, int exits) {
object linkrm ;
string linkdr ;
linkdr = query("doors/"+dir+"/linked") ;
linkrm = query("exits/"+dir) ;
linkrm->delete_door(linkdr) ;
if (exits) linkrm->delete("exits/"+linkdr) ;
delete_door(dir) ;
if (exits) delete("exits/"+dir) ;
}
/* EOF */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment