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