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 "info-reader/fixed-map-parser.h"
15 #include "dungeon/dungeon.h"
16 #include "dungeon/quest.h"
17 #include "floor/floor-town.h"
18 #include "game-option/map-screen-options.h"
19 #include "grid/feature.h"
20 #include "grid/grid.h"
21 #include "info-reader/parse-error-types.h"
22 #include "io/files-util.h"
23 #include "io/tokenizer.h"
24 #include "main/init.h"
25 #include "monster-floor/monster-generator.h"
26 #include "monster-floor/monster-remover.h"
27 #include "monster-floor/monster-summon.h"
28 #include "monster/monster-status.h"
29 #include "monster/monster-util.h"
30 #include "monster/monster-info.h"
31 #include "monster-floor/place-monster-types.h"
32 #include "player/player-effects.h"
33 #include "player/player-status.h"
34 #include "realm/realm-names-table.h"
35 #include "spell-realm/spells-hex.h"
36 #include "system/system-variables.h"
37 #include "view/display-main-window.h"
38 #include "world/world.h"
40 #define MAX_FEAT_IN_TERRAIN 18
45 wilderness_type **wilderness;
47 bool generate_encounter;
50 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
51 * @param feat_type 非一様確率を再現するための要素数100の配列
52 * @param prob 元の確率テーブル
55 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
57 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
59 lim[0] = prob[0].percent;
60 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
61 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
63 for (i = 0; i < 100; i++)
65 while (i == lim[cur]) cur++;
66 feat_type[i] = prob[cur].feat;
72 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
73 * / Fill the arrays of floors and walls in the good proportions
77 void set_floor_and_wall(DUNGEON_IDX type)
79 DUNGEON_IDX cur_type = 255;
83 if (cur_type == type) return;
86 d_ptr = &d_info[type];
88 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
89 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
91 feat_wall_outer = d_ptr->outer_wall;
92 feat_wall_inner = d_ptr->inner_wall;
93 feat_wall_solid = d_ptr->outer_wall;
98 * @brief プラズマフラクタル的地形生成の再帰中間処理
99 * / Helper for plasma generation.
107 * @param depth_max 深みの最大値
110 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)
113 * Average the four corners & perturb it a bit.
114 * tmp is a random int +/- rough
116 FEAT_IDX tmp2 = rough*2 + 1;
117 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
119 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
121 /* Division always rounds down, so we round up again */
122 if (((x1 + x2 + x3 + x4) % 4) > 1)
126 if (avg < 0) avg = 0;
127 if (avg > depth_max) avg = depth_max;
129 /* Set the new value. */
130 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
135 * @brief プラズマフラクタル的地形生成の再帰末端処理
136 * / Helper for plasma generation.
137 * @param x1 中間末端部1の重み
138 * @param x2 中間末端部2の重み
139 * @param x3 中間末端部3の重み
140 * @param xmid 最終末端部座標X
141 * @param ymid 最終末端部座標Y
143 * @param depth_max 深みの最大値
146 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)
149 * Average the three corners & perturb it a bit.
150 * tmp is a random int +/- rough
152 FEAT_IDX tmp2 = rough * 2 + 1;
153 FEAT_IDX tmp = randint0(tmp2) - rough;
155 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
157 /* Division always rounds down, so we round up again */
158 if ((x1 + x2 + x3) % 3) avg++;
161 if (avg < 0) avg = 0;
162 if (avg > depth_max) avg = depth_max;
164 /* Set the new value. */
165 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
170 * @brief プラズマフラクタル的地形生成の開始処理
171 * / Helper for plasma generation.
172 * @param x1 処理範囲の左上X座標
173 * @param y1 処理範囲の左上Y座標
174 * @param x2 処理範囲の右下X座標
175 * @param y2 処理範囲の右下Y座標
176 * @param depth_max 深みの最大値
181 * A generic function to generate the plasma fractal.
182 * Note that it uses ``cave_feat'' as temporary storage.
183 * The values in ``cave_feat'' after this function
184 * are NOT actual features; They are raw heights which
185 * need to be converted to features.
188 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;
195 if (x1 + 1 == x2) return;
197 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,
198 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
200 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,
201 xmid, y1, rough, depth_max);
203 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,
204 x2, ymid, rough, depth_max);
206 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,
207 xmid, y2, rough, depth_max);
209 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,
210 x1, ymid, rough, depth_max);
213 /* Recurse the four quadrants */
214 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
215 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
216 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
217 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
222 * The default table in terrain level generation.
224 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
227 * @brief 荒野フロア生成のサブルーチン
228 * @param terrain 荒野地形ID
229 * @param seed 乱数の固定シード
231 * @param corner 広域マップの角部分としての生成ならばTRUE
234 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
236 /* The outer wall is easy */
237 if (terrain == TERRAIN_EDGE)
239 /* Create level background */
240 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
242 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
244 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
251 /* Hack -- Backup the RNG state */
252 u32b state_backup[4];
253 Rand_state_backup(state_backup);
255 /* Hack -- Induce consistant flavors */
256 Rand_state_set(seed);
258 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
261 /* Create level background */
262 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
264 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
266 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
272 * Initialize the four corners
273 * ToDo: calculate the medium height of the adjacent
274 * terrains for every corner.
276 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
277 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
278 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
279 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
281 /* Hack -- only four corners */
284 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
285 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
286 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
287 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];
288 Rand_state_restore(state_backup);
292 /* Hack -- preserve four corners */
293 s16b north_west = floor_ptr->grid_array[1][1].feat;
294 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
295 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
296 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
298 /* x1, y1, x2, y2, num_depths, roughness */
299 FEAT_IDX roughness = 1; /* The roughness of the level. */
300 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
302 /* Hack -- copyback four corners */
303 floor_ptr->grid_array[1][1].feat = north_west;
304 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
305 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
306 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
308 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
310 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
312 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
316 Rand_state_restore(state_backup);
321 * @brief 荒野フロア生成のメインルーチン /
322 * Load a town or generate a terrain level using "plasma" fractals.
323 * @param player_ptr プレーヤーへの参照ポインタ
326 * @param border 広域マップの辺部分としての生成ならばTRUE
327 * @param corner 広域マップの角部分としての生成ならばTRUE
331 * x and y are the coordinates of the area in the wilderness.
332 * Border and corner are optimization flags to speed up the
333 * generation of the fractal terrain.
334 * If border is set then only the border of the terrain should
335 * be generated (for initializing the border structure).
336 * If corner is set then only the corners of the area are needed.
339 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
341 /* Number of the town (if any) */
342 player_ptr->town_num = wilderness[y][x].town;
344 /* Set the base level */
345 floor_type *floor_ptr = player_ptr->current_floor_ptr;
346 floor_ptr->base_level = wilderness[y][x].level;
348 /* Set the dungeon level */
349 floor_ptr->dun_level = 0;
351 /* Set the monster generation level */
352 floor_ptr->monster_level = floor_ptr->base_level;
354 /* Set the object generation level */
355 floor_ptr->object_level = floor_ptr->base_level;
358 /* Create the town */
359 if (player_ptr->town_num)
361 /* Reset the buildings */
364 /* Initialize the town */
366 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
368 init_flags = INIT_CREATE_DUNGEON;
370 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
372 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
376 int terrain = wilderness[y][x].terrain;
377 u32b seed = wilderness[y][x].seed;
379 generate_wilderness_area(floor_ptr, terrain, seed, corner);
382 if (!corner && !wilderness[y][x].town)
385 * Place roads in the wilderness
386 * ToDo: make the road a bit more interresting
388 if (wilderness[y][x].road)
390 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
393 if (wilderness[y-1][x].road)
396 for (y1 = 1; y1 < MAX_HGT/2; y1++)
399 floor_ptr->grid_array[y1][x1].feat = feat_floor;
403 if (wilderness[y+1][x].road)
406 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
409 floor_ptr->grid_array[y1][x1].feat = feat_floor;
413 if (wilderness[y][x+1].road)
416 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
419 floor_ptr->grid_array[y1][x1].feat = feat_floor;
423 if (wilderness[y][x-1].road)
426 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);
443 if (!is_winner) return;
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);
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++)
496 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
500 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
502 for (int i = 1; i < MAX_WID - 1; i++)
504 border.south[i] = floor_ptr->grid_array[1][i].feat;
508 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
510 for (int i = 1; i < MAX_HGT - 1; i++)
512 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
516 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
518 for (int i = 1; i < MAX_HGT - 1; i++)
520 border.east[i] = floor_ptr->grid_array[i][1].feat;
523 /* North west corner */
524 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
525 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
527 /* North east corner */
528 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
529 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
531 /* South west corner */
532 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
533 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
535 /* South east corner */
536 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
537 border.south_east = floor_ptr->grid_array[1][1].feat;
539 /* Create terrain of the current area */
540 generate_area(creature_ptr, y, x, FALSE, FALSE);
542 /* Special boundary walls -- North */
543 for (int i = 0; i < MAX_WID; i++)
545 floor_ptr->grid_array[0][i].feat = feat_permanent;
546 floor_ptr->grid_array[0][i].mimic = border.north[i];
549 /* Special boundary walls -- South */
550 for (int i = 0; i < MAX_WID; i++)
552 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
553 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
556 /* Special boundary walls -- West */
557 for (int i = 0; i < MAX_HGT; i++)
559 floor_ptr->grid_array[i][0].feat = feat_permanent;
560 floor_ptr->grid_array[i][0].mimic = border.west[i];
563 /* Special boundary walls -- East */
564 for (int i = 0; i < MAX_HGT; i++)
566 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
567 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
570 floor_ptr->grid_array[0][0].mimic = border.north_west;
571 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
572 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
573 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
575 /* Light up or darken the area */
576 for (y = 0; y < floor_ptr->height; y++)
578 for (x = 0; x < floor_ptr->width; x++)
581 g_ptr = &floor_ptr->grid_array[y][x];
586 g_ptr->info |= CAVE_GLOW;
588 /* Hack -- Memorize lit grids if allowed */
589 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
593 /* Feature code (applying "mimic" field) */
595 f_ptr = &f_info[get_feat_mimic(g_ptr)];
597 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
598 !have_flag(f_ptr->flags, FF_ENTRANCE))
601 g_ptr->info &= ~(CAVE_GLOW);
603 /* Darken "boring" features */
604 if (!have_flag(f_ptr->flags, FF_REMEMBER))
606 /* Forget the grid */
607 g_ptr->info &= ~(CAVE_MARK);
613 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
615 g_ptr->info |= CAVE_GLOW;
617 /* Hack -- Memorize lit grids if allowed */
618 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
622 if (creature_ptr->teleport_town)
624 for (y = 0; y < floor_ptr->height; y++)
626 for (x = 0; x < floor_ptr->width; x++)
629 g_ptr = &floor_ptr->grid_array[y][x];
631 /* Seeing true feature code (ignore mimic) */
633 f_ptr = &f_info[g_ptr->feat];
635 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
637 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
642 delete_monster_idx(creature_ptr, g_ptr->m_idx);
645 creature_ptr->oldpy = y;
646 creature_ptr->oldpx = x;
650 creature_ptr->teleport_town = FALSE;
652 else if (creature_ptr->leaving_dungeon)
654 for (y = 0; y < floor_ptr->height; y++)
656 for (x = 0; x < floor_ptr->width; x++)
659 g_ptr = &floor_ptr->grid_array[y][x];
661 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
665 delete_monster_idx(creature_ptr, g_ptr->m_idx);
668 creature_ptr->oldpy = y;
669 creature_ptr->oldpx = x;
673 creature_ptr->teleport_town = FALSE;
676 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
677 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
679 /* Make some residents */
680 for (int i = 0; i < lim; i++)
684 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
685 mode |= PM_ALLOW_SLEEP;
687 /* Make a resident */
688 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
691 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
692 generate_encounter = FALSE;
694 /* Fill the arrays of floors and walls in the good proportions */
695 set_floor_and_wall(0);
697 /* Set rewarded quests to finished */
698 for (int i = 0; i < max_q_idx; i++)
700 if (quest[i].status == QUEST_STATUS_REWARDED)
701 quest[i].status = QUEST_STATUS_FINISHED;
705 static s16b conv_terrain2feat[MAX_WILDERNESS];
708 * @brief 広域マップの生成(簡易処理版) /
709 * Build the wilderness area. -DG-
712 void wilderness_gen_small(player_type *creature_ptr)
714 /* To prevent stupid things */
715 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
716 for (int i = 0; i < MAX_WID; i++)
718 for (int j = 0; j < MAX_HGT; j++)
720 floor_ptr->grid_array[j][i].feat = feat_permanent;
724 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
727 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
729 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
731 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
733 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
734 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
735 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
739 if (wilderness[j][i].road)
741 floor_ptr->grid_array[j][i].feat = feat_floor;
742 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
746 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
748 floor_ptr->grid_array[j][i].feat = feat_entrance;
749 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
750 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
754 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
755 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
759 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
760 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
762 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
763 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
765 /* Assume illegal panel */
766 panel_row_min = floor_ptr->height;
767 panel_col_min = floor_ptr->width;
769 creature_ptr->x = creature_ptr->wilderness_x;
770 creature_ptr->y = creature_ptr->wilderness_y;
771 creature_ptr->town_num = 0;
775 typedef struct wilderness_grid wilderness_grid;
777 struct wilderness_grid
779 int terrain; /* Terrain type */
780 TOWN_IDX town; /* Town number */
781 DEPTH level; /* Level of the wilderness */
782 byte road; /* Road */
783 char name[32]; /* Name of the town/wilderness */
787 static wilderness_grid w_letter[255];
790 * @brief w_info.txtのデータ解析 /
791 * Parse a sub-file of the "extra info"
792 * @param buf 読み取ったデータ行のバッファ
794 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
796 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
797 * @param y 広域マップの高さを返す参照ポインタ
798 * @param x 広域マップの幅を返す参照ポインタ
801 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
803 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
809 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
822 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
824 int index = zz[0][0];
827 w_letter[index].terrain = atoi(zz[1]);
829 w_letter[index].terrain = 0;
832 w_letter[index].level = (s16b)atoi(zz[2]);
834 w_letter[index].level = 0;
837 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
839 w_letter[index].town = 0;
842 w_letter[index].road = (byte)atoi(zz[4]);
844 w_letter[index].road = 0;
847 strcpy(w_letter[index].name, zz[5]);
849 w_letter[index].name[0] = 0;
854 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
860 /* Process "W:D:<layout> */
861 /* Layout of the wilderness */
867 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
870 wilderness[*y][*x].terrain = w_letter[id].terrain;
871 wilderness[*y][*x].level = w_letter[id].level;
872 wilderness[*y][*x].town = w_letter[id].town;
873 wilderness[*y][*x].road = w_letter[id].road;
874 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
881 /* Process "W:P:<x>:<y> - starting position in the wilderness */
884 bool is_corner = creature_ptr->wilderness_x == 0;
885 is_corner = creature_ptr->wilderness_y == 0;
886 if (!is_corner) break;
888 if (tokenize(buf + 4, 2, zz, 0) != 2)
890 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
893 creature_ptr->wilderness_y = atoi(zz[0]);
894 creature_ptr->wilderness_x = atoi(zz[1]);
896 if ((creature_ptr->wilderness_x < 1) ||
897 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
898 (creature_ptr->wilderness_y < 1) ||
899 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
901 return PARSE_ERROR_OUT_OF_BOUNDS;
908 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
911 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
913 if (!d_info[i].maxdepth) continue;
914 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
915 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
917 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
926 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
927 * Generate the random seeds for the wilderness
930 void seed_wilderness(void)
932 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
934 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
936 wilderness[y][x].seed = randint0(0x10000000);
937 wilderness[y][x].entrance = 0;
944 * Pointer to wilderness_type
946 typedef wilderness_type *wilderness_type_ptr;
949 * @brief ゲーム開始時の荒野初期化メインルーチン /
950 * Initialize wilderness array
953 errr init_wilderness(void)
955 /* Allocate the wilderness (two-dimension array) */
956 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
957 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
959 /* Init the other pointers */
960 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
962 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
965 generate_encounter = FALSE;
971 * @brief 荒野の地勢設定を初期化する /
972 * Initialize wilderness array
973 * @param terrain 初期化したい地勢ID
974 * @param feat_global 基本的な地形ID
975 * @param fmt 地勢内の地形数を参照するための独自フォーマット
978 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
980 /* Begin the varargs stuff */
984 /* Wilderness terrains on global map */
985 conv_terrain2feat[terrain] = feat_global;
987 /* Wilderness terrains on local map */
990 for (concptr p = fmt; *p; p++)
994 plog_fmt("Format error");
998 FEAT_IDX feat = (s16b)va_arg(vp, int);
999 int num = va_arg(vp, int);
1000 int lim = cur + num;
1002 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1004 terrain_table[terrain][cur] = feat;
1007 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1012 if (cur < MAX_FEAT_IN_TERRAIN)
1014 plog_fmt("Too few parameters");
1022 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1023 * Initialize arrays for wilderness terrains
1026 void init_wilderness_terrains(void)
1028 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1029 feat_permanent, MAX_FEAT_IN_TERRAIN);
1031 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1032 feat_floor, MAX_FEAT_IN_TERRAIN);
1034 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1035 feat_deep_water, 12,
1036 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1038 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1040 feat_shallow_water, 12,
1043 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1045 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1050 feat_shallow_water, 4,
1051 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1053 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1059 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1061 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1067 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1069 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1074 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1076 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1079 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1081 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1082 feat_shallow_lava, 14,
1084 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1086 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1088 feat_shallow_lava, 3,
1090 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1092 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1098 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1103 * @brief 荒野から広域マップへの切り替え処理 /
1104 * Initialize arrays for wilderness terrains
1105 * @param encount 襲撃時TRUE
1106 * @return 切り替えが行われた場合はTRUEを返す。
1108 bool change_wild_mode(player_type *creature_ptr, bool encount)
1110 generate_encounter = encount;
1112 /* It is in the middle of changing map */
1113 if (creature_ptr->leaving) return FALSE;
1115 if (lite_town || vanilla_town)
1117 msg_print(_("荒野なんてない。", "No global map."));
1121 if (creature_ptr->wild_mode)
1123 /* Save the location in the global map */
1124 creature_ptr->wilderness_x = creature_ptr->x;
1125 creature_ptr->wilderness_y = creature_ptr->y;
1127 /* Give first move to the player */
1128 creature_ptr->energy_need = 0;
1130 /* Go back to the ordinary map */
1131 creature_ptr->wild_mode = FALSE;
1132 creature_ptr->leaving = TRUE;
1136 bool have_pet = FALSE;
1137 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1139 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1141 if (!monster_is_valid(m_ptr)) continue;
1142 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1143 if (monster_csleep_remaining(m_ptr)) continue;
1144 if (m_ptr->cdis > MAX_SIGHT) continue;
1145 if (!is_hostile(m_ptr)) continue;
1146 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1147 "You cannot enter global map, since there is some monsters nearby!"));
1148 free_turn(creature_ptr);
1154 concptr msg = _("ペットを置いて広域マップに入りますか?",
1155 "Do you leave your pets behind? ");
1157 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL))
1159 free_turn(creature_ptr);
1164 take_turn(creature_ptr, 1000);
1166 /* Remember the position */
1167 creature_ptr->oldpx = creature_ptr->x;
1168 creature_ptr->oldpy = creature_ptr->y;
1170 /* Cancel hex spelling */
1171 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1173 /* Cancel any special action */
1174 set_action(creature_ptr, ACTION_NONE);
1176 /* Go into the global map */
1177 creature_ptr->wild_mode = TRUE;
1178 creature_ptr->leaving = TRUE;