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/dungeon.h"
16 #include "dungeon/quest.h"
17 #include "floor/cave.h"
18 #include "floor/floor-town.h"
19 #include "game-option/birth-options.h"
20 #include "game-option/map-screen-options.h"
21 #include "grid/feature.h"
22 #include "grid/grid.h"
23 #include "info-reader/fixed-map-parser.h"
24 #include "info-reader/parse-error-types.h"
25 #include "io/files-util.h"
26 #include "io/tokenizer.h"
27 #include "market/building-initializer.h"
28 #include "monster-floor/monster-generator.h"
29 #include "monster-floor/monster-remover.h"
30 #include "monster-floor/monster-summon.h"
31 #include "monster-floor/place-monster-types.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-status.h"
34 #include "monster/monster-util.h"
35 #include "player-status/player-energy.h"
36 #include "player/attack-defense-types.h"
37 #include "player/player-status.h"
38 #include "realm/realm-names-table.h"
39 #include "spell-realm/spells-hex.h"
40 #include "status/action-setter.h"
41 #include "system/floor-type-definition.h"
42 #include "system/grid-type-definition.h"
43 #include "system/monster-type-definition.h"
44 #include "system/player-type-definition.h"
45 #include "system/system-variables.h"
46 #include "util/bit-flags-calculator.h"
47 #include "view/display-messages.h"
48 #include "window/main-window-util.h"
49 #include "world/world.h"
51 #define MAX_FEAT_IN_TERRAIN 18
53 std::vector<std::vector<wilderness_type>> wilderness;
54 bool generate_encounter;
56 typedef struct border_type {
57 int16_t north[MAX_WID];
58 int16_t south[MAX_WID];
59 int16_t east[MAX_HGT];
60 int16_t west[MAX_HGT];
68 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
69 * @param feat_type 非一様確率を再現するための要素数100の配列
70 * @param prob 元の確率テーブル
72 static void set_floor_and_wall_aux(int16_t feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
74 int lim[DUNGEON_FEAT_PROB_NUM];
75 lim[0] = prob[0].percent;
76 for (int i = 1; i < DUNGEON_FEAT_PROB_NUM; i++)
77 lim[i] = lim[i - 1] + prob[i].percent;
79 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100)
80 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
83 for (int i = 0; i < 100; i++) {
87 feat_type[i] = prob[cur].feat;
92 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
93 * / Fill the arrays of floors and walls in the good proportions
96 void set_floor_and_wall(DUNGEON_IDX type)
98 DUNGEON_IDX cur_type = 255;
103 dungeon_type *d_ptr = &d_info[type];
105 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
106 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
108 feat_wall_outer = d_ptr->outer_wall;
109 feat_wall_inner = d_ptr->inner_wall;
110 feat_wall_solid = d_ptr->outer_wall;
114 * @brief プラズマフラクタル的地形生成の再帰中間処理
115 * / Helper for plasma generation.
123 * @param depth_max 深みの最大値
125 static void perturb_point_mid(
126 floor_type *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)
128 FEAT_IDX tmp2 = rough * 2 + 1;
129 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
130 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
131 if (((x1 + x2 + x3 + x4) % 4) > 1)
140 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
144 * @brief プラズマフラクタル的地形生成の再帰末端処理
145 * / Helper for plasma generation.
146 * @param x1 中間末端部1の重み
147 * @param x2 中間末端部2の重み
148 * @param x3 中間末端部3の重み
149 * @param xmid 最終末端部座標X
150 * @param ymid 最終末端部座標Y
152 * @param depth_max 深みの最大値
154 static void perturb_point_end(floor_type *floor_ptr, FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
156 FEAT_IDX tmp2 = rough * 2 + 1;
157 FEAT_IDX tmp = randint0(tmp2) - rough;
158 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
159 if ((x1 + x2 + x3) % 3)
168 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
172 * @brief プラズマフラクタル的地形生成の開始処理
173 * / Helper for plasma generation.
174 * @param x1 処理範囲の左上X座標
175 * @param y1 処理範囲の左上Y座標
176 * @param x2 処理範囲の右下X座標
177 * @param y2 処理範囲の右下Y座標
178 * @param depth_max 深みの最大値
182 * A generic function to generate the plasma fractal.
183 * Note that it uses ``cave_feat'' as temporary storage.
184 * The values in ``cave_feat'' after this function
185 * are NOT actual features; They are raw heights which
186 * need to be converted to features.
189 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
191 POSITION xmid = (x2 - x1) / 2 + x1;
192 POSITION ymid = (y2 - y1) / 2 + y1;
196 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,
197 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
199 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);
201 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);
203 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);
205 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);
206 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
207 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
208 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
209 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
212 /* The default table in terrain level generation. */
213 static int16_t terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
216 * @brief 荒野フロア生成のサブルーチン
217 * @param terrain 荒野地形ID
218 * @param seed 乱数の固定シード
220 * @param corner 広域マップの角部分としての生成ならばTRUE
222 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, uint32_t seed, bool corner)
224 if (terrain == TERRAIN_EDGE) {
225 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
226 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
227 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
232 uint32_t state_backup[4];
233 Rand_state_backup(state_backup);
234 Rand_state_set(seed);
235 int table_size = sizeof(terrain_table[0]) / sizeof(int16_t);
237 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
238 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
239 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
241 floor_ptr->grid_array[1][1].feat = (int16_t)randint0(table_size);
242 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (int16_t)randint0(table_size);
243 floor_ptr->grid_array[1][MAX_WID - 2].feat = (int16_t)randint0(table_size);
244 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (int16_t)randint0(table_size);
246 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
247 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
248 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
249 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];
250 Rand_state_restore(state_backup);
254 int16_t north_west = floor_ptr->grid_array[1][1].feat;
255 int16_t south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
256 int16_t north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
257 int16_t south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
258 FEAT_IDX roughness = 1; /* The roughness of the level. */
259 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
260 floor_ptr->grid_array[1][1].feat = north_west;
261 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
262 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
263 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
264 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
265 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
266 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
268 Rand_state_restore(state_backup);
272 * @brief 荒野フロア生成のメインルーチン /
273 * Load a town or generate a terrain level using "plasma" fractals.
274 * @param player_ptr プレイヤーへの参照ポインタ
277 * @param border 広域マップの辺部分としての生成ならばTRUE
278 * @param corner 広域マップの角部分としての生成ならばTRUE
281 * x and y are the coordinates of the area in the wilderness.
282 * Border and corner are optimization flags to speed up the
283 * generation of the fractal terrain.
284 * If border is set then only the border of the terrain should
285 * be generated (for initializing the border structure).
286 * If corner is set then only the corners of the area are needed.
289 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
291 player_ptr->town_num = wilderness[y][x].town;
292 floor_type *floor_ptr = player_ptr->current_floor_ptr;
293 floor_ptr->base_level = wilderness[y][x].level;
294 floor_ptr->dun_level = 0;
295 floor_ptr->monster_level = floor_ptr->base_level;
296 floor_ptr->object_level = floor_ptr->base_level;
297 if (player_ptr->town_num) {
299 if (border || corner)
300 init_flags = i2enum<init_flags_type>(INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES);
302 init_flags = INIT_CREATE_DUNGEON;
304 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
305 if (!corner && !border)
306 player_ptr->visit |= (1UL << (player_ptr->town_num - 1));
308 int terrain = wilderness[y][x].terrain;
309 uint32_t seed = wilderness[y][x].seed;
310 generate_wilderness_area(floor_ptr, terrain, seed, corner);
313 if (!corner && !wilderness[y][x].town) {
314 //!< @todo make the road a bit more interresting.
315 if (wilderness[y][x].road) {
316 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
318 if (wilderness[y - 1][x].road) {
320 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
322 floor_ptr->grid_array[y1][x1].feat = feat_floor;
326 if (wilderness[y + 1][x].road) {
328 for (y1 = MAX_HGT / 2; y1 < MAX_HGT - 1; y1++) {
330 floor_ptr->grid_array[y1][x1].feat = feat_floor;
334 if (wilderness[y][x + 1].road) {
336 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
338 floor_ptr->grid_array[y1][x1].feat = feat_floor;
342 if (wilderness[y][x - 1].road) {
344 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
346 floor_ptr->grid_array[y1][x1].feat = feat_floor;
352 bool is_winner = wilderness[y][x].entrance > 0;
353 is_winner &= (wilderness[y][x].town == 0);
354 bool is_wild_winner = d_info[wilderness[y][x].entrance].flags.has_not(DF::WINNER);
355 is_winner &= ((w_ptr->total_winner != 0) || is_wild_winner);
359 uint32_t state_backup[4];
360 Rand_state_backup(state_backup);
361 Rand_state_set(wilderness[y][x].seed);
362 int dy = rand_range(6, floor_ptr->height - 6);
363 int dx = rand_range(6, floor_ptr->width - 6);
364 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
365 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
366 Rand_state_restore(state_backup);
369 /* Border of the wilderness area */
370 static border_type border;
374 * Build the wilderness area outside of the town.
375 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
376 * @param player_ptr プレイヤーへの参照ポインタ
378 void wilderness_gen(player_type *player_ptr)
380 floor_type *floor_ptr = player_ptr->current_floor_ptr;
381 floor_ptr->height = MAX_HGT;
382 floor_ptr->width = MAX_WID;
383 panel_row_min = floor_ptr->height;
384 panel_col_min = floor_ptr->width;
385 parse_fixed_map(player_ptr, "w_info.txt", 0, 0, w_ptr->max_wild_y, w_ptr->max_wild_x);
386 POSITION x = player_ptr->wilderness_x;
387 POSITION y = player_ptr->wilderness_y;
388 get_mon_num_prep(player_ptr, get_monster_hook(player_ptr), nullptr);
391 generate_area(player_ptr, y - 1, x, true, false);
392 for (int i = 1; i < MAX_WID - 1; i++)
393 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
396 generate_area(player_ptr, y + 1, x, true, false);
397 for (int i = 1; i < MAX_WID - 1; i++)
398 border.south[i] = floor_ptr->grid_array[1][i].feat;
401 generate_area(player_ptr, y, x - 1, true, false);
402 for (int i = 1; i < MAX_HGT - 1; i++)
403 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
406 generate_area(player_ptr, y, x + 1, true, false);
407 for (int i = 1; i < MAX_HGT - 1; i++)
408 border.east[i] = floor_ptr->grid_array[i][1].feat;
410 /* North west corner */
411 generate_area(player_ptr, y - 1, x - 1, false, true);
412 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
414 /* North east corner */
415 generate_area(player_ptr, y - 1, x + 1, false, true);
416 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
418 /* South west corner */
419 generate_area(player_ptr, y + 1, x - 1, false, true);
420 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
422 /* South east corner */
423 generate_area(player_ptr, y + 1, x + 1, false, true);
424 border.south_east = floor_ptr->grid_array[1][1].feat;
426 /* Create terrain of the current area */
427 generate_area(player_ptr, y, x, false, false);
429 /* Special boundary walls -- North */
430 for (int i = 0; i < MAX_WID; i++) {
431 floor_ptr->grid_array[0][i].feat = feat_permanent;
432 floor_ptr->grid_array[0][i].mimic = border.north[i];
435 /* Special boundary walls -- South */
436 for (int i = 0; i < MAX_WID; i++) {
437 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
438 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
441 /* Special boundary walls -- West */
442 for (int i = 0; i < MAX_HGT; i++) {
443 floor_ptr->grid_array[i][0].feat = feat_permanent;
444 floor_ptr->grid_array[i][0].mimic = border.west[i];
447 /* Special boundary walls -- East */
448 for (int i = 0; i < MAX_HGT; i++) {
449 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
450 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
453 floor_ptr->grid_array[0][0].mimic = border.north_west;
454 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
455 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
456 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
457 for (y = 0; y < floor_ptr->height; y++) {
458 for (x = 0; x < floor_ptr->width; x++) {
460 g_ptr = &floor_ptr->grid_array[y][x];
462 g_ptr->info |= CAVE_GLOW;
463 if (view_perma_grids)
464 g_ptr->info |= CAVE_MARK;
470 f_ptr = &f_info[g_ptr->get_feat_mimic()];
471 if (!g_ptr->is_mirror() && f_ptr->flags.has_none_of({FF::QUEST_ENTER, FF::ENTRANCE})) {
472 g_ptr->info &= ~(CAVE_GLOW);
473 if (f_ptr->flags.has_not(FF::REMEMBER))
474 g_ptr->info &= ~(CAVE_MARK);
479 if (f_ptr->flags.has_not(FF::ENTRANCE))
482 g_ptr->info |= CAVE_GLOW;
483 if (view_perma_grids)
484 g_ptr->info |= CAVE_MARK;
488 if (player_ptr->teleport_town) {
489 for (y = 0; y < floor_ptr->height; y++) {
490 for (x = 0; x < floor_ptr->width; x++) {
492 g_ptr = &floor_ptr->grid_array[y][x];
494 f_ptr = &f_info[g_ptr->feat];
495 if (f_ptr->flags.has_not(FF::BLDG))
498 if ((f_ptr->subtype != 4) && !((player_ptr->town_num == 1) && (f_ptr->subtype == 0)))
501 if (g_ptr->m_idx != 0)
502 delete_monster_idx(player_ptr, g_ptr->m_idx);
504 player_ptr->oldpy = y;
505 player_ptr->oldpx = x;
509 player_ptr->teleport_town = false;
510 } else if (player_ptr->leaving_dungeon) {
511 for (y = 0; y < floor_ptr->height; y++) {
512 for (x = 0; x < floor_ptr->width; x++) {
514 g_ptr = &floor_ptr->grid_array[y][x];
515 if (!g_ptr->cave_has_flag(FF::ENTRANCE))
518 if (g_ptr->m_idx != 0)
519 delete_monster_idx(player_ptr, g_ptr->m_idx);
521 player_ptr->oldpy = y;
522 player_ptr->oldpx = x;
526 player_ptr->teleport_town = false;
529 player_place(player_ptr, player_ptr->oldpy, player_ptr->oldpx);
530 int lim = generate_encounter ? 40 : MIN_M_ALLOC_TN;
531 for (int i = 0; i < lim; i++) {
533 if (!(generate_encounter || (one_in_(2) && (!player_ptr->town_num))))
534 mode |= PM_ALLOW_SLEEP;
536 (void)alloc_monster(player_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
539 if (generate_encounter)
540 player_ptr->ambush_flag = true;
542 generate_encounter = false;
543 set_floor_and_wall(0);
544 for (int i = 0; i < max_q_idx; i++)
545 if (quest[i].status == QUEST_STATUS_REWARDED)
546 quest[i].status = QUEST_STATUS_FINISHED;
549 static int16_t conv_terrain2feat[MAX_WILDERNESS];
552 * @brief 広域マップの生成(簡易処理版) /
553 * Build the wilderness area. -DG-
555 void wilderness_gen_small(player_type *player_ptr)
557 floor_type *floor_ptr = player_ptr->current_floor_ptr;
558 for (int i = 0; i < MAX_WID; i++)
559 for (int j = 0; j < MAX_HGT; j++)
560 floor_ptr->grid_array[j][i].feat = feat_permanent;
562 parse_fixed_map(player_ptr, "w_info.txt", 0, 0, w_ptr->max_wild_y, w_ptr->max_wild_x);
563 for (int i = 0; i < w_ptr->max_wild_x; i++) {
564 for (int j = 0; j < w_ptr->max_wild_y; j++) {
565 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN)) {
566 floor_ptr->grid_array[j][i].feat = (int16_t)feat_town;
567 floor_ptr->grid_array[j][i].special = (int16_t)wilderness[j][i].town;
568 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
572 if (wilderness[j][i].road) {
573 floor_ptr->grid_array[j][i].feat = feat_floor;
574 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
578 if (wilderness[j][i].entrance && (w_ptr->total_winner || d_info[wilderness[j][i].entrance].flags.has_not(DF::WINNER))) {
579 floor_ptr->grid_array[j][i].feat = feat_entrance;
580 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
581 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
585 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
586 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
590 floor_ptr->height = (int16_t)w_ptr->max_wild_y;
591 floor_ptr->width = (int16_t)w_ptr->max_wild_x;
592 if (floor_ptr->height > MAX_HGT)
593 floor_ptr->height = MAX_HGT;
595 if (floor_ptr->width > MAX_WID)
596 floor_ptr->width = MAX_WID;
598 panel_row_min = floor_ptr->height;
599 panel_col_min = floor_ptr->width;
600 player_ptr->x = player_ptr->wilderness_x;
601 player_ptr->y = player_ptr->wilderness_y;
602 player_ptr->town_num = 0;
605 typedef struct wilderness_grid {
606 wt_type terrain; /* Terrain type */
607 int16_t town; /* Town number */
608 DEPTH level; /* Level of the wilderness */
609 byte road; /* Road */
610 char name[32]; /* Name of the town/wilderness */
613 static wilderness_grid w_letter[255];
616 * @brief w_info.txtのデータ解析 /
617 * Parse a sub-file of the "extra info"
618 * @param buf 読み取ったデータ行のバッファ
620 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
622 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
623 * @param y 広域マップの高さを返す参照ポインタ
624 * @param x 広域マップの幅を返す参照ポインタ
626 parse_error_type parse_line_wilderness(player_type *player_ptr, char *buf, int xmin, int xmax, int *y, int *x)
628 if (!(buf[0] == 'W'))
629 return (PARSE_ERROR_GENERIC);
634 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
637 return PARSE_ERROR_NONE;
642 return PARSE_ERROR_NONE;
647 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
648 int index = zz[0][0];
651 w_letter[index].terrain = i2enum<wt_type>(atoi(zz[1]));
653 w_letter[index].terrain = TERRAIN_EDGE;
656 w_letter[index].level = (int16_t)atoi(zz[2]);
658 w_letter[index].level = 0;
661 w_letter[index].town = static_cast<int16_t>(atoi(zz[3]));
663 w_letter[index].town = 0;
666 w_letter[index].road = (byte)atoi(zz[4]);
668 w_letter[index].road = 0;
671 strcpy(w_letter[index].name, zz[5]);
673 w_letter[index].name[0] = 0;
676 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
682 /* Process "W:D:<layout> */
683 /* Layout of the wilderness */
688 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
690 wilderness[*y][*x].terrain = w_letter[id].terrain;
691 wilderness[*y][*x].level = w_letter[id].level;
692 wilderness[*y][*x].town = w_letter[id].town;
693 wilderness[*y][*x].road = w_letter[id].road;
694 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
701 /* Process "W:P:<x>:<y> - starting position in the wilderness */
703 bool is_corner = player_ptr->wilderness_x == 0;
704 is_corner = player_ptr->wilderness_y == 0;
708 if (tokenize(buf + 4, 2, zz, 0) != 2) {
709 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
712 player_ptr->wilderness_y = atoi(zz[0]);
713 player_ptr->wilderness_x = atoi(zz[1]);
715 if ((player_ptr->wilderness_x < 1) || (player_ptr->wilderness_x > w_ptr->max_wild_x) || (player_ptr->wilderness_y < 1)
716 || (player_ptr->wilderness_y > w_ptr->max_wild_y)) {
717 return PARSE_ERROR_OUT_OF_BOUNDS;
724 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
727 for (const auto &d_ref : d_info) {
728 if (d_ref.idx == 0 || !d_ref.maxdepth)
730 wilderness[d_ref.dy][d_ref.dx].entrance = static_cast<byte>(d_ref.idx);
731 if (!wilderness[d_ref.dy][d_ref.dx].town) {
732 wilderness[d_ref.dy][d_ref.dx].level = d_ref.mindepth;
736 return PARSE_ERROR_NONE;
740 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
741 * Generate the random seeds for the wilderness
743 void seed_wilderness(void)
745 for (POSITION x = 0; x < w_ptr->max_wild_x; x++)
746 for (POSITION y = 0; y < w_ptr->max_wild_y; y++) {
747 wilderness[y][x].seed = randint0(0x10000000);
748 wilderness[y][x].entrance = 0;
752 /* Pointer to wilderness_type */
753 typedef wilderness_type *wilderness_type_ptr;
756 * @brief ゲーム開始時の荒野初期化メインルーチン /
757 * Initialize wilderness array
760 errr init_wilderness(void)
762 wilderness.assign(w_ptr->max_wild_y, std::vector<wilderness_type>(w_ptr->max_wild_x));
764 generate_encounter = false;
769 * @brief 荒野の地勢設定を初期化する /
770 * Initialize wilderness array
771 * @param terrain 初期化したい地勢ID
772 * @param feat_global 基本的な地形ID
773 * @param fmt 地勢内の地形数を参照するための独自フォーマット
775 static void init_terrain_table(int terrain, int16_t feat_global, concptr fmt, ...)
779 conv_terrain2feat[terrain] = feat_global;
782 for (concptr p = fmt; *p; p++) {
784 plog_fmt("Format error");
788 FEAT_IDX feat = (int16_t)va_arg(vp, int);
789 int num = va_arg(vp, int);
791 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
792 terrain_table[terrain][cur] = feat;
794 if (cur >= MAX_FEAT_IN_TERRAIN)
800 if (cur < MAX_FEAT_IN_TERRAIN)
801 plog_fmt("Too few parameters");
807 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
808 * Initialize arrays for wilderness terrains
810 void init_wilderness_terrains(void)
812 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
813 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
814 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
815 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,
816 MAX_FEAT_IN_TERRAIN - 17);
817 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,
818 MAX_FEAT_IN_TERRAIN - 11);
820 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);
822 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);
823 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);
824 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
825 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);
827 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);
828 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,
829 MAX_FEAT_IN_TERRAIN - 8);
833 * @brief 荒野から広域マップへの切り替え処理 /
834 * Initialize arrays for wilderness terrains
835 * @param encount 襲撃時TRUE
836 * @return 切り替えが行われた場合はTRUEを返す。
838 bool change_wild_mode(player_type *player_ptr, bool encount)
840 generate_encounter = encount;
841 if (player_ptr->leaving)
844 if (lite_town || vanilla_town) {
845 msg_print(_("荒野なんてない。", "No global map."));
849 if (player_ptr->wild_mode) {
850 player_ptr->wilderness_x = player_ptr->x;
851 player_ptr->wilderness_y = player_ptr->y;
852 player_ptr->energy_need = 0;
853 player_ptr->wild_mode = false;
854 player_ptr->leaving = true;
858 bool has_pet = false;
859 PlayerEnergy energy(player_ptr);
860 for (int i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
861 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
862 if (!monster_is_valid(m_ptr))
865 if (is_pet(m_ptr) && i != player_ptr->riding)
868 if (monster_csleep_remaining(m_ptr) || (m_ptr->cdis > MAX_SIGHT) || !is_hostile(m_ptr))
871 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there are some monsters nearby!"));
872 energy.reset_player_turn();
877 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
878 if (!get_check_strict(player_ptr, msg, CHECK_OKAY_CANCEL)) {
879 energy.reset_player_turn();
884 energy.set_player_turn_energy(1000);
885 player_ptr->oldpx = player_ptr->x;
886 player_ptr->oldpy = player_ptr->y;
887 SpellHex spell_hex(player_ptr);
888 if (spell_hex.is_spelling_any()) {
889 spell_hex.stop_all_spells();
892 set_action(player_ptr, ACTION_NONE);
893 player_ptr->wild_mode = true;
894 player_ptr->leaving = true;