5 #include "floor-generate.h"
7 #include "rooms-city.h"
13 * Precalculate buildings' location of underground arcade
15 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
17 POSITION i, y, x, center_y, center_x;
18 int tmp, attempt = 10000;
19 POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
20 POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
21 ugbldg_type *cur_ugbldg;
22 bool **ugarcade_used, abort;
24 /* Allocate "ugarcade_used" array (2-dimension) */
25 C_MAKE(ugarcade_used, town_hgt, bool *);
26 C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
27 for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
29 /* Calculate building locations */
30 for (i = 0; i < n; i++)
32 cur_ugbldg = &ugbldg[i];
33 (void)WIPE(cur_ugbldg, ugbldg_type);
37 /* Find the "center" of the store */
38 center_y = rand_range(2, town_hgt - 3);
39 center_x = rand_range(2, town_wid - 3);
41 /* Determine the store boundaries */
42 tmp = center_y - randint1(max_bldg_hgt);
43 cur_ugbldg->y0 = MAX(tmp, 1);
44 tmp = center_x - randint1(max_bldg_wid);
45 cur_ugbldg->x0 = MAX(tmp, 1);
46 tmp = center_y + randint1(max_bldg_hgt);
47 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
48 tmp = center_x + randint1(max_bldg_wid);
49 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
51 /* Scan this building's area */
52 for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
54 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
56 if (ugarcade_used[y][x])
65 } while (abort && attempt); /* Accept this building if no overlapping */
67 /* Failed to generate underground arcade */
71 * Mark to ugarcade_used[][] as "used"
72 * Note: Building-adjacent grids are included for preventing
73 * connected bulidings.
75 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
77 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
79 ugarcade_used[y][x] = TRUE;
84 /* Free "ugarcade_used" array (2-dimension) */
85 C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
86 C_KILL(ugarcade_used, town_hgt, bool *);
88 /* If i < n, generation is not allowed */
94 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
98 * @param stotes[] 生成する店舗のリスト
101 * Note: ltcy and ltcx indicate "left top corner".
103 static void build_stores(POSITION ltcy, POSITION ltcx, int stores[], int n)
108 ugbldg_type *cur_ugbldg;
110 for (i = 0; i < n; i++)
112 cur_ugbldg = &ugbldg[i];
114 /* Generate new room */
116 ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
117 ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
121 for (i = 0; i < n; i++)
123 cur_ugbldg = &ugbldg[i];
125 /* Build an invulnerable rectangular building */
126 generate_fill_perm_bold(
127 ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
128 ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
130 /* Pick a door direction (S,N,E,W) */
136 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
142 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
147 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
153 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
158 for (j = 0; j < max_f_idx; j++)
160 if (have_flag(f_info[j].flags, FF_STORE))
162 if (f_info[j].subtype == stores[i]) break;
166 /* Clear previous contents, add a store door */
169 cave_set_feat(ltcy + y, ltcx + x, j);
172 store_init(NO_TOWN, stores[i]);
179 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
182 * Town logic flow for generation of new town\n
183 * Originally from Vanilla 3.0.3\n
185 * We start with a fully wiped current_floor_ptr->grid_array of normal floors.\n
187 * Note that town_gen_hack() plays games with the R.N.G.\n
189 * This function does NOT do anything about the owners of the stores,\n
190 * nor the contents thereof. It only handles the physical layout.\n
192 bool build_type16(void)
196 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
197 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
199 int n = sizeof stores / sizeof(int);
200 POSITION i, y, x, y1, x1, yval, xval;
201 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
202 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
203 bool prevent_bm = FALSE;
205 /* Hack -- If already exist black market, prevent building */
206 for (y = 0; (y < current_floor_ptr->height) && !prevent_bm; y++)
208 for (x = 0; x < current_floor_ptr->width; x++)
210 if (current_floor_ptr->grid_array[y][x].feat == FF_STORE)
212 prevent_bm = (f_info[current_floor_ptr->grid_array[y][x].feat].subtype == STORE_BLACK);
217 for (i = 0; i < n; i++)
219 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
221 if (!n) return FALSE;
223 /* Allocate buildings array */
224 C_MAKE(ugbldg, n, ugbldg_type);
226 /* If cannot build stores, abort */
227 if (!precalc_ugarcade(town_hgt, town_wid, n))
229 /* Free buildings array */
230 C_KILL(ugbldg, n, ugbldg_type);
234 /* Find and reserve some space in the dungeon. Get center of room. */
235 if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
237 /* Free buildings array */
238 C_KILL(ugbldg, n, ugbldg_type);
242 /* Get top left corner */
243 y1 = yval - (town_hgt / 2);
244 x1 = xval - (town_wid / 2);
246 /* Generate new room */
248 y1 + town_hgt / 3, x1 + town_wid / 3,
249 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
252 build_stores(y1, x1, stores, n);
254 msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));
256 /* Free buildings array */
257 C_KILL(ugbldg, n, ugbldg_type);