5 #include "rooms-city.h"
11 * Precalculate buildings' location of underground arcade
13 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
15 POSITION i, y, x, center_y, center_x;
16 int tmp, attempt = 10000;
17 POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
18 POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
19 ugbldg_type *cur_ugbldg;
20 bool **ugarcade_used, abort;
22 /* Allocate "ugarcade_used" array (2-dimension) */
23 C_MAKE(ugarcade_used, town_hgt, bool *);
24 C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
25 for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
27 /* Calculate building locations */
28 for (i = 0; i < n; i++)
30 cur_ugbldg = &ugbldg[i];
31 (void)WIPE(cur_ugbldg, ugbldg_type);
35 /* Find the "center" of the store */
36 center_y = rand_range(2, town_hgt - 3);
37 center_x = rand_range(2, town_wid - 3);
39 /* Determine the store boundaries */
40 tmp = center_y - randint1(max_bldg_hgt);
41 cur_ugbldg->y0 = MAX(tmp, 1);
42 tmp = center_x - randint1(max_bldg_wid);
43 cur_ugbldg->x0 = MAX(tmp, 1);
44 tmp = center_y + randint1(max_bldg_hgt);
45 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
46 tmp = center_x + randint1(max_bldg_wid);
47 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
49 /* Scan this building's area */
50 for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
52 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
54 if (ugarcade_used[y][x])
63 } while (abort && attempt); /* Accept this building if no overlapping */
65 /* Failed to generate underground arcade */
69 * Mark to ugarcade_used[][] as "used"
70 * Note: Building-adjacent grids are included for preventing
71 * connected bulidings.
73 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
75 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
77 ugarcade_used[y][x] = TRUE;
82 /* Free "ugarcade_used" array (2-dimension) */
83 C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
84 C_KILL(ugarcade_used, town_hgt, bool *);
86 /* If i < n, generation is not allowed */
92 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
96 * @param stotes[] 生成する店舗のリスト
99 * Note: ltcy and ltcx indicate "left top corner".
101 static void build_stores(POSITION ltcy, POSITION ltcx, int stores[], int n)
106 ugbldg_type *cur_ugbldg;
108 for (i = 0; i < n; i++)
110 cur_ugbldg = &ugbldg[i];
112 /* Generate new room */
114 ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
115 ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
119 for (i = 0; i < n; i++)
121 cur_ugbldg = &ugbldg[i];
123 /* Build an invulnerable rectangular building */
124 generate_fill_perm_bold(
125 ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
126 ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
128 /* Pick a door direction (S,N,E,W) */
134 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
140 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
145 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
151 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
156 for (j = 0; j < max_f_idx; j++)
158 if (have_flag(f_info[j].flags, FF_STORE))
160 if (f_info[j].subtype == stores[i]) break;
164 /* Clear previous contents, add a store door */
167 cave_set_feat(ltcy + y, ltcx + x, j);
170 store_init(NO_TOWN, stores[i]);
177 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
180 * Town logic flow for generation of new town\n
181 * Originally from Vanilla 3.0.3\n
183 * We start with a fully wiped current_floor_ptr->grid_array of normal floors.\n
185 * Note that town_gen_hack() plays games with the R.N.G.\n
187 * This function does NOT do anything about the owners of the stores,\n
188 * nor the contents thereof. It only handles the physical layout.\n
190 bool build_type16(void)
194 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
195 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
197 int n = sizeof stores / sizeof(int);
198 POSITION i, y, x, y1, x1, yval, xval;
199 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
200 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
201 bool prevent_bm = FALSE;
203 /* Hack -- If already exist black market, prevent building */
204 for (y = 0; (y < current_floor_ptr->height) && !prevent_bm; y++)
206 for (x = 0; x < current_floor_ptr->width; x++)
208 if (current_floor_ptr->grid_array[y][x].feat == FF_STORE)
210 prevent_bm = (f_info[current_floor_ptr->grid_array[y][x].feat].subtype == STORE_BLACK);
215 for (i = 0; i < n; i++)
217 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
219 if (!n) return FALSE;
221 /* Allocate buildings array */
222 C_MAKE(ugbldg, n, ugbldg_type);
224 /* If cannot build stores, abort */
225 if (!precalc_ugarcade(town_hgt, town_wid, n))
227 /* Free buildings array */
228 C_KILL(ugbldg, n, ugbldg_type);
232 /* Find and reserve some space in the dungeon. Get center of room. */
233 if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
235 /* Free buildings array */
236 C_KILL(ugbldg, n, ugbldg_type);
240 /* Get top left corner */
241 y1 = yval - (town_hgt / 2);
242 x1 = xval - (town_wid / 2);
244 /* Generate new room */
246 y1 + town_hgt / 3, x1 + town_wid / 3,
247 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
250 build_stores(y1, x1, stores, n);
252 msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));
254 /* Free buildings array */
255 C_KILL(ugbldg, n, ugbldg_type);