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 "system/angband.h"
14 #include "util/util.h"
15 #include "system/system-variables.h"
17 #include "dungeon/dungeon.h"
18 #include "floor/wild.h"
19 #include "world/world.h"
20 #include "monster/monster.h"
21 #include "realm/realm-hex.h"
22 #include "player/player-status.h"
23 #include "player/player-effects.h"
24 #include "grid/grid.h"
25 #include "monster/monster-status.h"
26 #include "dungeon/quest.h"
27 #include "dungeon/dungeon-file.h"
28 #include "io/tokenizer.h"
29 #include "io/files-util.h"
30 #include "grid/feature.h"
31 #include "floor/floor-town.h"
32 #include "realm/realm.h"
34 #include "view/display-main-window.h"
36 #define MAX_FEAT_IN_TERRAIN 18
41 wilderness_type **wilderness;
43 bool generate_encounter;
46 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
47 * @param feat_type 非一様確率を再現するための要素数100の配列
48 * @param prob 元の確率テーブル
51 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
53 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
55 lim[0] = prob[0].percent;
56 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
57 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
59 for (i = 0; i < 100; i++)
61 while (i == lim[cur]) cur++;
62 feat_type[i] = prob[cur].feat;
68 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
69 * / Fill the arrays of floors and walls in the good proportions
73 void set_floor_and_wall(DUNGEON_IDX type)
75 DUNGEON_IDX cur_type = 255;
79 if (cur_type == type) return;
82 d_ptr = &d_info[type];
84 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
85 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
87 feat_wall_outer = d_ptr->outer_wall;
88 feat_wall_inner = d_ptr->inner_wall;
89 feat_wall_solid = d_ptr->outer_wall;
94 * @brief プラズマフラクタル的地形生成の再帰中間処理
95 * / Helper for plasma generation.
103 * @param depth_max 深みの最大値
106 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)
109 * Average the four corners & perturb it a bit.
110 * tmp is a random int +/- rough
112 FEAT_IDX tmp2 = rough*2 + 1;
113 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
115 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
117 /* Division always rounds down, so we round up again */
118 if (((x1 + x2 + x3 + x4) % 4) > 1)
122 if (avg < 0) avg = 0;
123 if (avg > depth_max) avg = depth_max;
125 /* Set the new value. */
126 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
131 * @brief プラズマフラクタル的地形生成の再帰末端処理
132 * / Helper for plasma generation.
133 * @param x1 中間末端部1の重み
134 * @param x2 中間末端部2の重み
135 * @param x3 中間末端部3の重み
136 * @param xmid 最終末端部座標X
137 * @param ymid 最終末端部座標Y
139 * @param depth_max 深みの最大値
142 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)
145 * Average the three corners & perturb it a bit.
146 * tmp is a random int +/- rough
148 FEAT_IDX tmp2 = rough * 2 + 1;
149 FEAT_IDX tmp = randint0(tmp2) - rough;
151 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
153 /* Division always rounds down, so we round up again */
154 if ((x1 + x2 + x3) % 3) avg++;
157 if (avg < 0) avg = 0;
158 if (avg > depth_max) avg = depth_max;
160 /* Set the new value. */
161 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
166 * @brief プラズマフラクタル的地形生成の開始処理
167 * / Helper for plasma generation.
168 * @param x1 処理範囲の左上X座標
169 * @param y1 処理範囲の左上Y座標
170 * @param x2 処理範囲の右下X座標
171 * @param y2 処理範囲の右下Y座標
172 * @param depth_max 深みの最大値
177 * A generic function to generate the plasma fractal.
178 * Note that it uses ``cave_feat'' as temporary storage.
179 * The values in ``cave_feat'' after this function
180 * are NOT actual features; They are raw heights which
181 * need to be converted to features.
184 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
187 POSITION xmid = (x2 - x1) / 2 + x1;
188 POSITION ymid = (y2 - y1) / 2 + y1;
191 if (x1 + 1 == x2) return;
193 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,
194 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
196 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,
197 xmid, y1, rough, depth_max);
199 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,
200 x2, ymid, rough, depth_max);
202 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,
203 xmid, y2, rough, depth_max);
205 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,
206 x1, ymid, rough, depth_max);
209 /* Recurse the four quadrants */
210 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
211 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
212 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
213 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
218 * The default table in terrain level generation.
220 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
223 * @brief 荒野フロア生成のサブルーチン
224 * @param terrain 荒野地形ID
225 * @param seed 乱数の固定シード
227 * @param corner 広域マップの角部分としての生成ならばTRUE
230 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
232 /* The outer wall is easy */
233 if (terrain == TERRAIN_EDGE)
235 /* Create level background */
236 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
238 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
240 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
247 /* Hack -- Backup the RNG state */
248 u32b state_backup[4];
249 Rand_state_backup(state_backup);
251 /* Hack -- Induce consistant flavors */
252 Rand_state_set(seed);
254 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
257 /* Create level background */
258 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
260 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
262 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
268 * Initialize the four corners
269 * ToDo: calculate the medium height of the adjacent
270 * terrains for every corner.
272 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
273 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
274 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
275 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
277 /* Hack -- only four corners */
280 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
281 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
282 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
283 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];
284 Rand_state_restore(state_backup);
288 /* Hack -- preserve four corners */
289 s16b north_west = floor_ptr->grid_array[1][1].feat;
290 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
291 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
292 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
294 /* x1, y1, x2, y2, num_depths, roughness */
295 FEAT_IDX roughness = 1; /* The roughness of the level. */
296 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
298 /* Hack -- copyback four corners */
299 floor_ptr->grid_array[1][1].feat = north_west;
300 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
301 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
302 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
304 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
306 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
308 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
312 Rand_state_restore(state_backup);
317 * @brief 荒野フロア生成のメインルーチン /
318 * Load a town or generate a terrain level using "plasma" fractals.
319 * @param player_ptr プレーヤーへの参照ポインタ
322 * @param border 広域マップの辺部分としての生成ならばTRUE
323 * @param corner 広域マップの角部分としての生成ならばTRUE
327 * x and y are the coordinates of the area in the wilderness.
328 * Border and corner are optimization flags to speed up the
329 * generation of the fractal terrain.
330 * If border is set then only the border of the terrain should
331 * be generated (for initializing the border structure).
332 * If corner is set then only the corners of the area are needed.
335 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
337 /* Number of the town (if any) */
338 player_ptr->town_num = wilderness[y][x].town;
340 /* Set the base level */
341 floor_type *floor_ptr = player_ptr->current_floor_ptr;
342 floor_ptr->base_level = wilderness[y][x].level;
344 /* Set the dungeon level */
345 floor_ptr->dun_level = 0;
347 /* Set the monster generation level */
348 floor_ptr->monster_level = floor_ptr->base_level;
350 /* Set the object generation level */
351 floor_ptr->object_level = floor_ptr->base_level;
354 /* Create the town */
355 if (player_ptr->town_num)
357 /* Reset the buildings */
360 /* Initialize the town */
362 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
364 init_flags = INIT_CREATE_DUNGEON;
366 process_dungeon_file(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
368 if (!corner && !border) player_ptr->visit |= (1L << (player_ptr->town_num - 1));
372 int terrain = wilderness[y][x].terrain;
373 u32b seed = wilderness[y][x].seed;
375 generate_wilderness_area(floor_ptr, terrain, seed, corner);
378 if (!corner && !wilderness[y][x].town)
381 * Place roads in the wilderness
382 * ToDo: make the road a bit more interresting
384 if (wilderness[y][x].road)
386 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
389 if (wilderness[y-1][x].road)
392 for (y1 = 1; y1 < MAX_HGT/2; y1++)
395 floor_ptr->grid_array[y1][x1].feat = feat_floor;
399 if (wilderness[y+1][x].road)
402 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
405 floor_ptr->grid_array[y1][x1].feat = feat_floor;
409 if (wilderness[y][x+1].road)
412 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
415 floor_ptr->grid_array[y1][x1].feat = feat_floor;
419 if (wilderness[y][x-1].road)
422 for (x1 = 1; x1 < MAX_WID/2; x1++)
425 floor_ptr->grid_array[y1][x1].feat = feat_floor;
432 * 本来は '> 0'で良いと思われるがエンバグするのも怖いので'!= 0'と記載する
433 * 問題なければ'> 0'へ置き換えること
435 bool is_winner = wilderness[y][x].entrance != 0;
436 is_winner &= !wilderness[y][x].town != 0;
437 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
438 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
439 if (!is_winner) return;
441 /* Hack -- Backup the RNG state */
442 u32b state_backup[4];
443 Rand_state_backup(state_backup);
445 /* Hack -- Induce consistant flavors */
446 Rand_state_set(wilderness[y][x].seed);
448 int dy = rand_range(6, floor_ptr->height - 6);
449 int dx = rand_range(6, floor_ptr->width - 6);
451 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
452 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
454 /* Hack -- Restore the RNG state */
455 Rand_state_restore(state_backup);
460 * Border of the wilderness area
462 static border_type border;
466 * Build the wilderness area outside of the town.
467 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
468 * @param creature_ptr プレーヤーへの参照ポインタ
471 void wilderness_gen(player_type *creature_ptr)
474 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
475 floor_ptr->height = MAX_HGT;
476 floor_ptr->width = MAX_WID;
478 /* Assume illegal panel */
479 panel_row_min = floor_ptr->height;
480 panel_col_min = floor_ptr->width;
482 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
483 POSITION x = creature_ptr->wilderness_x;
484 POSITION y = creature_ptr->wilderness_y;
485 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
488 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
490 for (int i = 1; i < MAX_WID - 1; i++)
492 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
496 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
498 for (int i = 1; i < MAX_WID - 1; i++)
500 border.south[i] = floor_ptr->grid_array[1][i].feat;
504 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
506 for (int i = 1; i < MAX_HGT - 1; i++)
508 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
512 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
514 for (int i = 1; i < MAX_HGT - 1; i++)
516 border.east[i] = floor_ptr->grid_array[i][1].feat;
519 /* North west corner */
520 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
521 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
523 /* North east corner */
524 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
525 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
527 /* South west corner */
528 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
529 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
531 /* South east corner */
532 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
533 border.south_east = floor_ptr->grid_array[1][1].feat;
535 /* Create terrain of the current area */
536 generate_area(creature_ptr, y, x, FALSE, FALSE);
538 /* Special boundary walls -- North */
539 for (int i = 0; i < MAX_WID; i++)
541 floor_ptr->grid_array[0][i].feat = feat_permanent;
542 floor_ptr->grid_array[0][i].mimic = border.north[i];
545 /* Special boundary walls -- South */
546 for (int i = 0; i < MAX_WID; i++)
548 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
549 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
552 /* Special boundary walls -- West */
553 for (int i = 0; i < MAX_HGT; i++)
555 floor_ptr->grid_array[i][0].feat = feat_permanent;
556 floor_ptr->grid_array[i][0].mimic = border.west[i];
559 /* Special boundary walls -- East */
560 for (int i = 0; i < MAX_HGT; i++)
562 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
563 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
566 floor_ptr->grid_array[0][0].mimic = border.north_west;
567 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
568 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
569 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
571 /* Light up or darken the area */
572 for (y = 0; y < floor_ptr->height; y++)
574 for (x = 0; x < floor_ptr->width; x++)
577 g_ptr = &floor_ptr->grid_array[y][x];
582 g_ptr->info |= CAVE_GLOW;
584 /* Hack -- Memorize lit grids if allowed */
585 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
589 /* Feature code (applying "mimic" field) */
591 f_ptr = &f_info[get_feat_mimic(g_ptr)];
593 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
594 !have_flag(f_ptr->flags, FF_ENTRANCE))
597 g_ptr->info &= ~(CAVE_GLOW);
599 /* Darken "boring" features */
600 if (!have_flag(f_ptr->flags, FF_REMEMBER))
602 /* Forget the grid */
603 g_ptr->info &= ~(CAVE_MARK);
609 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
611 g_ptr->info |= CAVE_GLOW;
613 /* Hack -- Memorize lit grids if allowed */
614 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
618 if (creature_ptr->teleport_town)
620 for (y = 0; y < floor_ptr->height; y++)
622 for (x = 0; x < floor_ptr->width; x++)
625 g_ptr = &floor_ptr->grid_array[y][x];
627 /* Seeing true feature code (ignore mimic) */
629 f_ptr = &f_info[g_ptr->feat];
631 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
633 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
638 delete_monster_idx(creature_ptr, g_ptr->m_idx);
641 creature_ptr->oldpy = y;
642 creature_ptr->oldpx = x;
646 creature_ptr->teleport_town = FALSE;
648 else if (creature_ptr->leaving_dungeon)
650 for (y = 0; y < floor_ptr->height; y++)
652 for (x = 0; x < floor_ptr->width; x++)
655 g_ptr = &floor_ptr->grid_array[y][x];
657 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
661 delete_monster_idx(creature_ptr, g_ptr->m_idx);
664 creature_ptr->oldpy = y;
665 creature_ptr->oldpx = x;
669 creature_ptr->teleport_town = FALSE;
672 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
673 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
675 /* Make some residents */
676 for (int i = 0; i < lim; i++)
680 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
681 mode |= PM_ALLOW_SLEEP;
683 /* Make a resident */
684 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode);
687 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
688 generate_encounter = FALSE;
690 /* Fill the arrays of floors and walls in the good proportions */
691 set_floor_and_wall(0);
693 /* Set rewarded quests to finished */
694 for (int i = 0; i < max_q_idx; i++)
696 if (quest[i].status == QUEST_STATUS_REWARDED)
697 quest[i].status = QUEST_STATUS_FINISHED;
701 static s16b conv_terrain2feat[MAX_WILDERNESS];
704 * @brief 広域マップの生成(簡易処理版) /
705 * Build the wilderness area. -DG-
708 void wilderness_gen_small(player_type *creature_ptr)
710 /* To prevent stupid things */
711 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
712 for (int i = 0; i < MAX_WID; i++)
714 for (int j = 0; j < MAX_HGT; j++)
716 floor_ptr->grid_array[j][i].feat = feat_permanent;
720 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
723 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
725 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
727 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
729 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
730 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
731 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
735 if (wilderness[j][i].road)
737 floor_ptr->grid_array[j][i].feat = feat_floor;
738 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
742 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
744 floor_ptr->grid_array[j][i].feat = feat_entrance;
745 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
746 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
750 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
751 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
755 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
756 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
758 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
759 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
761 /* Assume illegal panel */
762 panel_row_min = floor_ptr->height;
763 panel_col_min = floor_ptr->width;
765 creature_ptr->x = creature_ptr->wilderness_x;
766 creature_ptr->y = creature_ptr->wilderness_y;
767 creature_ptr->town_num = 0;
771 typedef struct wilderness_grid wilderness_grid;
773 struct wilderness_grid
775 int terrain; /* Terrain type */
776 TOWN_IDX town; /* Town number */
777 DEPTH level; /* Level of the wilderness */
778 byte road; /* Road */
779 char name[32]; /* Name of the town/wilderness */
783 static wilderness_grid w_letter[255];
786 * @brief w_info.txtのデータ解析 /
787 * Parse a sub-file of the "extra info"
788 * @param buf 読み取ったデータ行のバッファ
790 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
792 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
793 * @param y 広域マップの高さを返す参照ポインタ
794 * @param x 広域マップの幅を返す参照ポインタ
797 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
799 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
805 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
818 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
820 int index = zz[0][0];
823 w_letter[index].terrain = atoi(zz[1]);
825 w_letter[index].terrain = 0;
828 w_letter[index].level = (s16b)atoi(zz[2]);
830 w_letter[index].level = 0;
833 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
835 w_letter[index].town = 0;
838 w_letter[index].road = (byte)atoi(zz[4]);
840 w_letter[index].road = 0;
843 strcpy(w_letter[index].name, zz[5]);
845 w_letter[index].name[0] = 0;
850 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
856 /* Process "W:D:<layout> */
857 /* Layout of the wilderness */
863 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
866 wilderness[*y][*x].terrain = w_letter[id].terrain;
867 wilderness[*y][*x].level = w_letter[id].level;
868 wilderness[*y][*x].town = w_letter[id].town;
869 wilderness[*y][*x].road = w_letter[id].road;
870 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
877 /* Process "W:P:<x>:<y> - starting position in the wilderness */
880 bool is_corner = creature_ptr->wilderness_x == 0;
881 is_corner = creature_ptr->wilderness_y == 0;
882 if (!is_corner) break;
884 if (tokenize(buf + 4, 2, zz, 0) != 2)
886 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
889 creature_ptr->wilderness_y = atoi(zz[0]);
890 creature_ptr->wilderness_x = atoi(zz[1]);
892 if ((creature_ptr->wilderness_x < 1) ||
893 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
894 (creature_ptr->wilderness_y < 1) ||
895 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
897 return PARSE_ERROR_OUT_OF_BOUNDS;
904 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
907 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
909 if (!d_info[i].maxdepth) continue;
910 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
911 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
913 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
922 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
923 * Generate the random seeds for the wilderness
926 void seed_wilderness(void)
928 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
930 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
932 wilderness[y][x].seed = randint0(0x10000000);
933 wilderness[y][x].entrance = 0;
940 * Pointer to wilderness_type
942 typedef wilderness_type *wilderness_type_ptr;
945 * @brief ゲーム開始時の荒野初期化メインルーチン /
946 * Initialize wilderness array
949 errr init_wilderness(void)
951 /* Allocate the wilderness (two-dimension array) */
952 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
953 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
955 /* Init the other pointers */
956 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
958 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
961 generate_encounter = FALSE;
967 * @brief 荒野の地勢設定を初期化する /
968 * Initialize wilderness array
969 * @param terrain 初期化したい地勢ID
970 * @param feat_global 基本的な地形ID
971 * @param fmt 地勢内の地形数を参照するための独自フォーマット
974 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
976 /* Begin the varargs stuff */
980 /* Wilderness terrains on global map */
981 conv_terrain2feat[terrain] = feat_global;
983 /* Wilderness terrains on local map */
986 for (concptr p = fmt; *p; p++)
990 plog_fmt("Format error");
994 FEAT_IDX feat = (s16b)va_arg(vp, int);
995 int num = va_arg(vp, int);
998 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1000 terrain_table[terrain][cur] = feat;
1003 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1008 if (cur < MAX_FEAT_IN_TERRAIN)
1010 plog_fmt("Too few parameters");
1018 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1019 * Initialize arrays for wilderness terrains
1022 void init_wilderness_terrains(void)
1024 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1025 feat_permanent, MAX_FEAT_IN_TERRAIN);
1027 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1028 feat_floor, MAX_FEAT_IN_TERRAIN);
1030 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1031 feat_deep_water, 12,
1032 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1034 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1036 feat_shallow_water, 12,
1039 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1041 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1046 feat_shallow_water, 4,
1047 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1049 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1055 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1057 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1063 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1065 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1070 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1072 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1075 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1077 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1078 feat_shallow_lava, 14,
1080 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1082 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1084 feat_shallow_lava, 3,
1086 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1088 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1094 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1099 * @brief 荒野から広域マップへの切り替え処理 /
1100 * Initialize arrays for wilderness terrains
1101 * @param encount 襲撃時TRUE
1102 * @return 切り替えが行われた場合はTRUEを返す。
1104 bool change_wild_mode(player_type *creature_ptr, bool encount)
1106 generate_encounter = encount;
1108 /* It is in the middle of changing map */
1109 if (creature_ptr->leaving) return FALSE;
1111 if (lite_town || vanilla_town)
1113 msg_print(_("荒野なんてない。", "No global map."));
1117 if (creature_ptr->wild_mode)
1119 /* Save the location in the global map */
1120 creature_ptr->wilderness_x = creature_ptr->x;
1121 creature_ptr->wilderness_y = creature_ptr->y;
1123 /* Give first move to the player */
1124 creature_ptr->energy_need = 0;
1126 /* Go back to the ordinary map */
1127 creature_ptr->wild_mode = FALSE;
1128 creature_ptr->leaving = TRUE;
1132 bool have_pet = FALSE;
1133 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1135 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1137 if (!monster_is_valid(m_ptr)) continue;
1138 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1139 if (MON_CSLEEP(m_ptr)) continue;
1140 if (m_ptr->cdis > MAX_SIGHT) continue;
1141 if (!is_hostile(m_ptr)) continue;
1142 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1143 "You cannot enter global map, since there is some monsters nearby!"));
1144 free_turn(creature_ptr);
1150 concptr msg = _("ペットを置いて広域マップに入りますか?",
1151 "Do you leave your pets behind? ");
1153 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1155 free_turn(creature_ptr);
1160 take_turn(creature_ptr, 1000);
1162 /* Remember the position */
1163 creature_ptr->oldpx = creature_ptr->x;
1164 creature_ptr->oldpy = creature_ptr->y;
1166 /* Cancel hex spelling */
1167 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1169 /* Cancel any special action */
1170 set_action(creature_ptr, ACTION_NONE);
1172 /* Go into the global map */
1173 creature_ptr->wild_mode = TRUE;
1174 creature_ptr->leaving = TRUE;