I like what you've done here; however, I have a suggestion for you. In your code, it looks like you have the option of adding individual files to the list rather than every room in a specific directory, however, I do not see where your code actually takes that input and uses it. I would suggest adding this above where you process the domain files:
foreach(string fil in sites)
{
foo = load_object(fil)->GetShort();
sites += ({ fil });
if(!str) message("system", "[" + i++ +"] %^YELLOW%^" + foo + "%^RESET%^", this_player());
}
I also changed one line that was causing me some trouble (I mentioned this on another thread). I changed:
if(!str) message("system", "[" + i++ +"] %^YELLOW%^" + foo + "%^RESET%^ (" + sites +")", this_player());
to this:
if(!str) message("system", "[" + i++ +"] %^YELLOW%^" + foo + "%^RESET%^", this_player());
The complete code would look like this:
#include <lib.h>
inherit LIB_DAEMON;
mixed cmd(string str) {
object ob; /* object to teleport to, if requested */
string *fils; /* list of filenames in directory (path not included)*/
string foo; /* short description of room */
int i=1; /* teleport sites index */
int dn; /* total number of domains */
string intstr; /* path corresponding to numeric index */
string *domains; /* directories */
string *sites; /* filenames including full path for rooms */
/* Domains is the array that contains list of directories to look for rooms in. Feel free to add in more. */
domains = ({ "" }); /* fill in a few blanks to startup */
domains += ({ "/domains/campus/room/" });
domains += ({ "/domains/town/room/" });
sites = ({ "" }); /* fill in a few blanks to startup*/
sites += ({ "" });
foreach(string fil in sites)
{
foo = load_object(fil)->GetShort();
sites += ({ fil });
if(!str) message("system", "[" + i++ +"] %^YELLOW%^" + foo + "%^RESET%^", this_player());
}
dn = sizeof(domains); /* Domain refers to directory containing rooms. Site refers to specific rooms */
while(dn-- >0){
fils = get_dir(domains[dn]+"*.c");
/* Core of teleport.c. Grabs file by file from directory. Feeds filename including path and corresponding index into sites array for later retrieval if required */
foreach(string fil in fils){
foo = load_object(domains[dn] + fil)->GetShort();
sites += ({ domains[dn] +fil});
if(!str) message("system", "[" + i++ +"] %^YELLOW%^" + foo + "%^RESET%^", this_player());
} /*endforeach*/
} /*endwhile*/
/* Teleport X where X can be an index (integer), exact path (string) of room, or an object. If X were integer, intstr is the string of filename (including path) X refers to */
intstr = sites[to_int(str)+1];
if(!str) return "Teleport where?"; /* no parameter supplied */
/* Goto object if that happens to be the parameter to go to */
if((ob = find_living(lower_case(str))) &&
(!ob->GetInvis() || !archp(ob)) && ob=environment(ob)) {
if(ob == environment(this_player())) {
message("my_action", "You twitch.", this_player());
if(hiddenp(this_player())) return 1;
message("other_action", (string)this_player()->GetName()+
" twitches.", ob, ({ this_player() }));
return 1;
}
}
if(ob && ob->GetInvis() && creatorp(ob) && !archp(this_player())) ob = 0;
if(!ob) str = absolute_path((string)this_player()->query_cwd(), str);
if(ob) {
this_player()->eventMoveLiving(ob, "");
return 1;
}
if(file_exists(intstr)) str = intstr;
if(!file_exists(str)) str += ".c";
if(!file_exists(str)) {
write("Location not found."); /* Parameter given but no match */
return 1;
}
else this_player()->eventMoveLiving(str, ""); /* Actual moving of you to destination. Three ifs above sorts out index and file extension issues */
return 1;
}
void help() {
message("help",
"Syntax: <Teleport [living thing|file|number]>\n\n"
"This command will move you to where the living thing is if it can "
"be found, otherwise it will search for the file named or file that corresponds to the index number and try to "
"move you into that placele.\n\nSee also: home, move, trans, expel.",
this_player()
);
}
Daelas