diff --git a/src/util/wld2html.c b/src/util/wld2html.c index ac3c111..410d0bc 100755 --- a/src/util/wld2html.c +++ b/src/util/wld2html.c @@ -12,7 +12,6 @@ #include "conf.h" #include "sysdep.h" - #define NOWHERE -1 /* nil reference for room-database */ /* The cardinal directions: used as index to room_data.dir_option[] */ @@ -22,14 +21,17 @@ #define WEST 3 #define UP 4 #define DOWN 5 +#define NORTHWEST 6 +#define NORTHEAST 7 +#define SOUTHEAST 8 +#define SOUTHWEST 9 -#define NUM_OF_DIRS 6 +#define NUM_OF_DIRS 10 #define CREATE(result, type, number) do {\ if (!((result) = (type *) calloc ((number), sizeof(type))))\ { perror("malloc failure"); abort(); } } while(0) - /* Exit info: used in room_data.dir_option.exit_info */ #define EX_ISDOOR (1 << 0) /* Exit is a door */ #define EX_CLOSED (1 << 1) /* The door is closed */ @@ -45,7 +47,7 @@ typedef unsigned short int ush_int; typedef char bool; typedef char byte; -typedef sh_int room_num; +typedef int room_num; typedef sh_int obj_num; @@ -133,13 +135,14 @@ struct room_data { struct room_data *world = NULL; /* array of rooms */ int top_of_world = 0; /* ref to top element of world */ +int rec_count = 0; /* local functions */ char *fread_string(FILE * fl, char *error); void setup_dir(FILE * fl, int room, int dir); -void index_boot(char *name); +void index_boot(int cnt, char **name); void discrete_load(FILE * fl); void parse_room(FILE * fl, int virtual_nr); void parse_mobile(FILE * mob_f, int nr); @@ -150,7 +153,7 @@ void write_output(void); char *dir_names[] = -{"North", "East", "South", "West", "Up", "Down"}; +{"North", "East", "South", "West", "Up", "Down","North West","North East","South East","South West"}; /************************************************************************* @@ -160,14 +163,12 @@ char *dir_names[] = /* body of the booting system */ int main(int argc, char **argv) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + if (argc < 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } - index_boot(argv[1]); - log("Renumbering rooms."); - renum_world(); + index_boot(argc,argv); log("Writing output."); write_output(); @@ -176,6 +177,21 @@ int main(int argc, char **argv) return (0); } +/* Since the world is loaded into memory by index + * and not room number, we need to search through + * all rooms and return the correct one. This is + * used to generate door information (ie: the name) + */ +struct room_data* findRoom(int nr) +{ + int i; + + for (i=0;ito_room != NOWHERE) { - found = 1; - fprintf(fl, " %s to %s

\n", - world[world[i].dir_option[door]->to_room].number, - dir_names[door], - world[world[i].dir_option[door]->to_room].name); + world[i].dir_option[door]->to_room != NOWHERE) { + found = 1; + //this call gets a pointer to the room referenced by the to_room for the door. + //This fixes a lot of issues introduced with the whole 'renumbering rooms' call + //and the binary search that didn't work well. + struct room_data* to_room = findRoom(world[i].dir_option[door]->to_room); + fprintf(fl, " %s to %s

\n", + to_room->number, + dir_names[door], + to_room->name); } if (!found) fprintf(fl, "None!"); fclose(fl); } -} +} /* function to count how many hash-mark delimited records exist in a file */ int count_hash_records(FILE * fl) @@ -231,19 +262,35 @@ int count_hash_records(FILE * fl) -void index_boot(char *name) +void index_boot(int cnt, char **names) { FILE *db_file; - int rec_count = 0; - if (!(db_file = fopen(name, "r"))) { - perror("error opening world file"); - exit(1); + //throw first entry away as that is the executable. + for (int i=1;ito_room != NOWHERE) - world[room].dir_option[door]->to_room = - real_room(world[room].dir_option[door]->to_room, - world[room].number); -} - - - /************************************************************************* * procedures for resetting, both play-time and boot-time * *********************************************************************** */ @@ -467,32 +498,6 @@ char *fread_string(FILE * fl, char *error) -/* returns the real number of the room with given virtual number */ -int real_room(int virtual, int reference) -{ - int bot, top, mid; - - bot = 0; - top = top_of_world; - - /* perform binary search on world-table */ - for (;;) { - mid = (bot + top) / 2; - - if ((world + mid)->number == virtual) - return (mid); - if (bot >= top) { - fprintf(stderr, "Room %d does not exist in database (referenced in room %d)\n", virtual, reference); - return (-1); - } - if ((world + mid)->number > virtual) - top = mid - 1; - else - bot = mid + 1; - } -} - - /* get_line reads the next non-blank line off of the input stream. * The newline character is removed from the input. Lines which begin * with '*' are considered to be comments.