2 * @brief ダンジョンの生成 / Dungeon generation
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
6 * This software may be copied and distributed for educational, research,\n
7 * and not for profit purposes provided that this copyright and statement\n
8 * are included in all such copies. Other copyrights may also apply.\n
9 * 2014 Deskull rearranged comment for Doxygen. \n
12 #include "floor/floor-generator.h"
13 #include "dungeon/dungeon-flag-types.h"
14 #include "dungeon/dungeon.h"
15 #include "dungeon/quest.h"
16 #include "floor/cave-generator.h"
17 #include "floor/floor-events.h"
18 #include "floor/floor-save.h" // todo precalc_cur_num_of_pet() が依存している、違和感.
19 #include "floor/floor-util.h"
20 #include "floor/wild.h"
21 #include "game-option/birth-options.h"
22 #include "game-option/cheat-types.h"
23 #include "game-option/game-play-options.h"
24 #include "game-option/play-record-options.h"
25 #include "grid/feature.h"
26 #include "grid/grid.h"
27 #include "info-reader/feature-reader.h"
28 #include "info-reader/fixed-map-parser.h"
29 #include "io/write-diary.h"
30 #include "market/arena-info-table.h"
31 #include "monster-floor/monster-generator.h"
32 #include "monster-floor/monster-remover.h"
33 #include "monster-floor/place-monster-types.h"
34 #include "monster-race/monster-race.h"
35 #include "monster/monster-flag-types.h"
36 #include "monster/monster-status-setter.h"
37 #include "monster/monster-status.h"
38 #include "monster/monster-update.h"
39 #include "monster/monster-util.h"
40 #include "system/building-type-definition.h"
41 #include "system/floor-type-definition.h"
42 #include "system/system-variables.h"
43 #include "view/display-messages.h"
44 #include "window/main-window-util.h"
45 #include "wizard/wizard-messages.h"
46 #include "world/world.h"
49 * @brief 闘技場用のアリーナ地形を作成する / Builds the on_defeat_arena_monster after it is entered -KMW-
50 * @param player_ptr プレーヤーへの参照ポインタ
53 static void build_arena(player_type *player_ptr, POSITION *start_y, POSITION *start_x)
55 POSITION yval = SCREEN_HGT / 2;
56 POSITION xval = SCREEN_WID / 2;
57 POSITION y_height = yval - 10;
58 POSITION y_depth = yval + 10;
59 POSITION x_left = xval - 32;
60 POSITION x_right = xval + 32;
61 floor_type *floor_ptr = player_ptr->current_floor_ptr;
62 for (POSITION i = y_height; i <= y_height + 5; i++)
63 for (POSITION j = x_left; j <= x_right; j++) {
64 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
65 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
68 for (POSITION i = y_depth; i >= y_depth - 5; i--)
69 for (POSITION j = x_left; j <= x_right; j++) {
70 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
71 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
74 for (POSITION j = x_left; j <= x_left + 17; j++)
75 for (POSITION i = y_height; i <= y_depth; i++) {
76 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
77 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
80 for (POSITION j = x_right; j >= x_right - 17; j--)
81 for (POSITION i = y_height; i <= y_depth; i++) {
82 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
83 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
86 place_bold(player_ptr, y_height + 6, x_left + 18, GB_EXTRA_PERM);
87 floor_ptr->grid_array[y_height + 6][x_left + 18].info |= CAVE_GLOW | CAVE_MARK;
88 place_bold(player_ptr, y_depth - 6, x_left + 18, GB_EXTRA_PERM);
89 floor_ptr->grid_array[y_depth - 6][x_left + 18].info |= CAVE_GLOW | CAVE_MARK;
90 place_bold(player_ptr, y_height + 6, x_right - 18, GB_EXTRA_PERM);
91 floor_ptr->grid_array[y_height + 6][x_right - 18].info |= CAVE_GLOW | CAVE_MARK;
92 place_bold(player_ptr, y_depth - 6, x_right - 18, GB_EXTRA_PERM);
93 floor_ptr->grid_array[y_depth - 6][x_right - 18].info |= CAVE_GLOW | CAVE_MARK;
95 *start_y = y_height + 5;
97 floor_ptr->grid_array[*start_y][*start_x].feat = f_tag_to_index("ARENA_GATE");
98 floor_ptr->grid_array[*start_y][*start_x].info |= CAVE_GLOW | CAVE_MARK;
102 * @brief 挑戦時闘技場への入場処理 / Town logic flow for generation of on_defeat_arena_monster -KMW-
105 static void generate_challenge_arena(player_type *challanger_ptr)
109 floor_type *floor_ptr = challanger_ptr->current_floor_ptr;
110 floor_ptr->height = SCREEN_HGT;
111 floor_ptr->width = SCREEN_WID;
114 for (y = 0; y < MAX_HGT; y++)
115 for (x = 0; x < MAX_WID; x++) {
116 place_bold(challanger_ptr, y, x, GB_SOLID_PERM);
117 floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
120 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
121 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
122 floor_ptr->grid_array[y][x].feat = feat_floor;
124 build_arena(challanger_ptr, &y, &x);
125 player_place(challanger_ptr, y, x);
126 if (place_monster_aux(challanger_ptr, 0, challanger_ptr->y + 5, challanger_ptr->x, arena_info[challanger_ptr->arena_number].r_idx, PM_NO_KAGE | PM_NO_PET))
129 challanger_ptr->exit_bldg = TRUE;
130 challanger_ptr->arena_number++;
131 msg_print(_("相手は欠場した。あなたの不戦勝だ。", "The enemy is unable to appear. You won by default."));
135 * @brief モンスター闘技場のフロア生成 / Builds the on_defeat_arena_monster after it is entered -KMW-
136 * @param player_ptr プレーヤーへの参照ポインタ
139 static void build_battle(player_type *player_ptr, POSITION *y, POSITION *x)
141 POSITION yval = SCREEN_HGT / 2;
142 POSITION xval = SCREEN_WID / 2;
143 POSITION y_height = yval - 10;
144 POSITION y_depth = yval + 10;
145 POSITION x_left = xval - 32;
146 POSITION x_right = xval + 32;
148 floor_type *floor_ptr = player_ptr->current_floor_ptr;
149 for (int i = y_height; i <= y_height + 5; i++)
150 for (int j = x_left; j <= x_right; j++) {
151 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
152 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
155 for (int i = y_depth; i >= y_depth - 3; i--)
156 for (int j = x_left; j <= x_right; j++) {
157 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
158 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
161 for (int j = x_left; j <= x_left + 17; j++)
162 for (int i = y_height; i <= y_depth; i++) {
163 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
164 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
167 for (int j = x_right; j >= x_right - 17; j--)
168 for (int i = y_height; i <= y_depth; i++) {
169 place_bold(player_ptr, i, j, GB_EXTRA_PERM);
170 floor_ptr->grid_array[i][j].info |= (CAVE_GLOW | CAVE_MARK);
173 place_bold(player_ptr, y_height + 6, x_left + 18, GB_EXTRA_PERM);
174 floor_ptr->grid_array[y_height + 6][x_left + 18].info |= CAVE_GLOW | CAVE_MARK;
175 place_bold(player_ptr, y_depth - 4, x_left + 18, GB_EXTRA_PERM);
176 floor_ptr->grid_array[y_depth - 4][x_left + 18].info |= CAVE_GLOW | CAVE_MARK;
177 place_bold(player_ptr, y_height + 6, x_right - 18, GB_EXTRA_PERM);
178 floor_ptr->grid_array[y_height + 6][x_right - 18].info |= CAVE_GLOW | CAVE_MARK;
179 place_bold(player_ptr, y_depth - 4, x_right - 18, GB_EXTRA_PERM);
180 floor_ptr->grid_array[y_depth - 4][x_right - 18].info |= CAVE_GLOW | CAVE_MARK;
182 for (int i = y_height + 1; i <= y_height + 5; i++)
183 for (int j = x_left + 20 + 2 * (y_height + 5 - i); j <= x_right - 20 - 2 * (y_height + 5 - i); j++) {
184 floor_ptr->grid_array[i][j].feat = feat_permanent_glass_wall;
187 POSITION last_y = y_height + 1;
188 POSITION last_x = xval;
189 floor_ptr->grid_array[last_y][last_x].feat = f_tag_to_index("BUILDING_3");
190 floor_ptr->grid_array[last_y][last_x].info |= CAVE_GLOW | CAVE_MARK;
196 * @brief モンスター闘技場への導入処理 / Town logic flow for generation of on_defeat_arena_monster -KMW-
199 static void generate_gambling_arena(player_type *creature_ptr)
204 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
205 for (y = 0; y < MAX_HGT; y++)
206 for (x = 0; x < MAX_WID; x++) {
207 place_bold(creature_ptr, y, x, GB_SOLID_PERM);
208 floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
211 for (y = qy + 1; y < qy + SCREEN_HGT - 1; y++)
212 for (x = qx + 1; x < qx + SCREEN_WID - 1; x++)
213 floor_ptr->grid_array[y][x].feat = feat_floor;
215 build_battle(creature_ptr, &y, &x);
216 player_place(creature_ptr, y, x);
217 for (MONSTER_IDX i = 0; i < 4; i++) {
218 place_monster_aux(creature_ptr, 0, creature_ptr->y + 8 + (i / 2) * 4, creature_ptr->x - 2 + (i % 2) * 4, battle_mon[i], (PM_NO_KAGE | PM_NO_PET));
219 set_friendly(&floor_ptr->m_list[floor_ptr->grid_array[creature_ptr->y + 8 + (i / 2) * 4][creature_ptr->x - 2 + (i % 2) * 4].m_idx]);
222 for (MONSTER_IDX i = 1; i < floor_ptr->m_max; i++) {
223 monster_type *m_ptr = &floor_ptr->m_list[i];
224 if (!monster_is_valid(m_ptr))
227 m_ptr->mflag2 |= MFLAG2_MARK | MFLAG2_SHOW;
228 update_monster(creature_ptr, i, FALSE);
233 * @brief 固定マップクエストのフロア生成 / Generate a quest level
234 * @param player_ptr プレーヤーへの参照ポインタ
237 static void generate_fixed_floor(player_type *player_ptr)
239 floor_type *floor_ptr = player_ptr->current_floor_ptr;
240 for (POSITION y = 0; y < floor_ptr->height; y++)
241 for (POSITION x = 0; x < floor_ptr->width; x++)
242 place_bold(player_ptr, y, x, GB_SOLID_PERM);
244 floor_ptr->base_level = quest[floor_ptr->inside_quest].level;
245 floor_ptr->dun_level = floor_ptr->base_level;
246 floor_ptr->object_level = floor_ptr->base_level;
247 floor_ptr->monster_level = floor_ptr->base_level;
249 exe_write_diary(player_ptr, DIARY_TO_QUEST, floor_ptr->inside_quest, NULL);
251 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), NULL);
252 init_flags = INIT_CREATE_DUNGEON;
253 parse_fixed_map(player_ptr, "q_info.txt", 0, 0, MAX_HGT, MAX_WID);
257 * @brief ダンジョン時のランダムフロア生成 / Make a real level
258 * @param player_ptr プレーヤーへの参照ポインタ
260 * @return フロアの生成に成功したらTRUE
262 static bool level_gen(player_type *player_ptr, concptr *why)
264 floor_type *floor_ptr = player_ptr->current_floor_ptr;
265 DUNGEON_IDX d_idx = floor_ptr->dungeon_idx;
266 if ((always_small_levels || ironman_small_levels || (one_in_(SMALL_LEVEL) && small_levels) || (d_info[d_idx].flags1 & DF1_BEGINNER)
267 || (d_info[d_idx].flags1 & DF1_SMALLEST))
268 && !(d_info[d_idx].flags1 & DF1_BIG)) {
271 if (d_info[d_idx].flags1 & DF1_SMALLEST) {
274 } else if (d_info[d_idx].flags1 & DF1_BEGINNER) {
278 level_height = randint1(MAX_HGT / SCREEN_HGT);
279 level_width = randint1(MAX_WID / SCREEN_WID);
280 bool is_first_level_area = TRUE;
281 bool is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
282 while (is_first_level_area || is_max_area) {
283 level_height = randint1(MAX_HGT / SCREEN_HGT);
284 level_width = randint1(MAX_WID / SCREEN_WID);
285 is_first_level_area = FALSE;
286 is_max_area = (level_height == MAX_HGT / SCREEN_HGT) && (level_width == MAX_WID / SCREEN_WID);
290 floor_ptr->height = level_height * SCREEN_HGT;
291 floor_ptr->width = level_width * SCREEN_WID;
292 panel_row_min = floor_ptr->height;
293 panel_col_min = floor_ptr->width;
296 player_ptr, CHEAT_DUNGEON, _("小さなフロア: X:%d, Y:%d", "A 'small' dungeon level: X:%d, Y:%d."), floor_ptr->width, floor_ptr->height);
298 floor_ptr->height = MAX_HGT;
299 floor_ptr->width = MAX_WID;
300 panel_row_min = floor_ptr->height;
301 panel_col_min = floor_ptr->width;
304 return cave_gen(player_ptr, why);
308 * @brief フロアに存在する全マスの記憶状態を初期化する / Wipe all unnecessary flags after grid_array generation
311 void wipe_generate_random_floor_flags(floor_type *floor_ptr)
313 for (POSITION y = 0; y < floor_ptr->height; y++)
314 for (POSITION x = 0; x < floor_ptr->width; x++)
315 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
317 if (floor_ptr->dun_level > 0)
318 for (POSITION y = 1; y < floor_ptr->height - 1; y++)
319 for (POSITION x = 1; x < floor_ptr->width - 1; x++)
320 floor_ptr->grid_array[y][x].info |= CAVE_UNSAFE;
324 * @brief フロアの全情報を初期化する / Clear and empty floor.
325 * @parama player_ptr プレーヤーへの参照ポインタ
328 void clear_cave(player_type *player_ptr)
330 floor_type *floor_ptr = player_ptr->current_floor_ptr;
331 (void)C_WIPE(floor_ptr->o_list, floor_ptr->o_max, object_type);
332 floor_ptr->o_max = 1;
333 floor_ptr->o_cnt = 0;
335 for (int i = 1; i < max_r_idx; i++)
336 r_info[i].cur_num = 0;
338 (void)C_WIPE(floor_ptr->m_list, floor_ptr->m_max, monster_type);
339 floor_ptr->m_max = 1;
340 floor_ptr->m_cnt = 0;
341 for (int i = 0; i < MAX_MTIMED; i++)
342 floor_ptr->mproc_max[i] = 0;
344 precalc_cur_num_of_pet(player_ptr);
345 for (POSITION y = 0; y < MAX_HGT; y++) {
346 for (POSITION x = 0; x < MAX_WID; x++) {
347 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
360 floor_ptr->base_level = floor_ptr->dun_level;
361 floor_ptr->monster_level = floor_ptr->base_level;
362 floor_ptr->object_level = floor_ptr->base_level;
366 * ダンジョンのランダムフロアを生成する / Generates a random dungeon level -RAK-
367 * @parama player_ptr プレーヤーへの参照ポインタ
369 * @note Hack -- regenerate any "overflow" levels
371 void generate_floor(player_type *player_ptr)
373 floor_type *floor_ptr = player_ptr->current_floor_ptr;
374 floor_ptr->dungeon_idx = player_ptr->dungeon_idx;
375 set_floor_and_wall(floor_ptr->dungeon_idx);
376 for (int num = 0; TRUE; num++) {
379 clear_cave(player_ptr);
380 player_ptr->x = player_ptr->y = 0;
381 if (floor_ptr->inside_arena)
382 generate_challenge_arena(player_ptr);
383 else if (player_ptr->phase_out)
384 generate_gambling_arena(player_ptr);
385 else if (floor_ptr->inside_quest)
386 generate_fixed_floor(player_ptr);
387 else if (!floor_ptr->dun_level)
388 if (player_ptr->wild_mode)
389 wilderness_gen_small(player_ptr);
391 wilderness_gen(player_ptr);
393 okay = level_gen(player_ptr, &why);
395 if (floor_ptr->o_max >= current_world_ptr->max_o_idx) {
396 why = _("アイテムが多すぎる", "too many objects");
398 } else if (floor_ptr->m_max >= current_world_ptr->max_m_idx) {
399 why = _("モンスターが多すぎる", "too many monsters");
407 msg_format(_("生成やり直し(%s)", "Generation restarted (%s)"), why);
409 wipe_o_list(floor_ptr);
410 wipe_monsters_list(player_ptr);
413 glow_deep_lava_and_bldg(player_ptr);
414 player_ptr->enter_dungeon = FALSE;
415 wipe_generate_random_floor_flags(floor_ptr);