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 "info-reader/parse-error-types.h"
21 #include "io/files-util.h"
22 #include "io/tokenizer.h"
23 #include "main/init.h"
24 #include "monster/monster-status.h"
25 #include "monster/monster.h"
26 #include "player/player-effects.h"
27 #include "player/player-status.h"
28 #include "realm/realm-names-table.h"
29 #include "spell-realm/spells-hex.h"
30 #include "system/system-variables.h"
31 #include "util/util.h"
32 #include "view/display-main-window.h"
33 #include "world/world.h"
35 #define MAX_FEAT_IN_TERRAIN 18
40 wilderness_type **wilderness;
42 bool generate_encounter;
45 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
46 * @param feat_type 非一様確率を再現するための要素数100の配列
47 * @param prob 元の確率テーブル
50 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
52 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
54 lim[0] = prob[0].percent;
55 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
56 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
58 for (i = 0; i < 100; i++)
60 while (i == lim[cur]) cur++;
61 feat_type[i] = prob[cur].feat;
67 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
68 * / Fill the arrays of floors and walls in the good proportions
72 void set_floor_and_wall(DUNGEON_IDX type)
74 DUNGEON_IDX cur_type = 255;
78 if (cur_type == type) return;
81 d_ptr = &d_info[type];
83 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
84 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
86 feat_wall_outer = d_ptr->outer_wall;
87 feat_wall_inner = d_ptr->inner_wall;
88 feat_wall_solid = d_ptr->outer_wall;
93 * @brief プラズマフラクタル的地形生成の再帰中間処理
94 * / Helper for plasma generation.
102 * @param depth_max 深みの最大値
105 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)
108 * Average the four corners & perturb it a bit.
109 * tmp is a random int +/- rough
111 FEAT_IDX tmp2 = rough*2 + 1;
112 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
114 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
116 /* Division always rounds down, so we round up again */
117 if (((x1 + x2 + x3 + x4) % 4) > 1)
121 if (avg < 0) avg = 0;
122 if (avg > depth_max) avg = depth_max;
124 /* Set the new value. */
125 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
130 * @brief プラズマフラクタル的地形生成の再帰末端処理
131 * / Helper for plasma generation.
132 * @param x1 中間末端部1の重み
133 * @param x2 中間末端部2の重み
134 * @param x3 中間末端部3の重み
135 * @param xmid 最終末端部座標X
136 * @param ymid 最終末端部座標Y
138 * @param depth_max 深みの最大値
141 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)
144 * Average the three corners & perturb it a bit.
145 * tmp is a random int +/- rough
147 FEAT_IDX tmp2 = rough * 2 + 1;
148 FEAT_IDX tmp = randint0(tmp2) - rough;
150 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
152 /* Division always rounds down, so we round up again */
153 if ((x1 + x2 + x3) % 3) avg++;
156 if (avg < 0) avg = 0;
157 if (avg > depth_max) avg = depth_max;
159 /* Set the new value. */
160 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
165 * @brief プラズマフラクタル的地形生成の開始処理
166 * / Helper for plasma generation.
167 * @param x1 処理範囲の左上X座標
168 * @param y1 処理範囲の左上Y座標
169 * @param x2 処理範囲の右下X座標
170 * @param y2 処理範囲の右下Y座標
171 * @param depth_max 深みの最大値
176 * A generic function to generate the plasma fractal.
177 * Note that it uses ``cave_feat'' as temporary storage.
178 * The values in ``cave_feat'' after this function
179 * are NOT actual features; They are raw heights which
180 * need to be converted to features.
183 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
186 POSITION xmid = (x2 - x1) / 2 + x1;
187 POSITION ymid = (y2 - y1) / 2 + y1;
190 if (x1 + 1 == x2) return;
192 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,
193 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
195 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,
196 xmid, y1, rough, depth_max);
198 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,
199 x2, ymid, rough, depth_max);
201 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,
202 xmid, y2, rough, depth_max);
204 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,
205 x1, ymid, rough, depth_max);
208 /* Recurse the four quadrants */
209 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
210 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
211 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
212 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
217 * The default table in terrain level generation.
219 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
222 * @brief 荒野フロア生成のサブルーチン
223 * @param terrain 荒野地形ID
224 * @param seed 乱数の固定シード
226 * @param corner 広域マップの角部分としての生成ならばTRUE
229 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
231 /* The outer wall is easy */
232 if (terrain == TERRAIN_EDGE)
234 /* Create level background */
235 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
237 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
239 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
246 /* Hack -- Backup the RNG state */
247 u32b state_backup[4];
248 Rand_state_backup(state_backup);
250 /* Hack -- Induce consistant flavors */
251 Rand_state_set(seed);
253 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
256 /* Create level background */
257 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
259 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
261 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
267 * Initialize the four corners
268 * ToDo: calculate the medium height of the adjacent
269 * terrains for every corner.
271 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
272 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
273 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
274 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
276 /* Hack -- only four corners */
279 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
280 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
281 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
282 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];
283 Rand_state_restore(state_backup);
287 /* Hack -- preserve four corners */
288 s16b north_west = floor_ptr->grid_array[1][1].feat;
289 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
290 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
291 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
293 /* x1, y1, x2, y2, num_depths, roughness */
294 FEAT_IDX roughness = 1; /* The roughness of the level. */
295 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
297 /* Hack -- copyback four corners */
298 floor_ptr->grid_array[1][1].feat = north_west;
299 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
300 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
301 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
303 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
305 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
307 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
311 Rand_state_restore(state_backup);
316 * @brief 荒野フロア生成のメインルーチン /
317 * Load a town or generate a terrain level using "plasma" fractals.
318 * @param player_ptr プレーヤーへの参照ポインタ
321 * @param border 広域マップの辺部分としての生成ならばTRUE
322 * @param corner 広域マップの角部分としての生成ならばTRUE
326 * x and y are the coordinates of the area in the wilderness.
327 * Border and corner are optimization flags to speed up the
328 * generation of the fractal terrain.
329 * If border is set then only the border of the terrain should
330 * be generated (for initializing the border structure).
331 * If corner is set then only the corners of the area are needed.
334 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
336 /* Number of the town (if any) */
337 player_ptr->town_num = wilderness[y][x].town;
339 /* Set the base level */
340 floor_type *floor_ptr = player_ptr->current_floor_ptr;
341 floor_ptr->base_level = wilderness[y][x].level;
343 /* Set the dungeon level */
344 floor_ptr->dun_level = 0;
346 /* Set the monster generation level */
347 floor_ptr->monster_level = floor_ptr->base_level;
349 /* Set the object generation level */
350 floor_ptr->object_level = floor_ptr->base_level;
353 /* Create the town */
354 if (player_ptr->town_num)
356 /* Reset the buildings */
359 /* Initialize the town */
361 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
363 init_flags = INIT_CREATE_DUNGEON;
365 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
367 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
371 int terrain = wilderness[y][x].terrain;
372 u32b seed = wilderness[y][x].seed;
374 generate_wilderness_area(floor_ptr, terrain, seed, corner);
377 if (!corner && !wilderness[y][x].town)
380 * Place roads in the wilderness
381 * ToDo: make the road a bit more interresting
383 if (wilderness[y][x].road)
385 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
388 if (wilderness[y-1][x].road)
391 for (y1 = 1; y1 < MAX_HGT/2; y1++)
394 floor_ptr->grid_array[y1][x1].feat = feat_floor;
398 if (wilderness[y+1][x].road)
401 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
404 floor_ptr->grid_array[y1][x1].feat = feat_floor;
408 if (wilderness[y][x+1].road)
411 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
414 floor_ptr->grid_array[y1][x1].feat = feat_floor;
418 if (wilderness[y][x-1].road)
421 for (x1 = 1; x1 < MAX_WID/2; x1++)
424 floor_ptr->grid_array[y1][x1].feat = feat_floor;
431 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
432 * 問題なければ'> 0'へ置き換えること
434 bool is_winner = wilderness[y][x].entrance != 0;
435 is_winner &= !wilderness[y][x].town != 0;
436 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
437 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
438 if (!is_winner) return;
440 /* Hack -- Backup the RNG state */
441 u32b state_backup[4];
442 Rand_state_backup(state_backup);
444 /* Hack -- Induce consistant flavors */
445 Rand_state_set(wilderness[y][x].seed);
447 int dy = rand_range(6, floor_ptr->height - 6);
448 int dx = rand_range(6, floor_ptr->width - 6);
450 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
451 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
453 /* Hack -- Restore the RNG state */
454 Rand_state_restore(state_backup);
459 * Border of the wilderness area
461 static border_type border;
465 * Build the wilderness area outside of the town.
466 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
467 * @param creature_ptr プレーヤーへの参照ポインタ
470 void wilderness_gen(player_type *creature_ptr)
473 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
474 floor_ptr->height = MAX_HGT;
475 floor_ptr->width = MAX_WID;
477 /* Assume illegal panel */
478 panel_row_min = floor_ptr->height;
479 panel_col_min = floor_ptr->width;
481 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
482 POSITION x = creature_ptr->wilderness_x;
483 POSITION y = creature_ptr->wilderness_y;
484 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
487 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
489 for (int i = 1; i < MAX_WID - 1; i++)
491 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
495 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
497 for (int i = 1; i < MAX_WID - 1; i++)
499 border.south[i] = floor_ptr->grid_array[1][i].feat;
503 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
505 for (int i = 1; i < MAX_HGT - 1; i++)
507 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
511 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
513 for (int i = 1; i < MAX_HGT - 1; i++)
515 border.east[i] = floor_ptr->grid_array[i][1].feat;
518 /* North west corner */
519 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
520 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
522 /* North east corner */
523 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
524 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
526 /* South west corner */
527 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
528 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
530 /* South east corner */
531 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
532 border.south_east = floor_ptr->grid_array[1][1].feat;
534 /* Create terrain of the current area */
535 generate_area(creature_ptr, y, x, FALSE, FALSE);
537 /* Special boundary walls -- North */
538 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++)
547 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
548 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
551 /* Special boundary walls -- West */
552 for (int i = 0; i < MAX_HGT; i++)
554 floor_ptr->grid_array[i][0].feat = feat_permanent;
555 floor_ptr->grid_array[i][0].mimic = border.west[i];
558 /* Special boundary walls -- East */
559 for (int i = 0; i < MAX_HGT; i++)
561 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
562 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
565 floor_ptr->grid_array[0][0].mimic = border.north_west;
566 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
567 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
568 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
570 /* Light up or darken the area */
571 for (y = 0; y < floor_ptr->height; y++)
573 for (x = 0; x < floor_ptr->width; x++)
576 g_ptr = &floor_ptr->grid_array[y][x];
581 g_ptr->info |= CAVE_GLOW;
583 /* Hack -- Memorize lit grids if allowed */
584 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
588 /* Feature code (applying "mimic" field) */
590 f_ptr = &f_info[get_feat_mimic(g_ptr)];
592 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
593 !have_flag(f_ptr->flags, FF_ENTRANCE))
596 g_ptr->info &= ~(CAVE_GLOW);
598 /* Darken "boring" features */
599 if (!have_flag(f_ptr->flags, FF_REMEMBER))
601 /* Forget the grid */
602 g_ptr->info &= ~(CAVE_MARK);
608 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
610 g_ptr->info |= CAVE_GLOW;
612 /* Hack -- Memorize lit grids if allowed */
613 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
617 if (creature_ptr->teleport_town)
619 for (y = 0; y < floor_ptr->height; y++)
621 for (x = 0; x < floor_ptr->width; x++)
624 g_ptr = &floor_ptr->grid_array[y][x];
626 /* Seeing true feature code (ignore mimic) */
628 f_ptr = &f_info[g_ptr->feat];
630 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
632 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
637 delete_monster_idx(creature_ptr, g_ptr->m_idx);
640 creature_ptr->oldpy = y;
641 creature_ptr->oldpx = x;
645 creature_ptr->teleport_town = FALSE;
647 else if (creature_ptr->leaving_dungeon)
649 for (y = 0; y < floor_ptr->height; y++)
651 for (x = 0; x < floor_ptr->width; x++)
654 g_ptr = &floor_ptr->grid_array[y][x];
656 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
660 delete_monster_idx(creature_ptr, g_ptr->m_idx);
663 creature_ptr->oldpy = y;
664 creature_ptr->oldpx = x;
668 creature_ptr->teleport_town = FALSE;
671 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
672 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
674 /* Make some residents */
675 for (int i = 0; i < lim; i++)
679 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
680 mode |= PM_ALLOW_SLEEP;
682 /* Make a resident */
683 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode);
686 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
687 generate_encounter = FALSE;
689 /* Fill the arrays of floors and walls in the good proportions */
690 set_floor_and_wall(0);
692 /* Set rewarded quests to finished */
693 for (int i = 0; i < max_q_idx; i++)
695 if (quest[i].status == QUEST_STATUS_REWARDED)
696 quest[i].status = QUEST_STATUS_FINISHED;
700 static s16b conv_terrain2feat[MAX_WILDERNESS];
703 * @brief 広域マップの生成(簡易処理版) /
704 * Build the wilderness area. -DG-
707 void wilderness_gen_small(player_type *creature_ptr)
709 /* To prevent stupid things */
710 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
711 for (int i = 0; i < MAX_WID; i++)
713 for (int j = 0; j < MAX_HGT; j++)
715 floor_ptr->grid_array[j][i].feat = feat_permanent;
719 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
722 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
724 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
726 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
728 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
729 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
730 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
734 if (wilderness[j][i].road)
736 floor_ptr->grid_array[j][i].feat = feat_floor;
737 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
741 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
743 floor_ptr->grid_array[j][i].feat = feat_entrance;
744 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
745 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
749 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
750 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
754 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
755 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
757 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
758 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
760 /* Assume illegal panel */
761 panel_row_min = floor_ptr->height;
762 panel_col_min = floor_ptr->width;
764 creature_ptr->x = creature_ptr->wilderness_x;
765 creature_ptr->y = creature_ptr->wilderness_y;
766 creature_ptr->town_num = 0;
770 typedef struct wilderness_grid wilderness_grid;
772 struct wilderness_grid
774 int terrain; /* Terrain type */
775 TOWN_IDX town; /* Town number */
776 DEPTH level; /* Level of the wilderness */
777 byte road; /* Road */
778 char name[32]; /* Name of the town/wilderness */
782 static wilderness_grid w_letter[255];
785 * @brief w_info.txtのデータ解析 /
786 * Parse a sub-file of the "extra info"
787 * @param buf 読み取ったデータ行のバッファ
789 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
791 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
792 * @param y 広域マップの高さを返す参照ポインタ
793 * @param x 広域マップの幅を返す参照ポインタ
796 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
798 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
804 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
817 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
819 int index = zz[0][0];
822 w_letter[index].terrain = atoi(zz[1]);
824 w_letter[index].terrain = 0;
827 w_letter[index].level = (s16b)atoi(zz[2]);
829 w_letter[index].level = 0;
832 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
834 w_letter[index].town = 0;
837 w_letter[index].road = (byte)atoi(zz[4]);
839 w_letter[index].road = 0;
842 strcpy(w_letter[index].name, zz[5]);
844 w_letter[index].name[0] = 0;
849 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
855 /* Process "W:D:<layout> */
856 /* Layout of the wilderness */
862 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
865 wilderness[*y][*x].terrain = w_letter[id].terrain;
866 wilderness[*y][*x].level = w_letter[id].level;
867 wilderness[*y][*x].town = w_letter[id].town;
868 wilderness[*y][*x].road = w_letter[id].road;
869 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
876 /* Process "W:P:<x>:<y> - starting position in the wilderness */
879 bool is_corner = creature_ptr->wilderness_x == 0;
880 is_corner = creature_ptr->wilderness_y == 0;
881 if (!is_corner) break;
883 if (tokenize(buf + 4, 2, zz, 0) != 2)
885 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
888 creature_ptr->wilderness_y = atoi(zz[0]);
889 creature_ptr->wilderness_x = atoi(zz[1]);
891 if ((creature_ptr->wilderness_x < 1) ||
892 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
893 (creature_ptr->wilderness_y < 1) ||
894 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
896 return PARSE_ERROR_OUT_OF_BOUNDS;
903 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
906 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
908 if (!d_info[i].maxdepth) continue;
909 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
910 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
912 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
921 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
922 * Generate the random seeds for the wilderness
925 void seed_wilderness(void)
927 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
929 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
931 wilderness[y][x].seed = randint0(0x10000000);
932 wilderness[y][x].entrance = 0;
939 * Pointer to wilderness_type
941 typedef wilderness_type *wilderness_type_ptr;
944 * @brief ゲーム開始時の荒野初期化メインルーチン /
945 * Initialize wilderness array
948 errr init_wilderness(void)
950 /* Allocate the wilderness (two-dimension array) */
951 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
952 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
954 /* Init the other pointers */
955 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
957 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
960 generate_encounter = FALSE;
966 * @brief 荒野の地勢設定を初期化する /
967 * Initialize wilderness array
968 * @param terrain 初期化したい地勢ID
969 * @param feat_global 基本的な地形ID
970 * @param fmt 地勢内の地形数を参照するための独自フォーマット
973 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
975 /* Begin the varargs stuff */
979 /* Wilderness terrains on global map */
980 conv_terrain2feat[terrain] = feat_global;
982 /* Wilderness terrains on local map */
985 for (concptr p = fmt; *p; p++)
989 plog_fmt("Format error");
993 FEAT_IDX feat = (s16b)va_arg(vp, int);
994 int num = va_arg(vp, int);
997 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
999 terrain_table[terrain][cur] = feat;
1002 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1007 if (cur < MAX_FEAT_IN_TERRAIN)
1009 plog_fmt("Too few parameters");
1017 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1018 * Initialize arrays for wilderness terrains
1021 void init_wilderness_terrains(void)
1023 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1024 feat_permanent, MAX_FEAT_IN_TERRAIN);
1026 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1027 feat_floor, MAX_FEAT_IN_TERRAIN);
1029 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1030 feat_deep_water, 12,
1031 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1033 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1035 feat_shallow_water, 12,
1038 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1040 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1045 feat_shallow_water, 4,
1046 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1048 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1054 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1056 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1062 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1064 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1069 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1071 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1074 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1076 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1077 feat_shallow_lava, 14,
1079 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1081 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1083 feat_shallow_lava, 3,
1085 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1087 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1093 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1098 * @brief 荒野から広域マップへの切り替え処理 /
1099 * Initialize arrays for wilderness terrains
1100 * @param encount 襲撃時TRUE
1101 * @return 切り替えが行われた場合はTRUEを返す。
1103 bool change_wild_mode(player_type *creature_ptr, bool encount)
1105 generate_encounter = encount;
1107 /* It is in the middle of changing map */
1108 if (creature_ptr->leaving) return FALSE;
1110 if (lite_town || vanilla_town)
1112 msg_print(_("荒野なんてない。", "No global map."));
1116 if (creature_ptr->wild_mode)
1118 /* Save the location in the global map */
1119 creature_ptr->wilderness_x = creature_ptr->x;
1120 creature_ptr->wilderness_y = creature_ptr->y;
1122 /* Give first move to the player */
1123 creature_ptr->energy_need = 0;
1125 /* Go back to the ordinary map */
1126 creature_ptr->wild_mode = FALSE;
1127 creature_ptr->leaving = TRUE;
1131 bool have_pet = FALSE;
1132 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1134 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1136 if (!monster_is_valid(m_ptr)) continue;
1137 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1138 if (MON_CSLEEP(m_ptr)) continue;
1139 if (m_ptr->cdis > MAX_SIGHT) continue;
1140 if (!is_hostile(m_ptr)) continue;
1141 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1142 "You cannot enter global map, since there is some monsters nearby!"));
1143 free_turn(creature_ptr);
1149 concptr msg = _("ペットを置いて広域マップに入りますか?",
1150 "Do you leave your pets behind? ");
1152 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1154 free_turn(creature_ptr);
1159 take_turn(creature_ptr, 1000);
1161 /* Remember the position */
1162 creature_ptr->oldpx = creature_ptr->x;
1163 creature_ptr->oldpy = creature_ptr->y;
1165 /* Cancel hex spelling */
1166 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1168 /* Cancel any special action */
1169 set_action(creature_ptr, ACTION_NONE);
1171 /* Go into the global map */
1172 creature_ptr->wild_mode = TRUE;
1173 creature_ptr->leaving = TRUE;