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-status/player-energy.h"
36 #include "player/attack-defense-types.h"
37 #include "player/player-status.h"
38 #include "realm/realm-names-table.h"
39 #include "spell-realm/spells-hex.h"
40 #include "status/action-setter.h"
41 #include "system/floor-type-definition.h"
42 #include "system/monster-type-definition.h"
43 #include "system/player-type-definition.h"
44 #include "system/system-variables.h"
45 #include "util/bit-flags-calculator.h"
46 #include "view/display-messages.h"
47 #include "window/main-window-util.h"
48 #include "world/world.h"
50 #define MAX_FEAT_IN_TERRAIN 18
52 wilderness_type **wilderness;
53 bool generate_encounter;
55 typedef struct border_type {
67 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
68 * @param feat_type 非一様確率を再現するための要素数100の配列
69 * @param prob 元の確率テーブル
72 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
74 int lim[DUNGEON_FEAT_PROB_NUM];
75 lim[0] = prob[0].percent;
76 for (int i = 1; i < DUNGEON_FEAT_PROB_NUM; i++)
77 lim[i] = lim[i - 1] + prob[i].percent;
79 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100)
80 lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
83 for (int i = 0; i < 100; i++) {
87 feat_type[i] = prob[cur].feat;
92 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
93 * / Fill the arrays of floors and walls in the good proportions
97 void set_floor_and_wall(DUNGEON_IDX type)
99 DUNGEON_IDX cur_type = 255;
100 if (cur_type == type)
104 dungeon_type *d_ptr = &d_info[type];
106 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
107 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
109 feat_wall_outer = d_ptr->outer_wall;
110 feat_wall_inner = d_ptr->inner_wall;
111 feat_wall_solid = d_ptr->outer_wall;
115 * @brief プラズマフラクタル的地形生成の再帰中間処理
116 * / Helper for plasma generation.
124 * @param depth_max 深みの最大値
127 static void perturb_point_mid(
128 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)
130 FEAT_IDX tmp2 = rough * 2 + 1;
131 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
132 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
133 if (((x1 + x2 + x3 + x4) % 4) > 1)
142 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
146 * @brief プラズマフラクタル的地形生成の再帰末端処理
147 * / Helper for plasma generation.
148 * @param x1 中間末端部1の重み
149 * @param x2 中間末端部2の重み
150 * @param x3 中間末端部3の重み
151 * @param xmid 最終末端部座標X
152 * @param ymid 最終末端部座標Y
154 * @param depth_max 深みの最大値
157 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)
159 FEAT_IDX tmp2 = rough * 2 + 1;
160 FEAT_IDX tmp = randint0(tmp2) - rough;
161 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
162 if ((x1 + x2 + x3) % 3)
171 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
175 * @brief プラズマフラクタル的地形生成の開始処理
176 * / Helper for plasma generation.
177 * @param x1 処理範囲の左上X座標
178 * @param y1 処理範囲の左上Y座標
179 * @param x2 処理範囲の右下X座標
180 * @param y2 処理範囲の右下Y座標
181 * @param depth_max 深みの最大値
186 * A generic function to generate the plasma fractal.
187 * Note that it uses ``cave_feat'' as temporary storage.
188 * The values in ``cave_feat'' after this function
189 * are NOT actual features; They are raw heights which
190 * need to be converted to features.
193 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
195 POSITION xmid = (x2 - x1) / 2 + x1;
196 POSITION ymid = (y2 - y1) / 2 + y1;
200 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,
201 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
203 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);
205 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);
207 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);
209 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);
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);
216 /* The default table in terrain level generation. */
217 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
220 * @brief 荒野フロア生成のサブルーチン
221 * @param terrain 荒野地形ID
222 * @param seed 乱数の固定シード
224 * @param corner 広域マップの角部分としての生成ならばTRUE
227 static void generate_wilderness_area(floor_type *floor_ptr, int terrain, u32b seed, bool corner)
229 if (terrain == TERRAIN_EDGE) {
230 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
231 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
232 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
237 u32b state_backup[4];
238 Rand_state_backup(state_backup);
239 Rand_state_set(seed);
240 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
242 for (POSITION y1 = 0; y1 < MAX_HGT; y1++)
243 for (POSITION x1 = 0; x1 < MAX_WID; x1++)
244 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
246 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
247 floor_ptr->grid_array[MAX_HGT - 2][1].feat = (s16b)randint0(table_size);
248 floor_ptr->grid_array[1][MAX_WID - 2].feat = (s16b)randint0(table_size);
249 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = (s16b)randint0(table_size);
251 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
252 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
253 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
254 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];
255 Rand_state_restore(state_backup);
259 s16b north_west = floor_ptr->grid_array[1][1].feat;
260 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
261 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
262 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
263 FEAT_IDX roughness = 1; /* The roughness of the level. */
264 plasma_recursive(floor_ptr, 1, 1, MAX_WID - 2, MAX_HGT - 2, table_size - 1, roughness);
265 floor_ptr->grid_array[1][1].feat = north_west;
266 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
267 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
268 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
269 for (POSITION y1 = 1; y1 < MAX_HGT - 1; y1++)
270 for (POSITION x1 = 1; x1 < MAX_WID - 1; x1++)
271 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
273 Rand_state_restore(state_backup);
277 * @brief 荒野フロア生成のメインルーチン /
278 * Load a town or generate a terrain level using "plasma" fractals.
279 * @param player_ptr プレーヤーへの参照ポインタ
282 * @param border 広域マップの辺部分としての生成ならばTRUE
283 * @param corner 広域マップの角部分としての生成ならばTRUE
287 * x and y are the coordinates of the area in the wilderness.
288 * Border and corner are optimization flags to speed up the
289 * generation of the fractal terrain.
290 * If border is set then only the border of the terrain should
291 * be generated (for initializing the border structure).
292 * If corner is set then only the corners of the area are needed.
295 static void generate_area(player_type *player_ptr, POSITION y, POSITION x, bool border, bool corner)
297 player_ptr->town_num = wilderness[y][x].town;
298 floor_type *floor_ptr = player_ptr->current_floor_ptr;
299 floor_ptr->base_level = wilderness[y][x].level;
300 floor_ptr->dun_level = 0;
301 floor_ptr->monster_level = floor_ptr->base_level;
302 floor_ptr->object_level = floor_ptr->base_level;
303 if (player_ptr->town_num) {
305 if (border || corner)
306 init_flags = static_cast<init_flags_type>(INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES);
308 init_flags = INIT_CREATE_DUNGEON;
310 parse_fixed_map(player_ptr, "t_info.txt", 0, 0, MAX_HGT, MAX_WID);
311 if (!corner && !border)
312 player_ptr->visit |= (1UL << (player_ptr->town_num - 1));
314 int terrain = wilderness[y][x].terrain;
315 u32b seed = wilderness[y][x].seed;
316 generate_wilderness_area(floor_ptr, terrain, seed, corner);
319 if (!corner && !wilderness[y][x].town) {
320 //!< @todo make the road a bit more interresting.
321 if (wilderness[y][x].road) {
322 floor_ptr->grid_array[MAX_HGT / 2][MAX_WID / 2].feat = feat_floor;
324 if (wilderness[y - 1][x].road) {
326 for (y1 = 1; y1 < MAX_HGT / 2; y1++) {
328 floor_ptr->grid_array[y1][x1].feat = feat_floor;
332 if (wilderness[y + 1][x].road) {
334 for (y1 = MAX_HGT / 2; y1 < MAX_HGT - 1; y1++) {
336 floor_ptr->grid_array[y1][x1].feat = feat_floor;
340 if (wilderness[y][x + 1].road) {
342 for (x1 = MAX_WID / 2; x1 < MAX_WID - 1; x1++) {
344 floor_ptr->grid_array[y1][x1].feat = feat_floor;
348 if (wilderness[y][x - 1].road) {
350 for (x1 = 1; x1 < MAX_WID / 2; x1++) {
352 floor_ptr->grid_array[y1][x1].feat = feat_floor;
358 bool is_winner = wilderness[y][x].entrance > 0;
359 is_winner &= (wilderness[y][x].town == 0);
360 bool is_wild_winner = (d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER) == 0;
361 is_winner &= ((current_world_ptr->total_winner != 0) || is_wild_winner);
365 u32b state_backup[4];
366 Rand_state_backup(state_backup);
367 Rand_state_set(wilderness[y][x].seed);
368 int dy = rand_range(6, floor_ptr->height - 6);
369 int dx = rand_range(6, floor_ptr->width - 6);
370 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
371 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
372 Rand_state_restore(state_backup);
375 /* Border of the wilderness area */
376 static border_type border;
380 * Build the wilderness area outside of the town.
381 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
382 * @param creature_ptr プレーヤーへの参照ポインタ
385 void wilderness_gen(player_type *creature_ptr)
387 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
388 floor_ptr->height = MAX_HGT;
389 floor_ptr->width = MAX_WID;
390 panel_row_min = floor_ptr->height;
391 panel_col_min = floor_ptr->width;
392 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
393 POSITION x = creature_ptr->wilderness_x;
394 POSITION y = creature_ptr->wilderness_y;
395 get_mon_num_prep(creature_ptr, get_monster_hook(creature_ptr), NULL);
398 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
399 for (int i = 1; i < MAX_WID - 1; i++)
400 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
403 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
404 for (int i = 1; i < MAX_WID - 1; i++)
405 border.south[i] = floor_ptr->grid_array[1][i].feat;
408 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
409 for (int i = 1; i < MAX_HGT - 1; i++)
410 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
413 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
414 for (int i = 1; i < MAX_HGT - 1; i++)
415 border.east[i] = floor_ptr->grid_array[i][1].feat;
417 /* North west corner */
418 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
419 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
421 /* North east corner */
422 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
423 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
425 /* South west corner */
426 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
427 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
429 /* South east corner */
430 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
431 border.south_east = floor_ptr->grid_array[1][1].feat;
433 /* Create terrain of the current area */
434 generate_area(creature_ptr, y, x, FALSE, FALSE);
436 /* Special boundary walls -- North */
437 for (int i = 0; i < MAX_WID; i++) {
438 floor_ptr->grid_array[0][i].feat = feat_permanent;
439 floor_ptr->grid_array[0][i].mimic = border.north[i];
442 /* Special boundary walls -- South */
443 for (int i = 0; i < MAX_WID; i++) {
444 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
445 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
448 /* Special boundary walls -- West */
449 for (int i = 0; i < MAX_HGT; i++) {
450 floor_ptr->grid_array[i][0].feat = feat_permanent;
451 floor_ptr->grid_array[i][0].mimic = border.west[i];
454 /* Special boundary walls -- East */
455 for (int i = 0; i < MAX_HGT; i++) {
456 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
457 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
460 floor_ptr->grid_array[0][0].mimic = border.north_west;
461 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
462 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
463 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
464 for (y = 0; y < floor_ptr->height; y++) {
465 for (x = 0; x < floor_ptr->width; x++) {
467 g_ptr = &floor_ptr->grid_array[y][x];
469 g_ptr->info |= CAVE_GLOW;
470 if (view_perma_grids)
471 g_ptr->info |= CAVE_MARK;
477 f_ptr = &f_info[get_feat_mimic(g_ptr)];
478 if (!is_mirror_grid(g_ptr) && !has_flag(f_ptr->flags, FF_QUEST_ENTER) && !has_flag(f_ptr->flags, FF_ENTRANCE)) {
479 g_ptr->info &= ~(CAVE_GLOW);
480 if (!has_flag(f_ptr->flags, FF_REMEMBER))
481 g_ptr->info &= ~(CAVE_MARK);
486 if (!has_flag(f_ptr->flags, FF_ENTRANCE))
489 g_ptr->info |= CAVE_GLOW;
490 if (view_perma_grids)
491 g_ptr->info |= CAVE_MARK;
495 if (creature_ptr->teleport_town) {
496 for (y = 0; y < floor_ptr->height; y++) {
497 for (x = 0; x < floor_ptr->width; x++) {
499 g_ptr = &floor_ptr->grid_array[y][x];
501 f_ptr = &f_info[g_ptr->feat];
502 if (!has_flag(f_ptr->flags, FF_BLDG))
505 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
508 if (g_ptr->m_idx != 0)
509 delete_monster_idx(creature_ptr, g_ptr->m_idx);
511 creature_ptr->oldpy = y;
512 creature_ptr->oldpx = x;
516 creature_ptr->teleport_town = FALSE;
517 } else if (creature_ptr->leaving_dungeon) {
518 for (y = 0; y < floor_ptr->height; y++) {
519 for (x = 0; x < floor_ptr->width; x++) {
521 g_ptr = &floor_ptr->grid_array[y][x];
522 if (!cave_has_flag_grid(g_ptr, FF_ENTRANCE))
525 if (g_ptr->m_idx != 0)
526 delete_monster_idx(creature_ptr, g_ptr->m_idx);
528 creature_ptr->oldpy = y;
529 creature_ptr->oldpx = x;
533 creature_ptr->teleport_town = FALSE;
536 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
537 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
538 for (int i = 0; i < lim; i++) {
540 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
541 mode |= PM_ALLOW_SLEEP;
543 (void)alloc_monster(creature_ptr, generate_encounter ? 0 : 3, mode, summon_specific);
546 if (generate_encounter)
547 creature_ptr->ambush_flag = TRUE;
549 generate_encounter = FALSE;
550 set_floor_and_wall(0);
551 for (int i = 0; i < max_q_idx; i++)
552 if (quest[i].status == QUEST_STATUS_REWARDED)
553 quest[i].status = QUEST_STATUS_FINISHED;
556 static s16b conv_terrain2feat[MAX_WILDERNESS];
559 * @brief 広域マップの生成(簡易処理版) /
560 * Build the wilderness area. -DG-
563 void wilderness_gen_small(player_type *creature_ptr)
565 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
566 for (int i = 0; i < MAX_WID; i++)
567 for (int j = 0; j < MAX_HGT; j++)
568 floor_ptr->grid_array[j][i].feat = feat_permanent;
570 parse_fixed_map(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
571 for (int i = 0; i < current_world_ptr->max_wild_x; i++) {
572 for (int j = 0; j < current_world_ptr->max_wild_y; j++) {
573 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN)) {
574 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
575 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
576 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
580 if (wilderness[j][i].road) {
581 floor_ptr->grid_array[j][i].feat = feat_floor;
582 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
586 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER))) {
587 floor_ptr->grid_array[j][i].feat = feat_entrance;
588 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
589 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
593 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
594 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
598 floor_ptr->height = (s16b)current_world_ptr->max_wild_y;
599 floor_ptr->width = (s16b)current_world_ptr->max_wild_x;
600 if (floor_ptr->height > MAX_HGT)
601 floor_ptr->height = MAX_HGT;
603 if (floor_ptr->width > MAX_WID)
604 floor_ptr->width = MAX_WID;
606 panel_row_min = floor_ptr->height;
607 panel_col_min = floor_ptr->width;
608 creature_ptr->x = creature_ptr->wilderness_x;
609 creature_ptr->y = creature_ptr->wilderness_y;
610 creature_ptr->town_num = 0;
613 typedef struct wilderness_grid {
614 wt_type terrain; /* Terrain type */
615 TOWN_IDX town; /* Town number */
616 DEPTH level; /* Level of the wilderness */
617 byte road; /* Road */
618 char name[32]; /* Name of the town/wilderness */
621 static wilderness_grid w_letter[255];
624 * @brief w_info.txtのデータ解析 /
625 * Parse a sub-file of the "extra info"
626 * @param buf 読み取ったデータ行のバッファ
628 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
630 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
631 * @param y 広域マップの高さを返す参照ポインタ
632 * @param x 広域マップの幅を返す参照ポインタ
635 parse_error_type parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
637 if (!(buf[0] == 'W'))
638 return (PARSE_ERROR_GENERIC);
643 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
646 return PARSE_ERROR_NONE;
651 return PARSE_ERROR_NONE;
656 if ((num = tokenize(buf + 4, 6, zz, 0)) > 1) {
657 int index = zz[0][0];
660 w_letter[index].terrain = static_cast<wt_type>(atoi(zz[1]));
662 w_letter[index].terrain = TERRAIN_EDGE;
665 w_letter[index].level = (s16b)atoi(zz[2]);
667 w_letter[index].level = 0;
670 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
672 w_letter[index].town = 0;
675 w_letter[index].road = (byte)atoi(zz[4]);
677 w_letter[index].road = 0;
680 strcpy(w_letter[index].name, zz[5]);
682 w_letter[index].name[0] = 0;
685 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
691 /* Process "W:D:<layout> */
692 /* Layout of the wilderness */
697 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++) {
699 wilderness[*y][*x].terrain = w_letter[id].terrain;
700 wilderness[*y][*x].level = w_letter[id].level;
701 wilderness[*y][*x].town = w_letter[id].town;
702 wilderness[*y][*x].road = w_letter[id].road;
703 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
710 /* Process "W:P:<x>:<y> - starting position in the wilderness */
712 bool is_corner = creature_ptr->wilderness_x == 0;
713 is_corner = creature_ptr->wilderness_y == 0;
717 if (tokenize(buf + 4, 2, zz, 0) != 2) {
718 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
721 creature_ptr->wilderness_y = atoi(zz[0]);
722 creature_ptr->wilderness_x = atoi(zz[1]);
724 if ((creature_ptr->wilderness_x < 1) || (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) || (creature_ptr->wilderness_y < 1)
725 || (creature_ptr->wilderness_y > current_world_ptr->max_wild_y)) {
726 return PARSE_ERROR_OUT_OF_BOUNDS;
733 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
736 for (int i = 1; i < current_world_ptr->max_d_idx; i++) {
737 if (!d_info[i].maxdepth)
739 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte)i;
740 if (!wilderness[d_info[i].dy][d_info[i].dx].town) {
741 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
745 return PARSE_ERROR_NONE;
749 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
750 * Generate the random seeds for the wilderness
753 void seed_wilderness(void)
755 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
756 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++) {
757 wilderness[y][x].seed = randint0(0x10000000);
758 wilderness[y][x].entrance = 0;
762 /* Pointer to wilderness_type */
763 typedef wilderness_type *wilderness_type_ptr;
766 * @brief ゲーム開始時の荒野初期化メインルーチン /
767 * Initialize wilderness array
770 errr init_wilderness(void)
772 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
773 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
774 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
775 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
777 generate_encounter = FALSE;
782 * @brief 荒野の地勢設定を初期化する /
783 * Initialize wilderness array
784 * @param terrain 初期化したい地勢ID
785 * @param feat_global 基本的な地形ID
786 * @param fmt 地勢内の地形数を参照するための独自フォーマット
789 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
793 conv_terrain2feat[terrain] = feat_global;
796 for (concptr p = fmt; *p; p++) {
798 plog_fmt("Format error");
802 FEAT_IDX feat = (s16b)va_arg(vp, int);
803 int num = va_arg(vp, int);
805 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
806 terrain_table[terrain][cur] = feat;
808 if (cur >= MAX_FEAT_IN_TERRAIN)
814 if (cur < MAX_FEAT_IN_TERRAIN)
815 plog_fmt("Too few parameters");
821 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
822 * Initialize arrays for wilderness terrains
825 void init_wilderness_terrains(void)
827 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a", feat_permanent, MAX_FEAT_IN_TERRAIN);
828 init_terrain_table(TERRAIN_TOWN, feat_town, "a", feat_floor, MAX_FEAT_IN_TERRAIN);
829 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab", feat_deep_water, 12, feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
830 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,
831 MAX_FEAT_IN_TERRAIN - 17);
832 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,
833 MAX_FEAT_IN_TERRAIN - 11);
835 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);
837 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);
838 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);
839 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc", feat_floor, 2, feat_dirt, 13, feat_grass, MAX_FEAT_IN_TERRAIN - 15);
840 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);
842 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);
843 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,
844 MAX_FEAT_IN_TERRAIN - 8);
848 * @brief 荒野から広域マップへの切り替え処理 /
849 * Initialize arrays for wilderness terrains
850 * @param encount 襲撃時TRUE
851 * @return 切り替えが行われた場合はTRUEを返す。
853 bool change_wild_mode(player_type *creature_ptr, bool encount)
855 generate_encounter = encount;
856 if (creature_ptr->leaving)
859 if (lite_town || vanilla_town) {
860 msg_print(_("荒野なんてない。", "No global map."));
864 if (creature_ptr->wild_mode) {
865 creature_ptr->wilderness_x = creature_ptr->x;
866 creature_ptr->wilderness_y = creature_ptr->y;
867 creature_ptr->energy_need = 0;
868 creature_ptr->wild_mode = FALSE;
869 creature_ptr->leaving = TRUE;
873 bool has_pet = FALSE;
874 PlayerEnergy energy(creature_ptr);
875 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
876 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
877 if (!monster_is_valid(m_ptr))
880 if (is_pet(m_ptr) && i != creature_ptr->riding)
883 if (monster_csleep_remaining(m_ptr) || (m_ptr->cdis > MAX_SIGHT) || !is_hostile(m_ptr))
886 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!", "You cannot enter global map, since there are some monsters nearby!"));
887 energy.reset_player_turn();
892 concptr msg = _("ペットを置いて広域マップに入りますか?", "Do you leave your pets behind? ");
893 if (!get_check_strict(creature_ptr, msg, CHECK_OKAY_CANCEL)) {
894 energy.reset_player_turn();
899 energy.update_player_turn_energy(1000, update_turn_type::ENERGY_SUBSTITUTION);
900 creature_ptr->oldpx = creature_ptr->x;
901 creature_ptr->oldpy = creature_ptr->y;
902 if (hex_spelling_any(creature_ptr))
903 stop_hex_spell_all(creature_ptr);
905 set_action(creature_ptr, ACTION_NONE);
906 creature_ptr->wild_mode = TRUE;
907 creature_ptr->leaving = TRUE;