2 * @brief 荒野マップの生成とルール管理 / Wilderness generation
5 * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
6 * This software may be copied and distributed for educational, research, and
7 * not for profit purposes provided that this copyright and statement are
8 * included in all such copies.
9 * 2013 Deskull rearranged comment for Doxygen.
12 #include "floor/wild.h"
13 #include "core/asking-player.h"
14 #include "dungeon/dungeon-flag-types.h"
15 #include "dungeon/dungeon.h"
16 #include "dungeon/quest.h"
17 #include "floor/cave.h"
18 #include "floor/floor-town.h"
19 #include "game-option/birth-options.h"
20 #include "game-option/map-screen-options.h"
21 #include "grid/feature.h"
22 #include "grid/grid.h"
23 #include "info-reader/fixed-map-parser.h"
24 #include "info-reader/parse-error-types.h"
25 #include "io/files-util.h"
26 #include "io/tokenizer.h"
27 #include "market/building-initializer.h"
28 #include "monster-floor/monster-generator.h"
29 #include "monster-floor/monster-remover.h"
30 #include "monster-floor/monster-summon.h"
31 #include "monster-floor/place-monster-types.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-status.h"
34 #include "monster/monster-util.h"
35 #include "player/attack-defense-types.h"
36 #include "player/player-status.h"
37 #include "realm/realm-names-table.h"
38 #include "spell-realm/spells-hex.h"
39 #include "status/action-setter.h"
40 #include "system/floor-type-definition.h"
41 #include "system/system-variables.h"
42 #include "util/bit-flags-calculator.h"
43 #include "view/display-messages.h"
44 #include "window/main-window-util.h"
45 #include "world/world.h"
47 #define MAX_FEAT_IN_TERRAIN 18
49 wilderness_type **wilderness;
50 bool generate_encounter;
52 typedef struct border_type {
64 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
65 * @param feat_type 非一様確率を再現するための要素数100の配列
66 * @param prob 元の確率テーブル
69 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
71 int lim[DUNGEON_FEAT_PROB_NUM];
72 lim[0] = prob[0].percent;
73 for (int i = 1; i < DUNGEON_FEAT_PROB_NUM; i++)
74 lim[i] = lim[i - 1] + prob[i].percent;
76 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100)
77 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
80 for (int i = 0; i < 100; i++) {
84 feat_type[i] = prob[cur].feat;
89 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
90 * / Fill the arrays of floors and walls in the good proportions
94 void set_floor_and_wall(DUNGEON_IDX type)
96 DUNGEON_IDX cur_type = 255;
101 dungeon_type *d_ptr = &d_info[type];
103 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
104 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
106 feat_wall_outer = d_ptr->outer_wall;
107 feat_wall_inner = d_ptr->inner_wall;
108 feat_wall_solid = d_ptr->outer_wall;
112 * @brief プラズマフラクタル的地形生成の再帰中間処理
113 * / Helper for plasma generation.
121 * @param depth_max 深みの最大値
124 static void perturb_point_mid(
125 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)
127 FEAT_IDX tmp2 = rough * 2 + 1;
128 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
129 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
130 if (((x1 + x2 + x3 + x4) % 4) > 1)
139 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
143 * @brief プラズマフラクタル的地形生成の再帰末端処理
144 * / Helper for plasma generation.
145 * @param x1 中間末端部1の重み
146 * @param x2 中間末端部2の重み
147 * @param x3 中間末端部3の重み
148 * @param xmid 最終末端部座標X
149 * @param ymid 最終末端部座標Y
151 * @param depth_max 深みの最大値
154 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)
156 FEAT_IDX tmp2 = rough * 2 + 1;
157 FEAT_IDX tmp = randint0(tmp2) - rough;
158 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
159 if ((x1 + x2 + x3) % 3)
168 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)
192 POSITION xmid = (x2 - x1) / 2 + x1;
193 POSITION ymid = (y2 - y1) / 2 + y1;
197 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,
198 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
200 floor_ptr, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[ymid][xmid].feat, xmid, y1, rough, depth_max);
202 floor_ptr, floor_ptr->grid_array[y1][x2].feat, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[ymid][xmid].feat, x2, ymid, rough, depth_max);
204 floor_ptr, floor_ptr->grid_array[y2][x2].feat, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[ymid][xmid].feat, xmid, y2, rough, depth_max);
206 floor_ptr, floor_ptr->grid_array[y2][x1].feat, floor_ptr->grid_array[y1][x1].feat, floor_ptr->grid_array[ymid][xmid].feat, x1, ymid, rough, depth_max);
207 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
208 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
209 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
210 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
213 /* The default table in terrain level generation. */
214 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
217 * @brief 荒野フロア生成のサブルーチン
218 * @param terrain 荒野地形ID
219 * @param seed 乱数の固定シード
221 * @param corner 広域マップの角部分としての生成ならばTRUE
224 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
226 if (terrain == TERRAIN_EDGE) {
227 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
228 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
229 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
234 u32b state_backup[4];
235 Rand_state_backup(state_backup);
236 Rand_state_set(seed);
237 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
239 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
240 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
241 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
243 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
244 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (s16b)randint0(table_size);
245 floor_ptr->grid_array[1][MAX_WID - 2].feat = (s16b)randint0(table_size);
246 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (s16b)randint0(table_size);
248 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
249 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
250 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
251 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];
252 Rand_state_restore(state_backup);
256 s16b north_west = floor_ptr->grid_array[1][1].feat;
257 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
258 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
259 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
260 FEAT_IDX roughness = 1; /* The roughness of the level. */
261 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
262 floor_ptr->grid_array[1][1].feat = north_west;
263 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
264 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
265 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
266 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
267 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
268 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
270 Rand_state_restore(state_backup);
274 * @brief 荒野フロア生成のメインルーチン /
275 * Load a town or generate a terrain level using "plasma" fractals.
276 * @param player_ptr プレーヤーへの参照ポインタ
279 * @param border 広域マップの辺部分としての生成ならばTRUE
280 * @param corner 広域マップの角部分としての生成ならばTRUE
284 * x and y are the coordinates of the area in the wilderness.
285 * Border and corner are optimization flags to speed up the
286 * generation of the fractal terrain.
287 * If border is set then only the border of the terrain should
288 * be generated (for initializing the border structure).
289 * If corner is set then only the corners of the area are needed.
292 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
294 player_ptr->town_num = wilderness[y][x].town;
295 floor_type *floor_ptr = player_ptr->current_floor_ptr;
296 floor_ptr->base_level = wilderness[y][x].level;
297 floor_ptr->dun_level = 0;
298 floor_ptr->monster_level = floor_ptr->base_level;
299 floor_ptr->object_level = floor_ptr->base_level;
300 if (player_ptr->town_num) {
303 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
305 init_flags = INIT_CREATE_DUNGEON;
307 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
308 if (!corner && !border)
309 player_ptr->visit |= (1UL << (player_ptr->town_num - 1));
311 int terrain = wilderness[y][x].terrain;
312 u32b seed = wilderness[y][x].seed;
313 generate_wilderness_area(floor_ptr, terrain, seed, corner);
316 if (!corner && !wilderness[y][x].town) {
317 // todo make the road a bit more interresting.
318 if (wilderness[y][x].road) {
319 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
321 if (wilderness[y - 1][x].road) {
323 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
325 floor_ptr->grid_array[y1][x1].feat = feat_floor;
329 if (wilderness[y + 1][x].road) {
331 for (y1 = MAX_HGT / 2; y1 < MAX_HGT - 1; y1++) {
333 floor_ptr->grid_array[y1][x1].feat = feat_floor;
337 if (wilderness[y][x + 1].road) {
339 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
341 floor_ptr->grid_array[y1][x1].feat = feat_floor;
345 if (wilderness[y][x - 1].road) {
347 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
349 floor_ptr->grid_array[y1][x1].feat = feat_floor;
355 bool is_winner = wilderness[y][x].entrance > 0;
356 is_winner &= (wilderness[y][x].town == 0);
357 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
358 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
362 u32b state_backup[4];
363 Rand_state_backup(state_backup);
364 Rand_state_set(wilderness[y][x].seed);
365 int dy = rand_range(6, floor_ptr->height - 6);
366 int dx = rand_range(6, floor_ptr->width - 6);
367 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
368 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
369 Rand_state_restore(state_backup);
372 /* Border of the wilderness area */
373 static border_type border;
377 * Build the wilderness area outside of the town.
378 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
379 * @param creature_ptr プレーヤーへの参照ポインタ
382 void wilderness_gen(player_type *creature_ptr)
384 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
385 floor_ptr->height = MAX_HGT;
386 floor_ptr->width = MAX_WID;
387 panel_row_min = floor_ptr->height;
388 panel_col_min = floor_ptr->width;
389 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
390 POSITION x = creature_ptr->wilderness_x;
391 POSITION y = creature_ptr->wilderness_y;
392 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
395 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
396 for (int i = 1; i < MAX_WID - 1; i++)
397 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
400 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
401 for (int i = 1; i < MAX_WID - 1; i++)
402 border.south[i] = floor_ptr->grid_array[1][i].feat;
405 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
406 for (int i = 1; i < MAX_HGT - 1; i++)
407 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
410 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
411 for (int i = 1; i < MAX_HGT - 1; i++)
412 border.east[i] = floor_ptr->grid_array[i][1].feat;
414 /* North west corner */
415 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
416 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
418 /* North east corner */
419 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
420 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
422 /* South west corner */
423 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
424 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
426 /* South east corner */
427 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
428 border.south_east = floor_ptr->grid_array[1][1].feat;
430 /* Create terrain of the current area */
431 generate_area(creature_ptr, y, x, FALSE, FALSE);
433 /* Special boundary walls -- North */
434 for (int i = 0; i < MAX_WID; i++) {
435 floor_ptr->grid_array[0][i].feat = feat_permanent;
436 floor_ptr->grid_array[0][i].mimic = border.north[i];
439 /* Special boundary walls -- South */
440 for (int i = 0; i < MAX_WID; i++) {
441 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
442 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
445 /* Special boundary walls -- West */
446 for (int i = 0; i < MAX_HGT; i++) {
447 floor_ptr->grid_array[i][0].feat = feat_permanent;
448 floor_ptr->grid_array[i][0].mimic = border.west[i];
451 /* Special boundary walls -- East */
452 for (int i = 0; i < MAX_HGT; i++) {
453 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
454 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
457 floor_ptr->grid_array[0][0].mimic = border.north_west;
458 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
459 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
460 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
461 for (y = 0; y < floor_ptr->height; y++) {
462 for (x = 0; x < floor_ptr->width; x++) {
464 g_ptr = &floor_ptr->grid_array[y][x];
466 g_ptr->info |= CAVE_GLOW;
467 if (view_perma_grids)
468 g_ptr->info |= CAVE_MARK;
474 f_ptr = &f_info[get_feat_mimic(g_ptr)];
475 if (!is_mirror_grid(g_ptr) && !has_flag(f_ptr->flags, FF_QUEST_ENTER) && !has_flag(f_ptr->flags, FF_ENTRANCE)) {
476 g_ptr->info &= ~(CAVE_GLOW);
477 if (!has_flag(f_ptr->flags, FF_REMEMBER))
478 g_ptr->info &= ~(CAVE_MARK);
483 if (!has_flag(f_ptr->flags, FF_ENTRANCE))
486 g_ptr->info |= CAVE_GLOW;
487 if (view_perma_grids)
488 g_ptr->info |= CAVE_MARK;
492 if (creature_ptr->teleport_town) {
493 for (y = 0; y < floor_ptr->height; y++) {
494 for (x = 0; x < floor_ptr->width; x++) {
496 g_ptr = &floor_ptr->grid_array[y][x];
498 f_ptr = &f_info[g_ptr->feat];
499 if (!has_flag(f_ptr->flags, FF_BLDG))
502 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
505 if (g_ptr->m_idx != 0)
506 delete_monster_idx(creature_ptr, g_ptr->m_idx);
508 creature_ptr->oldpy = y;
509 creature_ptr->oldpx = x;
513 creature_ptr->teleport_town = FALSE;
514 } else if (creature_ptr->leaving_dungeon) {
515 for (y = 0; y < floor_ptr->height; y++) {
516 for (x = 0; x < floor_ptr->width; x++) {
518 g_ptr = &floor_ptr->grid_array[y][x];
519 if (!cave_has_flag_grid(g_ptr, FF_ENTRANCE))
522 if (g_ptr->m_idx != 0)
523 delete_monster_idx(creature_ptr, g_ptr->m_idx);
525 creature_ptr->oldpy = y;
526 creature_ptr->oldpx = x;
530 creature_ptr->teleport_town = FALSE;
533 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
534 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
535 for (int i = 0; i < lim; i++) {
537 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
538 mode |= PM_ALLOW_SLEEP;
540 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
543 if (generate_encounter)
544 creature_ptr->ambush_flag = TRUE;
546 generate_encounter = FALSE;
547 set_floor_and_wall(0);
548 for (int i = 0; i < max_q_idx; i++)
549 if (quest[i].status == QUEST_STATUS_REWARDED)
550 quest[i].status = QUEST_STATUS_FINISHED;
553 static s16b conv_terrain2feat[MAX_WILDERNESS];
556 * @brief 広域マップの生成(簡易処理版) /
557 * Build the wilderness area. -DG-
560 void wilderness_gen_small(player_type *creature_ptr)
562 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
563 for (int i = 0; i < MAX_WID; i++)
564 for (int j = 0; j < MAX_HGT; j++)
565 floor_ptr->grid_array[j][i].feat = feat_permanent;
567 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
568 for (int i = 0; i < current_world_ptr->max_wild_x; i++) {
569 for (int j = 0; j < current_world_ptr->max_wild_y; j++) {
570 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN)) {
571 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
572 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
573 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
577 if (wilderness[j][i].road) {
578 floor_ptr->grid_array[j][i].feat = feat_floor;
579 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
583 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER))) {
584 floor_ptr->grid_array[j][i].feat = feat_entrance;
585 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
586 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
590 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
591 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
595 floor_ptr->height = (s16b)current_world_ptr->max_wild_y;
596 floor_ptr->width = (s16b)current_world_ptr->max_wild_x;
597 if (floor_ptr->height > MAX_HGT)
598 floor_ptr->height = MAX_HGT;
600 if (floor_ptr->width > MAX_WID)
601 floor_ptr->width = MAX_WID;
603 panel_row_min = floor_ptr->height;
604 panel_col_min = floor_ptr->width;
605 creature_ptr->x = creature_ptr->wilderness_x;
606 creature_ptr->y = creature_ptr->wilderness_y;
607 creature_ptr->town_num = 0;
610 typedef struct wilderness_grid {
611 wt_type terrain; /* Terrain type */
612 TOWN_IDX town; /* Town number */
613 DEPTH level; /* Level of the wilderness */
614 byte road; /* Road */
615 char name[32]; /* Name of the town/wilderness */
618 static wilderness_grid w_letter[255];
621 * @brief w_info.txtのデータ解析 /
622 * Parse a sub-file of the "extra info"
623 * @param buf 読み取ったデータ行のバッファ
625 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
627 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
628 * @param y 広域マップの高さを返す参照ポインタ
629 * @param x 広域マップの幅を返す参照ポインタ
632 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
634 if (!(buf[0] == 'W'))
635 return (PARSE_ERROR_GENERIC);
640 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
653 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
654 int index = zz[0][0];
657 w_letter[index].terrain = atoi(zz[1]);
659 w_letter[index].terrain = 0;
662 w_letter[index].level = (s16b)atoi(zz[2]);
664 w_letter[index].level = 0;
667 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
669 w_letter[index].town = 0;
672 w_letter[index].road = (byte)atoi(zz[4]);
674 w_letter[index].road = 0;
677 strcpy(w_letter[index].name, zz[5]);
679 w_letter[index].name[0] = 0;
682 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
688 /* Process "W:D:<layout> */
689 /* Layout of the wilderness */
694 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
696 wilderness[*y][*x].terrain = w_letter[id].terrain;
697 wilderness[*y][*x].level = w_letter[id].level;
698 wilderness[*y][*x].town = w_letter[id].town;
699 wilderness[*y][*x].road = w_letter[id].road;
700 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
707 /* Process "W:P:<x>:<y> - starting position in the wilderness */
709 bool is_corner = creature_ptr->wilderness_x == 0;
710 is_corner = creature_ptr->wilderness_y == 0;
714 if (tokenize(buf + 4, 2, zz, 0) != 2) {
715 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
718 creature_ptr->wilderness_y = atoi(zz[0]);
719 creature_ptr->wilderness_x = atoi(zz[1]);
721 if ((creature_ptr->wilderness_x < 1) || (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) || (creature_ptr->wilderness_y < 1)
722 || (creature_ptr->wilderness_y > current_world_ptr->max_wild_y)) {
723 return PARSE_ERROR_OUT_OF_BOUNDS;
730 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
733 for (int i = 1; i < current_world_ptr->max_d_idx; i++) {
734 if (!d_info[i].maxdepth)
736 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
737 if (!wilderness[d_info[i].dy][d_info[i].dx].town) {
738 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
746 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
747 * Generate the random seeds for the wilderness
750 void seed_wilderness(void)
752 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
753 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++) {
754 wilderness[y][x].seed = randint0(0x10000000);
755 wilderness[y][x].entrance = 0;
759 /* Pointer to wilderness_type */
760 typedef wilderness_type *wilderness_type_ptr;
763 * @brief ゲーム開始時の荒野初期化メインルーチン /
764 * Initialize wilderness array
767 errr init_wilderness(void)
769 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
770 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
771 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
772 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
774 generate_encounter = FALSE;
779 * @brief 荒野の地勢設定を初期化する /
780 * Initialize wilderness array
781 * @param terrain 初期化したい地勢ID
782 * @param feat_global 基本的な地形ID
783 * @param fmt 地勢内の地形数を参照するための独自フォーマット
786 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
790 conv_terrain2feat[terrain] = feat_global;
793 for (concptr p = fmt; *p; p++) {
795 plog_fmt("Format error");
799 FEAT_IDX feat = (s16b)va_arg(vp, int);
800 int num = va_arg(vp, int);
802 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
803 terrain_table[terrain][cur] = feat;
805 if (cur >= MAX_FEAT_IN_TERRAIN)
811 if (cur < MAX_FEAT_IN_TERRAIN)
812 plog_fmt("Too few parameters");
818 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
819 * Initialize arrays for wilderness terrains
822 void init_wilderness_terrains(void)
824 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
825 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
826 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
827 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde", feat_deep_water, 3, feat_shallow_water, 12, feat_floor, 1, feat_dirt, 1, feat_grass,
828 MAX_FEAT_IN_TERRAIN - 17);
829 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef", feat_dirt, 2, feat_grass, 3, feat_tree, 1, feat_brake, 1, feat_shallow_water, 4, feat_swamp,
830 MAX_FEAT_IN_TERRAIN - 11);
832 TERRAIN_DIRT, feat_dirt, "abcdef", feat_floor, 3, feat_dirt, 10, feat_flower, 1, feat_brake, 1, feat_grass, 1, feat_tree, MAX_FEAT_IN_TERRAIN - 16);
834 TERRAIN_GRASS, feat_grass, "abcdef", feat_floor, 2, feat_dirt, 2, feat_grass, 9, feat_flower, 1, feat_brake, 2, feat_tree, MAX_FEAT_IN_TERRAIN - 16);
835 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde", feat_floor, 2, feat_dirt, 1, feat_tree, 11, feat_brake, 2, feat_grass, MAX_FEAT_IN_TERRAIN - 16);
836 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
837 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc", feat_shallow_lava, 14, feat_deep_lava, 3, feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
839 TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd", feat_dirt, 3, feat_shallow_lava, 3, feat_deep_lava, 10, feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
840 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef", feat_floor, 1, feat_brake, 1, feat_grass, 2, feat_dirt, 2, feat_tree, 2, feat_mountain,
841 MAX_FEAT_IN_TERRAIN - 8);
845 * @brief 荒野から広域マップへの切り替え処理 /
846 * Initialize arrays for wilderness terrains
847 * @param encount 襲撃時TRUE
848 * @return 切り替えが行われた場合はTRUEを返す。
850 bool change_wild_mode(player_type *creature_ptr, bool encount)
852 generate_encounter = encount;
853 if (creature_ptr->leaving)
856 if (lite_town || vanilla_town) {
857 msg_print(_("荒野なんてない。", "No global map."));
861 if (creature_ptr->wild_mode) {
862 creature_ptr->wilderness_x = creature_ptr->x;
863 creature_ptr->wilderness_y = creature_ptr->y;
864 creature_ptr->energy_need = 0;
865 creature_ptr->wild_mode = FALSE;
866 creature_ptr->leaving = TRUE;
870 bool has_pet = FALSE;
871 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
872 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
873 if (!monster_is_valid(m_ptr))
876 if (is_pet(m_ptr) && i != creature_ptr->riding)
879 if (monster_csleep_remaining(m_ptr) || (m_ptr->cdis > MAX_SIGHT) || !is_hostile(m_ptr))
882 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there are some monsters nearby!"));
883 free_turn(creature_ptr);
888 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
889 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL)) {
890 free_turn(creature_ptr);
895 take_turn(creature_ptr, 1000);
896 creature_ptr->oldpx = creature_ptr->x;
897 creature_ptr->oldpy = creature_ptr->y;
898 if (hex_spelling_any(creature_ptr))
899 stop_hex_spell_all(creature_ptr);
901 set_action(creature_ptr, ACTION_NONE);
902 creature_ptr->wild_mode = TRUE;
903 creature_ptr->leaving = TRUE;