Dead Souls HideExit code
Attachment: Click for related file download
This is my update to the /lib/exits.c and /lib/std/room.c to make obvious exits easier to use and worth with. It adds the following:
- a sub-mapping to the Exits mapping in exits.c to include ([ “obv” : 0 or 1 ]).
- HideExit(dir), which hides the given exit (and should be used in your room code to hide exits)
- GetObvMap(), which returns a mapping of direction and hidden [Example where south is hidden by HideExit(“south”): ([ “west” : 1, “north” : 1, “east” : 1, “south” : 0 ]) ].
Room Exits default to Obvious, so there is no need to set them. The old SetObviousExits and its related functions are still included and valid for compatibility purposes.
I will be releasing another version of this code for use with muds who want more than the [n, s, e, w, u] exit list.
Insert this code into /lib/exits.c:
//Use this to get whether or not an exit is obvious. int GetExitObv( string str ) { if( !Exits[str] ) return 0; else return Exits[str]["obv"]; } //Use this or GetFullExitData to get a mapping of obvious or not, to use for visible/invisible doors in std/room.c mapping GetObvMap() { mapping ret = ([]); foreach(string key in keys(Exits)){ ret[key] = Exits[key]["obv"]; } return ret; } //Use this to hide an exit int HideExit( string dir ) { return Exits[dir]["obv"] = 0; }
Replace the existing GenerateObviousExits() in /lib/std/room.c with this:
int GenerateObviousExits(){ string *normals; string *exits; string dir_string, enters; mapping obv; exits = GetExits(); obv = GetObvMap(); enters = ""; normals = ({ "north", "south", "east", "west", "up", "down" }); normals += ({ "northeast", "southeast", "northwest", "southwest" }); normals += ({ "out" }); dir_string = ""; if(sizeof(GetEnters(1)-({0}))){ foreach(string enter in this_object()->GetEnters(1)){ if (obv["enter "+enter] == 1) { enters += "enter "+enter; if(member_array(enter,this_object()->GetEnters(1)) != sizeof(this_object()->GetEnters(1)) -1) { enters +=", "; } } } } if(member_array("north",exits) != -1 && obv["north"] == 1) dir_string += "n, "; if(member_array("south",exits) != -1 && obv["south"] == 1) dir_string += "s, "; if(member_array("east",exits) != -1 && obv["east"] == 1) dir_string += "e, "; if(member_array("west",exits) != -1 && obv["west"] == 1) dir_string += "w, "; if(member_array("northeast",exits) != -1 && obv["northeast"] == 1) dir_string += "ne, "; if(member_array("northwest",exits) != -1 && obv["northwest"] == 1) dir_string += "nw, "; if(member_array("southeast",exits) != -1 && obv["southeast"] == 1) dir_string += "se, "; if(member_array("southwest",exits) != -1 && obv["southwest"] == 1) dir_string += "sw, "; if(member_array("up",exits) != -1 && obv["up"] == 1) dir_string += "u, "; if(member_array("down",exits) != -1 && obv["down"] == 1) dir_string += "d, "; if(member_array("out",exits) != -1 && obv["out"] == 1) dir_string += "out, "; if(sizeof(this_object()->GetEnters(1) - ({0}) )) { if(sizeof(this_object()->GetExits())) dir_string += ", "; dir_string += enters; } if(last(dir_string,2) == ", ") dir_string = truncate(dir_string,2); dir_string = replace_string(dir_string,", , ",", "); if(ObviousVisible) SetObviousExits(dir_string); return 1; }