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 "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 "main/init.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/player-effects.h"
35 #include "player/player-status.h"
36 #include "realm/realm-names-table.h"
37 #include "spell-realm/spells-hex.h"
38 #include "system/system-variables.h"
39 #include "util/bit-flags-calculator.h"
40 #include "view/display-main-window.h"
41 #include "view/display-messages.h"
42 #include "world/world.h"
44 #define MAX_FEAT_IN_TERRAIN 18
49 wilderness_type **wilderness;
51 bool generate_encounter;
54 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
55 * @param feat_type 非一様確率を再現するための要素数100の配列
56 * @param prob 元の確率テーブル
59 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
61 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
63 lim[0] = prob[0].percent;
64 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
65 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
67 for (i = 0; i < 100; i++)
69 while (i == lim[cur]) cur++;
70 feat_type[i] = prob[cur].feat;
76 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
77 * / Fill the arrays of floors and walls in the good proportions
81 void set_floor_and_wall(DUNGEON_IDX type)
83 DUNGEON_IDX cur_type = 255;
87 if (cur_type == type) return;
90 d_ptr = &d_info[type];
92 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
93 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
95 feat_wall_outer = d_ptr->outer_wall;
96 feat_wall_inner = d_ptr->inner_wall;
97 feat_wall_solid = d_ptr->outer_wall;
102 * @brief プラズマフラクタル的地形生成の再帰中間処理
103 * / Helper for plasma generation.
111 * @param depth_max 深みの最大値
114 static void perturb_point_mid(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)
117 * Average the four corners & perturb it a bit.
118 * tmp is a random int +/- rough
120 FEAT_IDX tmp2 = rough*2 + 1;
121 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
123 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
125 /* Division always rounds down, so we round up again */
126 if (((x1 + x2 + x3 + x4) % 4) > 1)
130 if (avg < 0) avg = 0;
131 if (avg > depth_max) avg = depth_max;
133 /* Set the new value. */
134 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
139 * @brief プラズマフラクタル的地形生成の再帰末端処理
140 * / Helper for plasma generation.
141 * @param x1 中間末端部1の重み
142 * @param x2 中間末端部2の重み
143 * @param x3 中間末端部3の重み
144 * @param xmid 最終末端部座標X
145 * @param ymid 最終末端部座標Y
147 * @param depth_max 深みの最大値
150 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)
153 * Average the three corners & perturb it a bit.
154 * tmp is a random int +/- rough
156 FEAT_IDX tmp2 = rough * 2 + 1;
157 FEAT_IDX tmp = randint0(tmp2) - rough;
159 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
161 /* Division always rounds down, so we round up again */
162 if ((x1 + x2 + x3) % 3) avg++;
165 if (avg < 0) avg = 0;
166 if (avg > depth_max) avg = depth_max;
168 /* Set the new value. */
169 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
174 * @brief プラズマフラクタル的地形生成の開始処理
175 * / Helper for plasma generation.
176 * @param x1 処理範囲の左上X座標
177 * @param y1 処理範囲の左上Y座標
178 * @param x2 処理範囲の右下X座標
179 * @param y2 処理範囲の右下Y座標
180 * @param depth_max 深みの最大値
185 * A generic function to generate the plasma fractal.
186 * Note that it uses ``cave_feat'' as temporary storage.
187 * The values in ``cave_feat'' after this function
188 * are NOT actual features; They are raw heights which
189 * need to be converted to features.
192 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
195 POSITION xmid = (x2 - x1) / 2 + x1;
196 POSITION ymid = (y2 - y1) / 2 + y1;
199 if (x1 + 1 == x2) return;
201 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,
202 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
204 perturb_point_end(floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[ymid][xmid].feat,
205 xmid, y1, rough, depth_max);
207 perturb_point_end(floor_ptr, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[ymid][xmid].feat,
208 x2, ymid, rough, depth_max);
210 perturb_point_end(floor_ptr, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[ymid][xmid].feat,
211 xmid, y2, rough, depth_max);
213 perturb_point_end(floor_ptr, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[ymid][xmid].feat,
214 x1, ymid, rough, depth_max);
217 /* Recurse the four quadrants */
218 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
219 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
220 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
221 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
226 * The default table in terrain level generation.
228 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
231 * @brief 荒野フロア生成のサブルーチン
232 * @param terrain 荒野地形ID
233 * @param seed 乱数の固定シード
235 * @param corner 広域マップの角部分としての生成ならばTRUE
238 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
240 /* The outer wall is easy */
241 if (terrain == TERRAIN_EDGE)
243 /* Create level background */
244 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
246 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
248 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
255 /* Hack -- Backup the RNG state */
256 u32b state_backup[4];
257 Rand_state_backup(state_backup);
259 /* Hack -- Induce consistant flavors */
260 Rand_state_set(seed);
262 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
265 /* Create level background */
266 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
268 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
270 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
276 * Initialize the four corners
277 * ToDo: calculate the medium height of the adjacent
278 * terrains for every corner.
280 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
281 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
282 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
283 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
285 /* Hack -- only four corners */
288 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
289 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
290 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
291 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];
292 Rand_state_restore(state_backup);
296 /* Hack -- preserve four corners */
297 s16b north_west = floor_ptr->grid_array[1][1].feat;
298 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
299 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
300 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
302 /* x1, y1, x2, y2, num_depths, roughness */
303 FEAT_IDX roughness = 1; /* The roughness of the level. */
304 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
306 /* Hack -- copyback four corners */
307 floor_ptr->grid_array[1][1].feat = north_west;
308 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
309 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
310 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
312 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
314 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
316 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
320 Rand_state_restore(state_backup);
325 * @brief 荒野フロア生成のメインルーチン /
326 * Load a town or generate a terrain level using "plasma" fractals.
327 * @param player_ptr プレーヤーへの参照ポインタ
330 * @param border 広域マップの辺部分としての生成ならばTRUE
331 * @param corner 広域マップの角部分としての生成ならばTRUE
335 * x and y are the coordinates of the area in the wilderness.
336 * Border and corner are optimization flags to speed up the
337 * generation of the fractal terrain.
338 * If border is set then only the border of the terrain should
339 * be generated (for initializing the border structure).
340 * If corner is set then only the corners of the area are needed.
343 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
345 /* Number of the town (if any) */
346 player_ptr->town_num = wilderness[y][x].town;
348 /* Set the base level */
349 floor_type *floor_ptr = player_ptr->current_floor_ptr;
350 floor_ptr->base_level = wilderness[y][x].level;
352 /* Set the dungeon level */
353 floor_ptr->dun_level = 0;
355 /* Set the monster generation level */
356 floor_ptr->monster_level = floor_ptr->base_level;
358 /* Set the object generation level */
359 floor_ptr->object_level = floor_ptr->base_level;
362 /* Create the town */
363 if (player_ptr->town_num)
365 /* Reset the buildings */
368 /* Initialize the town */
370 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
372 init_flags = INIT_CREATE_DUNGEON;
374 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
376 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
380 int terrain = wilderness[y][x].terrain;
381 u32b seed = wilderness[y][x].seed;
383 generate_wilderness_area(floor_ptr, terrain, seed, corner);
386 if (!corner && !wilderness[y][x].town)
389 * Place roads in the wilderness
390 * ToDo: make the road a bit more interresting
392 if (wilderness[y][x].road)
394 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
397 if (wilderness[y-1][x].road)
400 for (y1 = 1; y1 < MAX_HGT/2; y1++)
403 floor_ptr->grid_array[y1][x1].feat = feat_floor;
407 if (wilderness[y+1][x].road)
410 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
413 floor_ptr->grid_array[y1][x1].feat = feat_floor;
417 if (wilderness[y][x+1].road)
420 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
423 floor_ptr->grid_array[y1][x1].feat = feat_floor;
427 if (wilderness[y][x-1].road)
430 for (x1 = 1; x1 < MAX_WID/2; x1++)
433 floor_ptr->grid_array[y1][x1].feat = feat_floor;
440 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
441 * 問題なければ'> 0'へ置き換えること
443 bool is_winner = wilderness[y][x].entrance != 0;
444 is_winner &= !wilderness[y][x].town != 0;
445 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
446 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
447 if (!is_winner) return;
449 /* Hack -- Backup the RNG state */
450 u32b state_backup[4];
451 Rand_state_backup(state_backup);
453 /* Hack -- Induce consistant flavors */
454 Rand_state_set(wilderness[y][x].seed);
456 int dy = rand_range(6, floor_ptr->height - 6);
457 int dx = rand_range(6, floor_ptr->width - 6);
459 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
460 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
462 /* Hack -- Restore the RNG state */
463 Rand_state_restore(state_backup);
468 * Border of the wilderness area
470 static border_type border;
474 * Build the wilderness area outside of the town.
475 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
476 * @param creature_ptr プレーヤーへの参照ポインタ
479 void wilderness_gen(player_type *creature_ptr)
482 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
483 floor_ptr->height = MAX_HGT;
484 floor_ptr->width = MAX_WID;
486 /* Assume illegal panel */
487 panel_row_min = floor_ptr->height;
488 panel_col_min = floor_ptr->width;
490 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
491 POSITION x = creature_ptr->wilderness_x;
492 POSITION y = creature_ptr->wilderness_y;
493 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
496 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
498 for (int i = 1; i < MAX_WID - 1; i++)
500 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
504 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
506 for (int i = 1; i < MAX_WID - 1; i++)
508 border.south[i] = floor_ptr->grid_array[1][i].feat;
512 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
514 for (int i = 1; i < MAX_HGT - 1; i++)
516 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
520 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
522 for (int i = 1; i < MAX_HGT - 1; i++)
524 border.east[i] = floor_ptr->grid_array[i][1].feat;
527 /* North west corner */
528 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
529 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
531 /* North east corner */
532 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
533 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
535 /* South west corner */
536 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
537 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
539 /* South east corner */
540 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
541 border.south_east = floor_ptr->grid_array[1][1].feat;
543 /* Create terrain of the current area */
544 generate_area(creature_ptr, y, x, FALSE, FALSE);
546 /* Special boundary walls -- North */
547 for (int i = 0; i < MAX_WID; i++)
549 floor_ptr->grid_array[0][i].feat = feat_permanent;
550 floor_ptr->grid_array[0][i].mimic = border.north[i];
553 /* Special boundary walls -- South */
554 for (int i = 0; i < MAX_WID; i++)
556 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
557 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
560 /* Special boundary walls -- West */
561 for (int i = 0; i < MAX_HGT; i++)
563 floor_ptr->grid_array[i][0].feat = feat_permanent;
564 floor_ptr->grid_array[i][0].mimic = border.west[i];
567 /* Special boundary walls -- East */
568 for (int i = 0; i < MAX_HGT; i++)
570 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
571 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
574 floor_ptr->grid_array[0][0].mimic = border.north_west;
575 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
576 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
577 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
579 /* Light up or darken the area */
580 for (y = 0; y < floor_ptr->height; y++)
582 for (x = 0; x < floor_ptr->width; x++)
585 g_ptr = &floor_ptr->grid_array[y][x];
590 g_ptr->info |= CAVE_GLOW;
592 /* Hack -- Memorize lit grids if allowed */
593 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
597 /* Feature code (applying "mimic" field) */
599 f_ptr = &f_info[get_feat_mimic(g_ptr)];
601 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
602 !have_flag(f_ptr->flags, FF_ENTRANCE))
605 g_ptr->info &= ~(CAVE_GLOW);
607 /* Darken "boring" features */
608 if (!have_flag(f_ptr->flags, FF_REMEMBER))
610 /* Forget the grid */
611 g_ptr->info &= ~(CAVE_MARK);
617 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
619 g_ptr->info |= CAVE_GLOW;
621 /* Hack -- Memorize lit grids if allowed */
622 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
626 if (creature_ptr->teleport_town)
628 for (y = 0; y < floor_ptr->height; y++)
630 for (x = 0; x < floor_ptr->width; x++)
633 g_ptr = &floor_ptr->grid_array[y][x];
635 /* Seeing true feature code (ignore mimic) */
637 f_ptr = &f_info[g_ptr->feat];
639 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
641 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
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;
656 else if (creature_ptr->leaving_dungeon)
658 for (y = 0; y < floor_ptr->height; y++)
660 for (x = 0; x < floor_ptr->width; x++)
663 g_ptr = &floor_ptr->grid_array[y][x];
665 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
669 delete_monster_idx(creature_ptr, g_ptr->m_idx);
672 creature_ptr->oldpy = y;
673 creature_ptr->oldpx = x;
677 creature_ptr->teleport_town = FALSE;
680 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
681 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
683 /* Make some residents */
684 for (int i = 0; i < lim; i++)
688 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
689 mode |= PM_ALLOW_SLEEP;
691 /* Make a resident */
692 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
695 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
696 generate_encounter = FALSE;
698 /* Fill the arrays of floors and walls in the good proportions */
699 set_floor_and_wall(0);
701 /* Set rewarded quests to finished */
702 for (int i = 0; i < max_q_idx; i++)
704 if (quest[i].status == QUEST_STATUS_REWARDED)
705 quest[i].status = QUEST_STATUS_FINISHED;
709 static s16b conv_terrain2feat[MAX_WILDERNESS];
712 * @brief 広域マップの生成(簡易処理版) /
713 * Build the wilderness area. -DG-
716 void wilderness_gen_small(player_type *creature_ptr)
718 /* To prevent stupid things */
719 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
720 for (int i = 0; i < MAX_WID; i++)
722 for (int j = 0; j < MAX_HGT; j++)
724 floor_ptr->grid_array[j][i].feat = feat_permanent;
728 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
731 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
733 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
735 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
737 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
738 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
739 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
743 if (wilderness[j][i].road)
745 floor_ptr->grid_array[j][i].feat = feat_floor;
746 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
750 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
752 floor_ptr->grid_array[j][i].feat = feat_entrance;
753 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
754 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
758 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
759 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
763 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
764 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
766 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
767 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
769 /* Assume illegal panel */
770 panel_row_min = floor_ptr->height;
771 panel_col_min = floor_ptr->width;
773 creature_ptr->x = creature_ptr->wilderness_x;
774 creature_ptr->y = creature_ptr->wilderness_y;
775 creature_ptr->town_num = 0;
779 typedef struct wilderness_grid wilderness_grid;
781 struct wilderness_grid
783 int terrain; /* Terrain type */
784 TOWN_IDX town; /* Town number */
785 DEPTH level; /* Level of the wilderness */
786 byte road; /* Road */
787 char name[32]; /* Name of the town/wilderness */
791 static wilderness_grid w_letter[255];
794 * @brief w_info.txtのデータ解析 /
795 * Parse a sub-file of the "extra info"
796 * @param buf 読み取ったデータ行のバッファ
798 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
800 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
801 * @param y 広域マップの高さを返す参照ポインタ
802 * @param x 広域マップの幅を返す参照ポインタ
805 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
807 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
813 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
826 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
828 int index = zz[0][0];
831 w_letter[index].terrain = atoi(zz[1]);
833 w_letter[index].terrain = 0;
836 w_letter[index].level = (s16b)atoi(zz[2]);
838 w_letter[index].level = 0;
841 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
843 w_letter[index].town = 0;
846 w_letter[index].road = (byte)atoi(zz[4]);
848 w_letter[index].road = 0;
851 strcpy(w_letter[index].name, zz[5]);
853 w_letter[index].name[0] = 0;
858 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
864 /* Process "W:D:<layout> */
865 /* Layout of the wilderness */
871 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
874 wilderness[*y][*x].terrain = w_letter[id].terrain;
875 wilderness[*y][*x].level = w_letter[id].level;
876 wilderness[*y][*x].town = w_letter[id].town;
877 wilderness[*y][*x].road = w_letter[id].road;
878 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
885 /* Process "W:P:<x>:<y> - starting position in the wilderness */
888 bool is_corner = creature_ptr->wilderness_x == 0;
889 is_corner = creature_ptr->wilderness_y == 0;
890 if (!is_corner) break;
892 if (tokenize(buf + 4, 2, zz, 0) != 2)
894 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
897 creature_ptr->wilderness_y = atoi(zz[0]);
898 creature_ptr->wilderness_x = atoi(zz[1]);
900 if ((creature_ptr->wilderness_x < 1) ||
901 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
902 (creature_ptr->wilderness_y < 1) ||
903 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
905 return PARSE_ERROR_OUT_OF_BOUNDS;
912 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
915 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
917 if (!d_info[i].maxdepth) continue;
918 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
919 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
921 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
930 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
931 * Generate the random seeds for the wilderness
934 void seed_wilderness(void)
936 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
938 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
940 wilderness[y][x].seed = randint0(0x10000000);
941 wilderness[y][x].entrance = 0;
948 * Pointer to wilderness_type
950 typedef wilderness_type *wilderness_type_ptr;
953 * @brief ゲーム開始時の荒野初期化メインルーチン /
954 * Initialize wilderness array
957 errr init_wilderness(void)
959 /* Allocate the wilderness (two-dimension array) */
960 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
961 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
963 /* Init the other pointers */
964 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
966 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
969 generate_encounter = FALSE;
975 * @brief 荒野の地勢設定を初期化する /
976 * Initialize wilderness array
977 * @param terrain 初期化したい地勢ID
978 * @param feat_global 基本的な地形ID
979 * @param fmt 地勢内の地形数を参照するための独自フォーマット
982 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
984 /* Begin the varargs stuff */
988 /* Wilderness terrains on global map */
989 conv_terrain2feat[terrain] = feat_global;
991 /* Wilderness terrains on local map */
994 for (concptr p = fmt; *p; p++)
998 plog_fmt("Format error");
1002 FEAT_IDX feat = (s16b)va_arg(vp, int);
1003 int num = va_arg(vp, int);
1004 int lim = cur + num;
1006 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1008 terrain_table[terrain][cur] = feat;
1011 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1016 if (cur < MAX_FEAT_IN_TERRAIN)
1018 plog_fmt("Too few parameters");
1026 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1027 * Initialize arrays for wilderness terrains
1030 void init_wilderness_terrains(void)
1032 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1033 feat_permanent, MAX_FEAT_IN_TERRAIN);
1035 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1036 feat_floor, MAX_FEAT_IN_TERRAIN);
1038 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1039 feat_deep_water, 12,
1040 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1042 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1044 feat_shallow_water, 12,
1047 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1049 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1054 feat_shallow_water, 4,
1055 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1057 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1063 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1065 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1071 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1073 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1078 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1080 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1083 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1085 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1086 feat_shallow_lava, 14,
1088 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1090 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1092 feat_shallow_lava, 3,
1094 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1096 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1102 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1107 * @brief 荒野から広域マップへの切り替え処理 /
1108 * Initialize arrays for wilderness terrains
1109 * @param encount 襲撃時TRUE
1110 * @return 切り替えが行われた場合はTRUEを返す。
1112 bool change_wild_mode(player_type *creature_ptr, bool encount)
1114 generate_encounter = encount;
1116 /* It is in the middle of changing map */
1117 if (creature_ptr->leaving) return FALSE;
1119 if (lite_town || vanilla_town)
1121 msg_print(_("荒野なんてない。", "No global map."));
1125 if (creature_ptr->wild_mode)
1127 /* Save the location in the global map */
1128 creature_ptr->wilderness_x = creature_ptr->x;
1129 creature_ptr->wilderness_y = creature_ptr->y;
1131 /* Give first move to the player */
1132 creature_ptr->energy_need = 0;
1134 /* Go back to the ordinary map */
1135 creature_ptr->wild_mode = FALSE;
1136 creature_ptr->leaving = TRUE;
1140 bool have_pet = FALSE;
1141 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1143 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1145 if (!monster_is_valid(m_ptr)) continue;
1146 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1147 if (monster_csleep_remaining(m_ptr)) continue;
1148 if (m_ptr->cdis > MAX_SIGHT) continue;
1149 if (!is_hostile(m_ptr)) continue;
1150 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1151 "You cannot enter global map, since there is some monsters nearby!"));
1152 free_turn(creature_ptr);
1158 concptr msg = _("ペットを置いて広域マップに入りますか?",
1159 "Do you leave your pets behind? ");
1161 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL))
1163 free_turn(creature_ptr);
1168 take_turn(creature_ptr, 1000);
1170 /* Remember the position */
1171 creature_ptr->oldpx = creature_ptr->x;
1172 creature_ptr->oldpy = creature_ptr->y;
1174 /* Cancel hex spelling */
1175 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1177 /* Cancel any special action */
1178 set_action(creature_ptr, ACTION_NONE);
1180 /* Go into the global map */
1181 creature_ptr->wild_mode = TRUE;
1182 creature_ptr->leaving = TRUE;