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 "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-remover.h"
25 #include "monster/monster-status.h"
26 #include "monster/monster-util.h"
27 #include "monster/monster-info.h"
28 #include "monster/monster2.h"
29 #include "monster/place-monster-types.h"
30 #include "player/player-effects.h"
31 #include "player/player-status.h"
32 #include "realm/realm-names-table.h"
33 #include "spell-realm/spells-hex.h"
34 #include "system/system-variables.h"
35 #include "view/display-main-window.h"
36 #include "world/world.h"
38 #define MAX_FEAT_IN_TERRAIN 18
43 wilderness_type **wilderness;
45 bool generate_encounter;
48 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
49 * @param feat_type 非一様確率を再現するための要素数100の配列
50 * @param prob 元の確率テーブル
53 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
55 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
57 lim[0] = prob[0].percent;
58 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
59 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
61 for (i = 0; i < 100; i++)
63 while (i == lim[cur]) cur++;
64 feat_type[i] = prob[cur].feat;
70 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
71 * / Fill the arrays of floors and walls in the good proportions
75 void set_floor_and_wall(DUNGEON_IDX type)
77 DUNGEON_IDX cur_type = 255;
81 if (cur_type == type) return;
84 d_ptr = &d_info[type];
86 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
87 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
89 feat_wall_outer = d_ptr->outer_wall;
90 feat_wall_inner = d_ptr->inner_wall;
91 feat_wall_solid = d_ptr->outer_wall;
96 * @brief プラズマフラクタル的地形生成の再帰中間処理
97 * / Helper for plasma generation.
105 * @param depth_max 深みの最大値
108 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)
111 * Average the four corners & perturb it a bit.
112 * tmp is a random int +/- rough
114 FEAT_IDX tmp2 = rough*2 + 1;
115 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
117 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
119 /* Division always rounds down, so we round up again */
120 if (((x1 + x2 + x3 + x4) % 4) > 1)
124 if (avg < 0) avg = 0;
125 if (avg > depth_max) avg = depth_max;
127 /* Set the new value. */
128 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
133 * @brief プラズマフラクタル的地形生成の再帰末端処理
134 * / Helper for plasma generation.
135 * @param x1 中間末端部1の重み
136 * @param x2 中間末端部2の重み
137 * @param x3 中間末端部3の重み
138 * @param xmid 最終末端部座標X
139 * @param ymid 最終末端部座標Y
141 * @param depth_max 深みの最大値
144 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)
147 * Average the three corners & perturb it a bit.
148 * tmp is a random int +/- rough
150 FEAT_IDX tmp2 = rough * 2 + 1;
151 FEAT_IDX tmp = randint0(tmp2) - rough;
153 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
155 /* Division always rounds down, so we round up again */
156 if ((x1 + x2 + x3) % 3) avg++;
159 if (avg < 0) avg = 0;
160 if (avg > depth_max) avg = depth_max;
162 /* Set the new value. */
163 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
168 * @brief プラズマフラクタル的地形生成の開始処理
169 * / Helper for plasma generation.
170 * @param x1 処理範囲の左上X座標
171 * @param y1 処理範囲の左上Y座標
172 * @param x2 処理範囲の右下X座標
173 * @param y2 処理範囲の右下Y座標
174 * @param depth_max 深みの最大値
179 * A generic function to generate the plasma fractal.
180 * Note that it uses ``cave_feat'' as temporary storage.
181 * The values in ``cave_feat'' after this function
182 * are NOT actual features; They are raw heights which
183 * need to be converted to features.
186 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
189 POSITION xmid = (x2 - x1) / 2 + x1;
190 POSITION ymid = (y2 - y1) / 2 + y1;
193 if (x1 + 1 == x2) return;
195 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,
196 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
198 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,
199 xmid, y1, rough, depth_max);
201 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,
202 x2, ymid, rough, depth_max);
204 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,
205 xmid, y2, rough, depth_max);
207 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,
208 x1, ymid, rough, depth_max);
211 /* Recurse the four quadrants */
212 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
213 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
214 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
215 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
220 * The default table in terrain level generation.
222 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
225 * @brief 荒野フロア生成のサブルーチン
226 * @param terrain 荒野地形ID
227 * @param seed 乱数の固定シード
229 * @param corner 広域マップの角部分としての生成ならばTRUE
232 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
234 /* The outer wall is easy */
235 if (terrain == TERRAIN_EDGE)
237 /* Create level background */
238 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
240 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
242 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
249 /* Hack -- Backup the RNG state */
250 u32b state_backup[4];
251 Rand_state_backup(state_backup);
253 /* Hack -- Induce consistant flavors */
254 Rand_state_set(seed);
256 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
259 /* Create level background */
260 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
262 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
264 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
270 * Initialize the four corners
271 * ToDo: calculate the medium height of the adjacent
272 * terrains for every corner.
274 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
275 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
276 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
277 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
279 /* Hack -- only four corners */
282 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
283 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
284 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
285 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];
286 Rand_state_restore(state_backup);
290 /* Hack -- preserve four corners */
291 s16b north_west = floor_ptr->grid_array[1][1].feat;
292 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
293 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
294 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
296 /* x1, y1, x2, y2, num_depths, roughness */
297 FEAT_IDX roughness = 1; /* The roughness of the level. */
298 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
300 /* Hack -- copyback four corners */
301 floor_ptr->grid_array[1][1].feat = north_west;
302 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
303 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
304 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
306 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
308 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
310 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
314 Rand_state_restore(state_backup);
319 * @brief 荒野フロア生成のメインルーチン /
320 * Load a town or generate a terrain level using "plasma" fractals.
321 * @param player_ptr プレーヤーへの参照ポインタ
324 * @param border 広域マップの辺部分としての生成ならばTRUE
325 * @param corner 広域マップの角部分としての生成ならばTRUE
329 * x and y are the coordinates of the area in the wilderness.
330 * Border and corner are optimization flags to speed up the
331 * generation of the fractal terrain.
332 * If border is set then only the border of the terrain should
333 * be generated (for initializing the border structure).
334 * If corner is set then only the corners of the area are needed.
337 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
339 /* Number of the town (if any) */
340 player_ptr->town_num = wilderness[y][x].town;
342 /* Set the base level */
343 floor_type *floor_ptr = player_ptr->current_floor_ptr;
344 floor_ptr->base_level = wilderness[y][x].level;
346 /* Set the dungeon level */
347 floor_ptr->dun_level = 0;
349 /* Set the monster generation level */
350 floor_ptr->monster_level = floor_ptr->base_level;
352 /* Set the object generation level */
353 floor_ptr->object_level = floor_ptr->base_level;
356 /* Create the town */
357 if (player_ptr->town_num)
359 /* Reset the buildings */
362 /* Initialize the town */
364 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
366 init_flags = INIT_CREATE_DUNGEON;
368 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
370 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
374 int terrain = wilderness[y][x].terrain;
375 u32b seed = wilderness[y][x].seed;
377 generate_wilderness_area(floor_ptr, terrain, seed, corner);
380 if (!corner && !wilderness[y][x].town)
383 * Place roads in the wilderness
384 * ToDo: make the road a bit more interresting
386 if (wilderness[y][x].road)
388 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
391 if (wilderness[y-1][x].road)
394 for (y1 = 1; y1 < MAX_HGT/2; y1++)
397 floor_ptr->grid_array[y1][x1].feat = feat_floor;
401 if (wilderness[y+1][x].road)
404 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
407 floor_ptr->grid_array[y1][x1].feat = feat_floor;
411 if (wilderness[y][x+1].road)
414 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
417 floor_ptr->grid_array[y1][x1].feat = feat_floor;
421 if (wilderness[y][x-1].road)
424 for (x1 = 1; x1 < MAX_WID/2; x1++)
427 floor_ptr->grid_array[y1][x1].feat = feat_floor;
434 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
435 * 問題なければ'> 0'へ置き換えること
437 bool is_winner = wilderness[y][x].entrance != 0;
438 is_winner &= !wilderness[y][x].town != 0;
439 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
440 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
441 if (!is_winner) return;
443 /* Hack -- Backup the RNG state */
444 u32b state_backup[4];
445 Rand_state_backup(state_backup);
447 /* Hack -- Induce consistant flavors */
448 Rand_state_set(wilderness[y][x].seed);
450 int dy = rand_range(6, floor_ptr->height - 6);
451 int dx = rand_range(6, floor_ptr->width - 6);
453 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
454 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
456 /* Hack -- Restore the RNG state */
457 Rand_state_restore(state_backup);
462 * Border of the wilderness area
464 static border_type border;
468 * Build the wilderness area outside of the town.
469 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
470 * @param creature_ptr プレーヤーへの参照ポインタ
473 void wilderness_gen(player_type *creature_ptr)
476 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
477 floor_ptr->height = MAX_HGT;
478 floor_ptr->width = MAX_WID;
480 /* Assume illegal panel */
481 panel_row_min = floor_ptr->height;
482 panel_col_min = floor_ptr->width;
484 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
485 POSITION x = creature_ptr->wilderness_x;
486 POSITION y = creature_ptr->wilderness_y;
487 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
490 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
492 for (int i = 1; i < MAX_WID - 1; i++)
494 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
498 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
500 for (int i = 1; i < MAX_WID - 1; i++)
502 border.south[i] = floor_ptr->grid_array[1][i].feat;
506 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
508 for (int i = 1; i < MAX_HGT - 1; i++)
510 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
514 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
516 for (int i = 1; i < MAX_HGT - 1; i++)
518 border.east[i] = floor_ptr->grid_array[i][1].feat;
521 /* North west corner */
522 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
523 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
525 /* North east corner */
526 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
527 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
529 /* South west corner */
530 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
531 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
533 /* South east corner */
534 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
535 border.south_east = floor_ptr->grid_array[1][1].feat;
537 /* Create terrain of the current area */
538 generate_area(creature_ptr, y, x, FALSE, FALSE);
540 /* Special boundary walls -- North */
541 for (int i = 0; i < MAX_WID; i++)
543 floor_ptr->grid_array[0][i].feat = feat_permanent;
544 floor_ptr->grid_array[0][i].mimic = border.north[i];
547 /* Special boundary walls -- South */
548 for (int i = 0; i < MAX_WID; i++)
550 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
551 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
554 /* Special boundary walls -- West */
555 for (int i = 0; i < MAX_HGT; i++)
557 floor_ptr->grid_array[i][0].feat = feat_permanent;
558 floor_ptr->grid_array[i][0].mimic = border.west[i];
561 /* Special boundary walls -- East */
562 for (int i = 0; i < MAX_HGT; i++)
564 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
565 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
568 floor_ptr->grid_array[0][0].mimic = border.north_west;
569 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
570 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
571 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
573 /* Light up or darken the area */
574 for (y = 0; y < floor_ptr->height; y++)
576 for (x = 0; x < floor_ptr->width; x++)
579 g_ptr = &floor_ptr->grid_array[y][x];
584 g_ptr->info |= CAVE_GLOW;
586 /* Hack -- Memorize lit grids if allowed */
587 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
591 /* Feature code (applying "mimic" field) */
593 f_ptr = &f_info[get_feat_mimic(g_ptr)];
595 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
596 !have_flag(f_ptr->flags, FF_ENTRANCE))
599 g_ptr->info &= ~(CAVE_GLOW);
601 /* Darken "boring" features */
602 if (!have_flag(f_ptr->flags, FF_REMEMBER))
604 /* Forget the grid */
605 g_ptr->info &= ~(CAVE_MARK);
611 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
613 g_ptr->info |= CAVE_GLOW;
615 /* Hack -- Memorize lit grids if allowed */
616 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
620 if (creature_ptr->teleport_town)
622 for (y = 0; y < floor_ptr->height; y++)
624 for (x = 0; x < floor_ptr->width; x++)
627 g_ptr = &floor_ptr->grid_array[y][x];
629 /* Seeing true feature code (ignore mimic) */
631 f_ptr = &f_info[g_ptr->feat];
633 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
635 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
640 delete_monster_idx(creature_ptr, g_ptr->m_idx);
643 creature_ptr->oldpy = y;
644 creature_ptr->oldpx = x;
648 creature_ptr->teleport_town = FALSE;
650 else if (creature_ptr->leaving_dungeon)
652 for (y = 0; y < floor_ptr->height; y++)
654 for (x = 0; x < floor_ptr->width; x++)
657 g_ptr = &floor_ptr->grid_array[y][x];
659 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
663 delete_monster_idx(creature_ptr, g_ptr->m_idx);
666 creature_ptr->oldpy = y;
667 creature_ptr->oldpx = x;
671 creature_ptr->teleport_town = FALSE;
674 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
675 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
677 /* Make some residents */
678 for (int i = 0; i < lim; i++)
682 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
683 mode |= PM_ALLOW_SLEEP;
685 /* Make a resident */
686 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode);
689 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
690 generate_encounter = FALSE;
692 /* Fill the arrays of floors and walls in the good proportions */
693 set_floor_and_wall(0);
695 /* Set rewarded quests to finished */
696 for (int i = 0; i < max_q_idx; i++)
698 if (quest[i].status == QUEST_STATUS_REWARDED)
699 quest[i].status = QUEST_STATUS_FINISHED;
703 static s16b conv_terrain2feat[MAX_WILDERNESS];
706 * @brief 広域マップの生成(簡易処理版) /
707 * Build the wilderness area. -DG-
710 void wilderness_gen_small(player_type *creature_ptr)
712 /* To prevent stupid things */
713 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
714 for (int i = 0; i < MAX_WID; i++)
716 for (int j = 0; j < MAX_HGT; j++)
718 floor_ptr->grid_array[j][i].feat = feat_permanent;
722 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
725 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
727 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
729 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
731 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
732 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
733 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
737 if (wilderness[j][i].road)
739 floor_ptr->grid_array[j][i].feat = feat_floor;
740 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
744 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
746 floor_ptr->grid_array[j][i].feat = feat_entrance;
747 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
748 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
752 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
753 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
757 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
758 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
760 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
761 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
763 /* Assume illegal panel */
764 panel_row_min = floor_ptr->height;
765 panel_col_min = floor_ptr->width;
767 creature_ptr->x = creature_ptr->wilderness_x;
768 creature_ptr->y = creature_ptr->wilderness_y;
769 creature_ptr->town_num = 0;
773 typedef struct wilderness_grid wilderness_grid;
775 struct wilderness_grid
777 int terrain; /* Terrain type */
778 TOWN_IDX town; /* Town number */
779 DEPTH level; /* Level of the wilderness */
780 byte road; /* Road */
781 char name[32]; /* Name of the town/wilderness */
785 static wilderness_grid w_letter[255];
788 * @brief w_info.txtのデータ解析 /
789 * Parse a sub-file of the "extra info"
790 * @param buf 読み取ったデータ行のバッファ
792 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
794 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
795 * @param y 広域マップの高さを返す参照ポインタ
796 * @param x 広域マップの幅を返す参照ポインタ
799 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
801 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
807 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
820 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
822 int index = zz[0][0];
825 w_letter[index].terrain = atoi(zz[1]);
827 w_letter[index].terrain = 0;
830 w_letter[index].level = (s16b)atoi(zz[2]);
832 w_letter[index].level = 0;
835 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
837 w_letter[index].town = 0;
840 w_letter[index].road = (byte)atoi(zz[4]);
842 w_letter[index].road = 0;
845 strcpy(w_letter[index].name, zz[5]);
847 w_letter[index].name[0] = 0;
852 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
858 /* Process "W:D:<layout> */
859 /* Layout of the wilderness */
865 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
868 wilderness[*y][*x].terrain = w_letter[id].terrain;
869 wilderness[*y][*x].level = w_letter[id].level;
870 wilderness[*y][*x].town = w_letter[id].town;
871 wilderness[*y][*x].road = w_letter[id].road;
872 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
879 /* Process "W:P:<x>:<y> - starting position in the wilderness */
882 bool is_corner = creature_ptr->wilderness_x == 0;
883 is_corner = creature_ptr->wilderness_y == 0;
884 if (!is_corner) break;
886 if (tokenize(buf + 4, 2, zz, 0) != 2)
888 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
891 creature_ptr->wilderness_y = atoi(zz[0]);
892 creature_ptr->wilderness_x = atoi(zz[1]);
894 if ((creature_ptr->wilderness_x < 1) ||
895 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
896 (creature_ptr->wilderness_y < 1) ||
897 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
899 return PARSE_ERROR_OUT_OF_BOUNDS;
906 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
909 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
911 if (!d_info[i].maxdepth) continue;
912 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
913 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
915 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
924 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
925 * Generate the random seeds for the wilderness
928 void seed_wilderness(void)
930 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
932 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
934 wilderness[y][x].seed = randint0(0x10000000);
935 wilderness[y][x].entrance = 0;
942 * Pointer to wilderness_type
944 typedef wilderness_type *wilderness_type_ptr;
947 * @brief ゲーム開始時の荒野初期化メインルーチン /
948 * Initialize wilderness array
951 errr init_wilderness(void)
953 /* Allocate the wilderness (two-dimension array) */
954 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
955 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
957 /* Init the other pointers */
958 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
960 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
963 generate_encounter = FALSE;
969 * @brief 荒野の地勢設定を初期化する /
970 * Initialize wilderness array
971 * @param terrain 初期化したい地勢ID
972 * @param feat_global 基本的な地形ID
973 * @param fmt 地勢内の地形数を参照するための独自フォーマット
976 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
978 /* Begin the varargs stuff */
982 /* Wilderness terrains on global map */
983 conv_terrain2feat[terrain] = feat_global;
985 /* Wilderness terrains on local map */
988 for (concptr p = fmt; *p; p++)
992 plog_fmt("Format error");
996 FEAT_IDX feat = (s16b)va_arg(vp, int);
997 int num = va_arg(vp, int);
1000 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1002 terrain_table[terrain][cur] = feat;
1005 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1010 if (cur < MAX_FEAT_IN_TERRAIN)
1012 plog_fmt("Too few parameters");
1020 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1021 * Initialize arrays for wilderness terrains
1024 void init_wilderness_terrains(void)
1026 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1027 feat_permanent, MAX_FEAT_IN_TERRAIN);
1029 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1030 feat_floor, MAX_FEAT_IN_TERRAIN);
1032 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1033 feat_deep_water, 12,
1034 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1036 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1038 feat_shallow_water, 12,
1041 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1043 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1048 feat_shallow_water, 4,
1049 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1051 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1057 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1059 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1065 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1067 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1072 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1074 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1077 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1079 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1080 feat_shallow_lava, 14,
1082 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1084 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1086 feat_shallow_lava, 3,
1088 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1090 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1096 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1101 * @brief 荒野から広域マップへの切り替え処理 /
1102 * Initialize arrays for wilderness terrains
1103 * @param encount 襲撃時TRUE
1104 * @return 切り替えが行われた場合はTRUEを返す。
1106 bool change_wild_mode(player_type *creature_ptr, bool encount)
1108 generate_encounter = encount;
1110 /* It is in the middle of changing map */
1111 if (creature_ptr->leaving) return FALSE;
1113 if (lite_town || vanilla_town)
1115 msg_print(_("荒野なんてない。", "No global map."));
1119 if (creature_ptr->wild_mode)
1121 /* Save the location in the global map */
1122 creature_ptr->wilderness_x = creature_ptr->x;
1123 creature_ptr->wilderness_y = creature_ptr->y;
1125 /* Give first move to the player */
1126 creature_ptr->energy_need = 0;
1128 /* Go back to the ordinary map */
1129 creature_ptr->wild_mode = FALSE;
1130 creature_ptr->leaving = TRUE;
1134 bool have_pet = FALSE;
1135 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1137 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1139 if (!monster_is_valid(m_ptr)) continue;
1140 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1141 if (monster_csleep_remaining(m_ptr)) continue;
1142 if (m_ptr->cdis > MAX_SIGHT) continue;
1143 if (!is_hostile(m_ptr)) continue;
1144 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1145 "You cannot enter global map, since there is some monsters nearby!"));
1146 free_turn(creature_ptr);
1152 concptr msg = _("ペットを置いて広域マップに入りますか?",
1153 "Do you leave your pets behind? ");
1155 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1157 free_turn(creature_ptr);
1162 take_turn(creature_ptr, 1000);
1164 /* Remember the position */
1165 creature_ptr->oldpx = creature_ptr->x;
1166 creature_ptr->oldpy = creature_ptr->y;
1168 /* Cancel hex spelling */
1169 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1171 /* Cancel any special action */
1172 set_action(creature_ptr, ACTION_NONE);
1174 /* Go into the global map */
1175 creature_ptr->wild_mode = TRUE;
1176 creature_ptr->leaving = TRUE;