OSDN Git Service

[Refactor] #37353 ベースアイテム判定処理を objectkind-hook.c/h へ分離。
[hengband/hengband.git] / src / rooms-city.c
1 #include "angband.h"\r
2 #include "grid.h"\r
3 #include "generate.h"\r
4 #include "rooms.h"\r
5 #include "rooms-city.h"\r
6 #include "store.h"\r
7 \r
8 \r
9 \r
10 /*\r
11 * Precalculate buildings' location of underground arcade\r
12 */\r
13 static bool precalc_ugarcade(int town_hgt, int town_wid, int n)\r
14 {\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
20 \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
25 \r
26         /* Calculate building locations */\r
27         for (i = 0; i < n; i++)\r
28         {\r
29                 cur_ugbldg = &ugbldg[i];\r
30                 (void)WIPE(cur_ugbldg, ugbldg_type);\r
31 \r
32                 do\r
33                 {\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
37 \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
47 \r
48                         /* Scan this building's area */\r
49                         for (abort = FALSE, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++)\r
50                         {\r
51                                 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++)\r
52                                 {\r
53                                         if (ugarcade_used[y][x])\r
54                                         {\r
55                                                 abort = TRUE;\r
56                                                 break;\r
57                                         }\r
58                                 }\r
59                         }\r
60 \r
61                         attempt--;\r
62                 } while (abort && attempt); /* Accept this building if no overlapping */\r
63 \r
64                                                                         /* Failed to generate underground arcade */\r
65                 if (!attempt) break;\r
66 \r
67                 /*\r
68                 * Mark to ugarcade_used[][] as "used"\r
69                 * Note: Building-adjacent grids are included for preventing\r
70                 * connected bulidings.\r
71                 */\r
72                 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++)\r
73                 {\r
74                         for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++)\r
75                         {\r
76                                 ugarcade_used[y][x] = TRUE;\r
77                         }\r
78                 }\r
79         }\r
80 \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
84 \r
85         /* If i < n, generation is not allowed */\r
86         return i == n;\r
87 }\r
88 \r
89 \r
90 /*!\r
91 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings\r
92 * @return なし\r
93 * @param ltcy 生成基準Y座標\r
94 * @param ltcx 生成基準X座標\r
95 * @param stotes[] 生成する店舗のリスト\r
96 * @param n 生成する店舗の数\r
97 * @note\r
98 * Note: ltcy and ltcx indicate "left top corner".\r
99 */\r
100 static void build_stores(int ltcy, int ltcx, int stores[], int n)\r
101 {\r
102         int i, y, x;\r
103         IDX j;\r
104         ugbldg_type *cur_ugbldg;\r
105 \r
106         for (i = 0; i < n; i++)\r
107         {\r
108                 cur_ugbldg = &ugbldg[i];\r
109 \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
114                         FALSE);\r
115         }\r
116 \r
117         for (i = 0; i < n; i++)\r
118         {\r
119                 cur_ugbldg = &ugbldg[i];\r
120 \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
125 \r
126                 /* Pick a door direction (S,N,E,W) */\r
127                 switch (randint0(4))\r
128                 {\r
129                         /* Bottom side */\r
130                 case 0:\r
131                         y = cur_ugbldg->y1;\r
132                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);\r
133                         break;\r
134 \r
135                         /* Top side */\r
136                 case 1:\r
137                         y = cur_ugbldg->y0;\r
138                         x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);\r
139                         break;\r
140 \r
141                         /* Right side */\r
142                 case 2:\r
143                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);\r
144                         x = cur_ugbldg->x1;\r
145                         break;\r
146 \r
147                         /* Left side */\r
148                 default:\r
149                         y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);\r
150                         x = cur_ugbldg->x0;\r
151                         break;\r
152                 }\r
153 \r
154                 for (j = 0; j < max_f_idx; j++)\r
155                 {\r
156                         if (have_flag(f_info[j].flags, FF_STORE))\r
157                         {\r
158                                 if (f_info[j].subtype == stores[i]) break;\r
159                         }\r
160                 }\r
161 \r
162                 /* Clear previous contents, add a store door */\r
163                 if (j < max_f_idx)\r
164                 {\r
165                         cave_set_feat(ltcy + y, ltcx + x, j);\r
166 \r
167                         /* Init store */\r
168                         store_init(NO_TOWN, stores[i]);\r
169                 }\r
170         }\r
171 }\r
172 \r
173 \r
174 /*!\r
175 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade\r
176 * @return なし\r
177 * @details\r
178 * Town logic flow for generation of new town\n\r
179 * Originally from Vanilla 3.0.3\n\r
180 *\n\r
181 * We start with a fully wiped cave of normal floors.\n\r
182 *\n\r
183 * Note that town_gen_hack() plays games with the R.N.G.\n\r
184 *\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
187 */\r
188 bool build_type16(void)\r
189 {\r
190         int stores[] =\r
191         {\r
192                 STORE_GENERAL, STORE_ARMOURY, STORE_WEAPON, STORE_TEMPLE,\r
193                 STORE_ALCHEMIST, STORE_MAGIC, STORE_BLACK, STORE_BOOK,\r
194         };\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
200 \r
201         /* Hack -- If already exist black market, prevent building */\r
202         for (y = 0; (y < cur_hgt) && !prevent_bm; y++)\r
203         {\r
204                 for (x = 0; x < cur_wid; x++)\r
205                 {\r
206                         if (cave[y][x].feat == FF_STORE)\r
207                         {\r
208                                 prevent_bm = (f_info[cave[y][x].feat].subtype == STORE_BLACK);\r
209                                 break;\r
210                         }\r
211                 }\r
212         }\r
213         for (i = 0; i < n; i++)\r
214         {\r
215                 if ((stores[i] == STORE_BLACK) && prevent_bm) stores[i] = stores[--n];\r
216         }\r
217         if (!n) return FALSE;\r
218 \r
219         /* Allocate buildings array */\r
220         C_MAKE(ugbldg, n, ugbldg_type);\r
221 \r
222         /* If cannot build stores, abort */\r
223         if (!precalc_ugarcade(town_hgt, town_wid, n))\r
224         {\r
225                 /* Free buildings array */\r
226                 C_KILL(ugbldg, n, ugbldg_type);\r
227                 return FALSE;\r
228         }\r
229 \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
232         {\r
233                 /* Free buildings array */\r
234                 C_KILL(ugbldg, n, ugbldg_type);\r
235                 return FALSE;\r
236         }\r
237 \r
238         /* Get top left corner */\r
239         y1 = yval - (town_hgt / 2);\r
240         x1 = xval - (town_wid / 2);\r
241 \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
246 \r
247         /* Build stores */\r
248         build_stores(y1, x1, stores, n);\r
249 \r
250         msg_print_wizard(CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));\r
251 \r
252         /* Free buildings array */\r
253         C_KILL(ugbldg, n, ugbldg_type);\r
254 \r
255         return TRUE;\r
256 }\r
257 \r