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 "view/display-messages.h"
40 #include "world/world.h"
42 #define MAX_FEAT_IN_TERRAIN 18
47 wilderness_type **wilderness;
49 bool generate_encounter;
52 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
53 * @param feat_type 非一様確率を再現するための要素数100の配列
54 * @param prob 元の確率テーブル
57 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
59 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
61 lim[0] = prob[0].percent;
62 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
63 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
65 for (i = 0; i < 100; i++)
67 while (i == lim[cur]) cur++;
68 feat_type[i] = prob[cur].feat;
74 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
75 * / Fill the arrays of floors and walls in the good proportions
79 void set_floor_and_wall(DUNGEON_IDX type)
81 DUNGEON_IDX cur_type = 255;
85 if (cur_type == type) return;
88 d_ptr = &d_info[type];
90 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
91 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
93 feat_wall_outer = d_ptr->outer_wall;
94 feat_wall_inner = d_ptr->inner_wall;
95 feat_wall_solid = d_ptr->outer_wall;
100 * @brief プラズマフラクタル的地形生成の再帰中間処理
101 * / Helper for plasma generation.
109 * @param depth_max 深みの最大値
112 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)
115 * Average the four corners & perturb it a bit.
116 * tmp is a random int +/- rough
118 FEAT_IDX tmp2 = rough*2 + 1;
119 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
121 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
123 /* Division always rounds down, so we round up again */
124 if (((x1 + x2 + x3 + x4) % 4) > 1)
128 if (avg < 0) avg = 0;
129 if (avg > depth_max) avg = depth_max;
131 /* Set the new value. */
132 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
137 * @brief プラズマフラクタル的地形生成の再帰末端処理
138 * / Helper for plasma generation.
139 * @param x1 中間末端部1の重み
140 * @param x2 中間末端部2の重み
141 * @param x3 中間末端部3の重み
142 * @param xmid 最終末端部座標X
143 * @param ymid 最終末端部座標Y
145 * @param depth_max 深みの最大値
148 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)
151 * Average the three corners & perturb it a bit.
152 * tmp is a random int +/- rough
154 FEAT_IDX tmp2 = rough * 2 + 1;
155 FEAT_IDX tmp = randint0(tmp2) - rough;
157 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
159 /* Division always rounds down, so we round up again */
160 if ((x1 + x2 + x3) % 3) avg++;
163 if (avg < 0) avg = 0;
164 if (avg > depth_max) avg = depth_max;
166 /* Set the new value. */
167 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
172 * @brief プラズマフラクタル的地形生成の開始処理
173 * / Helper for plasma generation.
174 * @param x1 処理範囲の左上X座標
175 * @param y1 処理範囲の左上Y座標
176 * @param x2 処理範囲の右下X座標
177 * @param y2 処理範囲の右下Y座標
178 * @param depth_max 深みの最大値
183 * A generic function to generate the plasma fractal.
184 * Note that it uses ``cave_feat'' as temporary storage.
185 * The values in ``cave_feat'' after this function
186 * are NOT actual features; They are raw heights which
187 * need to be converted to features.
190 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
193 POSITION xmid = (x2 - x1) / 2 + x1;
194 POSITION ymid = (y2 - y1) / 2 + y1;
197 if (x1 + 1 == x2) return;
199 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,
200 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
202 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,
203 xmid, y1, rough, depth_max);
205 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,
206 x2, ymid, rough, depth_max);
208 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,
209 xmid, y2, rough, depth_max);
211 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,
212 x1, ymid, rough, depth_max);
215 /* Recurse the four quadrants */
216 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
217 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
218 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
219 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
224 * The default table in terrain level generation.
226 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
229 * @brief 荒野フロア生成のサブルーチン
230 * @param terrain 荒野地形ID
231 * @param seed 乱数の固定シード
233 * @param corner 広域マップの角部分としての生成ならばTRUE
236 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
238 /* The outer wall is easy */
239 if (terrain == TERRAIN_EDGE)
241 /* Create level background */
242 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
244 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
246 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
253 /* Hack -- Backup the RNG state */
254 u32b state_backup[4];
255 Rand_state_backup(state_backup);
257 /* Hack -- Induce consistant flavors */
258 Rand_state_set(seed);
260 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
263 /* Create level background */
264 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
266 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
268 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
274 * Initialize the four corners
275 * ToDo: calculate the medium height of the adjacent
276 * terrains for every corner.
278 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
279 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
280 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
281 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
283 /* Hack -- only four corners */
286 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
287 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
288 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
289 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];
290 Rand_state_restore(state_backup);
294 /* Hack -- preserve four corners */
295 s16b north_west = floor_ptr->grid_array[1][1].feat;
296 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
297 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
298 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
300 /* x1, y1, x2, y2, num_depths, roughness */
301 FEAT_IDX roughness = 1; /* The roughness of the level. */
302 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
304 /* Hack -- copyback four corners */
305 floor_ptr->grid_array[1][1].feat = north_west;
306 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
307 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
308 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
310 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
312 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
314 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
318 Rand_state_restore(state_backup);
323 * @brief 荒野フロア生成のメインルーチン /
324 * Load a town or generate a terrain level using "plasma" fractals.
325 * @param player_ptr プレーヤーへの参照ポインタ
328 * @param border 広域マップの辺部分としての生成ならばTRUE
329 * @param corner 広域マップの角部分としての生成ならばTRUE
333 * x and y are the coordinates of the area in the wilderness.
334 * Border and corner are optimization flags to speed up the
335 * generation of the fractal terrain.
336 * If border is set then only the border of the terrain should
337 * be generated (for initializing the border structure).
338 * If corner is set then only the corners of the area are needed.
341 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
343 /* Number of the town (if any) */
344 player_ptr->town_num = wilderness[y][x].town;
346 /* Set the base level */
347 floor_type *floor_ptr = player_ptr->current_floor_ptr;
348 floor_ptr->base_level = wilderness[y][x].level;
350 /* Set the dungeon level */
351 floor_ptr->dun_level = 0;
353 /* Set the monster generation level */
354 floor_ptr->monster_level = floor_ptr->base_level;
356 /* Set the object generation level */
357 floor_ptr->object_level = floor_ptr->base_level;
360 /* Create the town */
361 if (player_ptr->town_num)
363 /* Reset the buildings */
366 /* Initialize the town */
368 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
370 init_flags = INIT_CREATE_DUNGEON;
372 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
374 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
378 int terrain = wilderness[y][x].terrain;
379 u32b seed = wilderness[y][x].seed;
381 generate_wilderness_area(floor_ptr, terrain, seed, corner);
384 if (!corner && !wilderness[y][x].town)
387 * Place roads in the wilderness
388 * ToDo: make the road a bit more interresting
390 if (wilderness[y][x].road)
392 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
395 if (wilderness[y-1][x].road)
398 for (y1 = 1; y1 < MAX_HGT/2; y1++)
401 floor_ptr->grid_array[y1][x1].feat = feat_floor;
405 if (wilderness[y+1][x].road)
408 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
411 floor_ptr->grid_array[y1][x1].feat = feat_floor;
415 if (wilderness[y][x+1].road)
418 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
421 floor_ptr->grid_array[y1][x1].feat = feat_floor;
425 if (wilderness[y][x-1].road)
428 for (x1 = 1; x1 < MAX_WID/2; x1++)
431 floor_ptr->grid_array[y1][x1].feat = feat_floor;
438 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
439 * 問題なければ'> 0'へ置き換えること
441 bool is_winner = wilderness[y][x].entrance != 0;
442 is_winner &= !wilderness[y][x].town != 0;
443 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
444 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
445 if (!is_winner) return;
447 /* Hack -- Backup the RNG state */
448 u32b state_backup[4];
449 Rand_state_backup(state_backup);
451 /* Hack -- Induce consistant flavors */
452 Rand_state_set(wilderness[y][x].seed);
454 int dy = rand_range(6, floor_ptr->height - 6);
455 int dx = rand_range(6, floor_ptr->width - 6);
457 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
458 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
460 /* Hack -- Restore the RNG state */
461 Rand_state_restore(state_backup);
466 * Border of the wilderness area
468 static border_type border;
472 * Build the wilderness area outside of the town.
473 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
474 * @param creature_ptr プレーヤーへの参照ポインタ
477 void wilderness_gen(player_type *creature_ptr)
480 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
481 floor_ptr->height = MAX_HGT;
482 floor_ptr->width = MAX_WID;
484 /* Assume illegal panel */
485 panel_row_min = floor_ptr->height;
486 panel_col_min = floor_ptr->width;
488 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
489 POSITION x = creature_ptr->wilderness_x;
490 POSITION y = creature_ptr->wilderness_y;
491 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
494 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
496 for (int i = 1; i < MAX_WID - 1; i++)
498 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
502 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
504 for (int i = 1; i < MAX_WID - 1; i++)
506 border.south[i] = floor_ptr->grid_array[1][i].feat;
510 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
512 for (int i = 1; i < MAX_HGT - 1; i++)
514 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
518 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
520 for (int i = 1; i < MAX_HGT - 1; i++)
522 border.east[i] = floor_ptr->grid_array[i][1].feat;
525 /* North west corner */
526 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
527 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
529 /* North east corner */
530 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
531 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
533 /* South west corner */
534 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
535 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
537 /* South east corner */
538 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
539 border.south_east = floor_ptr->grid_array[1][1].feat;
541 /* Create terrain of the current area */
542 generate_area(creature_ptr, y, x, FALSE, FALSE);
544 /* Special boundary walls -- North */
545 for (int i = 0; i < MAX_WID; i++)
547 floor_ptr->grid_array[0][i].feat = feat_permanent;
548 floor_ptr->grid_array[0][i].mimic = border.north[i];
551 /* Special boundary walls -- South */
552 for (int i = 0; i < MAX_WID; i++)
554 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
555 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
558 /* Special boundary walls -- West */
559 for (int i = 0; i < MAX_HGT; i++)
561 floor_ptr->grid_array[i][0].feat = feat_permanent;
562 floor_ptr->grid_array[i][0].mimic = border.west[i];
565 /* Special boundary walls -- East */
566 for (int i = 0; i < MAX_HGT; i++)
568 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
569 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
572 floor_ptr->grid_array[0][0].mimic = border.north_west;
573 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
574 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
575 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
577 /* Light up or darken the area */
578 for (y = 0; y < floor_ptr->height; y++)
580 for (x = 0; x < floor_ptr->width; x++)
583 g_ptr = &floor_ptr->grid_array[y][x];
588 g_ptr->info |= CAVE_GLOW;
590 /* Hack -- Memorize lit grids if allowed */
591 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
595 /* Feature code (applying "mimic" field) */
597 f_ptr = &f_info[get_feat_mimic(g_ptr)];
599 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
600 !have_flag(f_ptr->flags, FF_ENTRANCE))
603 g_ptr->info &= ~(CAVE_GLOW);
605 /* Darken "boring" features */
606 if (!have_flag(f_ptr->flags, FF_REMEMBER))
608 /* Forget the grid */
609 g_ptr->info &= ~(CAVE_MARK);
615 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
617 g_ptr->info |= CAVE_GLOW;
619 /* Hack -- Memorize lit grids if allowed */
620 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
624 if (creature_ptr->teleport_town)
626 for (y = 0; y < floor_ptr->height; y++)
628 for (x = 0; x < floor_ptr->width; x++)
631 g_ptr = &floor_ptr->grid_array[y][x];
633 /* Seeing true feature code (ignore mimic) */
635 f_ptr = &f_info[g_ptr->feat];
637 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
639 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
644 delete_monster_idx(creature_ptr, g_ptr->m_idx);
647 creature_ptr->oldpy = y;
648 creature_ptr->oldpx = x;
652 creature_ptr->teleport_town = FALSE;
654 else if (creature_ptr->leaving_dungeon)
656 for (y = 0; y < floor_ptr->height; y++)
658 for (x = 0; x < floor_ptr->width; x++)
661 g_ptr = &floor_ptr->grid_array[y][x];
663 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
667 delete_monster_idx(creature_ptr, g_ptr->m_idx);
670 creature_ptr->oldpy = y;
671 creature_ptr->oldpx = x;
675 creature_ptr->teleport_town = FALSE;
678 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
679 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
681 /* Make some residents */
682 for (int i = 0; i < lim; i++)
686 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
687 mode |= PM_ALLOW_SLEEP;
689 /* Make a resident */
690 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
693 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
694 generate_encounter = FALSE;
696 /* Fill the arrays of floors and walls in the good proportions */
697 set_floor_and_wall(0);
699 /* Set rewarded quests to finished */
700 for (int i = 0; i < max_q_idx; i++)
702 if (quest[i].status == QUEST_STATUS_REWARDED)
703 quest[i].status = QUEST_STATUS_FINISHED;
707 static s16b conv_terrain2feat[MAX_WILDERNESS];
710 * @brief 広域マップの生成(簡易処理版) /
711 * Build the wilderness area. -DG-
714 void wilderness_gen_small(player_type *creature_ptr)
716 /* To prevent stupid things */
717 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
718 for (int i = 0; i < MAX_WID; i++)
720 for (int j = 0; j < MAX_HGT; j++)
722 floor_ptr->grid_array[j][i].feat = feat_permanent;
726 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
729 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
731 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
733 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
735 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
736 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
737 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
741 if (wilderness[j][i].road)
743 floor_ptr->grid_array[j][i].feat = feat_floor;
744 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
748 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
750 floor_ptr->grid_array[j][i].feat = feat_entrance;
751 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
752 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
756 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
757 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
761 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
762 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
764 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
765 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
767 /* Assume illegal panel */
768 panel_row_min = floor_ptr->height;
769 panel_col_min = floor_ptr->width;
771 creature_ptr->x = creature_ptr->wilderness_x;
772 creature_ptr->y = creature_ptr->wilderness_y;
773 creature_ptr->town_num = 0;
777 typedef struct wilderness_grid wilderness_grid;
779 struct wilderness_grid
781 int terrain; /* Terrain type */
782 TOWN_IDX town; /* Town number */
783 DEPTH level; /* Level of the wilderness */
784 byte road; /* Road */
785 char name[32]; /* Name of the town/wilderness */
789 static wilderness_grid w_letter[255];
792 * @brief w_info.txtのデータ解析 /
793 * Parse a sub-file of the "extra info"
794 * @param buf 読み取ったデータ行のバッファ
796 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
798 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
799 * @param y 広域マップの高さを返す参照ポインタ
800 * @param x 広域マップの幅を返す参照ポインタ
803 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
805 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
811 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
824 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
826 int index = zz[0][0];
829 w_letter[index].terrain = atoi(zz[1]);
831 w_letter[index].terrain = 0;
834 w_letter[index].level = (s16b)atoi(zz[2]);
836 w_letter[index].level = 0;
839 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
841 w_letter[index].town = 0;
844 w_letter[index].road = (byte)atoi(zz[4]);
846 w_letter[index].road = 0;
849 strcpy(w_letter[index].name, zz[5]);
851 w_letter[index].name[0] = 0;
856 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
862 /* Process "W:D:<layout> */
863 /* Layout of the wilderness */
869 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
872 wilderness[*y][*x].terrain = w_letter[id].terrain;
873 wilderness[*y][*x].level = w_letter[id].level;
874 wilderness[*y][*x].town = w_letter[id].town;
875 wilderness[*y][*x].road = w_letter[id].road;
876 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
883 /* Process "W:P:<x>:<y> - starting position in the wilderness */
886 bool is_corner = creature_ptr->wilderness_x == 0;
887 is_corner = creature_ptr->wilderness_y == 0;
888 if (!is_corner) break;
890 if (tokenize(buf + 4, 2, zz, 0) != 2)
892 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
895 creature_ptr->wilderness_y = atoi(zz[0]);
896 creature_ptr->wilderness_x = atoi(zz[1]);
898 if ((creature_ptr->wilderness_x < 1) ||
899 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
900 (creature_ptr->wilderness_y < 1) ||
901 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
903 return PARSE_ERROR_OUT_OF_BOUNDS;
910 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
913 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
915 if (!d_info[i].maxdepth) continue;
916 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
917 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
919 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
928 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
929 * Generate the random seeds for the wilderness
932 void seed_wilderness(void)
934 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
936 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
938 wilderness[y][x].seed = randint0(0x10000000);
939 wilderness[y][x].entrance = 0;
946 * Pointer to wilderness_type
948 typedef wilderness_type *wilderness_type_ptr;
951 * @brief ゲーム開始時の荒野初期化メインルーチン /
952 * Initialize wilderness array
955 errr init_wilderness(void)
957 /* Allocate the wilderness (two-dimension array) */
958 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
959 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
961 /* Init the other pointers */
962 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
964 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
967 generate_encounter = FALSE;
973 * @brief 荒野の地勢設定を初期化する /
974 * Initialize wilderness array
975 * @param terrain 初期化したい地勢ID
976 * @param feat_global 基本的な地形ID
977 * @param fmt 地勢内の地形数を参照するための独自フォーマット
980 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
982 /* Begin the varargs stuff */
986 /* Wilderness terrains on global map */
987 conv_terrain2feat[terrain] = feat_global;
989 /* Wilderness terrains on local map */
992 for (concptr p = fmt; *p; p++)
996 plog_fmt("Format error");
1000 FEAT_IDX feat = (s16b)va_arg(vp, int);
1001 int num = va_arg(vp, int);
1002 int lim = cur + num;
1004 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1006 terrain_table[terrain][cur] = feat;
1009 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1014 if (cur < MAX_FEAT_IN_TERRAIN)
1016 plog_fmt("Too few parameters");
1024 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1025 * Initialize arrays for wilderness terrains
1028 void init_wilderness_terrains(void)
1030 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1031 feat_permanent, MAX_FEAT_IN_TERRAIN);
1033 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1034 feat_floor, MAX_FEAT_IN_TERRAIN);
1036 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1037 feat_deep_water, 12,
1038 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1040 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1042 feat_shallow_water, 12,
1045 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1047 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1052 feat_shallow_water, 4,
1053 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1055 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1061 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1063 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1069 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1071 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1076 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1078 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1081 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1083 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1084 feat_shallow_lava, 14,
1086 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1088 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1090 feat_shallow_lava, 3,
1092 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1094 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1100 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1105 * @brief 荒野から広域マップへの切り替え処理 /
1106 * Initialize arrays for wilderness terrains
1107 * @param encount 襲撃時TRUE
1108 * @return 切り替えが行われた場合はTRUEを返す。
1110 bool change_wild_mode(player_type *creature_ptr, bool encount)
1112 generate_encounter = encount;
1114 /* It is in the middle of changing map */
1115 if (creature_ptr->leaving) return FALSE;
1117 if (lite_town || vanilla_town)
1119 msg_print(_("荒野なんてない。", "No global map."));
1123 if (creature_ptr->wild_mode)
1125 /* Save the location in the global map */
1126 creature_ptr->wilderness_x = creature_ptr->x;
1127 creature_ptr->wilderness_y = creature_ptr->y;
1129 /* Give first move to the player */
1130 creature_ptr->energy_need = 0;
1132 /* Go back to the ordinary map */
1133 creature_ptr->wild_mode = FALSE;
1134 creature_ptr->leaving = TRUE;
1138 bool have_pet = FALSE;
1139 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1141 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1143 if (!monster_is_valid(m_ptr)) continue;
1144 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1145 if (monster_csleep_remaining(m_ptr)) continue;
1146 if (m_ptr->cdis > MAX_SIGHT) continue;
1147 if (!is_hostile(m_ptr)) continue;
1148 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1149 "You cannot enter global map, since there is some monsters nearby!"));
1150 free_turn(creature_ptr);
1156 concptr msg = _("ペットを置いて広域マップに入りますか?",
1157 "Do you leave your pets behind? ");
1159 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL))
1161 free_turn(creature_ptr);
1166 take_turn(creature_ptr, 1000);
1168 /* Remember the position */
1169 creature_ptr->oldpx = creature_ptr->x;
1170 creature_ptr->oldpy = creature_ptr->y;
1172 /* Cancel hex spelling */
1173 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1175 /* Cancel any special action */
1176 set_action(creature_ptr, ACTION_NONE);
1178 /* Go into the global map */
1179 creature_ptr->wild_mode = TRUE;
1180 creature_ptr->leaving = TRUE;