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-flag-types.h"
16 #include "dungeon/dungeon.h"
17 #include "dungeon/quest.h"
18 #include "floor/cave.h"
19 #include "floor/floor-town.h"
20 #include "game-option/birth-options.h"
21 #include "game-option/map-screen-options.h"
22 #include "grid/feature.h"
23 #include "grid/grid.h"
24 #include "info-reader/fixed-map-parser.h"
25 #include "info-reader/parse-error-types.h"
26 #include "io/files-util.h"
27 #include "io/tokenizer.h"
28 #include "main/init.h"
29 #include "monster-floor/monster-generator.h"
30 #include "monster-floor/monster-remover.h"
31 #include "monster-floor/monster-summon.h"
32 #include "monster-floor/place-monster-types.h"
33 #include "monster/monster-info.h"
34 #include "monster/monster-status.h"
35 #include "monster/monster-util.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/system-variables.h"
43 #include "util/bit-flags-calculator.h"
44 #include "view/display-messages.h"
45 #include "window/main-window-util.h"
46 #include "world/world.h"
48 #define MAX_FEAT_IN_TERRAIN 18
53 wilderness_type **wilderness;
55 bool generate_encounter;
57 typedef struct border_type {
69 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
70 * @param feat_type 非一様確率を再現するための要素数100の配列
71 * @param prob 元の確率テーブル
74 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
76 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
78 lim[0] = prob[0].percent;
79 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++)
80 lim[i] = lim[i - 1] + prob[i].percent;
81 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100)
82 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
84 for (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
97 void set_floor_and_wall(DUNGEON_IDX type)
99 DUNGEON_IDX cur_type = 255;
103 if (cur_type == type)
107 d_ptr = &d_info[type];
109 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
110 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
112 feat_wall_outer = d_ptr->outer_wall;
113 feat_wall_inner = d_ptr->inner_wall;
114 feat_wall_solid = d_ptr->outer_wall;
118 * @brief プラズマフラクタル的地形生成の再帰中間処理
119 * / Helper for plasma generation.
127 * @param depth_max 深みの最大値
130 static void perturb_point_mid(
131 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)
134 * Average the four corners & perturb it a bit.
135 * tmp is a random int +/- rough
137 FEAT_IDX tmp2 = rough * 2 + 1;
138 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
140 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
142 /* Division always rounds down, so we round up again */
143 if (((x1 + x2 + x3 + x4) % 4) > 1)
152 /* Set the new value. */
153 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
157 * @brief プラズマフラクタル的地形生成の再帰末端処理
158 * / Helper for plasma generation.
159 * @param x1 中間末端部1の重み
160 * @param x2 中間末端部2の重み
161 * @param x3 中間末端部3の重み
162 * @param xmid 最終末端部座標X
163 * @param ymid 最終末端部座標Y
165 * @param depth_max 深みの最大値
168 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)
171 * Average the three corners & perturb it a bit.
172 * tmp is a random int +/- rough
174 FEAT_IDX tmp2 = rough * 2 + 1;
175 FEAT_IDX tmp = randint0(tmp2) - rough;
177 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
179 /* Division always rounds down, so we round up again */
180 if ((x1 + x2 + x3) % 3)
189 /* Set the new value. */
190 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
194 * @brief プラズマフラクタル的地形生成の開始処理
195 * / Helper for plasma generation.
196 * @param x1 処理範囲の左上X座標
197 * @param y1 処理範囲の左上Y座標
198 * @param x2 処理範囲の右下X座標
199 * @param y2 処理範囲の右下Y座標
200 * @param depth_max 深みの最大値
205 * A generic function to generate the plasma fractal.
206 * Note that it uses ``cave_feat'' as temporary storage.
207 * The values in ``cave_feat'' after this function
208 * are NOT actual features; They are raw heights which
209 * need to be converted to features.
212 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
215 POSITION xmid = (x2 - x1) / 2 + x1;
216 POSITION ymid = (y2 - y1) / 2 + y1;
222 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,
223 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);
229 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);
232 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);
235 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);
237 /* Recurse the four quadrants */
238 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
239 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
240 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
241 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
245 * The default table in terrain level generation.
247 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
250 * @brief 荒野フロア生成のサブルーチン
251 * @param terrain 荒野地形ID
252 * @param seed 乱数の固定シード
254 * @param corner 広域マップの角部分としての生成ならばTRUE
257 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
259 /* The outer wall is easy */
260 if (terrain == TERRAIN_EDGE) {
261 /* Create level background */
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 = feat_permanent;
271 /* Hack -- Backup the RNG state */
272 u32b state_backup[4];
273 Rand_state_backup(state_backup);
275 /* Hack -- Induce consistant flavors */
276 Rand_state_set(seed);
278 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
280 /* Create level background */
281 for (POSITION y1 = 0; y1 < MAX_HGT; y1++) {
282 for (POSITION x1 = 0; x1 < MAX_WID; x1++) {
283 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
289 * Initialize the four corners
290 * ToDo: calculate the medium height of the adjacent
291 * terrains for every corner.
293 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
294 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (s16b)randint0(table_size);
295 floor_ptr->grid_array[1][MAX_WID - 2].feat = (s16b)randint0(table_size);
296 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (s16b)randint0(table_size);
298 /* Hack -- only four corners */
300 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
301 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
302 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
303 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];
304 Rand_state_restore(state_backup);
308 /* Hack -- preserve four corners */
309 s16b north_west = floor_ptr->grid_array[1][1].feat;
310 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
311 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
312 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
314 /* x1, y1, x2, y2, num_depths, roughness */
315 FEAT_IDX roughness = 1; /* The roughness of the level. */
316 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
318 /* Hack -- copyback four corners */
319 floor_ptr->grid_array[1][1].feat = north_west;
320 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
321 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
322 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
324 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++) {
325 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++) {
326 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
330 Rand_state_restore(state_backup);
334 * @brief 荒野フロア生成のメインルーチン /
335 * Load a town or generate a terrain level using "plasma" fractals.
336 * @param player_ptr プレーヤーへの参照ポインタ
339 * @param border 広域マップの辺部分としての生成ならばTRUE
340 * @param corner 広域マップの角部分としての生成ならばTRUE
344 * x and y are the coordinates of the area in the wilderness.
345 * Border and corner are optimization flags to speed up the
346 * generation of the fractal terrain.
347 * If border is set then only the border of the terrain should
348 * be generated (for initializing the border structure).
349 * If corner is set then only the corners of the area are needed.
352 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
354 /* Number of the town (if any) */
355 player_ptr->town_num = wilderness[y][x].town;
357 /* Set the base level */
358 floor_type *floor_ptr = player_ptr->current_floor_ptr;
359 floor_ptr->base_level = wilderness[y][x].level;
361 /* Set the dungeon level */
362 floor_ptr->dun_level = 0;
364 /* Set the monster generation level */
365 floor_ptr->monster_level = floor_ptr->base_level;
367 /* Set the object generation level */
368 floor_ptr->object_level = floor_ptr->base_level;
370 /* Create the town */
371 if (player_ptr->town_num) {
372 /* Reset the buildings */
375 /* Initialize the town */
377 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
379 init_flags = INIT_CREATE_DUNGEON;
381 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
383 if (!corner && !border)
384 player_ptr->visit |= (1L << (player_ptr->town_num - 1));
386 int terrain = wilderness[y][x].terrain;
387 u32b seed = wilderness[y][x].seed;
389 generate_wilderness_area(floor_ptr, terrain, seed, corner);
392 if (!corner && !wilderness[y][x].town) {
394 * Place roads in the wilderness
395 * ToDo: make the road a bit more interresting
397 if (wilderness[y][x].road) {
398 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
401 if (wilderness[y - 1][x].road) {
403 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
405 floor_ptr->grid_array[y1][x1].feat = feat_floor;
409 if (wilderness[y + 1][x].road) {
411 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) {
419 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
421 floor_ptr->grid_array[y1][x1].feat = feat_floor;
425 if (wilderness[y][x - 1].road) {
427 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
429 floor_ptr->grid_array[y1][x1].feat = feat_floor;
436 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
437 * 問題なければ'> 0'へ置き換えること
439 bool is_winner = wilderness[y][x].entrance != 0;
440 is_winner &= !wilderness[y][x].town != 0;
441 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
442 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
446 /* Hack -- Backup the RNG state */
447 u32b state_backup[4];
448 Rand_state_backup(state_backup);
450 /* Hack -- Induce consistant flavors */
451 Rand_state_set(wilderness[y][x].seed);
453 int dy = rand_range(6, floor_ptr->height - 6);
454 int dx = rand_range(6, floor_ptr->width - 6);
456 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
457 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
459 /* Hack -- Restore the RNG state */
460 Rand_state_restore(state_backup);
464 * Border of the wilderness area
466 static border_type border;
470 * Build the wilderness area outside of the town.
471 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
472 * @param creature_ptr プレーヤーへの参照ポインタ
475 void wilderness_gen(player_type *creature_ptr)
478 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
479 floor_ptr->height = MAX_HGT;
480 floor_ptr->width = MAX_WID;
482 /* Assume illegal panel */
483 panel_row_min = floor_ptr->height;
484 panel_col_min = floor_ptr->width;
486 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
487 POSITION x = creature_ptr->wilderness_x;
488 POSITION y = creature_ptr->wilderness_y;
489 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
492 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
494 for (int i = 1; i < MAX_WID - 1; i++) {
495 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
499 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
501 for (int i = 1; i < MAX_WID - 1; i++) {
502 border.south[i] = floor_ptr->grid_array[1][i].feat;
506 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
508 for (int i = 1; i < MAX_HGT - 1; i++) {
509 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
513 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
515 for (int i = 1; i < MAX_HGT - 1; i++) {
516 border.east[i] = floor_ptr->grid_array[i][1].feat;
519 /* North west corner */
520 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
521 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
523 /* North east corner */
524 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
525 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
527 /* South west corner */
528 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
529 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
531 /* South east corner */
532 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
533 border.south_east = floor_ptr->grid_array[1][1].feat;
535 /* Create terrain of the current area */
536 generate_area(creature_ptr, y, x, FALSE, FALSE);
538 /* Special boundary walls -- North */
539 for (int i = 0; i < MAX_WID; i++) {
540 floor_ptr->grid_array[0][i].feat = feat_permanent;
541 floor_ptr->grid_array[0][i].mimic = border.north[i];
544 /* Special boundary walls -- South */
545 for (int i = 0; i < MAX_WID; i++) {
546 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
547 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
550 /* Special boundary walls -- West */
551 for (int i = 0; i < MAX_HGT; i++) {
552 floor_ptr->grid_array[i][0].feat = feat_permanent;
553 floor_ptr->grid_array[i][0].mimic = border.west[i];
556 /* Special boundary walls -- East */
557 for (int i = 0; i < MAX_HGT; i++) {
558 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
559 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
562 floor_ptr->grid_array[0][0].mimic = border.north_west;
563 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
564 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
565 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
567 /* Light up or darken the area */
568 for (y = 0; y < floor_ptr->height; y++) {
569 for (x = 0; x < floor_ptr->width; x++) {
571 g_ptr = &floor_ptr->grid_array[y][x];
575 g_ptr->info |= CAVE_GLOW;
577 /* Hack -- Memorize lit grids if allowed */
578 if (view_perma_grids)
579 g_ptr->info |= CAVE_MARK;
583 /* Feature code (applying "mimic" field) */
585 f_ptr = &f_info[get_feat_mimic(g_ptr)];
587 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) && !have_flag(f_ptr->flags, FF_ENTRANCE)) {
589 g_ptr->info &= ~(CAVE_GLOW);
591 /* Darken "boring" features */
592 if (!have_flag(f_ptr->flags, FF_REMEMBER)) {
593 /* Forget the grid */
594 g_ptr->info &= ~(CAVE_MARK);
600 if (!have_flag(f_ptr->flags, FF_ENTRANCE))
603 g_ptr->info |= CAVE_GLOW;
605 /* Hack -- Memorize lit grids if allowed */
606 if (view_perma_grids)
607 g_ptr->info |= CAVE_MARK;
611 if (creature_ptr->teleport_town) {
612 for (y = 0; y < floor_ptr->height; y++) {
613 for (x = 0; x < floor_ptr->width; x++) {
615 g_ptr = &floor_ptr->grid_array[y][x];
617 /* Seeing true feature code (ignore mimic) */
619 f_ptr = &f_info[g_ptr->feat];
621 if (!have_flag(f_ptr->flags, FF_BLDG))
624 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
628 delete_monster_idx(creature_ptr, g_ptr->m_idx);
631 creature_ptr->oldpy = y;
632 creature_ptr->oldpx = x;
636 creature_ptr->teleport_town = FALSE;
637 } else if (creature_ptr->leaving_dungeon) {
638 for (y = 0; y < floor_ptr->height; y++) {
639 for (x = 0; x < floor_ptr->width; x++) {
641 g_ptr = &floor_ptr->grid_array[y][x];
643 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE))
647 delete_monster_idx(creature_ptr, g_ptr->m_idx);
650 creature_ptr->oldpy = y;
651 creature_ptr->oldpx = x;
655 creature_ptr->teleport_town = FALSE;
658 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
659 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
661 /* Make some residents */
662 for (int i = 0; i < lim; i++) {
665 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
666 mode |= PM_ALLOW_SLEEP;
668 /* Make a resident */
669 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
672 if (generate_encounter)
673 creature_ptr->ambush_flag = TRUE;
674 generate_encounter = FALSE;
676 /* Fill the arrays of floors and walls in the good proportions */
677 set_floor_and_wall(0);
679 /* Set rewarded quests to finished */
680 for (int i = 0; i < max_q_idx; i++) {
681 if (quest[i].status == QUEST_STATUS_REWARDED)
682 quest[i].status = QUEST_STATUS_FINISHED;
686 static s16b conv_terrain2feat[MAX_WILDERNESS];
689 * @brief 広域マップの生成(簡易処理版) /
690 * Build the wilderness area. -DG-
693 void wilderness_gen_small(player_type *creature_ptr)
695 /* To prevent stupid things */
696 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
697 for (int i = 0; i < MAX_WID; i++) {
698 for (int j = 0; j < MAX_HGT; j++) {
699 floor_ptr->grid_array[j][i].feat = feat_permanent;
703 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
706 for (int i = 0; i < current_world_ptr->max_wild_x; i++) {
707 for (int j = 0; j < current_world_ptr->max_wild_y; j++) {
708 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN)) {
709 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
710 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
711 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
715 if (wilderness[j][i].road) {
716 floor_ptr->grid_array[j][i].feat = feat_floor;
717 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
721 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER))) {
722 floor_ptr->grid_array[j][i].feat = feat_entrance;
723 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
724 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
728 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
729 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
733 floor_ptr->height = (s16b)current_world_ptr->max_wild_y;
734 floor_ptr->width = (s16b)current_world_ptr->max_wild_x;
736 if (floor_ptr->height > MAX_HGT)
737 floor_ptr->height = MAX_HGT;
738 if (floor_ptr->width > MAX_WID)
739 floor_ptr->width = MAX_WID;
741 /* Assume illegal panel */
742 panel_row_min = floor_ptr->height;
743 panel_col_min = floor_ptr->width;
745 creature_ptr->x = creature_ptr->wilderness_x;
746 creature_ptr->y = creature_ptr->wilderness_y;
747 creature_ptr->town_num = 0;
750 typedef struct wilderness_grid wilderness_grid;
752 struct wilderness_grid {
753 int terrain; /* Terrain type */
754 TOWN_IDX town; /* Town number */
755 DEPTH level; /* Level of the wilderness */
756 byte road; /* Road */
757 char name[32]; /* Name of the town/wilderness */
760 static wilderness_grid w_letter[255];
763 * @brief w_info.txtのデータ解析 /
764 * Parse a sub-file of the "extra info"
765 * @param buf 読み取ったデータ行のバッファ
767 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
769 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
770 * @param y 広域マップの高さを返す参照ポインタ
771 * @param x 広域マップの幅を返す参照ポインタ
774 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
776 if (!(buf[0] == 'W'))
777 return (PARSE_ERROR_GENERIC);
782 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
795 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
796 int index = zz[0][0];
799 w_letter[index].terrain = atoi(zz[1]);
801 w_letter[index].terrain = 0;
804 w_letter[index].level = (s16b)atoi(zz[2]);
806 w_letter[index].level = 0;
809 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
811 w_letter[index].town = 0;
814 w_letter[index].road = (byte)atoi(zz[4]);
816 w_letter[index].road = 0;
819 strcpy(w_letter[index].name, zz[5]);
821 w_letter[index].name[0] = 0;
824 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
830 /* Process "W:D:<layout> */
831 /* Layout of the wilderness */
836 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
838 wilderness[*y][*x].terrain = w_letter[id].terrain;
839 wilderness[*y][*x].level = w_letter[id].level;
840 wilderness[*y][*x].town = w_letter[id].town;
841 wilderness[*y][*x].road = w_letter[id].road;
842 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
849 /* Process "W:P:<x>:<y> - starting position in the wilderness */
851 bool is_corner = creature_ptr->wilderness_x == 0;
852 is_corner = creature_ptr->wilderness_y == 0;
856 if (tokenize(buf + 4, 2, zz, 0) != 2) {
857 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
860 creature_ptr->wilderness_y = atoi(zz[0]);
861 creature_ptr->wilderness_x = atoi(zz[1]);
863 if ((creature_ptr->wilderness_x < 1) || (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) || (creature_ptr->wilderness_y < 1)
864 || (creature_ptr->wilderness_y > current_world_ptr->max_wild_y)) {
865 return PARSE_ERROR_OUT_OF_BOUNDS;
872 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
875 for (int i = 1; i < current_world_ptr->max_d_idx; i++) {
876 if (!d_info[i].maxdepth)
878 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
879 if (!wilderness[d_info[i].dy][d_info[i].dx].town) {
880 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
888 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
889 * Generate the random seeds for the wilderness
892 void seed_wilderness(void)
894 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++) {
895 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++) {
896 wilderness[y][x].seed = randint0(0x10000000);
897 wilderness[y][x].entrance = 0;
903 * Pointer to wilderness_type
905 typedef wilderness_type *wilderness_type_ptr;
908 * @brief ゲーム開始時の荒野初期化メインルーチン /
909 * Initialize wilderness array
912 errr init_wilderness(void)
914 /* Allocate the wilderness (two-dimension array) */
915 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
916 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
918 /* Init the other pointers */
919 for (int i = 1; i < current_world_ptr->max_wild_y; i++) {
920 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
923 generate_encounter = FALSE;
928 * @brief 荒野の地勢設定を初期化する /
929 * Initialize wilderness array
930 * @param terrain 初期化したい地勢ID
931 * @param feat_global 基本的な地形ID
932 * @param fmt 地勢内の地形数を参照するための独自フォーマット
935 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
937 /* Begin the varargs stuff */
941 /* Wilderness terrains on global map */
942 conv_terrain2feat[terrain] = feat_global;
944 /* Wilderness terrains on local map */
947 for (concptr p = fmt; *p; p++) {
949 plog_fmt("Format error");
953 FEAT_IDX feat = (s16b)va_arg(vp, int);
954 int num = va_arg(vp, int);
957 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++) {
958 terrain_table[terrain][cur] = feat;
961 if (cur >= MAX_FEAT_IN_TERRAIN)
967 if (cur < MAX_FEAT_IN_TERRAIN) {
968 plog_fmt("Too few parameters");
975 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
976 * Initialize arrays for wilderness terrains
979 void init_wilderness_terrains(void)
981 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
983 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
985 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
987 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,
988 MAX_FEAT_IN_TERRAIN - 17);
990 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,
991 MAX_FEAT_IN_TERRAIN - 11);
994 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);
997 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);
999 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);
1001 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1003 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);
1006 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);
1008 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,
1009 MAX_FEAT_IN_TERRAIN - 8);
1013 * @brief 荒野から広域マップへの切り替え処理 /
1014 * Initialize arrays for wilderness terrains
1015 * @param encount 襲撃時TRUE
1016 * @return 切り替えが行われた場合はTRUEを返す。
1018 bool change_wild_mode(player_type *creature_ptr, bool encount)
1020 generate_encounter = encount;
1022 /* It is in the middle of changing map */
1023 if (creature_ptr->leaving)
1026 if (lite_town || vanilla_town) {
1027 msg_print(_("荒野なんてない。", "No global map."));
1031 if (creature_ptr->wild_mode) {
1032 /* Save the location in the global map */
1033 creature_ptr->wilderness_x = creature_ptr->x;
1034 creature_ptr->wilderness_y = creature_ptr->y;
1036 /* Give first move to the player */
1037 creature_ptr->energy_need = 0;
1039 /* Go back to the ordinary map */
1040 creature_ptr->wild_mode = FALSE;
1041 creature_ptr->leaving = TRUE;
1045 bool have_pet = FALSE;
1046 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
1047 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1049 if (!monster_is_valid(m_ptr))
1051 if (is_pet(m_ptr) && i != creature_ptr->riding)
1053 if (monster_csleep_remaining(m_ptr))
1055 if (m_ptr->cdis > MAX_SIGHT)
1057 if (!is_hostile(m_ptr))
1059 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there is some monsters nearby!"));
1060 free_turn(creature_ptr);
1065 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
1067 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL)) {
1068 free_turn(creature_ptr);
1073 take_turn(creature_ptr, 1000);
1075 /* Remember the position */
1076 creature_ptr->oldpx = creature_ptr->x;
1077 creature_ptr->oldpy = creature_ptr->y;
1079 /* Cancel hex spelling */
1080 if (hex_spelling_any(creature_ptr))
1081 stop_hex_spell_all(creature_ptr);
1083 /* Cancel any special action */
1084 set_action(creature_ptr, ACTION_NONE);
1086 /* Go into the global map */
1087 creature_ptr->wild_mode = TRUE;
1088 creature_ptr->leaving = TRUE;