1 #include "angband.h"
\r
3 #include "generate.h"
\r
5 #include "rooms-city.h"
\r
11 * Precalculate buildings' location of underground arcade
\r
13 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)
\r
15 int i, y, x, center_y, center_x, tmp, attempt = 10000;
\r
16 int max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
\r
17 int max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
\r
18 ugbldg_type *cur_ugbldg;
\r
19 bool **ugarcade_used, abort;
\r
21 /* Allocate "ugarcade_used" array (2-dimension) */
\r
22 C_MAKE(ugarcade_used, town_hgt, bool *);
\r
23 C_MAKE(*ugarcade_used, town_hgt * town_wid, bool);
\r
24 for (y = 1; y < town_hgt; y++) ugarcade_used[y] = *ugarcade_used + y * town_wid;
\r
26 /* Calculate building locations */
\r
27 for (i = 0; i < n; i++)
\r
29 cur_ugbldg = &ugbldg[i];
\r
30 (void)WIPE(cur_ugbldg, ugbldg_type);
\r
34 /* Find the "center" of the store */
\r
35 center_y = rand_range(2, town_hgt - 3);
\r
36 center_x = rand_range(2, town_wid - 3);
\r
38 /* Determine the store boundaries */
\r
39 tmp = center_y - randint1(max_bldg_hgt);
\r
40 cur_ugbldg->y0 = MAX(tmp, 1);
\r
41 tmp = center_x - randint1(max_bldg_wid);
\r
42 cur_ugbldg->x0 = MAX(tmp, 1);
\r
43 tmp = center_y + randint1(max_bldg_hgt);
\r
44 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
\r
45 tmp = center_x + randint1(max_bldg_wid);
\r
46 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
\r
48 /* Scan this building's area */
\r
49 for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)
\r
51 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)
\r
53 if (ugarcade_used[y][x])
\r
62 } while (abort && attempt); /* Accept this building if no overlapping */
\r
64 /* Failed to generate underground arcade */
\r
65 if (!attempt) break;
\r
68 * Mark to ugarcade_used[][] as "used"
\r
69 * Note: Building-adjacent grids are included for preventing
\r
70 * connected bulidings.
\r
72 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)
\r
74 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)
\r
76 ugarcade_used[y][x] = TRUE;
\r
81 /* Free "ugarcade_used" array (2-dimension) */
\r
82 C_KILL(*ugarcade_used, town_hgt * town_wid, bool);
\r
83 C_KILL(ugarcade_used, town_hgt, bool *);
\r
85 /* If i < n, generation is not allowed */
\r
91 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
\r
93 * @param ltcy 生成基準Y座標
\r
94 * @param ltcx 生成基準X座標
\r
95 * @param stotes[] 生成する店舗のリスト
\r
98 * Note: ltcy and ltcx indicate "left top corner".
\r
100 static void build_stores(int ltcy, int ltcx, int stores[], int n)
\r
104 ugbldg_type *cur_ugbldg;
\r
106 for (i = 0; i < n; i++)
\r
108 cur_ugbldg = &ugbldg[i];
\r
110 /* Generate new room */
\r
111 generate_room_floor(
\r
112 ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2,
\r
113 ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2,
\r
117 for (i = 0; i < n; i++)
\r
119 cur_ugbldg = &ugbldg[i];
\r
121 /* Build an invulnerable rectangular building */
\r
122 generate_fill_perm_bold(
\r
123 ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0,
\r
124 ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
\r
126 /* Pick a door direction (S,N,E,W) */
\r
127 switch (randint0(4))
\r
131 y = cur_ugbldg->y1;
\r
132 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
\r
137 y = cur_ugbldg->y0;
\r
138 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
\r
143 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
\r
144 x = cur_ugbldg->x1;
\r
149 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
\r
150 x = cur_ugbldg->x0;
\r
154 for (j = 0; j < max_f_idx; j++)
\r
156 if (have_flag(f_info[j].flags, FF_STORE))
\r
158 if (f_info[j].subtype == stores[i]) break;
\r
162 /* Clear previous contents, add a store door */
\r
165 cave_set_feat(ltcy + y, ltcx + x, j);
\r
168 store_init(NO_TOWN, stores[i]);
\r
175 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
\r
178 * Town logic flow for generation of new town\n
\r
179 * Originally from Vanilla 3.0.3\n
\r
181 * We start with a fully wiped cave of normal floors.\n
\r
183 * Note that town_gen_hack() plays games with the R.N.G.\n
\r
185 * This function does NOT do anything about the owners of the stores,\n
\r
186 * nor the contents thereof. It only handles the physical layout.\n
\r
188 bool build_type16(void)
\r
192 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,
\r
193 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,
\r
195 int n = sizeof stores / sizeof(int);
\r
196 POSITION i, y, x, y1, x1, yval, xval;
\r
197 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
\r
198 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
\r
199 bool prevent_bm = FALSE;
\r
201 /* Hack -- If already exist black market, prevent building */
\r
202 for (y = 0; (y < cur_hgt) && !prevent_bm; y++)
\r
204 for (x = 0; x < cur_wid; x++)
\r
206 if (cave[y][x].feat == FF_STORE)
\r
208 prevent_bm = (f_info[cave[y][x].feat].subtype == STORE_BLACK);
\r
213 for (i = 0; i < n; i++)
\r
215 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];
\r
217 if (!n) return FALSE;
\r
219 /* Allocate buildings array */
\r
220 C_MAKE(ugbldg, n, ugbldg_type);
\r
222 /* If cannot build stores, abort */
\r
223 if (!precalc_ugarcade(town_hgt, town_wid, n))
\r
225 /* Free buildings array */
\r
226 C_KILL(ugbldg, n, ugbldg_type);
\r
230 /* Find and reserve some space in the dungeon. Get center of room. */
\r
231 if (!find_space(&yval, &xval, town_hgt + 4, town_wid + 4))
\r
233 /* Free buildings array */
\r
234 C_KILL(ugbldg, n, ugbldg_type);
\r
238 /* Get top left corner */
\r
239 y1 = yval - (town_hgt / 2);
\r
240 x1 = xval - (town_wid / 2);
\r
242 /* Generate new room */
\r
243 generate_room_floor(
\r
244 y1 + town_hgt / 3, x1 + town_wid / 3,
\r
245 y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, FALSE);
\r
248 build_stores(y1, x1, stores, n);
\r
250 msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));
\r
252 /* Free buildings array */
\r
253 C_KILL(ugbldg, n, ugbldg_type);
\r