1 #include "room/rooms-city.h"
2 #include "floor/floor-generator.h"
3 #include "floor/wild.h"
4 #include "game-option/cheat-types.h"
5 #include "grid/feature.h"
7 #include "room/space-finder.h"
8 #include "store/store-util.h"
9 #include "store/store.h"
10 #include "system/floor-type-definition.h"
11 #include "system/grid-type-definition.h"
12 #include "system/player-type-definition.h"
13 #include "util/bit-flags-calculator.h"
14 #include "wizard/wizard-messages.h"
19 * Precalculate buildings' location of underground arcade
21 static bool precalc_ugarcade(int town_hgt, int town_wid, int n, std::vector<ugbldg_type>& ugbldg)
23 POSITION i, y, x, center_y, center_x;
24 int tmp, attempt = 10000;
25 POSITION max_bldg_hgt = 3 * town_hgt / MAX_TOWN_HGT;
26 POSITION max_bldg_wid = 5 * town_wid / MAX_TOWN_WID;
27 ugbldg_type *cur_ugbldg;
28 std::vector<std::vector<bool>> ugarcade_used(town_hgt, std::vector<bool>(town_wid));
31 for (i = 0; i < n; i++) {
32 cur_ugbldg = &ugbldg[i];
35 center_y = rand_range(2, town_hgt - 3);
36 center_x = rand_range(2, town_wid - 3);
37 tmp = center_y - randint1(max_bldg_hgt);
38 cur_ugbldg->y0 = MAX(tmp, 1);
39 tmp = center_x - randint1(max_bldg_wid);
40 cur_ugbldg->x0 = MAX(tmp, 1);
41 tmp = center_y + randint1(max_bldg_hgt);
42 cur_ugbldg->y1 = MIN(tmp, town_hgt - 2);
43 tmp = center_x + randint1(max_bldg_wid);
44 cur_ugbldg->x1 = MIN(tmp, town_wid - 2);
45 for (abort = false, y = cur_ugbldg->y0; (y <= cur_ugbldg->y1) && !abort; y++) {
46 for (x = cur_ugbldg->x0; x <= cur_ugbldg->x1; x++) {
47 if (ugarcade_used[y][x]) {
55 } while (abort && attempt);
60 for (y = cur_ugbldg->y0 - 1; y <= cur_ugbldg->y1 + 1; y++) {
61 for (x = cur_ugbldg->x0 - 1; x <= cur_ugbldg->x1 + 1; x++) {
62 ugarcade_used[y][x] = true;
70 /* Create a new floor room with optional light */
71 static void generate_room_floor(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, int light)
74 for (POSITION y = y1; y <= y2; y++) {
75 for (POSITION x = x1; x <= x2; x++) {
76 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
77 place_grid(player_ptr, g_ptr, GB_FLOOR);
78 g_ptr->info |= (CAVE_ROOM);
80 g_ptr->info |= (CAVE_GLOW);
85 static void generate_fill_perm_bold(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
87 for (POSITION y = y1; y <= y2; y++)
88 for (POSITION x = x1; x <= x2; x++)
89 place_bold(player_ptr, y, x, GB_INNER_PERM);
93 * @brief タイプ16の部屋…地下都市生成のサブルーチン / Actually create buildings
94 * @param player_ptr プレイヤーへの参照ポインタ
97 * @param stotes[] 生成する店舗のリスト
100 * Note: ltcy and ltcx indicate "left top corner".
102 static void build_stores(player_type *player_ptr, POSITION ltcy, POSITION ltcx, StoreSaleType stores[], int n, const std::vector<ugbldg_type>& ugbldg)
106 const ugbldg_type *cur_ugbldg;
108 for (i = 0; i < n; i++) {
109 cur_ugbldg = &ugbldg[i];
110 generate_room_floor(player_ptr, ltcy + cur_ugbldg->y0 - 2, ltcx + cur_ugbldg->x0 - 2, ltcy + cur_ugbldg->y1 + 2, ltcx + cur_ugbldg->x1 + 2, false);
113 for (i = 0; i < n; i++) {
114 cur_ugbldg = &ugbldg[i];
115 generate_fill_perm_bold(player_ptr, ltcy + cur_ugbldg->y0, ltcx + cur_ugbldg->x0, ltcy + cur_ugbldg->y1, ltcx + cur_ugbldg->x1);
117 /* Pick a door direction (S,N,E,W) */
118 switch (randint0(4)) {
122 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
128 x = rand_range(cur_ugbldg->x0, cur_ugbldg->x1);
133 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
139 y = rand_range(cur_ugbldg->y0, cur_ugbldg->y1);
144 if (auto it = std::find_if(f_info.begin(), f_info.end(),
145 [subtype = stores[i]](const feature_type &f_ref) {
146 return f_ref.flags.has(FF::STORE) && (i2enum<StoreSaleType>(static_cast<int>(f_ref.subtype)) == subtype);
148 it != f_info.end()) {
149 cave_set_feat(player_ptr, ltcy + y, ltcx + x, (*it).idx);
150 store_init(NO_TOWN, stores[i]);
156 * @brief タイプ16の部屋…地下都市の生成 / Type 16 -- Underground Arcade
158 * Town logic flow for generation of new town\n
159 * Originally from Vanilla 3.0.3\n
161 * We start with a fully wiped grids of normal floors.\n
163 * Note that town_gen_hack() plays games with the R.N.G.\n
165 * This function does NOT do anything about the owners of the stores,\n
166 * nor the contents thereof. It only handles the physical layout.\n
168 bool build_type16(player_type *player_ptr, dun_data_type *dd_ptr)
170 StoreSaleType stores[] = {
171 StoreSaleType::GENERAL,
172 StoreSaleType::ARMOURY,
173 StoreSaleType::WEAPON,
174 StoreSaleType::TEMPLE,
175 StoreSaleType::ALCHEMIST,
176 StoreSaleType::MAGIC,
177 StoreSaleType::BLACK,
180 int n = sizeof stores / sizeof(int);
181 POSITION y1, x1, yval, xval;
182 int town_hgt = rand_range(MIN_TOWN_HGT, MAX_TOWN_HGT);
183 int town_wid = rand_range(MIN_TOWN_WID, MAX_TOWN_WID);
188 std::vector<ugbldg_type> ugbldg(n);
189 if (!precalc_ugarcade(town_hgt, town_wid, n, ugbldg)) {
193 if (!find_space(player_ptr, dd_ptr, &yval, &xval, town_hgt + 4, town_wid + 4)) {
197 y1 = yval - (town_hgt / 2);
198 x1 = xval - (town_wid / 2);
199 generate_room_floor(player_ptr, y1 + town_hgt / 3, x1 + town_wid / 3, y1 + town_hgt * 2 / 3, x1 + town_wid * 2 / 3, false);
200 build_stores(player_ptr, y1, x1, stores, n, ugbldg);
201 msg_print_wizard(player_ptr, CHEAT_DUNGEON, _("地下街を生成しました", "Underground arcade was generated."));