… | |
… | |
43 | /* clear map completely of all !floor objects: |
43 | /* clear map completely of all !floor objects: |
44 | * a rectangular area of xsize, ysize |
44 | * a rectangular area of xsize, ysize |
45 | * is cleared with the top left corner at xstart, ystart |
45 | * is cleared with the top left corner at xstart, ystart |
46 | */ |
46 | */ |
47 | static void |
47 | static void |
48 | nuke_map_region (maptile *map, char **layout, int xstart, int ystart, int xsize, int ysize) |
48 | nuke_map_region (maptile *map, char **maze, int xstart, int ystart, int xsize, int ysize) |
49 | { |
49 | { |
50 | for (int i = xstart; i < xstart + xsize; i++) |
50 | for (int i = xstart; i < xstart + xsize; i++) |
51 | for (int j = ystart; j < ystart + ysize; j++) |
51 | for (int j = ystart; j < ystart + ysize; j++) |
52 | { |
52 | { |
53 | layout[i][j] = 'S'; |
53 | maze[i][j] = 'S'; |
54 | |
54 | |
55 | for (object *tmp = map->at (i, j).bot; tmp; ) |
55 | for (object *tmp = map->at (i, j).bot; tmp; ) |
56 | if (tmp->flag [FLAG_IS_FLOOR]) |
56 | if (tmp->flag [FLAG_IS_FLOOR]) |
57 | tmp = tmp->above; |
57 | tmp = tmp->above; |
58 | else |
58 | else |
… | |
… | |
84 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
84 | dest_map->insert (new_ob, x + i, y + j, 0, INS_NO_MERGE | INS_NO_WALK_ON); |
85 | } |
85 | } |
86 | } |
86 | } |
87 | |
87 | |
88 | static int |
88 | static int |
89 | find_spot_for_submap (maptile *map, char **layout, int *ix, int *iy, int xsize, int ysize) |
89 | find_spot_for_submap (maptile *map, char **maze, int *ix, int *iy, int xsize, int ysize) |
90 | { |
90 | { |
91 | int blocked, i, j; |
91 | int blocked, i, j; |
92 | |
92 | |
93 | /* don't even try to place a submap into a map if the big map isn't |
93 | /* don't even try to place a submap into a map if the big map isn't |
94 | sufficiently large. */ |
94 | sufficiently large. */ |
… | |
… | |
98 | /* search a bit for a completely free spot. */ |
98 | /* search a bit for a completely free spot. */ |
99 | for (int tries = 0; tries < 20; tries++) |
99 | for (int tries = 0; tries < 20; tries++) |
100 | { |
100 | { |
101 | blocked = 0; |
101 | blocked = 0; |
102 | |
102 | |
103 | /* pick a random location in the layout */ |
103 | /* pick a random location in the maze */ |
104 | i = rmg_rndm (1, map->width - xsize - 2); |
104 | i = rmg_rndm (1, map->width - xsize - 2); |
105 | j = rmg_rndm (1, map->height - ysize - 2); |
105 | j = rmg_rndm (1, map->height - ysize - 2); |
106 | |
106 | |
107 | for (int l = i; l < i + xsize; l++) |
107 | for (int l = i; l < i + xsize; l++) |
108 | for (int m = j; m < j + ysize; m++) |
108 | for (int m = j; m < j + ysize; m++) |
… | |
… | |
116 | } |
116 | } |
117 | |
117 | |
118 | /* if we failed, relax the restrictions */ |
118 | /* if we failed, relax the restrictions */ |
119 | if (blocked) |
119 | if (blocked) |
120 | { /* failure, try a relaxed placer. */ |
120 | { /* failure, try a relaxed placer. */ |
121 | /* pick a random location in the layout */ |
121 | /* pick a random location in the maze */ |
122 | for (int tries = 0; tries < 10; tries++) |
122 | for (int tries = 0; tries < 10; tries++) |
123 | { |
123 | { |
124 | i = rmg_rndm (1, map->width - xsize - 2); |
124 | i = rmg_rndm (1, map->width - xsize - 2); |
125 | j = rmg_rndm (1, map->height - ysize - 2); |
125 | j = rmg_rndm (1, map->height - ysize - 2); |
126 | |
126 | |
127 | blocked = 0; |
127 | blocked = 0; |
128 | |
128 | |
129 | for (int l = i; l < i + xsize; l++) |
129 | for (int l = i; l < i + xsize; l++) |
130 | for (int m = j; m < j + ysize; m++) |
130 | for (int m = j; m < j + ysize; m++) |
131 | if (layout[l][m] != '#' && layout[l][m] != 'D' && layout[l][m] != 0) |
131 | if (maze[l][m] != '#' && maze[l][m] != 'D' && maze[l][m] != 0) |
132 | { |
132 | { |
133 | blocked = 1; |
133 | blocked = 1; |
134 | break; |
134 | break; |
135 | } |
135 | } |
136 | } |
136 | } |
… | |
… | |
306 | |
306 | |
307 | insert_ob_in_map (the_exit, map, NULL, 0); |
307 | insert_ob_in_map (the_exit, map, NULL, 0); |
308 | } |
308 | } |
309 | |
309 | |
310 | void |
310 | void |
311 | place_specials_in_map (maptile *map, char **layout, random_map_params *RP) |
311 | place_specials_in_map (maptile *map, char **maze, random_map_params *RP) |
312 | { |
312 | { |
313 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
313 | switch (rmg_rndm (NUM_OF_SPECIAL_TYPES)) |
314 | { |
314 | { |
315 | case SPECIAL_SUBMAP: |
315 | case SPECIAL_SUBMAP: |
316 | { |
316 | { |
… | |
… | |
320 | if (!special_map) |
320 | if (!special_map) |
321 | break; |
321 | break; |
322 | |
322 | |
323 | int ix, iy; /* map insertion locatons */ |
323 | int ix, iy; /* map insertion locatons */ |
324 | |
324 | |
325 | if (find_spot_for_submap (map, layout, &ix, &iy, special_map->width, special_map->height)) |
325 | if (find_spot_for_submap (map, maze, &ix, &iy, special_map->width, special_map->height)) |
326 | { |
326 | { |
327 | /* First, splatter everything in the dest map at the location */ |
327 | /* First, splatter everything in the dest map at the location */ |
328 | nuke_map_region (map, layout, ix, iy, special_map->width, special_map->height); |
328 | nuke_map_region (map, maze, ix, iy, special_map->width, special_map->height); |
329 | include_map_in_map (map, special_map, ix, iy); |
329 | include_map_in_map (map, special_map, ix, iy); |
330 | } |
330 | } |
331 | } |
331 | } |
332 | |
332 | |
333 | break; |
333 | break; |