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 "dungeon/dungeon-file.h"
15 #include "dungeon/dungeon.h"
16 #include "dungeon/quest.h"
17 #include "floor/floor-town.h"
18 #include "grid/feature.h"
19 #include "grid/grid.h"
20 #include "io/files-util.h"
21 #include "io/tokenizer.h"
22 #include "monster/monster-status.h"
23 #include "monster/monster.h"
24 #include "player/player-effects.h"
25 #include "player/player-status.h"
26 #include "realm/realm-names-table.h"
27 #include "spell-realm/spells-hex.h"
28 #include "system/system-variables.h"
29 #include "util/util.h"
30 #include "view/display-main-window.h"
31 #include "world/world.h"
33 #define MAX_FEAT_IN_TERRAIN 18
38 wilderness_type **wilderness;
40 bool generate_encounter;
43 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
44 * @param feat_type 非一様確率を再現するための要素数100の配列
45 * @param prob 元の確率テーブル
48 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
50 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
52 lim[0] = prob[0].percent;
53 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
54 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
56 for (i = 0; i < 100; i++)
58 while (i == lim[cur]) cur++;
59 feat_type[i] = prob[cur].feat;
65 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
66 * / Fill the arrays of floors and walls in the good proportions
70 void set_floor_and_wall(DUNGEON_IDX type)
72 DUNGEON_IDX cur_type = 255;
76 if (cur_type == type) return;
79 d_ptr = &d_info[type];
81 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
82 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
84 feat_wall_outer = d_ptr->outer_wall;
85 feat_wall_inner = d_ptr->inner_wall;
86 feat_wall_solid = d_ptr->outer_wall;
91 * @brief プラズマフラクタル的地形生成の再帰中間処理
92 * / Helper for plasma generation.
100 * @param depth_max 深みの最大値
103 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)
106 * Average the four corners & perturb it a bit.
107 * tmp is a random int +/- rough
109 FEAT_IDX tmp2 = rough*2 + 1;
110 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
112 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
114 /* Division always rounds down, so we round up again */
115 if (((x1 + x2 + x3 + x4) % 4) > 1)
119 if (avg < 0) avg = 0;
120 if (avg > depth_max) avg = depth_max;
122 /* Set the new value. */
123 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
128 * @brief プラズマフラクタル的地形生成の再帰末端処理
129 * / Helper for plasma generation.
130 * @param x1 中間末端部1の重み
131 * @param x2 中間末端部2の重み
132 * @param x3 中間末端部3の重み
133 * @param xmid 最終末端部座標X
134 * @param ymid 最終末端部座標Y
136 * @param depth_max 深みの最大値
139 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)
142 * Average the three corners & perturb it a bit.
143 * tmp is a random int +/- rough
145 FEAT_IDX tmp2 = rough * 2 + 1;
146 FEAT_IDX tmp = randint0(tmp2) - rough;
148 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
150 /* Division always rounds down, so we round up again */
151 if ((x1 + x2 + x3) % 3) avg++;
154 if (avg < 0) avg = 0;
155 if (avg > depth_max) avg = depth_max;
157 /* Set the new value. */
158 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
163 * @brief プラズマフラクタル的地形生成の開始処理
164 * / Helper for plasma generation.
165 * @param x1 処理範囲の左上X座標
166 * @param y1 処理範囲の左上Y座標
167 * @param x2 処理範囲の右下X座標
168 * @param y2 処理範囲の右下Y座標
169 * @param depth_max 深みの最大値
174 * A generic function to generate the plasma fractal.
175 * Note that it uses ``cave_feat'' as temporary storage.
176 * The values in ``cave_feat'' after this function
177 * are NOT actual features; They are raw heights which
178 * need to be converted to features.
181 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
184 POSITION xmid = (x2 - x1) / 2 + x1;
185 POSITION ymid = (y2 - y1) / 2 + y1;
188 if (x1 + 1 == x2) return;
190 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,
191 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
193 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,
194 xmid, y1, rough, depth_max);
196 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,
197 x2, ymid, rough, depth_max);
199 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,
200 xmid, y2, rough, depth_max);
202 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,
203 x1, ymid, rough, depth_max);
206 /* Recurse the four quadrants */
207 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
208 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
209 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
210 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
215 * The default table in terrain level generation.
217 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
220 * @brief 荒野フロア生成のサブルーチン
221 * @param terrain 荒野地形ID
222 * @param seed 乱数の固定シード
224 * @param corner 広域マップの角部分としての生成ならばTRUE
227 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
229 /* The outer wall is easy */
230 if (terrain == TERRAIN_EDGE)
232 /* Create level background */
233 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
235 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
237 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
244 /* Hack -- Backup the RNG state */
245 u32b state_backup[4];
246 Rand_state_backup(state_backup);
248 /* Hack -- Induce consistant flavors */
249 Rand_state_set(seed);
251 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
254 /* Create level background */
255 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
257 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
259 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
265 * Initialize the four corners
266 * ToDo: calculate the medium height of the adjacent
267 * terrains for every corner.
269 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
270 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
271 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
272 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
274 /* Hack -- only four corners */
277 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
278 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
279 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
280 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];
281 Rand_state_restore(state_backup);
285 /* Hack -- preserve four corners */
286 s16b north_west = floor_ptr->grid_array[1][1].feat;
287 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
288 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
289 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
291 /* x1, y1, x2, y2, num_depths, roughness */
292 FEAT_IDX roughness = 1; /* The roughness of the level. */
293 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
295 /* Hack -- copyback four corners */
296 floor_ptr->grid_array[1][1].feat = north_west;
297 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
298 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
299 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
301 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
303 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
305 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
309 Rand_state_restore(state_backup);
314 * @brief 荒野フロア生成のメインルーチン /
315 * Load a town or generate a terrain level using "plasma" fractals.
316 * @param player_ptr プレーヤーへの参照ポインタ
319 * @param border 広域マップの辺部分としての生成ならばTRUE
320 * @param corner 広域マップの角部分としての生成ならばTRUE
324 * x and y are the coordinates of the area in the wilderness.
325 * Border and corner are optimization flags to speed up the
326 * generation of the fractal terrain.
327 * If border is set then only the border of the terrain should
328 * be generated (for initializing the border structure).
329 * If corner is set then only the corners of the area are needed.
332 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
334 /* Number of the town (if any) */
335 player_ptr->town_num = wilderness[y][x].town;
337 /* Set the base level */
338 floor_type *floor_ptr = player_ptr->current_floor_ptr;
339 floor_ptr->base_level = wilderness[y][x].level;
341 /* Set the dungeon level */
342 floor_ptr->dun_level = 0;
344 /* Set the monster generation level */
345 floor_ptr->monster_level = floor_ptr->base_level;
347 /* Set the object generation level */
348 floor_ptr->object_level = floor_ptr->base_level;
351 /* Create the town */
352 if (player_ptr->town_num)
354 /* Reset the buildings */
357 /* Initialize the town */
359 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
361 init_flags = INIT_CREATE_DUNGEON;
363 process_dungeon_file(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
365 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
369 int terrain = wilderness[y][x].terrain;
370 u32b seed = wilderness[y][x].seed;
372 generate_wilderness_area(floor_ptr, terrain, seed, corner);
375 if (!corner && !wilderness[y][x].town)
378 * Place roads in the wilderness
379 * ToDo: make the road a bit more interresting
381 if (wilderness[y][x].road)
383 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
386 if (wilderness[y-1][x].road)
389 for (y1 = 1; y1 < MAX_HGT/2; y1++)
392 floor_ptr->grid_array[y1][x1].feat = feat_floor;
396 if (wilderness[y+1][x].road)
399 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
402 floor_ptr->grid_array[y1][x1].feat = feat_floor;
406 if (wilderness[y][x+1].road)
409 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
412 floor_ptr->grid_array[y1][x1].feat = feat_floor;
416 if (wilderness[y][x-1].road)
419 for (x1 = 1; x1 < MAX_WID/2; x1++)
422 floor_ptr->grid_array[y1][x1].feat = feat_floor;
429 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
430 * 問題なければ'> 0'へ置き換えること
432 bool is_winner = wilderness[y][x].entrance != 0;
433 is_winner &= !wilderness[y][x].town != 0;
434 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
435 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
436 if (!is_winner) return;
438 /* Hack -- Backup the RNG state */
439 u32b state_backup[4];
440 Rand_state_backup(state_backup);
442 /* Hack -- Induce consistant flavors */
443 Rand_state_set(wilderness[y][x].seed);
445 int dy = rand_range(6, floor_ptr->height - 6);
446 int dx = rand_range(6, floor_ptr->width - 6);
448 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
449 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
451 /* Hack -- Restore the RNG state */
452 Rand_state_restore(state_backup);
457 * Border of the wilderness area
459 static border_type border;
463 * Build the wilderness area outside of the town.
464 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
465 * @param creature_ptr プレーヤーへの参照ポインタ
468 void wilderness_gen(player_type *creature_ptr)
471 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
472 floor_ptr->height = MAX_HGT;
473 floor_ptr->width = MAX_WID;
475 /* Assume illegal panel */
476 panel_row_min = floor_ptr->height;
477 panel_col_min = floor_ptr->width;
479 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
480 POSITION x = creature_ptr->wilderness_x;
481 POSITION y = creature_ptr->wilderness_y;
482 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
485 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
487 for (int i = 1; i < MAX_WID - 1; i++)
489 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
493 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
495 for (int i = 1; i < MAX_WID - 1; i++)
497 border.south[i] = floor_ptr->grid_array[1][i].feat;
501 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
503 for (int i = 1; i < MAX_HGT - 1; i++)
505 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
509 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
511 for (int i = 1; i < MAX_HGT - 1; i++)
513 border.east[i] = floor_ptr->grid_array[i][1].feat;
516 /* North west corner */
517 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
518 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
520 /* North east corner */
521 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
522 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
524 /* South west corner */
525 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
526 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
528 /* South east corner */
529 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
530 border.south_east = floor_ptr->grid_array[1][1].feat;
532 /* Create terrain of the current area */
533 generate_area(creature_ptr, y, x, FALSE, FALSE);
535 /* Special boundary walls -- North */
536 for (int i = 0; i < MAX_WID; i++)
538 floor_ptr->grid_array[0][i].feat = feat_permanent;
539 floor_ptr->grid_array[0][i].mimic = border.north[i];
542 /* Special boundary walls -- South */
543 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++)
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++)
559 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
560 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
563 floor_ptr->grid_array[0][0].mimic = border.north_west;
564 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
565 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
566 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
568 /* Light up or darken the area */
569 for (y = 0; y < floor_ptr->height; y++)
571 for (x = 0; x < floor_ptr->width; x++)
574 g_ptr = &floor_ptr->grid_array[y][x];
579 g_ptr->info |= CAVE_GLOW;
581 /* Hack -- Memorize lit grids if allowed */
582 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
586 /* Feature code (applying "mimic" field) */
588 f_ptr = &f_info[get_feat_mimic(g_ptr)];
590 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
591 !have_flag(f_ptr->flags, FF_ENTRANCE))
594 g_ptr->info &= ~(CAVE_GLOW);
596 /* Darken "boring" features */
597 if (!have_flag(f_ptr->flags, FF_REMEMBER))
599 /* Forget the grid */
600 g_ptr->info &= ~(CAVE_MARK);
606 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
608 g_ptr->info |= CAVE_GLOW;
610 /* Hack -- Memorize lit grids if allowed */
611 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
615 if (creature_ptr->teleport_town)
617 for (y = 0; y < floor_ptr->height; y++)
619 for (x = 0; x < floor_ptr->width; x++)
622 g_ptr = &floor_ptr->grid_array[y][x];
624 /* Seeing true feature code (ignore mimic) */
626 f_ptr = &f_info[g_ptr->feat];
628 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
630 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
635 delete_monster_idx(creature_ptr, g_ptr->m_idx);
638 creature_ptr->oldpy = y;
639 creature_ptr->oldpx = x;
643 creature_ptr->teleport_town = FALSE;
645 else if (creature_ptr->leaving_dungeon)
647 for (y = 0; y < floor_ptr->height; y++)
649 for (x = 0; x < floor_ptr->width; x++)
652 g_ptr = &floor_ptr->grid_array[y][x];
654 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
658 delete_monster_idx(creature_ptr, g_ptr->m_idx);
661 creature_ptr->oldpy = y;
662 creature_ptr->oldpx = x;
666 creature_ptr->teleport_town = FALSE;
669 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
670 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
672 /* Make some residents */
673 for (int i = 0; i < lim; i++)
677 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
678 mode |= PM_ALLOW_SLEEP;
680 /* Make a resident */
681 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode);
684 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
685 generate_encounter = FALSE;
687 /* Fill the arrays of floors and walls in the good proportions */
688 set_floor_and_wall(0);
690 /* Set rewarded quests to finished */
691 for (int i = 0; i < max_q_idx; i++)
693 if (quest[i].status == QUEST_STATUS_REWARDED)
694 quest[i].status = QUEST_STATUS_FINISHED;
698 static s16b conv_terrain2feat[MAX_WILDERNESS];
701 * @brief 広域マップの生成(簡易処理版) /
702 * Build the wilderness area. -DG-
705 void wilderness_gen_small(player_type *creature_ptr)
707 /* To prevent stupid things */
708 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
709 for (int i = 0; i < MAX_WID; i++)
711 for (int j = 0; j < MAX_HGT; j++)
713 floor_ptr->grid_array[j][i].feat = feat_permanent;
717 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
720 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
722 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
724 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
726 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
727 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
728 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
732 if (wilderness[j][i].road)
734 floor_ptr->grid_array[j][i].feat = feat_floor;
735 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
739 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
741 floor_ptr->grid_array[j][i].feat = feat_entrance;
742 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
743 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
747 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
748 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
752 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
753 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
755 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
756 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
758 /* Assume illegal panel */
759 panel_row_min = floor_ptr->height;
760 panel_col_min = floor_ptr->width;
762 creature_ptr->x = creature_ptr->wilderness_x;
763 creature_ptr->y = creature_ptr->wilderness_y;
764 creature_ptr->town_num = 0;
768 typedef struct wilderness_grid wilderness_grid;
770 struct wilderness_grid
772 int terrain; /* Terrain type */
773 TOWN_IDX town; /* Town number */
774 DEPTH level; /* Level of the wilderness */
775 byte road; /* Road */
776 char name[32]; /* Name of the town/wilderness */
780 static wilderness_grid w_letter[255];
783 * @brief w_info.txtのデータ解析 /
784 * Parse a sub-file of the "extra info"
785 * @param buf 読み取ったデータ行のバッファ
787 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
789 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
790 * @param y 広域マップの高さを返す参照ポインタ
791 * @param x 広域マップの幅を返す参照ポインタ
794 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
796 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
802 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
815 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
817 int index = zz[0][0];
820 w_letter[index].terrain = atoi(zz[1]);
822 w_letter[index].terrain = 0;
825 w_letter[index].level = (s16b)atoi(zz[2]);
827 w_letter[index].level = 0;
830 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
832 w_letter[index].town = 0;
835 w_letter[index].road = (byte)atoi(zz[4]);
837 w_letter[index].road = 0;
840 strcpy(w_letter[index].name, zz[5]);
842 w_letter[index].name[0] = 0;
847 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
853 /* Process "W:D:<layout> */
854 /* Layout of the wilderness */
860 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
863 wilderness[*y][*x].terrain = w_letter[id].terrain;
864 wilderness[*y][*x].level = w_letter[id].level;
865 wilderness[*y][*x].town = w_letter[id].town;
866 wilderness[*y][*x].road = w_letter[id].road;
867 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
874 /* Process "W:P:<x>:<y> - starting position in the wilderness */
877 bool is_corner = creature_ptr->wilderness_x == 0;
878 is_corner = creature_ptr->wilderness_y == 0;
879 if (!is_corner) break;
881 if (tokenize(buf + 4, 2, zz, 0) != 2)
883 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
886 creature_ptr->wilderness_y = atoi(zz[0]);
887 creature_ptr->wilderness_x = atoi(zz[1]);
889 if ((creature_ptr->wilderness_x < 1) ||
890 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
891 (creature_ptr->wilderness_y < 1) ||
892 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
894 return PARSE_ERROR_OUT_OF_BOUNDS;
901 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
904 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
906 if (!d_info[i].maxdepth) continue;
907 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
908 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
910 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
919 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
920 * Generate the random seeds for the wilderness
923 void seed_wilderness(void)
925 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
927 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
929 wilderness[y][x].seed = randint0(0x10000000);
930 wilderness[y][x].entrance = 0;
937 * Pointer to wilderness_type
939 typedef wilderness_type *wilderness_type_ptr;
942 * @brief ゲーム開始時の荒野初期化メインルーチン /
943 * Initialize wilderness array
946 errr init_wilderness(void)
948 /* Allocate the wilderness (two-dimension array) */
949 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
950 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
952 /* Init the other pointers */
953 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
955 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
958 generate_encounter = FALSE;
964 * @brief 荒野の地勢設定を初期化する /
965 * Initialize wilderness array
966 * @param terrain 初期化したい地勢ID
967 * @param feat_global 基本的な地形ID
968 * @param fmt 地勢内の地形数を参照するための独自フォーマット
971 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
973 /* Begin the varargs stuff */
977 /* Wilderness terrains on global map */
978 conv_terrain2feat[terrain] = feat_global;
980 /* Wilderness terrains on local map */
983 for (concptr p = fmt; *p; p++)
987 plog_fmt("Format error");
991 FEAT_IDX feat = (s16b)va_arg(vp, int);
992 int num = va_arg(vp, int);
995 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
997 terrain_table[terrain][cur] = feat;
1000 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1005 if (cur < MAX_FEAT_IN_TERRAIN)
1007 plog_fmt("Too few parameters");
1015 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1016 * Initialize arrays for wilderness terrains
1019 void init_wilderness_terrains(void)
1021 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1022 feat_permanent, MAX_FEAT_IN_TERRAIN);
1024 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1025 feat_floor, MAX_FEAT_IN_TERRAIN);
1027 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1028 feat_deep_water, 12,
1029 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1031 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1033 feat_shallow_water, 12,
1036 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1038 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1043 feat_shallow_water, 4,
1044 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1046 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1052 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1054 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1060 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1062 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1067 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1069 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1072 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1074 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1075 feat_shallow_lava, 14,
1077 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1079 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1081 feat_shallow_lava, 3,
1083 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1085 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1091 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1096 * @brief 荒野から広域マップへの切り替え処理 /
1097 * Initialize arrays for wilderness terrains
1098 * @param encount 襲撃時TRUE
1099 * @return 切り替えが行われた場合はTRUEを返す。
1101 bool change_wild_mode(player_type *creature_ptr, bool encount)
1103 generate_encounter = encount;
1105 /* It is in the middle of changing map */
1106 if (creature_ptr->leaving) return FALSE;
1108 if (lite_town || vanilla_town)
1110 msg_print(_("荒野なんてない。", "No global map."));
1114 if (creature_ptr->wild_mode)
1116 /* Save the location in the global map */
1117 creature_ptr->wilderness_x = creature_ptr->x;
1118 creature_ptr->wilderness_y = creature_ptr->y;
1120 /* Give first move to the player */
1121 creature_ptr->energy_need = 0;
1123 /* Go back to the ordinary map */
1124 creature_ptr->wild_mode = FALSE;
1125 creature_ptr->leaving = TRUE;
1129 bool have_pet = FALSE;
1130 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1132 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1134 if (!monster_is_valid(m_ptr)) continue;
1135 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1136 if (MON_CSLEEP(m_ptr)) continue;
1137 if (m_ptr->cdis > MAX_SIGHT) continue;
1138 if (!is_hostile(m_ptr)) continue;
1139 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1140 "You cannot enter global map, since there is some monsters nearby!"));
1141 free_turn(creature_ptr);
1147 concptr msg = _("ペットを置いて広域マップに入りますか?",
1148 "Do you leave your pets behind? ");
1150 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1152 free_turn(creature_ptr);
1157 take_turn(creature_ptr, 1000);
1159 /* Remember the position */
1160 creature_ptr->oldpx = creature_ptr->x;
1161 creature_ptr->oldpy = creature_ptr->y;
1163 /* Cancel hex spelling */
1164 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1166 /* Cancel any special action */
1167 set_action(creature_ptr, ACTION_NONE);
1169 /* Go into the global map */
1170 creature_ptr->wild_mode = TRUE;
1171 creature_ptr->leaving = TRUE;