00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <global.h>
00035 #include <random_map.h>
00036 #include <rproto.h>
00037
00045 static int can_propagate(char item) {
00046 return (item == '\0' || item == '<' || item == '>') ? 1 : 0;
00047 }
00048
00061 static void put_floor(mapstruct *map, char **layout, int x, int y, object *floor_arch) {
00062 int dx, dy;
00063 object *floor;
00064
00065 floor = arch_to_object(floor_arch->arch);
00066 floor->x = x;
00067 floor->y = y;
00068 insert_ob_in_map(floor, map, floor, INS_NO_MERGE|INS_NO_WALK_ON);
00069
00070 for (dx = -1; dx < 2; dx++) {
00071 for (dy = -1; dy < 2; dy++) {
00072 if (GET_MAP_OB(map, x+dx, y+dy) == NULL && can_propagate(layout[x+dx][y+dy]))
00073 put_floor(map, layout, x+dx, y+dy, floor_arch);
00074 }
00075 }
00076 }
00077
00089 mapstruct *make_map_floor(char **layout, char *floorstyle, RMParms *RP) {
00090 char styledirname[256];
00091 char stylefilepath[256];
00092 mapstruct *style_map = NULL;
00093 object *the_floor;
00094 mapstruct *newMap = NULL;
00095 int x, y;
00096
00097
00098 newMap = get_empty_map(RP->Xsize, RP->Ysize);
00099
00100
00101 snprintf(styledirname, sizeof(styledirname), "%s", "/styles/floorstyles");
00102 snprintf(stylefilepath, sizeof(stylefilepath), "%s/%s", styledirname, floorstyle);
00103 style_map = find_style(styledirname, floorstyle, -1);
00104 if (style_map == NULL)
00105 return newMap;
00106
00107 if (RP->multiple_floors) {
00108 for (x = 0; x < RP->Xsize; x++) {
00109 for (y = 0; y < RP->Ysize; y++) {
00110 if (GET_MAP_OB(newMap, x, y) == NULL && layout[x][y] == '\0')
00111 put_floor(newMap, layout, x, y, pick_random_object(style_map));
00112 }
00113 }
00114 }
00115
00116
00117 if ((the_floor = pick_random_object(style_map)) != NULL) {
00118 object *thisfloor;
00119
00120 for (x = 0; x < RP->Xsize; x++)
00121 for (y = 0; y < RP->Ysize; y++) {
00122 if (GET_MAP_OB(newMap, x, y) != NULL)
00123 continue;
00124 thisfloor = arch_to_object(the_floor->arch);
00125 thisfloor->x = x;
00126 thisfloor->y = y;
00127 insert_ob_in_map(thisfloor, newMap, thisfloor, INS_NO_MERGE|INS_NO_WALK_ON);
00128 }
00129 }
00130 return newMap;
00131 }