6 #include "floor-generate.h"
8 #include "rooms-city.h"
14 * Precalculate buildings' location of underground arcade
16 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
18 POSITION i, y, x, center_y, center_x;
19 int tmp, attempt = 10000;
20 POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
21 POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
22 ugbldg_type *cur_ugbldg;
23 bool **ugarcade_used, abort;
25 /* Allocate "ugarcade_used" array (2-dimension) */
26 C_MAKE(ugarcade_used, town_hgt, bool *);
27 C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
28 for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
30 /* Calculate building locations */
31 for (i = 0; i < n; i++)
33 cur_ugbldg = &ugbldg[i];
34 (void)WIPE(cur_ugbldg, ugbldg_type);
38 /* Find the "center" of the store */
39 center_y = rand_range(2, town_hgt - 3);
40 center_x = rand_range(2, town_wid - 3);
42 /* Determine the store boundaries */
43 tmp = center_y - randint1(max_bldg_hgt);
44 cur_ugbldg->y0 = MAX(tmp, 1);
45 tmp = center_x - randint1(max_bldg_wid);
46 cur_ugbldg->x0 = MAX(tmp, 1);
47 tmp = center_y + randint1(max_bldg_hgt);
48 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
49 tmp = center_x + randint1(max_bldg_wid);
50 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
52 /* Scan this building's area */
53 for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
55 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
57 if (ugarcade_used[y][x])
66 } while (abort && attempt); /* Accept this building if no overlapping */
68 /* Failed to generate underground arcade */
72 * Mark to ugarcade_used[][] as "used"
73 * Note: Building-adjacent grids are included for preventing
74 * connected bulidings.
76 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
78 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
80 ugarcade_used[y][x] = TRUE;
85 /* Free "ugarcade_used" array (2-dimension) */
86 C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
87 C_KILL(ugarcade_used, town_hgt, bool *);
89 /* If i < n, generation is not allowed */
95 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
99 * @param stotes[] 生成する店舗のリスト
102 * Note: ltcy and ltcx indicate "left top corner".
104 static void build_stores(POSITION ltcy, POSITION ltcx, int stores[], int n)
109 ugbldg_type *cur_ugbldg;
111 for (i = 0; i < n; i++)
113 cur_ugbldg = &ugbldg[i];
115 /* Generate new room */
117 ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
118 ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
122 for (i = 0; i < n; i++)
124 cur_ugbldg = &ugbldg[i];
126 /* Build an invulnerable rectangular building */
127 generate_fill_perm_bold(
128 ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
129 ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
131 /* Pick a door direction (S,N,E,W) */
137 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
143 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
148 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
154 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
159 for (j = 0; j < max_f_idx; j++)
161 if (have_flag(f_info[j].flags, FF_STORE))
163 if (f_info[j].subtype == stores[i]) break;
167 /* Clear previous contents, add a store door */
170 cave_set_feat(ltcy + y, ltcx + x, j);
173 store_init(NO_TOWN, stores[i]);
180 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
183 * Town logic flow for generation of new town\n
184 * Originally from Vanilla 3.0.3\n
186 * We start with a fully wiped current_floor_ptr->grid_array of normal floors.\n
188 * Note that town_gen_hack() plays games with the R.N.G.\n
190 * This function does NOT do anything about the owners of the stores,\n
191 * nor the contents thereof. It only handles the physical layout.\n
193 bool build_type16(void)
197 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
198 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
200 int n = sizeof stores / sizeof(int);
201 POSITION i, y, x, y1, x1, yval, xval;
202 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
203 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
204 bool prevent_bm = FALSE;
206 /* Hack -- If already exist black market, prevent building */
207 for (y = 0; (y < current_floor_ptr->height) && !prevent_bm; y++)
209 for (x = 0; x < current_floor_ptr->width; x++)
211 if (current_floor_ptr->grid_array[y][x].feat == FF_STORE)
213 prevent_bm = (f_info[current_floor_ptr->grid_array[y][x].feat].subtype == STORE_BLACK);
218 for (i = 0; i < n; i++)
220 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
222 if (!n) return FALSE;
224 /* Allocate buildings array */
225 C_MAKE(ugbldg, n, ugbldg_type);
227 /* If cannot build stores, abort */
228 if (!precalc_ugarcade(town_hgt, town_wid, n))
230 /* Free buildings array */
231 C_KILL(ugbldg, n, ugbldg_type);
235 /* Find and reserve some space in the dungeon. Get center of room. */
236 if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
238 /* Free buildings array */
239 C_KILL(ugbldg, n, ugbldg_type);
243 /* Get top left corner */
244 y1 = yval - (town_hgt / 2);
245 x1 = xval - (town_wid / 2);
247 /* Generate new room */
249 y1 + town_hgt / 3, x1 + town_wid / 3,
250 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
253 build_stores(y1, x1, stores, n);
255 msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));
257 /* Free buildings array */
258 C_KILL(ugbldg, n, ugbldg_type);