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/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/parse-error-types.h"
23 #include "io/files-util.h"
24 #include "io/tokenizer.h"
25 #include "main/init.h"
26 #include "monster-floor/monster-generator.h"
27 #include "monster-floor/monster-remover.h"
28 #include "monster-floor/monster-summon.h"
29 #include "monster/monster-status.h"
30 #include "monster/monster-util.h"
31 #include "monster/monster-info.h"
32 #include "monster-floor/place-monster-types.h"
33 #include "player/player-effects.h"
34 #include "player/player-status.h"
35 #include "realm/realm-names-table.h"
36 #include "spell-realm/spells-hex.h"
37 #include "system/system-variables.h"
38 #include "view/display-main-window.h"
39 #include "world/world.h"
41 #define MAX_FEAT_IN_TERRAIN 18
46 wilderness_type **wilderness;
48 bool generate_encounter;
51 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
52 * @param feat_type 非一様確率を再現するための要素数100の配列
53 * @param prob 元の確率テーブル
56 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
58 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
60 lim[0] = prob[0].percent;
61 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
62 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
64 for (i = 0; i < 100; i++)
66 while (i == lim[cur]) cur++;
67 feat_type[i] = prob[cur].feat;
73 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
74 * / Fill the arrays of floors and walls in the good proportions
78 void set_floor_and_wall(DUNGEON_IDX type)
80 DUNGEON_IDX cur_type = 255;
84 if (cur_type == type) return;
87 d_ptr = &d_info[type];
89 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
90 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
92 feat_wall_outer = d_ptr->outer_wall;
93 feat_wall_inner = d_ptr->inner_wall;
94 feat_wall_solid = d_ptr->outer_wall;
99 * @brief プラズマフラクタル的地形生成の再帰中間処理
100 * / Helper for plasma generation.
108 * @param depth_max 深みの最大値
111 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)
114 * Average the four corners & perturb it a bit.
115 * tmp is a random int +/- rough
117 FEAT_IDX tmp2 = rough*2 + 1;
118 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
120 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
122 /* Division always rounds down, so we round up again */
123 if (((x1 + x2 + x3 + x4) % 4) > 1)
127 if (avg < 0) avg = 0;
128 if (avg > depth_max) avg = depth_max;
130 /* Set the new value. */
131 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
136 * @brief プラズマフラクタル的地形生成の再帰末端処理
137 * / Helper for plasma generation.
138 * @param x1 中間末端部1の重み
139 * @param x2 中間末端部2の重み
140 * @param x3 中間末端部3の重み
141 * @param xmid 最終末端部座標X
142 * @param ymid 最終末端部座標Y
144 * @param depth_max 深みの最大値
147 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)
150 * Average the three corners & perturb it a bit.
151 * tmp is a random int +/- rough
153 FEAT_IDX tmp2 = rough * 2 + 1;
154 FEAT_IDX tmp = randint0(tmp2) - rough;
156 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
158 /* Division always rounds down, so we round up again */
159 if ((x1 + x2 + x3) % 3) avg++;
162 if (avg < 0) avg = 0;
163 if (avg > depth_max) avg = depth_max;
165 /* Set the new value. */
166 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
171 * @brief プラズマフラクタル的地形生成の開始処理
172 * / Helper for plasma generation.
173 * @param x1 処理範囲の左上X座標
174 * @param y1 処理範囲の左上Y座標
175 * @param x2 処理範囲の右下X座標
176 * @param y2 処理範囲の右下Y座標
177 * @param depth_max 深みの最大値
182 * A generic function to generate the plasma fractal.
183 * Note that it uses ``cave_feat'' as temporary storage.
184 * The values in ``cave_feat'' after this function
185 * are NOT actual features; They are raw heights which
186 * need to be converted to features.
189 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
192 POSITION xmid = (x2 - x1) / 2 + x1;
193 POSITION ymid = (y2 - y1) / 2 + y1;
196 if (x1 + 1 == x2) return;
198 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,
199 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
201 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,
202 xmid, y1, rough, depth_max);
204 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,
205 x2, ymid, rough, depth_max);
207 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,
208 xmid, y2, rough, depth_max);
210 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,
211 x1, ymid, rough, depth_max);
214 /* Recurse the four quadrants */
215 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
216 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
217 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
218 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
223 * The default table in terrain level generation.
225 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
228 * @brief 荒野フロア生成のサブルーチン
229 * @param terrain 荒野地形ID
230 * @param seed 乱数の固定シード
232 * @param corner 広域マップの角部分としての生成ならばTRUE
235 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
237 /* The outer wall is easy */
238 if (terrain == TERRAIN_EDGE)
240 /* Create level background */
241 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
243 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
245 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
252 /* Hack -- Backup the RNG state */
253 u32b state_backup[4];
254 Rand_state_backup(state_backup);
256 /* Hack -- Induce consistant flavors */
257 Rand_state_set(seed);
259 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
262 /* Create level background */
263 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
265 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
267 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
273 * Initialize the four corners
274 * ToDo: calculate the medium height of the adjacent
275 * terrains for every corner.
277 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
278 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
279 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
280 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
282 /* Hack -- only four corners */
285 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
286 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
287 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
288 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];
289 Rand_state_restore(state_backup);
293 /* Hack -- preserve four corners */
294 s16b north_west = floor_ptr->grid_array[1][1].feat;
295 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
296 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
297 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
299 /* x1, y1, x2, y2, num_depths, roughness */
300 FEAT_IDX roughness = 1; /* The roughness of the level. */
301 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
303 /* Hack -- copyback four corners */
304 floor_ptr->grid_array[1][1].feat = north_west;
305 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
306 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
307 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
309 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
311 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
313 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
317 Rand_state_restore(state_backup);
322 * @brief 荒野フロア生成のメインルーチン /
323 * Load a town or generate a terrain level using "plasma" fractals.
324 * @param player_ptr プレーヤーへの参照ポインタ
327 * @param border 広域マップの辺部分としての生成ならばTRUE
328 * @param corner 広域マップの角部分としての生成ならばTRUE
332 * x and y are the coordinates of the area in the wilderness.
333 * Border and corner are optimization flags to speed up the
334 * generation of the fractal terrain.
335 * If border is set then only the border of the terrain should
336 * be generated (for initializing the border structure).
337 * If corner is set then only the corners of the area are needed.
340 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
342 /* Number of the town (if any) */
343 player_ptr->town_num = wilderness[y][x].town;
345 /* Set the base level */
346 floor_type *floor_ptr = player_ptr->current_floor_ptr;
347 floor_ptr->base_level = wilderness[y][x].level;
349 /* Set the dungeon level */
350 floor_ptr->dun_level = 0;
352 /* Set the monster generation level */
353 floor_ptr->monster_level = floor_ptr->base_level;
355 /* Set the object generation level */
356 floor_ptr->object_level = floor_ptr->base_level;
359 /* Create the town */
360 if (player_ptr->town_num)
362 /* Reset the buildings */
365 /* Initialize the town */
367 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
369 init_flags = INIT_CREATE_DUNGEON;
371 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
373 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
377 int terrain = wilderness[y][x].terrain;
378 u32b seed = wilderness[y][x].seed;
380 generate_wilderness_area(floor_ptr, terrain, seed, corner);
383 if (!corner && !wilderness[y][x].town)
386 * Place roads in the wilderness
387 * ToDo: make the road a bit more interresting
389 if (wilderness[y][x].road)
391 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
394 if (wilderness[y-1][x].road)
397 for (y1 = 1; y1 < MAX_HGT/2; y1++)
400 floor_ptr->grid_array[y1][x1].feat = feat_floor;
404 if (wilderness[y+1][x].road)
407 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
410 floor_ptr->grid_array[y1][x1].feat = feat_floor;
414 if (wilderness[y][x+1].road)
417 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
420 floor_ptr->grid_array[y1][x1].feat = feat_floor;
424 if (wilderness[y][x-1].road)
427 for (x1 = 1; x1 < MAX_WID/2; x1++)
430 floor_ptr->grid_array[y1][x1].feat = feat_floor;
437 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
438 * 問題なければ'> 0'へ置き換えること
440 bool is_winner = wilderness[y][x].entrance != 0;
441 is_winner &= !wilderness[y][x].town != 0;
442 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
443 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
444 if (!is_winner) return;
446 /* Hack -- Backup the RNG state */
447 u32b state_backup[4];
448 Rand_state_backup(state_backup);
450 /* Hack -- Induce consistant flavors */
451 Rand_state_set(wilderness[y][x].seed);
453 int dy = rand_range(6, floor_ptr->height - 6);
454 int dx = rand_range(6, floor_ptr->width - 6);
456 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
457 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
459 /* Hack -- Restore the RNG state */
460 Rand_state_restore(state_backup);
465 * Border of the wilderness area
467 static border_type border;
471 * Build the wilderness area outside of the town.
472 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
473 * @param creature_ptr プレーヤーへの参照ポインタ
476 void wilderness_gen(player_type *creature_ptr)
479 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
480 floor_ptr->height = MAX_HGT;
481 floor_ptr->width = MAX_WID;
483 /* Assume illegal panel */
484 panel_row_min = floor_ptr->height;
485 panel_col_min = floor_ptr->width;
487 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
488 POSITION x = creature_ptr->wilderness_x;
489 POSITION y = creature_ptr->wilderness_y;
490 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
493 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
495 for (int i = 1; i < MAX_WID - 1; i++)
497 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
501 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
503 for (int i = 1; i < MAX_WID - 1; i++)
505 border.south[i] = floor_ptr->grid_array[1][i].feat;
509 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
511 for (int i = 1; i < MAX_HGT - 1; i++)
513 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
517 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
519 for (int i = 1; i < MAX_HGT - 1; i++)
521 border.east[i] = floor_ptr->grid_array[i][1].feat;
524 /* North west corner */
525 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
526 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
528 /* North east corner */
529 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
530 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
532 /* South west corner */
533 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
534 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
536 /* South east corner */
537 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
538 border.south_east = floor_ptr->grid_array[1][1].feat;
540 /* Create terrain of the current area */
541 generate_area(creature_ptr, y, x, FALSE, FALSE);
543 /* Special boundary walls -- North */
544 for (int i = 0; i < MAX_WID; i++)
546 floor_ptr->grid_array[0][i].feat = feat_permanent;
547 floor_ptr->grid_array[0][i].mimic = border.north[i];
550 /* Special boundary walls -- South */
551 for (int i = 0; i < MAX_WID; i++)
553 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
554 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
557 /* Special boundary walls -- West */
558 for (int i = 0; i < MAX_HGT; i++)
560 floor_ptr->grid_array[i][0].feat = feat_permanent;
561 floor_ptr->grid_array[i][0].mimic = border.west[i];
564 /* Special boundary walls -- East */
565 for (int i = 0; i < MAX_HGT; i++)
567 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
568 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
571 floor_ptr->grid_array[0][0].mimic = border.north_west;
572 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
573 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
574 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
576 /* Light up or darken the area */
577 for (y = 0; y < floor_ptr->height; y++)
579 for (x = 0; x < floor_ptr->width; x++)
582 g_ptr = &floor_ptr->grid_array[y][x];
587 g_ptr->info |= CAVE_GLOW;
589 /* Hack -- Memorize lit grids if allowed */
590 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
594 /* Feature code (applying "mimic" field) */
596 f_ptr = &f_info[get_feat_mimic(g_ptr)];
598 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
599 !have_flag(f_ptr->flags, FF_ENTRANCE))
602 g_ptr->info &= ~(CAVE_GLOW);
604 /* Darken "boring" features */
605 if (!have_flag(f_ptr->flags, FF_REMEMBER))
607 /* Forget the grid */
608 g_ptr->info &= ~(CAVE_MARK);
614 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
616 g_ptr->info |= CAVE_GLOW;
618 /* Hack -- Memorize lit grids if allowed */
619 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
623 if (creature_ptr->teleport_town)
625 for (y = 0; y < floor_ptr->height; y++)
627 for (x = 0; x < floor_ptr->width; x++)
630 g_ptr = &floor_ptr->grid_array[y][x];
632 /* Seeing true feature code (ignore mimic) */
634 f_ptr = &f_info[g_ptr->feat];
636 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
638 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
643 delete_monster_idx(creature_ptr, g_ptr->m_idx);
646 creature_ptr->oldpy = y;
647 creature_ptr->oldpx = x;
651 creature_ptr->teleport_town = FALSE;
653 else if (creature_ptr->leaving_dungeon)
655 for (y = 0; y < floor_ptr->height; y++)
657 for (x = 0; x < floor_ptr->width; x++)
660 g_ptr = &floor_ptr->grid_array[y][x];
662 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
666 delete_monster_idx(creature_ptr, g_ptr->m_idx);
669 creature_ptr->oldpy = y;
670 creature_ptr->oldpx = x;
674 creature_ptr->teleport_town = FALSE;
677 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
678 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
680 /* Make some residents */
681 for (int i = 0; i < lim; i++)
685 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
686 mode |= PM_ALLOW_SLEEP;
688 /* Make a resident */
689 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
692 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
693 generate_encounter = FALSE;
695 /* Fill the arrays of floors and walls in the good proportions */
696 set_floor_and_wall(0);
698 /* Set rewarded quests to finished */
699 for (int i = 0; i < max_q_idx; i++)
701 if (quest[i].status == QUEST_STATUS_REWARDED)
702 quest[i].status = QUEST_STATUS_FINISHED;
706 static s16b conv_terrain2feat[MAX_WILDERNESS];
709 * @brief 広域マップの生成(簡易処理版) /
710 * Build the wilderness area. -DG-
713 void wilderness_gen_small(player_type *creature_ptr)
715 /* To prevent stupid things */
716 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
717 for (int i = 0; i < MAX_WID; i++)
719 for (int j = 0; j < MAX_HGT; j++)
721 floor_ptr->grid_array[j][i].feat = feat_permanent;
725 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
728 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
730 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
732 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
734 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
735 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
736 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
740 if (wilderness[j][i].road)
742 floor_ptr->grid_array[j][i].feat = feat_floor;
743 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
747 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
749 floor_ptr->grid_array[j][i].feat = feat_entrance;
750 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
751 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
755 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
756 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
760 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
761 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
763 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
764 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
766 /* Assume illegal panel */
767 panel_row_min = floor_ptr->height;
768 panel_col_min = floor_ptr->width;
770 creature_ptr->x = creature_ptr->wilderness_x;
771 creature_ptr->y = creature_ptr->wilderness_y;
772 creature_ptr->town_num = 0;
776 typedef struct wilderness_grid wilderness_grid;
778 struct wilderness_grid
780 int terrain; /* Terrain type */
781 TOWN_IDX town; /* Town number */
782 DEPTH level; /* Level of the wilderness */
783 byte road; /* Road */
784 char name[32]; /* Name of the town/wilderness */
788 static wilderness_grid w_letter[255];
791 * @brief w_info.txtのデータ解析 /
792 * Parse a sub-file of the "extra info"
793 * @param buf 読み取ったデータ行のバッファ
795 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
797 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
798 * @param y 広域マップの高さを返す参照ポインタ
799 * @param x 広域マップの幅を返す参照ポインタ
802 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
804 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
810 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
823 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
825 int index = zz[0][0];
828 w_letter[index].terrain = atoi(zz[1]);
830 w_letter[index].terrain = 0;
833 w_letter[index].level = (s16b)atoi(zz[2]);
835 w_letter[index].level = 0;
838 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
840 w_letter[index].town = 0;
843 w_letter[index].road = (byte)atoi(zz[4]);
845 w_letter[index].road = 0;
848 strcpy(w_letter[index].name, zz[5]);
850 w_letter[index].name[0] = 0;
855 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
861 /* Process "W:D:<layout> */
862 /* Layout of the wilderness */
868 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
871 wilderness[*y][*x].terrain = w_letter[id].terrain;
872 wilderness[*y][*x].level = w_letter[id].level;
873 wilderness[*y][*x].town = w_letter[id].town;
874 wilderness[*y][*x].road = w_letter[id].road;
875 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
882 /* Process "W:P:<x>:<y> - starting position in the wilderness */
885 bool is_corner = creature_ptr->wilderness_x == 0;
886 is_corner = creature_ptr->wilderness_y == 0;
887 if (!is_corner) break;
889 if (tokenize(buf + 4, 2, zz, 0) != 2)
891 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
894 creature_ptr->wilderness_y = atoi(zz[0]);
895 creature_ptr->wilderness_x = atoi(zz[1]);
897 if ((creature_ptr->wilderness_x < 1) ||
898 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
899 (creature_ptr->wilderness_y < 1) ||
900 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
902 return PARSE_ERROR_OUT_OF_BOUNDS;
909 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
912 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
914 if (!d_info[i].maxdepth) continue;
915 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
916 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
918 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
927 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
928 * Generate the random seeds for the wilderness
931 void seed_wilderness(void)
933 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
935 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
937 wilderness[y][x].seed = randint0(0x10000000);
938 wilderness[y][x].entrance = 0;
945 * Pointer to wilderness_type
947 typedef wilderness_type *wilderness_type_ptr;
950 * @brief ゲーム開始時の荒野初期化メインルーチン /
951 * Initialize wilderness array
954 errr init_wilderness(void)
956 /* Allocate the wilderness (two-dimension array) */
957 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
958 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
960 /* Init the other pointers */
961 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
963 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
966 generate_encounter = FALSE;
972 * @brief 荒野の地勢設定を初期化する /
973 * Initialize wilderness array
974 * @param terrain 初期化したい地勢ID
975 * @param feat_global 基本的な地形ID
976 * @param fmt 地勢内の地形数を参照するための独自フォーマット
979 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
981 /* Begin the varargs stuff */
985 /* Wilderness terrains on global map */
986 conv_terrain2feat[terrain] = feat_global;
988 /* Wilderness terrains on local map */
991 for (concptr p = fmt; *p; p++)
995 plog_fmt("Format error");
999 FEAT_IDX feat = (s16b)va_arg(vp, int);
1000 int num = va_arg(vp, int);
1001 int lim = cur + num;
1003 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1005 terrain_table[terrain][cur] = feat;
1008 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1013 if (cur < MAX_FEAT_IN_TERRAIN)
1015 plog_fmt("Too few parameters");
1023 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1024 * Initialize arrays for wilderness terrains
1027 void init_wilderness_terrains(void)
1029 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1030 feat_permanent, MAX_FEAT_IN_TERRAIN);
1032 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1033 feat_floor, MAX_FEAT_IN_TERRAIN);
1035 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1036 feat_deep_water, 12,
1037 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1039 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1041 feat_shallow_water, 12,
1044 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1046 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1051 feat_shallow_water, 4,
1052 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1054 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1060 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1062 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1068 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1070 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1075 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1077 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1080 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1082 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1083 feat_shallow_lava, 14,
1085 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1087 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1089 feat_shallow_lava, 3,
1091 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1093 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1099 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1104 * @brief 荒野から広域マップへの切り替え処理 /
1105 * Initialize arrays for wilderness terrains
1106 * @param encount 襲撃時TRUE
1107 * @return 切り替えが行われた場合はTRUEを返す。
1109 bool change_wild_mode(player_type *creature_ptr, bool encount)
1111 generate_encounter = encount;
1113 /* It is in the middle of changing map */
1114 if (creature_ptr->leaving) return FALSE;
1116 if (lite_town || vanilla_town)
1118 msg_print(_("荒野なんてない。", "No global map."));
1122 if (creature_ptr->wild_mode)
1124 /* Save the location in the global map */
1125 creature_ptr->wilderness_x = creature_ptr->x;
1126 creature_ptr->wilderness_y = creature_ptr->y;
1128 /* Give first move to the player */
1129 creature_ptr->energy_need = 0;
1131 /* Go back to the ordinary map */
1132 creature_ptr->wild_mode = FALSE;
1133 creature_ptr->leaving = TRUE;
1137 bool have_pet = FALSE;
1138 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1140 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1142 if (!monster_is_valid(m_ptr)) continue;
1143 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1144 if (monster_csleep_remaining(m_ptr)) continue;
1145 if (m_ptr->cdis > MAX_SIGHT) continue;
1146 if (!is_hostile(m_ptr)) continue;
1147 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1148 "You cannot enter global map, since there is some monsters nearby!"));
1149 free_turn(creature_ptr);
1155 concptr msg = _("ペットを置いて広域マップに入りますか?",
1156 "Do you leave your pets behind? ");
1158 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL))
1160 free_turn(creature_ptr);
1165 take_turn(creature_ptr, 1000);
1167 /* Remember the position */
1168 creature_ptr->oldpx = creature_ptr->x;
1169 creature_ptr->oldpy = creature_ptr->y;
1171 /* Cancel hex spelling */
1172 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1174 /* Cancel any special action */
1175 set_action(creature_ptr, ACTION_NONE);
1177 /* Go into the global map */
1178 creature_ptr->wild_mode = TRUE;
1179 creature_ptr->leaving = TRUE;