/* Clear, generate and display the map */ void draw_map( CHAR_DATA *ch, char *desc ) { int x, y; static char buf[MAX_STRING_LENGTH]; xprintf( buf, desc ); /* Remove undesirable characters */ reformat_desc( buf ); /* Clear map */ for( y = 0; y <= MAPY; y++ ) { for( x = 0; x <= MAPX; x++ ) { clear_coord( x, y ); } } /* Start with players pos at centre of map */ x = MAPX / 2; y = MAPY / 2; map[x][y].vnum = ch->in_room->vnum; map[x][y].depth = 0; /* Generate the map */ map_exits( ch, ch->in_room, x, y, 0 ); /* Current position should be a "X" */ map[x][y].tegn = 'X'; /* Send the map */ show_map( ch, buf ); }
/* Clear, generate and display the map */ void draw_room_map( CHAR_DATA * ch, const char *desc ) { int x, y; static char buf[MAX_STRING_LENGTH]; mudstrlcpy( buf, desc, MAX_STRING_LENGTH ); /* * Remove undesirable characters */ reformat_desc( buf ); /* * Clear map */ for ( y = 0; y <= MAPY; ++y ) { for ( x = 0; x <= MAPX; ++x ) { clear_coord( x, y ); } } /* * Start with players pos at centre of map */ x = MAPX / 2; y = MAPY / 2; dmap[x][y].vnum = ch->in_room->vnum; dmap[x][y].depth = 0; /* * Generate the map */ map_exits( ch, ch->in_room, x, y, 0 ); /* * Current position should be a "X" */ dmap[x][y].tegn = '@'; dmap[x][y].sector = -1; /* * Send the map */ show_map( ch, buf ); }
/* This function is recursive, ie it calls itself */ void map_exits( CHAR_DATA * ch, ROOM_INDEX_DATA * pRoom, int x, int y, int depth ) { static char map_chars[11] = "|-|-UD/\\\\/"; int door; int exitx = 0, exity = 0; int roomx = 0, roomy = 0; EXIT_DATA *pExit; /* * Setup this coord as a room - Change any symbols that can't be displayed here */ dmap[x][y].sector = pRoom->sector_type; switch ( pRoom->sector_type ) { case SECT_INSIDE: dmap[x][y].tegn = 'O'; dmap[x][y].sector = -1; break; case SECT_CITY: dmap[x][y].tegn = ':'; break; case SECT_FIELD: case SECT_FOREST: case SECT_HILLS: dmap[x][y].tegn = '*'; break; case SECT_MOUNTAIN: dmap[x][y].tegn = '@'; break; case SECT_WATER_SWIM: case SECT_WATER_NOSWIM: dmap[x][y].tegn = '='; break; case SECT_AIR: dmap[x][y].tegn = '~'; break; case SECT_DESERT: dmap[x][y].tegn = '+'; break; default: dmap[x][y].tegn = 'O'; dmap[x][y].sector = -1; bug( "%s: Bad sector type (%d) in room %d.", __FUNCTION__, pRoom->sector_type, pRoom->vnum ); break; } dmap[x][y].vnum = pRoom->vnum; dmap[x][y].depth = depth; // dmap[x][y].info = pRoom->room_flags; dmap[x][y].can_see = room_is_dark( pRoom ); /* * Limit recursion */ if ( depth > MAXDEPTH ) return; /* * This room is done, deal with it's exits */ for ( door = 0; door < 10; ++door ) { /* * Skip if there is no exit in this direction */ if ( !( pExit = get_exit( pRoom, door ) ) ) continue; /* * Skip up and down until I can figure out a good way to display it */ if ( door == 4 || door == 5 ) continue; /* * Get the coords for the next exit and room in this direction */ get_exit_dir( door, &exitx, &exity, x, y ); get_exit_dir( door, &roomx, &roomy, exitx, exity ); /* * Skip if coords fall outside map */ if ( BOUNDARY( exitx, exity ) || BOUNDARY( roomx, roomy ) ) continue; /* * Skip if there is no room beyond this exit */ if ( !pExit->to_room ) continue; /* * Ensure there are no clashes with previously defined rooms */ if ( ( dmap[roomx][roomy].vnum != 0 ) && ( dmap[roomx][roomy].vnum != pExit->to_room->vnum ) ) { /* * Use the new room if the depth is higher */ if ( dmap[roomx][roomy].depth <= depth ) continue; /* * It is so clear the old room */ clear_room( roomx, roomy ); } /* * No exits at MAXDEPTH */ if ( depth == MAXDEPTH ) continue; /* * No need for exits that are already mapped */ if ( dmap[exitx][exity].depth > 0 ) continue; /* * Fill in exit */ dmap[exitx][exity].depth = depth; dmap[exitx][exity].vnum = pExit->to_room->vnum; // dmap[exitx][exity].info = pExit->exit_info; dmap[exitx][exity].tegn = map_chars[door]; dmap[exitx][exity].sector = -1; /* * More to do? If so we recurse */ if ( depth < MAXDEPTH && ( ( dmap[roomx][roomy].vnum == pExit->to_room->vnum ) || ( dmap[roomx][roomy].vnum == 0 ) ) ) { /* * Depth increases by one each time */ map_exits( ch, pExit->to_room, roomx, roomy, depth + 1 ); } } }
/* This function is recursive, ie it calls itself */ void map_exits(CHAR_DATA *ch, ROOM_INDEX_DATA *pRoom, int x, int y, int depth) { static char map_chars [4] = "|-|-"; int door; int exitx = 0, exity = 0; int roomx = 0, roomy = 0; char buf[200]; // bugs EXIT_DATA *pExit; /* Setup this coord as a room */ switch(pRoom->sector_type) { case SECT_CITY: case SECT_INSIDE: case SECT_UNUSED: map[x][y].tegn = 'O'; break; case SECT_FIELD: case SECT_FOREST: case SECT_HILLS: map[x][y].tegn = '*'; break; case SECT_MOUNTAIN: map[x][y].tegn = '@'; break; case SECT_WATER_SWIM: case SECT_WATER_NOSWIM: map[x][y].tegn = '='; break; case SECT_AIR: map[x][y].tegn = '~'; break; case SECT_DESERT: map[x][y].tegn = '+'; break; default: map[x][y].tegn = 'O'; xprintf(buf, "Map_exits: Bad sector type (%d) in room %d.", pRoom->sector_type, pRoom->vnum); bug(buf, 0); break; } map[x][y].vnum = pRoom->vnum; map[x][y].depth = depth; map[x][y].info = pRoom->room_flags; map[x][y].can_see = room_is_dark( pRoom ); /* Limit recursion */ if ( depth > MAXDEPTH ) return; /* This room is done, deal with it's exits */ for( door = 0; door < 4; door++ ) { /* Skip if there is no exit in this direction */ if ( ( pExit = pRoom->exit[door] ) == NULL ) continue; /* Get the coords for the next exit and room in this direction */ get_exit_dir( door, &exitx, &exity, x, y ); get_exit_dir( door, &roomx, &roomy, exitx, exity ); /* Skip if coords fall outside map */ if ( BOUNDARY( exitx, exity ) || BOUNDARY( roomx, roomy )) continue; /* Skip if there is no room beyond this exit */ if ( pExit->to_room == NULL ) continue; /* Ensure there are no clashes with previously defined rooms */ if ( ( map[roomx][roomy].vnum != 0 ) && ( map[roomx][roomy].vnum != pExit->to_room->vnum )) { /* Use the new room if the depth is higher */ if ( map[roomx][roomy].depth <= depth ) continue; /* It is so clear the old room */ clear_room( roomx, roomy ); } /* No exits at MAXDEPTH */ if ( depth == MAXDEPTH ) continue; /* No need for exits that are already mapped */ if ( map[exitx][exity].depth > 0 ) continue; /* Fill in exit */ map[exitx][exity].depth = depth; map[exitx][exity].vnum = pExit->to_room->vnum; map[exitx][exity].info = pExit->exit_info; map[exitx][exity].tegn = map_chars[door]; /* More to do? If so we recurse */ if ( ( depth < MAXDEPTH ) && ( ( map[roomx][roomy].vnum == pExit->to_room->vnum ) || ( map[roomx][roomy].vnum == 0 ) ) ) { /* Depth increases by one each time */ map_exits( ch, pExit->to_room, roomx, roomy, depth + 1 ); } } }