2 * @brief 荒野マップの生成とルール管理 / Wilderness generation
5 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research, and
7 * not for profit purposes provided that this copyright and statement are
8 * included in all such copies.
9 * 2013 Deskull rearranged comment for Doxygen.
12 #include "floor/wild.h"
13 #include "core/asking-player.h"
14 #include "dungeon/dungeon-flag-types.h"
15 #include "dungeon/quest.h"
16 #include "floor/cave.h"
17 #include "floor/floor-town.h"
18 #include "game-option/birth-options.h"
19 #include "game-option/map-screen-options.h"
20 #include "grid/feature.h"
21 #include "grid/grid.h"
22 #include "info-reader/fixed-map-parser.h"
23 #include "info-reader/parse-error-types.h"
24 #include "io/files-util.h"
25 #include "io/tokenizer.h"
26 #include "market/building-initializer.h"
27 #include "monster-floor/monster-generator.h"
28 #include "monster-floor/monster-remover.h"
29 #include "monster-floor/monster-summon.h"
30 #include "monster-floor/place-monster-types.h"
31 #include "monster/monster-info.h"
32 #include "monster/monster-status.h"
33 #include "monster/monster-util.h"
34 #include "player-status/player-energy.h"
35 #include "player/attack-defense-types.h"
36 #include "player/player-status.h"
37 #include "realm/realm-names-table.h"
38 #include "spell-realm/spells-hex.h"
39 #include "status/action-setter.h"
40 #include "system/dungeon-info.h"
41 #include "system/floor-type-definition.h"
42 #include "system/grid-type-definition.h"
43 #include "system/monster-entity.h"
44 #include "system/player-type-definition.h"
45 #include "system/system-variables.h"
46 #include "system/terrain-type-definition.h"
47 #include "util/bit-flags-calculator.h"
48 #include "view/display-messages.h"
49 #include "window/main-window-util.h"
50 #include "world/world.h"
52 constexpr auto MAX_FEAT_IN_TERRAIN = 18;
54 std::vector<std::vector<wilderness_type>> wilderness;
55 static bool generate_encounter;
58 int16_t north[MAX_WID];
59 int16_t south[MAX_WID];
60 int16_t east[MAX_HGT];
61 int16_t west[MAX_HGT];
68 struct wilderness_grid {
69 wt_type terrain; /* Terrain type */
70 int16_t town; /* Town number */
71 DEPTH level; /* Level of the wilderness */
73 char name[32]; /* Name of the town/wilderness */
76 static border_type border;
78 static wilderness_grid w_letter[255];
80 /* The default table in terrain level generation. */
81 static int16_t terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
83 static int16_t conv_terrain2feat[MAX_WILDERNESS];
86 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
87 * @param feat_type 非一様確率を再現するための要素数100の配列
88 * @param prob 元の確率テーブル
90 static void set_floor_and_wall_aux(int16_t feat_type[100], const std::array<feat_prob, DUNGEON_FEAT_PROB_NUM> &prob)
92 std::array<int, DUNGEON_FEAT_PROB_NUM> lim{};
93 lim[0] = prob[0].percent;
94 for (int i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) {
95 lim[i] = lim[i - 1] + prob[i].percent;
98 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) {
99 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
103 for (int i = 0; i < 100; i++) {
104 while (i == lim[cur]) {
108 feat_type[i] = prob[cur].feat;
113 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
114 * / Fill the arrays of floors and walls in the good proportions
115 * @param type ダンジョンID
117 void set_floor_and_wall(DUNGEON_IDX type)
119 DUNGEON_IDX cur_type = 255;
120 if (cur_type == type) {
125 const auto &dungeon = dungeons_info[type];
126 set_floor_and_wall_aux(feat_ground_type, dungeon.floor);
127 set_floor_and_wall_aux(feat_wall_type, dungeon.fill);
128 feat_wall_outer = dungeon.outer_wall;
129 feat_wall_inner = dungeon.inner_wall;
130 feat_wall_solid = dungeon.outer_wall;
134 * @brief プラズマフラクタル的地形生成の再帰中間処理
135 * / Helper for plasma generation.
143 * @param depth_max 深みの最大値
145 static void perturb_point_mid(
146 FloorType *floor_ptr, FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
148 FEAT_IDX tmp2 = rough * 2 + 1;
149 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
150 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
151 if (((x1 + x2 + x3 + x4) % 4) > 1) {
159 if (avg > depth_max) {
163 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
167 * @brief プラズマフラクタル的地形生成の再帰末端処理
168 * / Helper for plasma generation.
169 * @param x1 中間末端部1の重み
170 * @param x2 中間末端部2の重み
171 * @param x3 中間末端部3の重み
172 * @param xmid 最終末端部座標X
173 * @param ymid 最終末端部座標Y
175 * @param depth_max 深みの最大値
177 static void perturb_point_end(FloorType *floor_ptr, FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
179 FEAT_IDX tmp2 = rough * 2 + 1;
180 FEAT_IDX tmp = randint0(tmp2) - rough;
181 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
182 if ((x1 + x2 + x3) % 3) {
190 if (avg > depth_max) {
194 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
198 * @brief プラズマフラクタル的地形生成の開始処理
199 * / Helper for plasma generation.
200 * @param x1 処理範囲の左上X座標
201 * @param y1 処理範囲の左上Y座標
202 * @param x2 処理範囲の右下X座標
203 * @param y2 処理範囲の右下Y座標
204 * @param depth_max 深みの最大値
208 * A generic function to generate the plasma fractal.
209 * Note that it uses ``cave_feat'' as temporary storage.
210 * The values in ``cave_feat'' after this function
211 * are NOT actual features; They are raw heights which
212 * need to be converted to features.
215 static void plasma_recursive(FloorType *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
217 POSITION xmid = (x2 - x1) / 2 + x1;
218 POSITION ymid = (y2 - y1) / 2 + y1;
223 perturb_point_mid(floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x2].feat,
224 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
226 floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[ymid][xmid].feat, xmid, y1, rough, depth_max);
228 floor_ptr, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[ymid][xmid].feat, x2, ymid, rough, depth_max);
230 floor_ptr, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[ymid][xmid].feat, xmid, y2, rough, depth_max);
232 floor_ptr, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[ymid][xmid].feat, x1, ymid, rough, depth_max);
233 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
234 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
235 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
236 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
240 * @brief 荒野フロア生成のサブルーチン
241 * @param terrain 荒野地形ID
242 * @param seed 乱数の固定シード
244 * @param corner 広域マップの角部分としての生成ならばTRUE
246 static void generate_wilderness_area(FloorType *floor_ptr, int terrain, uint32_t seed, bool corner)
248 if (terrain == TERRAIN_EDGE) {
249 for (POSITION y1 = 0; y1 < MAX_HGT; y1++) {
250 for (POSITION x1 = 0; x1 < MAX_WID; x1++) {
251 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
258 const auto rng_backup = w_ptr->rng;
259 w_ptr->rng.set_state(seed);
260 int table_size = sizeof(terrain_table[0]) / sizeof(int16_t);
262 for (POSITION y1 = 0; y1 < MAX_HGT; y1++) {
263 for (POSITION x1 = 0; x1 < MAX_WID; x1++) {
264 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
269 floor_ptr->grid_array[1][1].feat = (int16_t)randint0(table_size);
270 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (int16_t)randint0(table_size);
271 floor_ptr->grid_array[1][MAX_WID - 2].feat = (int16_t)randint0(table_size);
272 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (int16_t)randint0(table_size);
274 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
275 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
276 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
277 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat];
278 w_ptr->rng = rng_backup;
282 int16_t north_west = floor_ptr->grid_array[1][1].feat;
283 int16_t south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
284 int16_t north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
285 int16_t south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
286 FEAT_IDX roughness = 1; /* The roughness of the level. */
287 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
288 floor_ptr->grid_array[1][1].feat = north_west;
289 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
290 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
291 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
292 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++) {
293 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++) {
294 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
298 w_ptr->rng = rng_backup;
302 * @brief 荒野フロア生成のメインルーチン
303 * @param player_ptr プレイヤーへの参照ポインタ
306 * @param is_border 広域マップの辺部分としての生成ならばTRUE
307 * @param is_corner 広域マップの角部分としての生成ならばTRUE
309 static void generate_area(PlayerType *player_ptr, POSITION y, POSITION x, bool is_border, bool is_corner)
311 player_ptr->town_num = wilderness[y][x].town;
312 auto *floor_ptr = player_ptr->current_floor_ptr;
313 floor_ptr->base_level = wilderness[y][x].level;
314 floor_ptr->dun_level = 0;
315 floor_ptr->monster_level = floor_ptr->base_level;
316 floor_ptr->object_level = floor_ptr->base_level;
317 if (player_ptr->town_num) {
319 if (is_border || is_corner) {
320 init_flags = i2enum<init_flags_type>(INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES);
322 init_flags = INIT_CREATE_DUNGEON;
325 parse_fixed_map(player_ptr, TOWN_DEFINITION_LIST, 0, 0, MAX_HGT, MAX_WID);
326 if (!is_corner && !is_border) {
327 player_ptr->visit |= (1UL << (player_ptr->town_num - 1));
330 int terrain = wilderness[y][x].terrain;
331 uint32_t seed = wilderness[y][x].seed;
332 generate_wilderness_area(floor_ptr, terrain, seed, is_corner);
335 if (!is_corner && !wilderness[y][x].town) {
336 //!< @todo make the road a bit more interresting.
337 if (wilderness[y][x].road) {
338 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
340 if (wilderness[y - 1][x].road) {
342 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
344 floor_ptr->grid_array[y1][x1].feat = feat_floor;
348 if (wilderness[y + 1][x].road) {
350 for (y1 = MAX_HGT / 2; y1 < MAX_HGT - 1; y1++) {
352 floor_ptr->grid_array[y1][x1].feat = feat_floor;
356 if (wilderness[y][x + 1].road) {
358 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
360 floor_ptr->grid_array[y1][x1].feat = feat_floor;
364 if (wilderness[y][x - 1].road) {
366 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
368 floor_ptr->grid_array[y1][x1].feat = feat_floor;
374 bool is_winner = wilderness[y][x].entrance > 0;
375 is_winner &= (wilderness[y][x].town == 0);
376 bool is_wild_winner = dungeons_info[wilderness[y][x].entrance].flags.has_not(DungeonFeatureType::WINNER);
377 is_winner &= ((w_ptr->total_winner != 0) || is_wild_winner);
382 const auto rng_backup = w_ptr->rng;
383 w_ptr->rng.set_state(wilderness[y][x].seed);
384 int dy = rand_range(6, floor_ptr->height - 6);
385 int dx = rand_range(6, floor_ptr->width - 6);
386 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
387 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
388 w_ptr->rng = rng_backup;
392 * @brief 地上マップにモンスターを生成する
393 * @param player_ptr プレイヤーへの参照ポインタ
394 * @details '>' キーで普通に入った時と、襲撃を受けた時でモンスター数は異なる.
395 * また、集団生成や護衛は、最初に生成された1体だけがカウント対象である.
396 * よって、実際に生成されるモンスターは、コードの見た目より多くなる.
398 static void generate_wild_monsters(PlayerType *player_ptr)
400 constexpr auto num_ambush_monsters = 40;
401 constexpr auto num_normal_monsters = 8;
402 const auto lim = generate_encounter ? num_ambush_monsters : num_normal_monsters;
403 for (auto i = 0; i < lim; i++) {
405 if (!(generate_encounter || (one_in_(2) && (!player_ptr->town_num)))) {
406 mode |= PM_ALLOW_SLEEP;
409 (void)alloc_monster(player_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
415 * Build the wilderness area outside of the town.
416 * @todo 広域マップは恒常生成にする予定、PlayerTypeによる処理分岐は最終的に排除する。
417 * @param player_ptr プレイヤーへの参照ポインタ
419 void wilderness_gen(PlayerType *player_ptr)
421 auto &floor = *player_ptr->current_floor_ptr;
422 floor.height = MAX_HGT;
423 floor.width = MAX_WID;
424 panel_row_min = floor.height;
425 panel_col_min = floor.width;
426 parse_fixed_map(player_ptr, WILDERNESS_DEFINITION, 0, 0, w_ptr->max_wild_y, w_ptr->max_wild_x);
427 const auto wild_y = player_ptr->wilderness_y;
428 const auto wild_x = player_ptr->wilderness_x;
429 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), nullptr);
432 generate_area(player_ptr, wild_y - 1, wild_x, true, false);
433 for (int i = 1; i < MAX_WID - 1; i++) {
434 border.north[i] = floor.grid_array[MAX_HGT - 2][i].feat;
438 generate_area(player_ptr, wild_y + 1, wild_x, true, false);
439 for (int i = 1; i < MAX_WID - 1; i++) {
440 border.south[i] = floor.grid_array[1][i].feat;
444 generate_area(player_ptr, wild_y, wild_x - 1, true, false);
445 for (int i = 1; i < MAX_HGT - 1; i++) {
446 border.west[i] = floor.grid_array[i][MAX_WID - 2].feat;
450 generate_area(player_ptr, wild_y, wild_x + 1, true, false);
451 for (int i = 1; i < MAX_HGT - 1; i++) {
452 border.east[i] = floor.grid_array[i][1].feat;
455 /* North west corner */
456 generate_area(player_ptr, wild_y - 1, wild_x - 1, false, true);
457 border.north_west = floor.grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
459 /* North east corner */
460 generate_area(player_ptr, wild_y - 1, wild_x + 1, false, true);
461 border.north_east = floor.grid_array[MAX_HGT - 2][1].feat;
463 /* South west corner */
464 generate_area(player_ptr, wild_y + 1, wild_x - 1, false, true);
465 border.south_west = floor.grid_array[1][MAX_WID - 2].feat;
467 /* South east corner */
468 generate_area(player_ptr, wild_y + 1, wild_x + 1, false, true);
469 border.south_east = floor.grid_array[1][1].feat;
471 /* Create terrain of the current area */
472 generate_area(player_ptr, wild_y, wild_x, false, false);
474 /* Special boundary walls -- North */
475 for (auto i = 0; i < MAX_WID; i++) {
476 auto &grid = floor.get_grid({ 0, i });
477 grid.feat = feat_permanent;
478 grid.mimic = border.north[i];
481 /* Special boundary walls -- South */
482 for (auto i = 0; i < MAX_WID; i++) {
483 auto &grid = floor.get_grid({ MAX_HGT - 1, i });
484 grid.feat = feat_permanent;
485 grid.mimic = border.south[i];
488 /* Special boundary walls -- West */
489 for (auto i = 0; i < MAX_HGT; i++) {
490 auto &grid = floor.get_grid({ i, 0 });
491 grid.feat = feat_permanent;
492 grid.mimic = border.west[i];
495 /* Special boundary walls -- East */
496 for (auto i = 0; i < MAX_HGT; i++) {
497 auto &grid = floor.get_grid({ i, MAX_WID - 1 });
498 grid.feat = feat_permanent;
499 grid.mimic = border.east[i];
502 floor.get_grid({ 0, 0 }).mimic = border.north_west;
503 floor.get_grid({ 0, MAX_WID - 1 }).mimic = border.north_east;
504 floor.get_grid({ MAX_HGT - 1, 0 }).mimic = border.south_west;
505 floor.get_grid({ MAX_HGT - 1, MAX_WID - 1 }).mimic = border.south_east;
506 for (auto y = 0; y < floor.height; y++) {
507 for (auto x = 0; x < floor.width; x++) {
508 auto &grid = floor.get_grid({ y, x });
509 if (w_ptr->is_daytime()) {
510 grid.info |= CAVE_GLOW;
511 if (view_perma_grids) {
512 grid.info |= CAVE_MARK;
518 const auto &terrain = grid.get_terrain_mimic();
519 auto can_darken = !grid.is_mirror();
520 can_darken &= terrain.flags.has_none_of({ TerrainCharacteristics::QUEST_ENTER, TerrainCharacteristics::ENTRANCE });
522 grid.info &= ~(CAVE_GLOW);
523 if (terrain.flags.has_not(TerrainCharacteristics::REMEMBER)) {
524 grid.info &= ~(CAVE_MARK);
530 if (terrain.flags.has_not(TerrainCharacteristics::ENTRANCE)) {
534 grid.info |= CAVE_GLOW;
535 if (view_perma_grids) {
536 grid.info |= CAVE_MARK;
541 if (player_ptr->teleport_town) {
542 for (auto y = 0; y < floor.height; y++) {
543 for (auto x = 0; x < floor.width; x++) {
544 auto &grid = floor.get_grid({ y, x });
545 const auto &terrain = grid.get_terrain();
546 if (terrain.flags.has_not(TerrainCharacteristics::BLDG)) {
550 if ((terrain.subtype != 4) && !((player_ptr->town_num == 1) && (terrain.subtype == 0))) {
554 if (is_monster(grid.m_idx)) {
555 delete_monster_idx(player_ptr, grid.m_idx);
558 player_ptr->oldpy = y;
559 player_ptr->oldpx = x;
563 player_ptr->teleport_town = false;
564 } else if (player_ptr->leaving_dungeon) {
565 for (auto y = 0; y < floor.height; y++) {
566 for (auto x = 0; x < floor.width; x++) {
567 auto &grid = floor.get_grid({ y, x });
568 if (!grid.cave_has_flag(TerrainCharacteristics::ENTRANCE)) {
572 if (is_monster(grid.m_idx)) {
573 delete_monster_idx(player_ptr, grid.m_idx);
576 player_ptr->oldpy = y;
577 player_ptr->oldpx = x;
581 player_ptr->teleport_town = false;
584 player_place(player_ptr, player_ptr->oldpy, player_ptr->oldpx);
585 generate_wild_monsters(player_ptr);
586 if (generate_encounter) {
587 player_ptr->ambush_flag = true;
590 generate_encounter = false;
591 set_floor_and_wall(0);
592 auto &quest_list = QuestList::get_instance();
593 for (auto &[q_idx, quest] : quest_list) {
594 if (quest.status == QuestStatusType::REWARDED) {
595 quest.status = QuestStatusType::FINISHED;
601 * @brief 広域マップの生成(簡易処理版) /
602 * Build the wilderness area. -DG-
604 void wilderness_gen_small(PlayerType *player_ptr)
606 auto *floor_ptr = player_ptr->current_floor_ptr;
607 for (int i = 0; i < MAX_WID; i++) {
608 for (int j = 0; j < MAX_HGT; j++) {
609 floor_ptr->grid_array[j][i].feat = feat_permanent;
613 parse_fixed_map(player_ptr, WILDERNESS_DEFINITION, 0, 0, w_ptr->max_wild_y, w_ptr->max_wild_x);
614 for (int i = 0; i < w_ptr->max_wild_x; i++) {
615 for (int j = 0; j < w_ptr->max_wild_y; j++) {
616 if (wilderness[j][i].town && (wilderness[j][i].town != VALID_TOWNS)) {
617 floor_ptr->grid_array[j][i].feat = (int16_t)feat_town;
618 floor_ptr->grid_array[j][i].special = (int16_t)wilderness[j][i].town;
619 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
623 if (wilderness[j][i].road) {
624 floor_ptr->grid_array[j][i].feat = feat_floor;
625 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
629 if (wilderness[j][i].entrance && (w_ptr->total_winner || dungeons_info[wilderness[j][i].entrance].flags.has_not(DungeonFeatureType::WINNER))) {
630 floor_ptr->grid_array[j][i].feat = feat_entrance;
631 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
632 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
636 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
637 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
641 floor_ptr->height = (int16_t)w_ptr->max_wild_y;
642 floor_ptr->width = (int16_t)w_ptr->max_wild_x;
643 if (floor_ptr->height > MAX_HGT) {
644 floor_ptr->height = MAX_HGT;
647 if (floor_ptr->width > MAX_WID) {
648 floor_ptr->width = MAX_WID;
651 panel_row_min = floor_ptr->height;
652 panel_col_min = floor_ptr->width;
653 player_ptr->x = player_ptr->wilderness_x;
654 player_ptr->y = player_ptr->wilderness_y;
655 player_ptr->town_num = 0;
659 * @brief w_info.txtのデータ解析 /
660 * Parse a sub-file of the "extra info"
661 * @param buf 読み取ったデータ行のバッファ
663 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
665 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
666 * @param y 広域マップの高さを返す参照ポインタ
667 * @param x 広域マップの幅を返す参照ポインタ
669 parse_error_type parse_line_wilderness(PlayerType *player_ptr, char *buf, int xmin, int xmax, int *y, int *x)
671 if (!(buf[0] == 'W')) {
672 return PARSE_ERROR_GENERIC;
678 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
681 return PARSE_ERROR_NONE;
686 return PARSE_ERROR_NONE;
691 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
692 int index = zz[0][0];
695 w_letter[index].terrain = i2enum<wt_type>(atoi(zz[1]));
697 w_letter[index].terrain = TERRAIN_EDGE;
701 w_letter[index].level = (int16_t)atoi(zz[2]);
703 w_letter[index].level = 0;
707 w_letter[index].town = static_cast<int16_t>(atoi(zz[3]));
709 w_letter[index].town = 0;
713 w_letter[index].road = (byte)atoi(zz[4]);
715 w_letter[index].road = 0;
719 strcpy(w_letter[index].name, zz[5]);
721 w_letter[index].name[0] = 0;
725 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
731 /* Process "W:D:<layout> */
732 /* Layout of the wilderness */
737 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
739 wilderness[*y][*x].terrain = w_letter[id].terrain;
740 wilderness[*y][*x].level = w_letter[id].level;
741 wilderness[*y][*x].town = w_letter[id].town;
742 wilderness[*y][*x].road = w_letter[id].road;
743 towns_info[w_letter[id].town].name = w_letter[id].name;
750 /* Process "W:P:<x>:<y> - starting position in the wilderness */
752 bool is_corner = player_ptr->wilderness_x == 0;
753 is_corner = player_ptr->wilderness_y == 0;
758 if (tokenize(buf + 4, 2, zz, 0) != 2) {
759 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
762 player_ptr->wilderness_y = atoi(zz[0]);
763 player_ptr->wilderness_x = atoi(zz[1]);
765 auto out_of_bounds = (player_ptr->wilderness_x < 1);
766 out_of_bounds |= (player_ptr->wilderness_x > w_ptr->max_wild_x);
767 out_of_bounds |= (player_ptr->wilderness_y < 1);
768 out_of_bounds |= (player_ptr->wilderness_y > w_ptr->max_wild_y);
770 return PARSE_ERROR_OUT_OF_BOUNDS;
777 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
780 for (const auto &d_ref : dungeons_info) {
781 if (d_ref.idx == 0 || !d_ref.maxdepth) {
784 wilderness[d_ref.dy][d_ref.dx].entrance = static_cast<byte>(d_ref.idx);
785 if (!wilderness[d_ref.dy][d_ref.dx].town) {
786 wilderness[d_ref.dy][d_ref.dx].level = d_ref.mindepth;
790 return PARSE_ERROR_NONE;
794 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
795 * Generate the random seeds for the wilderness
797 void seed_wilderness(void)
799 for (POSITION x = 0; x < w_ptr->max_wild_x; x++) {
800 for (POSITION y = 0; y < w_ptr->max_wild_y; y++) {
801 wilderness[y][x].seed = randint0(0x10000000);
802 wilderness[y][x].entrance = 0;
808 * @brief 荒野の地勢設定を初期化する /
809 * Initialize wilderness array
810 * @param terrain 初期化したい地勢ID
811 * @param feat_global 基本的な地形ID
812 * @param fmt 地勢内の地形数を参照するための独自フォーマット
814 static void init_terrain_table(int terrain, int16_t feat_global, concptr fmt, ...)
818 conv_terrain2feat[terrain] = feat_global;
821 for (concptr p = fmt; *p; p++) {
823 plog_fmt("Format error");
827 FEAT_IDX feat = (int16_t)va_arg(vp, int);
828 int num = va_arg(vp, int);
830 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++) {
831 terrain_table[terrain][cur] = feat;
834 if (cur >= MAX_FEAT_IN_TERRAIN) {
841 if (cur < MAX_FEAT_IN_TERRAIN) {
842 plog_fmt("Too few parameters");
849 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
850 * Initialize arrays for wilderness terrains
852 void init_wilderness_terrains(void)
854 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
855 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
856 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
857 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde", feat_deep_water, 3, feat_shallow_water, 12, feat_floor, 1, feat_dirt, 1, feat_grass,
858 MAX_FEAT_IN_TERRAIN - 17);
859 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef", feat_dirt, 2, feat_grass, 3, feat_tree, 1, feat_brake, 1, feat_shallow_water, 4, feat_swamp,
860 MAX_FEAT_IN_TERRAIN - 11);
862 TERRAIN_DIRT, feat_dirt, "abcdef", feat_floor, 3, feat_dirt, 10, feat_flower, 1, feat_brake, 1, feat_grass, 1, feat_tree, MAX_FEAT_IN_TERRAIN - 16);
864 TERRAIN_GRASS, feat_grass, "abcdef", feat_floor, 2, feat_dirt, 2, feat_grass, 9, feat_flower, 1, feat_brake, 2, feat_tree, MAX_FEAT_IN_TERRAIN - 16);
865 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde", feat_floor, 2, feat_dirt, 1, feat_tree, 11, feat_brake, 2, feat_grass, MAX_FEAT_IN_TERRAIN - 16);
866 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
867 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc", feat_shallow_lava, 14, feat_deep_lava, 3, feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
869 TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd", feat_dirt, 3, feat_shallow_lava, 3, feat_deep_lava, 10, feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
870 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef", feat_floor, 1, feat_brake, 1, feat_grass, 2, feat_dirt, 2, feat_tree, 2, feat_mountain,
871 MAX_FEAT_IN_TERRAIN - 8);
874 void init_wilderness_encounter()
876 generate_encounter = false;
880 * @brief 荒野から広域マップへの切り替え処理 /
881 * Initialize arrays for wilderness terrains
882 * @param encount 襲撃時TRUE
883 * @return 切り替えが行われた場合はTRUEを返す。
885 bool change_wild_mode(PlayerType *player_ptr, bool encount)
887 generate_encounter = encount;
888 if (player_ptr->leaving) {
892 if (lite_town || vanilla_town) {
893 msg_print(_("荒野なんてない。", "No global map."));
897 if (player_ptr->wild_mode) {
898 player_ptr->wilderness_x = player_ptr->x;
899 player_ptr->wilderness_y = player_ptr->y;
900 player_ptr->energy_need = 0;
901 player_ptr->wild_mode = false;
902 player_ptr->leaving = true;
906 bool has_pet = false;
907 PlayerEnergy energy(player_ptr);
908 for (int i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
909 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
910 if (!m_ptr->is_valid()) {
914 if (m_ptr->is_pet() && i != player_ptr->riding) {
918 if (m_ptr->is_asleep() || (m_ptr->cdis > MAX_PLAYER_SIGHT) || !m_ptr->is_hostile()) {
922 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there are some monsters nearby!"));
923 energy.reset_player_turn();
928 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
929 if (!input_check_strict(player_ptr, msg, UserCheck::OKAY_CANCEL)) {
930 energy.reset_player_turn();
935 energy.set_player_turn_energy(1000);
936 player_ptr->oldpx = player_ptr->x;
937 player_ptr->oldpy = player_ptr->y;
938 SpellHex spell_hex(player_ptr);
939 if (spell_hex.is_spelling_any()) {
940 spell_hex.stop_all_spells();
943 set_action(player_ptr, ACTION_NONE);
944 player_ptr->wild_mode = true;
945 player_ptr->leaving = true;