3 * @brief 荒野マップの生成とルール管理 / Wilderness generation
6 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke\n
7 * This software may be copied and distributed for educational, research, and\n
8 * not for profit purposes provided that this copyright and statement are\n
9 * included in all such copies.\n
10 * 2013 Deskull rearranged comment for Doxygen.
13 #include "floor/wild.h"
14 #include "core/asking-player.h"
15 #include "dungeon/dungeon.h"
16 #include "dungeon/quest.h"
17 #include "floor/floor-town.h"
18 #include "floor/floor.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 "main/init.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/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/floor-type-definition.h"
41 #include "system/system-variables.h"
42 #include "util/bit-flags-calculator.h"
43 #include "view/display-messages.h"
44 #include "window/main-window-util.h"
45 #include "world/world.h"
47 #define MAX_FEAT_IN_TERRAIN 18
52 wilderness_type **wilderness;
54 bool generate_encounter;
56 typedef struct border_type {
68 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
69 * @param feat_type 非一様確率を再現するための要素数100の配列
70 * @param prob 元の確率テーブル
73 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
75 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
77 lim[0] = prob[0].percent;
78 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++)
79 lim[i] = lim[i - 1] + prob[i].percent;
80 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100)
81 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
83 for (i = 0; i < 100; i++) {
86 feat_type[i] = prob[cur].feat;
91 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
92 * / 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;
102 if (cur_type == type)
106 d_ptr = &d_info[type];
108 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
109 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
111 feat_wall_outer = d_ptr->outer_wall;
112 feat_wall_inner = d_ptr->inner_wall;
113 feat_wall_solid = d_ptr->outer_wall;
117 * @brief プラズマフラクタル的地形生成の再帰中間処理
118 * / Helper for plasma generation.
126 * @param depth_max 深みの最大値
129 static void perturb_point_mid(
130 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)
133 * Average the four corners & perturb it a bit.
134 * tmp is a random int +/- rough
136 FEAT_IDX tmp2 = rough * 2 + 1;
137 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
139 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
141 /* Division always rounds down, so we round up again */
142 if (((x1 + x2 + x3 + x4) % 4) > 1)
151 /* Set the new value. */
152 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
156 * @brief プラズマフラクタル的地形生成の再帰末端処理
157 * / Helper for plasma generation.
158 * @param x1 中間末端部1の重み
159 * @param x2 中間末端部2の重み
160 * @param x3 中間末端部3の重み
161 * @param xmid 最終末端部座標X
162 * @param ymid 最終末端部座標Y
164 * @param depth_max 深みの最大値
167 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)
170 * Average the three corners & perturb it a bit.
171 * tmp is a random int +/- rough
173 FEAT_IDX tmp2 = rough * 2 + 1;
174 FEAT_IDX tmp = randint0(tmp2) - rough;
176 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
178 /* Division always rounds down, so we round up again */
179 if ((x1 + x2 + x3) % 3)
188 /* Set the new value. */
189 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
193 * @brief プラズマフラクタル的地形生成の開始処理
194 * / Helper for plasma generation.
195 * @param x1 処理範囲の左上X座標
196 * @param y1 処理範囲の左上Y座標
197 * @param x2 処理範囲の右下X座標
198 * @param y2 処理範囲の右下Y座標
199 * @param depth_max 深みの最大値
204 * A generic function to generate the plasma fractal.
205 * Note that it uses ``cave_feat'' as temporary storage.
206 * The values in ``cave_feat'' after this function
207 * are NOT actual features; They are raw heights which
208 * need to be converted to features.
211 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
214 POSITION xmid = (x2 - x1) / 2 + x1;
215 POSITION ymid = (y2 - y1) / 2 + y1;
221 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,
222 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
225 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);
231 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);
234 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);
236 /* Recurse the four quadrants */
237 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
238 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
239 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
240 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
244 * The default table in terrain level generation.
246 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
249 * @brief 荒野フロア生成のサブルーチン
250 * @param terrain 荒野地形ID
251 * @param seed 乱数の固定シード
253 * @param corner 広域マップの角部分としての生成ならばTRUE
256 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
258 /* The outer wall is easy */
259 if (terrain == TERRAIN_EDGE) {
260 /* Create level background */
261 for (POSITION y1 = 0; y1 < MAX_HGT; y1++) {
262 for (POSITION x1 = 0; x1 < MAX_WID; x1++) {
263 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
270 /* Hack -- Backup the RNG state */
271 u32b state_backup[4];
272 Rand_state_backup(state_backup);
274 /* Hack -- Induce consistant flavors */
275 Rand_state_set(seed);
277 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
279 /* Create level background */
280 for (POSITION y1 = 0; y1 < MAX_HGT; y1++) {
281 for (POSITION x1 = 0; x1 < MAX_WID; x1++) {
282 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
288 * Initialize the four corners
289 * ToDo: calculate the medium height of the adjacent
290 * terrains for every corner.
292 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
293 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (s16b)randint0(table_size);
294 floor_ptr->grid_array[1][MAX_WID - 2].feat = (s16b)randint0(table_size);
295 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (s16b)randint0(table_size);
297 /* Hack -- only four corners */
299 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
300 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
301 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
302 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];
303 Rand_state_restore(state_backup);
307 /* Hack -- preserve four corners */
308 s16b north_west = floor_ptr->grid_array[1][1].feat;
309 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
310 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
311 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
313 /* x1, y1, x2, y2, num_depths, roughness */
314 FEAT_IDX roughness = 1; /* The roughness of the level. */
315 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
317 /* Hack -- copyback four corners */
318 floor_ptr->grid_array[1][1].feat = north_west;
319 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
320 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
321 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
323 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++) {
324 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++) {
325 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
329 Rand_state_restore(state_backup);
333 * @brief 荒野フロア生成のメインルーチン /
334 * Load a town or generate a terrain level using "plasma" fractals.
335 * @param player_ptr プレーヤーへの参照ポインタ
338 * @param border 広域マップの辺部分としての生成ならばTRUE
339 * @param corner 広域マップの角部分としての生成ならばTRUE
343 * x and y are the coordinates of the area in the wilderness.
344 * Border and corner are optimization flags to speed up the
345 * generation of the fractal terrain.
346 * If border is set then only the border of the terrain should
347 * be generated (for initializing the border structure).
348 * If corner is set then only the corners of the area are needed.
351 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
353 /* Number of the town (if any) */
354 player_ptr->town_num = wilderness[y][x].town;
356 /* Set the base level */
357 floor_type *floor_ptr = player_ptr->current_floor_ptr;
358 floor_ptr->base_level = wilderness[y][x].level;
360 /* Set the dungeon level */
361 floor_ptr->dun_level = 0;
363 /* Set the monster generation level */
364 floor_ptr->monster_level = floor_ptr->base_level;
366 /* Set the object generation level */
367 floor_ptr->object_level = floor_ptr->base_level;
369 /* Create the town */
370 if (player_ptr->town_num) {
371 /* Reset the buildings */
374 /* Initialize the town */
376 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
378 init_flags = INIT_CREATE_DUNGEON;
380 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
382 if (!corner && !border)
383 player_ptr->visit |= (1L << (player_ptr->town_num - 1));
385 int terrain = wilderness[y][x].terrain;
386 u32b seed = wilderness[y][x].seed;
388 generate_wilderness_area(floor_ptr, terrain, seed, corner);
391 if (!corner && !wilderness[y][x].town) {
393 * Place roads in the wilderness
394 * ToDo: make the road a bit more interresting
396 if (wilderness[y][x].road) {
397 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
400 if (wilderness[y - 1][x].road) {
402 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
404 floor_ptr->grid_array[y1][x1].feat = feat_floor;
408 if (wilderness[y + 1][x].road) {
410 for (y1 = MAX_HGT / 2; y1 < MAX_HGT - 1; y1++) {
412 floor_ptr->grid_array[y1][x1].feat = feat_floor;
416 if (wilderness[y][x + 1].road) {
418 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
420 floor_ptr->grid_array[y1][x1].feat = feat_floor;
424 if (wilderness[y][x - 1].road) {
426 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
428 floor_ptr->grid_array[y1][x1].feat = feat_floor;
435 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
436 * 問題なければ'> 0'へ置き換えること
438 bool is_winner = wilderness[y][x].entrance != 0;
439 is_winner &= !wilderness[y][x].town != 0;
440 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
441 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
445 /* Hack -- Backup the RNG state */
446 u32b state_backup[4];
447 Rand_state_backup(state_backup);
449 /* Hack -- Induce consistant flavors */
450 Rand_state_set(wilderness[y][x].seed);
452 int dy = rand_range(6, floor_ptr->height - 6);
453 int dx = rand_range(6, floor_ptr->width - 6);
455 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
456 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
458 /* Hack -- Restore the RNG state */
459 Rand_state_restore(state_backup);
463 * Border of the wilderness area
465 static border_type border;
469 * Build the wilderness area outside of the town.
470 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
471 * @param creature_ptr プレーヤーへの参照ポインタ
474 void wilderness_gen(player_type *creature_ptr)
477 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
478 floor_ptr->height = MAX_HGT;
479 floor_ptr->width = MAX_WID;
481 /* Assume illegal panel */
482 panel_row_min = floor_ptr->height;
483 panel_col_min = floor_ptr->width;
485 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
486 POSITION x = creature_ptr->wilderness_x;
487 POSITION y = creature_ptr->wilderness_y;
488 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
491 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
493 for (int i = 1; i < MAX_WID - 1; i++) {
494 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
498 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
500 for (int i = 1; i < MAX_WID - 1; i++) {
501 border.south[i] = floor_ptr->grid_array[1][i].feat;
505 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
507 for (int i = 1; i < MAX_HGT - 1; i++) {
508 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
512 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
514 for (int i = 1; i < MAX_HGT - 1; i++) {
515 border.east[i] = floor_ptr->grid_array[i][1].feat;
518 /* North west corner */
519 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
520 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
522 /* North east corner */
523 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
524 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
526 /* South west corner */
527 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
528 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
530 /* South east corner */
531 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
532 border.south_east = floor_ptr->grid_array[1][1].feat;
534 /* Create terrain of the current area */
535 generate_area(creature_ptr, y, x, FALSE, FALSE);
537 /* Special boundary walls -- North */
538 for (int i = 0; i < MAX_WID; i++) {
539 floor_ptr->grid_array[0][i].feat = feat_permanent;
540 floor_ptr->grid_array[0][i].mimic = border.north[i];
543 /* Special boundary walls -- South */
544 for (int i = 0; i < MAX_WID; i++) {
545 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
546 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
549 /* Special boundary walls -- West */
550 for (int i = 0; i < MAX_HGT; i++) {
551 floor_ptr->grid_array[i][0].feat = feat_permanent;
552 floor_ptr->grid_array[i][0].mimic = border.west[i];
555 /* Special boundary walls -- East */
556 for (int i = 0; i < MAX_HGT; i++) {
557 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
558 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
561 floor_ptr->grid_array[0][0].mimic = border.north_west;
562 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
563 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
564 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
566 /* Light up or darken the area */
567 for (y = 0; y < floor_ptr->height; y++) {
568 for (x = 0; x < floor_ptr->width; x++) {
570 g_ptr = &floor_ptr->grid_array[y][x];
574 g_ptr->info |= CAVE_GLOW;
576 /* Hack -- Memorize lit grids if allowed */
577 if (view_perma_grids)
578 g_ptr->info |= CAVE_MARK;
582 /* Feature code (applying "mimic" field) */
584 f_ptr = &f_info[get_feat_mimic(g_ptr)];
586 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) && !have_flag(f_ptr->flags, FF_ENTRANCE)) {
588 g_ptr->info &= ~(CAVE_GLOW);
590 /* Darken "boring" features */
591 if (!have_flag(f_ptr->flags, FF_REMEMBER)) {
592 /* Forget the grid */
593 g_ptr->info &= ~(CAVE_MARK);
599 if (!have_flag(f_ptr->flags, FF_ENTRANCE))
602 g_ptr->info |= CAVE_GLOW;
604 /* Hack -- Memorize lit grids if allowed */
605 if (view_perma_grids)
606 g_ptr->info |= CAVE_MARK;
610 if (creature_ptr->teleport_town) {
611 for (y = 0; y < floor_ptr->height; y++) {
612 for (x = 0; x < floor_ptr->width; x++) {
614 g_ptr = &floor_ptr->grid_array[y][x];
616 /* Seeing true feature code (ignore mimic) */
618 f_ptr = &f_info[g_ptr->feat];
620 if (!have_flag(f_ptr->flags, FF_BLDG))
623 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
627 delete_monster_idx(creature_ptr, g_ptr->m_idx);
630 creature_ptr->oldpy = y;
631 creature_ptr->oldpx = x;
635 creature_ptr->teleport_town = FALSE;
636 } else if (creature_ptr->leaving_dungeon) {
637 for (y = 0; y < floor_ptr->height; y++) {
638 for (x = 0; x < floor_ptr->width; x++) {
640 g_ptr = &floor_ptr->grid_array[y][x];
642 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE))
646 delete_monster_idx(creature_ptr, g_ptr->m_idx);
649 creature_ptr->oldpy = y;
650 creature_ptr->oldpx = x;
654 creature_ptr->teleport_town = FALSE;
657 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
658 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
660 /* Make some residents */
661 for (int i = 0; i < lim; i++) {
664 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
665 mode |= PM_ALLOW_SLEEP;
667 /* Make a resident */
668 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
671 if (generate_encounter)
672 creature_ptr->ambush_flag = TRUE;
673 generate_encounter = FALSE;
675 /* Fill the arrays of floors and walls in the good proportions */
676 set_floor_and_wall(0);
678 /* Set rewarded quests to finished */
679 for (int i = 0; i < max_q_idx; i++) {
680 if (quest[i].status == QUEST_STATUS_REWARDED)
681 quest[i].status = QUEST_STATUS_FINISHED;
685 static s16b conv_terrain2feat[MAX_WILDERNESS];
688 * @brief 広域マップの生成(簡易処理版) /
689 * Build the wilderness area. -DG-
692 void wilderness_gen_small(player_type *creature_ptr)
694 /* To prevent stupid things */
695 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
696 for (int i = 0; i < MAX_WID; i++) {
697 for (int j = 0; j < MAX_HGT; j++) {
698 floor_ptr->grid_array[j][i].feat = feat_permanent;
702 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
705 for (int i = 0; i < current_world_ptr->max_wild_x; i++) {
706 for (int j = 0; j < current_world_ptr->max_wild_y; j++) {
707 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN)) {
708 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
709 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
710 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
714 if (wilderness[j][i].road) {
715 floor_ptr->grid_array[j][i].feat = feat_floor;
716 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
720 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER))) {
721 floor_ptr->grid_array[j][i].feat = feat_entrance;
722 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
723 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
727 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
728 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
732 floor_ptr->height = (s16b)current_world_ptr->max_wild_y;
733 floor_ptr->width = (s16b)current_world_ptr->max_wild_x;
735 if (floor_ptr->height > MAX_HGT)
736 floor_ptr->height = MAX_HGT;
737 if (floor_ptr->width > MAX_WID)
738 floor_ptr->width = MAX_WID;
740 /* Assume illegal panel */
741 panel_row_min = floor_ptr->height;
742 panel_col_min = floor_ptr->width;
744 creature_ptr->x = creature_ptr->wilderness_x;
745 creature_ptr->y = creature_ptr->wilderness_y;
746 creature_ptr->town_num = 0;
749 typedef struct wilderness_grid wilderness_grid;
751 struct wilderness_grid {
752 int terrain; /* Terrain type */
753 TOWN_IDX town; /* Town number */
754 DEPTH level; /* Level of the wilderness */
755 byte road; /* Road */
756 char name[32]; /* Name of the town/wilderness */
759 static wilderness_grid w_letter[255];
762 * @brief w_info.txtのデータ解析 /
763 * Parse a sub-file of the "extra info"
764 * @param buf 読み取ったデータ行のバッファ
766 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
768 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
769 * @param y 広域マップの高さを返す参照ポインタ
770 * @param x 広域マップの幅を返す参照ポインタ
773 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
775 if (!(buf[0] == 'W'))
776 return (PARSE_ERROR_GENERIC);
781 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
794 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
795 int index = zz[0][0];
798 w_letter[index].terrain = atoi(zz[1]);
800 w_letter[index].terrain = 0;
803 w_letter[index].level = (s16b)atoi(zz[2]);
805 w_letter[index].level = 0;
808 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
810 w_letter[index].town = 0;
813 w_letter[index].road = (byte)atoi(zz[4]);
815 w_letter[index].road = 0;
818 strcpy(w_letter[index].name, zz[5]);
820 w_letter[index].name[0] = 0;
823 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
829 /* Process "W:D:<layout> */
830 /* Layout of the wilderness */
835 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
837 wilderness[*y][*x].terrain = w_letter[id].terrain;
838 wilderness[*y][*x].level = w_letter[id].level;
839 wilderness[*y][*x].town = w_letter[id].town;
840 wilderness[*y][*x].road = w_letter[id].road;
841 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
848 /* Process "W:P:<x>:<y> - starting position in the wilderness */
850 bool is_corner = creature_ptr->wilderness_x == 0;
851 is_corner = creature_ptr->wilderness_y == 0;
855 if (tokenize(buf + 4, 2, zz, 0) != 2) {
856 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
859 creature_ptr->wilderness_y = atoi(zz[0]);
860 creature_ptr->wilderness_x = atoi(zz[1]);
862 if ((creature_ptr->wilderness_x < 1) || (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) || (creature_ptr->wilderness_y < 1)
863 || (creature_ptr->wilderness_y > current_world_ptr->max_wild_y)) {
864 return PARSE_ERROR_OUT_OF_BOUNDS;
871 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
874 for (int i = 1; i < current_world_ptr->max_d_idx; i++) {
875 if (!d_info[i].maxdepth)
877 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
878 if (!wilderness[d_info[i].dy][d_info[i].dx].town) {
879 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
887 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
888 * Generate the random seeds for the wilderness
891 void seed_wilderness(void)
893 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++) {
894 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++) {
895 wilderness[y][x].seed = randint0(0x10000000);
896 wilderness[y][x].entrance = 0;
902 * Pointer to wilderness_type
904 typedef wilderness_type *wilderness_type_ptr;
907 * @brief ゲーム開始時の荒野初期化メインルーチン /
908 * Initialize wilderness array
911 errr init_wilderness(void)
913 /* Allocate the wilderness (two-dimension array) */
914 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
915 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
917 /* Init the other pointers */
918 for (int i = 1; i < current_world_ptr->max_wild_y; i++) {
919 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
922 generate_encounter = FALSE;
927 * @brief 荒野の地勢設定を初期化する /
928 * Initialize wilderness array
929 * @param terrain 初期化したい地勢ID
930 * @param feat_global 基本的な地形ID
931 * @param fmt 地勢内の地形数を参照するための独自フォーマット
934 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
936 /* Begin the varargs stuff */
940 /* Wilderness terrains on global map */
941 conv_terrain2feat[terrain] = feat_global;
943 /* Wilderness terrains on local map */
946 for (concptr p = fmt; *p; p++) {
948 plog_fmt("Format error");
952 FEAT_IDX feat = (s16b)va_arg(vp, int);
953 int num = va_arg(vp, int);
956 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++) {
957 terrain_table[terrain][cur] = feat;
960 if (cur >= MAX_FEAT_IN_TERRAIN)
966 if (cur < MAX_FEAT_IN_TERRAIN) {
967 plog_fmt("Too few parameters");
974 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
975 * Initialize arrays for wilderness terrains
978 void init_wilderness_terrains(void)
980 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
982 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
984 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
986 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,
987 MAX_FEAT_IN_TERRAIN - 17);
989 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,
990 MAX_FEAT_IN_TERRAIN - 11);
993 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);
996 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);
998 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);
1000 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1002 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);
1005 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);
1007 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,
1008 MAX_FEAT_IN_TERRAIN - 8);
1012 * @brief 荒野から広域マップへの切り替え処理 /
1013 * Initialize arrays for wilderness terrains
1014 * @param encount 襲撃時TRUE
1015 * @return 切り替えが行われた場合はTRUEを返す。
1017 bool change_wild_mode(player_type *creature_ptr, bool encount)
1019 generate_encounter = encount;
1021 /* It is in the middle of changing map */
1022 if (creature_ptr->leaving)
1025 if (lite_town || vanilla_town) {
1026 msg_print(_("荒野なんてない。", "No global map."));
1030 if (creature_ptr->wild_mode) {
1031 /* Save the location in the global map */
1032 creature_ptr->wilderness_x = creature_ptr->x;
1033 creature_ptr->wilderness_y = creature_ptr->y;
1035 /* Give first move to the player */
1036 creature_ptr->energy_need = 0;
1038 /* Go back to the ordinary map */
1039 creature_ptr->wild_mode = FALSE;
1040 creature_ptr->leaving = TRUE;
1044 bool have_pet = FALSE;
1045 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
1046 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1048 if (!monster_is_valid(m_ptr))
1050 if (is_pet(m_ptr) && i != creature_ptr->riding)
1052 if (monster_csleep_remaining(m_ptr))
1054 if (m_ptr->cdis > MAX_SIGHT)
1056 if (!is_hostile(m_ptr))
1058 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there is some monsters nearby!"));
1059 free_turn(creature_ptr);
1064 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
1066 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL)) {
1067 free_turn(creature_ptr);
1072 take_turn(creature_ptr, 1000);
1074 /* Remember the position */
1075 creature_ptr->oldpx = creature_ptr->x;
1076 creature_ptr->oldpy = creature_ptr->y;
1078 /* Cancel hex spelling */
1079 if (hex_spelling_any(creature_ptr))
1080 stop_hex_spell_all(creature_ptr);
1082 /* Cancel any special action */
1083 set_action(creature_ptr, ACTION_NONE);
1085 /* Go into the global map */
1086 creature_ptr->wild_mode = TRUE;
1087 creature_ptr->leaving = TRUE;