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 "view/display-main-window.h"
40 #include "view/display-messages.h"
41 #include "world/world.h"
43 #define MAX_FEAT_IN_TERRAIN 18
48 wilderness_type **wilderness;
50 bool generate_encounter;
53 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
54 * @param feat_type 非一様確率を再現するための要素数100の配列
55 * @param prob 元の確率テーブル
58 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
60 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
62 lim[0] = prob[0].percent;
63 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
64 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
66 for (i = 0; i < 100; i++)
68 while (i == lim[cur]) cur++;
69 feat_type[i] = prob[cur].feat;
75 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
76 * / Fill the arrays of floors and walls in the good proportions
80 void set_floor_and_wall(DUNGEON_IDX type)
82 DUNGEON_IDX cur_type = 255;
86 if (cur_type == type) return;
89 d_ptr = &d_info[type];
91 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
92 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
94 feat_wall_outer = d_ptr->outer_wall;
95 feat_wall_inner = d_ptr->inner_wall;
96 feat_wall_solid = d_ptr->outer_wall;
101 * @brief プラズマフラクタル的地形生成の再帰中間処理
102 * / Helper for plasma generation.
110 * @param depth_max 深みの最大値
113 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)
116 * Average the four corners & perturb it a bit.
117 * tmp is a random int +/- rough
119 FEAT_IDX tmp2 = rough*2 + 1;
120 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
122 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
124 /* Division always rounds down, so we round up again */
125 if (((x1 + x2 + x3 + x4) % 4) > 1)
129 if (avg < 0) avg = 0;
130 if (avg > depth_max) avg = depth_max;
132 /* Set the new value. */
133 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
138 * @brief プラズマフラクタル的地形生成の再帰末端処理
139 * / Helper for plasma generation.
140 * @param x1 中間末端部1の重み
141 * @param x2 中間末端部2の重み
142 * @param x3 中間末端部3の重み
143 * @param xmid 最終末端部座標X
144 * @param ymid 最終末端部座標Y
146 * @param depth_max 深みの最大値
149 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)
152 * Average the three corners & perturb it a bit.
153 * tmp is a random int +/- rough
155 FEAT_IDX tmp2 = rough * 2 + 1;
156 FEAT_IDX tmp = randint0(tmp2) - rough;
158 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
160 /* Division always rounds down, so we round up again */
161 if ((x1 + x2 + x3) % 3) avg++;
164 if (avg < 0) avg = 0;
165 if (avg > depth_max) avg = depth_max;
167 /* Set the new value. */
168 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
173 * @brief プラズマフラクタル的地形生成の開始処理
174 * / Helper for plasma generation.
175 * @param x1 処理範囲の左上X座標
176 * @param y1 処理範囲の左上Y座標
177 * @param x2 処理範囲の右下X座標
178 * @param y2 処理範囲の右下Y座標
179 * @param depth_max 深みの最大値
184 * A generic function to generate the plasma fractal.
185 * Note that it uses ``cave_feat'' as temporary storage.
186 * The values in ``cave_feat'' after this function
187 * are NOT actual features; They are raw heights which
188 * need to be converted to features.
191 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
194 POSITION xmid = (x2 - x1) / 2 + x1;
195 POSITION ymid = (y2 - y1) / 2 + y1;
198 if (x1 + 1 == x2) return;
200 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,
201 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
203 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,
204 xmid, y1, rough, depth_max);
206 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,
207 x2, ymid, rough, depth_max);
209 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,
210 xmid, y2, rough, depth_max);
212 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,
213 x1, ymid, rough, depth_max);
216 /* Recurse the four quadrants */
217 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
218 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
219 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
220 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
225 * The default table in terrain level generation.
227 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
230 * @brief 荒野フロア生成のサブルーチン
231 * @param terrain 荒野地形ID
232 * @param seed 乱数の固定シード
234 * @param corner 広域マップの角部分としての生成ならばTRUE
237 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
239 /* The outer wall is easy */
240 if (terrain == TERRAIN_EDGE)
242 /* Create level background */
243 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
245 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
247 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
254 /* Hack -- Backup the RNG state */
255 u32b state_backup[4];
256 Rand_state_backup(state_backup);
258 /* Hack -- Induce consistant flavors */
259 Rand_state_set(seed);
261 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
264 /* Create level background */
265 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
267 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
269 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
275 * Initialize the four corners
276 * ToDo: calculate the medium height of the adjacent
277 * terrains for every corner.
279 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
280 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
281 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
282 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
284 /* Hack -- only four corners */
287 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
288 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
289 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
290 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];
291 Rand_state_restore(state_backup);
295 /* Hack -- preserve four corners */
296 s16b north_west = floor_ptr->grid_array[1][1].feat;
297 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
298 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
299 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
301 /* x1, y1, x2, y2, num_depths, roughness */
302 FEAT_IDX roughness = 1; /* The roughness of the level. */
303 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
305 /* Hack -- copyback four corners */
306 floor_ptr->grid_array[1][1].feat = north_west;
307 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
308 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
309 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
311 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
313 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
315 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
319 Rand_state_restore(state_backup);
324 * @brief 荒野フロア生成のメインルーチン /
325 * Load a town or generate a terrain level using "plasma" fractals.
326 * @param player_ptr プレーヤーへの参照ポインタ
329 * @param border 広域マップの辺部分としての生成ならばTRUE
330 * @param corner 広域マップの角部分としての生成ならばTRUE
334 * x and y are the coordinates of the area in the wilderness.
335 * Border and corner are optimization flags to speed up the
336 * generation of the fractal terrain.
337 * If border is set then only the border of the terrain should
338 * be generated (for initializing the border structure).
339 * If corner is set then only the corners of the area are needed.
342 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
344 /* Number of the town (if any) */
345 player_ptr->town_num = wilderness[y][x].town;
347 /* Set the base level */
348 floor_type *floor_ptr = player_ptr->current_floor_ptr;
349 floor_ptr->base_level = wilderness[y][x].level;
351 /* Set the dungeon level */
352 floor_ptr->dun_level = 0;
354 /* Set the monster generation level */
355 floor_ptr->monster_level = floor_ptr->base_level;
357 /* Set the object generation level */
358 floor_ptr->object_level = floor_ptr->base_level;
361 /* Create the town */
362 if (player_ptr->town_num)
364 /* Reset the buildings */
367 /* Initialize the town */
369 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
371 init_flags = INIT_CREATE_DUNGEON;
373 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
375 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
379 int terrain = wilderness[y][x].terrain;
380 u32b seed = wilderness[y][x].seed;
382 generate_wilderness_area(floor_ptr, terrain, seed, corner);
385 if (!corner && !wilderness[y][x].town)
388 * Place roads in the wilderness
389 * ToDo: make the road a bit more interresting
391 if (wilderness[y][x].road)
393 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
396 if (wilderness[y-1][x].road)
399 for (y1 = 1; y1 < MAX_HGT/2; y1++)
402 floor_ptr->grid_array[y1][x1].feat = feat_floor;
406 if (wilderness[y+1][x].road)
409 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
412 floor_ptr->grid_array[y1][x1].feat = feat_floor;
416 if (wilderness[y][x+1].road)
419 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
422 floor_ptr->grid_array[y1][x1].feat = feat_floor;
426 if (wilderness[y][x-1].road)
429 for (x1 = 1; x1 < MAX_WID/2; x1++)
432 floor_ptr->grid_array[y1][x1].feat = feat_floor;
439 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
440 * 問題なければ'> 0'へ置き換えること
442 bool is_winner = wilderness[y][x].entrance != 0;
443 is_winner &= !wilderness[y][x].town != 0;
444 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
445 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
446 if (!is_winner) return;
448 /* Hack -- Backup the RNG state */
449 u32b state_backup[4];
450 Rand_state_backup(state_backup);
452 /* Hack -- Induce consistant flavors */
453 Rand_state_set(wilderness[y][x].seed);
455 int dy = rand_range(6, floor_ptr->height - 6);
456 int dx = rand_range(6, floor_ptr->width - 6);
458 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
459 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
461 /* Hack -- Restore the RNG state */
462 Rand_state_restore(state_backup);
467 * Border of the wilderness area
469 static border_type border;
473 * Build the wilderness area outside of the town.
474 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
475 * @param creature_ptr プレーヤーへの参照ポインタ
478 void wilderness_gen(player_type *creature_ptr)
481 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
482 floor_ptr->height = MAX_HGT;
483 floor_ptr->width = MAX_WID;
485 /* Assume illegal panel */
486 panel_row_min = floor_ptr->height;
487 panel_col_min = floor_ptr->width;
489 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
490 POSITION x = creature_ptr->wilderness_x;
491 POSITION y = creature_ptr->wilderness_y;
492 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
495 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
497 for (int i = 1; i < MAX_WID - 1; i++)
499 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
503 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
505 for (int i = 1; i < MAX_WID - 1; i++)
507 border.south[i] = floor_ptr->grid_array[1][i].feat;
511 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
513 for (int i = 1; i < MAX_HGT - 1; i++)
515 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
519 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
521 for (int i = 1; i < MAX_HGT - 1; i++)
523 border.east[i] = floor_ptr->grid_array[i][1].feat;
526 /* North west corner */
527 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
528 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
530 /* North east corner */
531 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
532 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
534 /* South west corner */
535 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
536 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
538 /* South east corner */
539 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
540 border.south_east = floor_ptr->grid_array[1][1].feat;
542 /* Create terrain of the current area */
543 generate_area(creature_ptr, y, x, FALSE, FALSE);
545 /* Special boundary walls -- North */
546 for (int i = 0; i < MAX_WID; i++)
548 floor_ptr->grid_array[0][i].feat = feat_permanent;
549 floor_ptr->grid_array[0][i].mimic = border.north[i];
552 /* Special boundary walls -- South */
553 for (int i = 0; i < MAX_WID; i++)
555 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
556 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
559 /* Special boundary walls -- West */
560 for (int i = 0; i < MAX_HGT; i++)
562 floor_ptr->grid_array[i][0].feat = feat_permanent;
563 floor_ptr->grid_array[i][0].mimic = border.west[i];
566 /* Special boundary walls -- East */
567 for (int i = 0; i < MAX_HGT; i++)
569 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
570 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
573 floor_ptr->grid_array[0][0].mimic = border.north_west;
574 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
575 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
576 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
578 /* Light up or darken the area */
579 for (y = 0; y < floor_ptr->height; y++)
581 for (x = 0; x < floor_ptr->width; x++)
584 g_ptr = &floor_ptr->grid_array[y][x];
589 g_ptr->info |= CAVE_GLOW;
591 /* Hack -- Memorize lit grids if allowed */
592 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
596 /* Feature code (applying "mimic" field) */
598 f_ptr = &f_info[get_feat_mimic(g_ptr)];
600 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
601 !have_flag(f_ptr->flags, FF_ENTRANCE))
604 g_ptr->info &= ~(CAVE_GLOW);
606 /* Darken "boring" features */
607 if (!have_flag(f_ptr->flags, FF_REMEMBER))
609 /* Forget the grid */
610 g_ptr->info &= ~(CAVE_MARK);
616 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
618 g_ptr->info |= CAVE_GLOW;
620 /* Hack -- Memorize lit grids if allowed */
621 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
625 if (creature_ptr->teleport_town)
627 for (y = 0; y < floor_ptr->height; y++)
629 for (x = 0; x < floor_ptr->width; x++)
632 g_ptr = &floor_ptr->grid_array[y][x];
634 /* Seeing true feature code (ignore mimic) */
636 f_ptr = &f_info[g_ptr->feat];
638 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
640 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
645 delete_monster_idx(creature_ptr, g_ptr->m_idx);
648 creature_ptr->oldpy = y;
649 creature_ptr->oldpx = x;
653 creature_ptr->teleport_town = FALSE;
655 else if (creature_ptr->leaving_dungeon)
657 for (y = 0; y < floor_ptr->height; y++)
659 for (x = 0; x < floor_ptr->width; x++)
662 g_ptr = &floor_ptr->grid_array[y][x];
664 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
668 delete_monster_idx(creature_ptr, g_ptr->m_idx);
671 creature_ptr->oldpy = y;
672 creature_ptr->oldpx = x;
676 creature_ptr->teleport_town = FALSE;
679 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
680 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
682 /* Make some residents */
683 for (int i = 0; i < lim; i++)
687 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
688 mode |= PM_ALLOW_SLEEP;
690 /* Make a resident */
691 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
694 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
695 generate_encounter = FALSE;
697 /* Fill the arrays of floors and walls in the good proportions */
698 set_floor_and_wall(0);
700 /* Set rewarded quests to finished */
701 for (int i = 0; i < max_q_idx; i++)
703 if (quest[i].status == QUEST_STATUS_REWARDED)
704 quest[i].status = QUEST_STATUS_FINISHED;
708 static s16b conv_terrain2feat[MAX_WILDERNESS];
711 * @brief 広域マップの生成(簡易処理版) /
712 * Build the wilderness area. -DG-
715 void wilderness_gen_small(player_type *creature_ptr)
717 /* To prevent stupid things */
718 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
719 for (int i = 0; i < MAX_WID; i++)
721 for (int j = 0; j < MAX_HGT; j++)
723 floor_ptr->grid_array[j][i].feat = feat_permanent;
727 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
730 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
732 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
734 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
736 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
737 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
738 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
742 if (wilderness[j][i].road)
744 floor_ptr->grid_array[j][i].feat = feat_floor;
745 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
749 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
751 floor_ptr->grid_array[j][i].feat = feat_entrance;
752 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
753 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
757 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
758 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
762 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
763 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
765 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
766 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
768 /* Assume illegal panel */
769 panel_row_min = floor_ptr->height;
770 panel_col_min = floor_ptr->width;
772 creature_ptr->x = creature_ptr->wilderness_x;
773 creature_ptr->y = creature_ptr->wilderness_y;
774 creature_ptr->town_num = 0;
778 typedef struct wilderness_grid wilderness_grid;
780 struct wilderness_grid
782 int terrain; /* Terrain type */
783 TOWN_IDX town; /* Town number */
784 DEPTH level; /* Level of the wilderness */
785 byte road; /* Road */
786 char name[32]; /* Name of the town/wilderness */
790 static wilderness_grid w_letter[255];
793 * @brief w_info.txtのデータ解析 /
794 * Parse a sub-file of the "extra info"
795 * @param buf 読み取ったデータ行のバッファ
797 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
799 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
800 * @param y 広域マップの高さを返す参照ポインタ
801 * @param x 広域マップの幅を返す参照ポインタ
804 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
806 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
812 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
825 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
827 int index = zz[0][0];
830 w_letter[index].terrain = atoi(zz[1]);
832 w_letter[index].terrain = 0;
835 w_letter[index].level = (s16b)atoi(zz[2]);
837 w_letter[index].level = 0;
840 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
842 w_letter[index].town = 0;
845 w_letter[index].road = (byte)atoi(zz[4]);
847 w_letter[index].road = 0;
850 strcpy(w_letter[index].name, zz[5]);
852 w_letter[index].name[0] = 0;
857 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
863 /* Process "W:D:<layout> */
864 /* Layout of the wilderness */
870 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
873 wilderness[*y][*x].terrain = w_letter[id].terrain;
874 wilderness[*y][*x].level = w_letter[id].level;
875 wilderness[*y][*x].town = w_letter[id].town;
876 wilderness[*y][*x].road = w_letter[id].road;
877 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
884 /* Process "W:P:<x>:<y> - starting position in the wilderness */
887 bool is_corner = creature_ptr->wilderness_x == 0;
888 is_corner = creature_ptr->wilderness_y == 0;
889 if (!is_corner) break;
891 if (tokenize(buf + 4, 2, zz, 0) != 2)
893 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
896 creature_ptr->wilderness_y = atoi(zz[0]);
897 creature_ptr->wilderness_x = atoi(zz[1]);
899 if ((creature_ptr->wilderness_x < 1) ||
900 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
901 (creature_ptr->wilderness_y < 1) ||
902 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
904 return PARSE_ERROR_OUT_OF_BOUNDS;
911 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
914 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
916 if (!d_info[i].maxdepth) continue;
917 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
918 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
920 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
929 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
930 * Generate the random seeds for the wilderness
933 void seed_wilderness(void)
935 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
937 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
939 wilderness[y][x].seed = randint0(0x10000000);
940 wilderness[y][x].entrance = 0;
947 * Pointer to wilderness_type
949 typedef wilderness_type *wilderness_type_ptr;
952 * @brief ゲーム開始時の荒野初期化メインルーチン /
953 * Initialize wilderness array
956 errr init_wilderness(void)
958 /* Allocate the wilderness (two-dimension array) */
959 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
960 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
962 /* Init the other pointers */
963 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
965 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
968 generate_encounter = FALSE;
974 * @brief 荒野の地勢設定を初期化する /
975 * Initialize wilderness array
976 * @param terrain 初期化したい地勢ID
977 * @param feat_global 基本的な地形ID
978 * @param fmt 地勢内の地形数を参照するための独自フォーマット
981 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
983 /* Begin the varargs stuff */
987 /* Wilderness terrains on global map */
988 conv_terrain2feat[terrain] = feat_global;
990 /* Wilderness terrains on local map */
993 for (concptr p = fmt; *p; p++)
997 plog_fmt("Format error");
1001 FEAT_IDX feat = (s16b)va_arg(vp, int);
1002 int num = va_arg(vp, int);
1003 int lim = cur + num;
1005 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1007 terrain_table[terrain][cur] = feat;
1010 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1015 if (cur < MAX_FEAT_IN_TERRAIN)
1017 plog_fmt("Too few parameters");
1025 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1026 * Initialize arrays for wilderness terrains
1029 void init_wilderness_terrains(void)
1031 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1032 feat_permanent, MAX_FEAT_IN_TERRAIN);
1034 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1035 feat_floor, MAX_FEAT_IN_TERRAIN);
1037 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1038 feat_deep_water, 12,
1039 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1041 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1043 feat_shallow_water, 12,
1046 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1048 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1053 feat_shallow_water, 4,
1054 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1056 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1062 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1064 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1070 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1072 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1077 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1079 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1082 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1084 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1085 feat_shallow_lava, 14,
1087 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1089 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1091 feat_shallow_lava, 3,
1093 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1095 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1101 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1106 * @brief 荒野から広域マップへの切り替え処理 /
1107 * Initialize arrays for wilderness terrains
1108 * @param encount 襲撃時TRUE
1109 * @return 切り替えが行われた場合はTRUEを返す。
1111 bool change_wild_mode(player_type *creature_ptr, bool encount)
1113 generate_encounter = encount;
1115 /* It is in the middle of changing map */
1116 if (creature_ptr->leaving) return FALSE;
1118 if (lite_town || vanilla_town)
1120 msg_print(_("荒野なんてない。", "No global map."));
1124 if (creature_ptr->wild_mode)
1126 /* Save the location in the global map */
1127 creature_ptr->wilderness_x = creature_ptr->x;
1128 creature_ptr->wilderness_y = creature_ptr->y;
1130 /* Give first move to the player */
1131 creature_ptr->energy_need = 0;
1133 /* Go back to the ordinary map */
1134 creature_ptr->wild_mode = FALSE;
1135 creature_ptr->leaving = TRUE;
1139 bool have_pet = FALSE;
1140 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1142 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1144 if (!monster_is_valid(m_ptr)) continue;
1145 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1146 if (monster_csleep_remaining(m_ptr)) continue;
1147 if (m_ptr->cdis > MAX_SIGHT) continue;
1148 if (!is_hostile(m_ptr)) continue;
1149 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1150 "You cannot enter global map, since there is some monsters nearby!"));
1151 free_turn(creature_ptr);
1157 concptr msg = _("ペットを置いて広域マップに入りますか?",
1158 "Do you leave your pets behind? ");
1160 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL))
1162 free_turn(creature_ptr);
1167 take_turn(creature_ptr, 1000);
1169 /* Remember the position */
1170 creature_ptr->oldpx = creature_ptr->x;
1171 creature_ptr->oldpy = creature_ptr->y;
1173 /* Cancel hex spelling */
1174 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1176 /* Cancel any special action */
1177 set_action(creature_ptr, ACTION_NONE);
1179 /* Go into the global map */
1180 creature_ptr->wild_mode = TRUE;
1181 creature_ptr->leaving = TRUE;