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.
22 #include "realm-hex.h"
23 #include "player-status.h"
24 #include "player-effects.h"
26 #include "monster-status.h"
28 #include "dungeon-file.h"
31 #include "floor-town.h"
34 #include "view-mainwindow.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;
431 bool is_winner = wilderness[y][x].entrance;
432 is_winner &= !wilderness[y][x].town;
433 is_winner &= (current_world_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER));
434 if (!is_winner) return;
436 /* Hack -- Backup the RNG state */
437 u32b state_backup[4];
438 Rand_state_backup(state_backup);
440 /* Hack -- Induce consistant flavors */
441 Rand_state_set(wilderness[y][x].seed);
443 int dy = rand_range(6, floor_ptr->height - 6);
444 int dx = rand_range(6, floor_ptr->width - 6);
446 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
447 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
449 /* Hack -- Restore the RNG state */
450 Rand_state_restore(state_backup);
455 * Border of the wilderness area
457 static border_type border;
461 * Build the wilderness area outside of the town.
462 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
463 * @param creature_ptr プレーヤーへの参照ポインタ
466 void wilderness_gen(player_type *creature_ptr)
469 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
470 floor_ptr->height = MAX_HGT;
471 floor_ptr->width = MAX_WID;
473 /* Assume illegal panel */
474 panel_row_min = floor_ptr->height;
475 panel_col_min = floor_ptr->width;
477 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
478 POSITION x = creature_ptr->wilderness_x;
479 POSITION y = creature_ptr->wilderness_y;
480 get_mon_num_prep(get_monster_hook(), NULL);
483 generate_area(creature_ptr, y - 1, x, TRUE, FALSE);
485 for (int i = 1; i < MAX_WID - 1; i++)
487 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
491 generate_area(creature_ptr, y + 1, x, TRUE, FALSE);
493 for (int i = 1; i < MAX_WID - 1; i++)
495 border.south[i] = floor_ptr->grid_array[1][i].feat;
499 generate_area(creature_ptr, y, x - 1, TRUE, FALSE);
501 for (int i = 1; i < MAX_HGT - 1; i++)
503 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
507 generate_area(creature_ptr, y, x + 1, TRUE, FALSE);
509 for (int i = 1; i < MAX_HGT - 1; i++)
511 border.east[i] = floor_ptr->grid_array[i][1].feat;
514 /* North west corner */
515 generate_area(creature_ptr, y - 1, x - 1, FALSE, TRUE);
516 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
518 /* North east corner */
519 generate_area(creature_ptr, y - 1, x + 1, FALSE, TRUE);
520 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
522 /* South west corner */
523 generate_area(creature_ptr, y + 1, x - 1, FALSE, TRUE);
524 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
526 /* South east corner */
527 generate_area(creature_ptr, y + 1, x + 1, FALSE, TRUE);
528 border.south_east = floor_ptr->grid_array[1][1].feat;
530 /* Create terrain of the current area */
531 generate_area(creature_ptr, y, x, FALSE, FALSE);
533 /* Special boundary walls -- North */
534 for (int i = 0; i < MAX_WID; i++)
536 floor_ptr->grid_array[0][i].feat = feat_permanent;
537 floor_ptr->grid_array[0][i].mimic = border.north[i];
540 /* Special boundary walls -- South */
541 for (int i = 0; i < MAX_WID; i++)
543 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
544 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
547 /* Special boundary walls -- West */
548 for (int i = 0; i < MAX_HGT; i++)
550 floor_ptr->grid_array[i][0].feat = feat_permanent;
551 floor_ptr->grid_array[i][0].mimic = border.west[i];
554 /* Special boundary walls -- East */
555 for (int i = 0; i < MAX_HGT; i++)
557 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
558 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
561 floor_ptr->grid_array[0][0].mimic = border.north_west;
562 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
563 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
564 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
566 /* Light up or darken the area */
567 for (y = 0; y < floor_ptr->height; y++)
569 for (x = 0; x < floor_ptr->width; x++)
572 g_ptr = &floor_ptr->grid_array[y][x];
577 g_ptr->info |= CAVE_GLOW;
579 /* Hack -- Memorize lit grids if allowed */
580 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
584 /* Feature code (applying "mimic" field) */
586 f_ptr = &f_info[get_feat_mimic(g_ptr)];
588 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
589 !have_flag(f_ptr->flags, FF_ENTRANCE))
592 g_ptr->info &= ~(CAVE_GLOW);
594 /* Darken "boring" features */
595 if (!have_flag(f_ptr->flags, FF_REMEMBER))
597 /* Forget the grid */
598 g_ptr->info &= ~(CAVE_MARK);
604 if (!have_flag(f_ptr->flags, FF_ENTRANCE)) continue;
606 g_ptr->info |= CAVE_GLOW;
608 /* Hack -- Memorize lit grids if allowed */
609 if (view_perma_grids) g_ptr->info |= CAVE_MARK;
613 if (creature_ptr->teleport_town)
615 for (y = 0; y < floor_ptr->height; y++)
617 for (x = 0; x < floor_ptr->width; x++)
620 g_ptr = &floor_ptr->grid_array[y][x];
622 /* Seeing true feature code (ignore mimic) */
624 f_ptr = &f_info[g_ptr->feat];
626 if (!have_flag(f_ptr->flags, FF_BLDG)) continue;
628 if ((f_ptr->subtype != 4) && !((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
633 delete_monster_idx(g_ptr->m_idx);
636 creature_ptr->oldpy = y;
637 creature_ptr->oldpx = x;
641 creature_ptr->teleport_town = FALSE;
643 else if (creature_ptr->leaving_dungeon)
645 for (y = 0; y < floor_ptr->height; y++)
647 for (x = 0; x < floor_ptr->width; x++)
650 g_ptr = &floor_ptr->grid_array[y][x];
652 if (!cave_have_flag_grid(g_ptr, FF_ENTRANCE)) continue;
656 delete_monster_idx(g_ptr->m_idx);
659 creature_ptr->oldpy = y;
660 creature_ptr->oldpx = x;
664 creature_ptr->teleport_town = FALSE;
667 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
668 int lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
670 /* Make some residents */
671 for (int i = 0; i < lim; i++)
675 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
676 mode |= PM_ALLOW_SLEEP;
678 /* Make a resident */
679 (void)alloc_monster(generate_encounter ? 0 : 3, mode);
682 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
683 generate_encounter = FALSE;
685 /* Fill the arrays of floors and walls in the good proportions */
686 set_floor_and_wall(0);
688 /* Set rewarded quests to finished */
689 for (int i = 0; i < max_q_idx; i++)
691 if (quest[i].status == QUEST_STATUS_REWARDED)
692 quest[i].status = QUEST_STATUS_FINISHED;
696 static s16b conv_terrain2feat[MAX_WILDERNESS];
699 * @brief 広域マップの生成(簡易処理版) /
700 * Build the wilderness area. -DG-
703 void wilderness_gen_small(player_type *creature_ptr)
705 /* To prevent stupid things */
706 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
707 for (int i = 0; i < MAX_WID; i++)
709 for (int j = 0; j < MAX_HGT; j++)
711 floor_ptr->grid_array[j][i].feat = feat_permanent;
715 process_dungeon_file(creature_ptr, "w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
718 for (int i = 0; i < current_world_ptr->max_wild_x; i++)
720 for (int j = 0; j < current_world_ptr->max_wild_y; j++)
722 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
724 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
725 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
726 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
730 if (wilderness[j][i].road)
732 floor_ptr->grid_array[j][i].feat = feat_floor;
733 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
737 if (wilderness[j][i].entrance && (current_world_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
739 floor_ptr->grid_array[j][i].feat = feat_entrance;
740 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
741 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
745 floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
746 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
750 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
751 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
753 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
754 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
756 /* Assume illegal panel */
757 panel_row_min = floor_ptr->height;
758 panel_col_min = floor_ptr->width;
760 creature_ptr->x = creature_ptr->wilderness_x;
761 creature_ptr->y = creature_ptr->wilderness_y;
762 creature_ptr->town_num = 0;
766 typedef struct wilderness_grid wilderness_grid;
768 struct wilderness_grid
770 int terrain; /* Terrain type */
771 TOWN_IDX town; /* Town number */
772 DEPTH level; /* Level of the wilderness */
773 byte road; /* Road */
774 char name[32]; /* Name of the town/wilderness */
778 static wilderness_grid w_letter[255];
781 * @brief w_info.txtのデータ解析 /
782 * Parse a sub-file of the "extra info"
783 * @param buf 読み取ったデータ行のバッファ
785 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
787 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
788 * @param y 広域マップの高さを返す参照ポインタ
789 * @param x 広域マップの幅を返す参照ポインタ
792 errr parse_line_wilderness(player_type *creature_ptr, char *buf, int xmin, int xmax, int *y, int *x)
794 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
800 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
813 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
815 int index = zz[0][0];
818 w_letter[index].terrain = atoi(zz[1]);
820 w_letter[index].terrain = 0;
823 w_letter[index].level = (s16b)atoi(zz[2]);
825 w_letter[index].level = 0;
828 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
830 w_letter[index].town = 0;
833 w_letter[index].road = (byte_hack)atoi(zz[4]);
835 w_letter[index].road = 0;
838 strcpy(w_letter[index].name, zz[5]);
840 w_letter[index].name[0] = 0;
845 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
851 /* Process "W:D:<layout> */
852 /* Layout of the wilderness */
858 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
861 wilderness[*y][*x].terrain = w_letter[id].terrain;
862 wilderness[*y][*x].level = w_letter[id].level;
863 wilderness[*y][*x].town = w_letter[id].town;
864 wilderness[*y][*x].road = w_letter[id].road;
865 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
872 /* Process "W:P:<x>:<y> - starting position in the wilderness */
875 bool is_corner = creature_ptr->wilderness_x == 0;
876 is_corner = creature_ptr->wilderness_y == 0;
877 if (!is_corner) break;
879 if (tokenize(buf + 4, 2, zz, 0) != 2)
881 return PARSE_ERROR_TOO_FEW_ARGUMENTS;
884 creature_ptr->wilderness_y = atoi(zz[0]);
885 creature_ptr->wilderness_x = atoi(zz[1]);
887 if ((creature_ptr->wilderness_x < 1) ||
888 (creature_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
889 (creature_ptr->wilderness_y < 1) ||
890 (creature_ptr->wilderness_y > current_world_ptr->max_wild_y))
892 return PARSE_ERROR_OUT_OF_BOUNDS;
899 return PARSE_ERROR_UNDEFINED_DIRECTIVE;
902 for (int i = 1; i < current_world_ptr->max_d_idx; i++)
904 if (!d_info[i].maxdepth) continue;
905 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte_hack)i;
906 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
908 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
917 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
918 * Generate the random seeds for the wilderness
921 void seed_wilderness(void)
923 for (POSITION x = 0; x < current_world_ptr->max_wild_x; x++)
925 for (POSITION y = 0; y < current_world_ptr->max_wild_y; y++)
927 wilderness[y][x].seed = randint0(0x10000000);
928 wilderness[y][x].entrance = 0;
935 * Pointer to wilderness_type
937 typedef wilderness_type *wilderness_type_ptr;
940 * @brief ゲーム開始時の荒野初期化メインルーチン /
941 * Initialize wilderness array
944 errr init_wilderness(void)
946 /* Allocate the wilderness (two-dimension array) */
947 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
948 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
950 /* Init the other pointers */
951 for (int i = 1; i < current_world_ptr->max_wild_y; i++)
953 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
956 generate_encounter = FALSE;
962 * @brief 荒野の地勢設定を初期化する /
963 * Initialize wilderness array
964 * @param terrain 初期化したい地勢ID
965 * @param feat_global 基本的な地形ID
966 * @param fmt 地勢内の地形数を参照するための独自フォーマット
969 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
971 /* Begin the varargs stuff */
975 /* Wilderness terrains on global map */
976 conv_terrain2feat[terrain] = feat_global;
978 /* Wilderness terrains on local map */
981 for (concptr p = fmt; *p; p++)
985 plog_fmt("Format error");
989 FEAT_IDX feat = (s16b)va_arg(vp, int);
990 int num = va_arg(vp, int);
993 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
995 terrain_table[terrain][cur] = feat;
998 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1003 if (cur < MAX_FEAT_IN_TERRAIN)
1005 plog_fmt("Too few parameters");
1013 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1014 * Initialize arrays for wilderness terrains
1017 void init_wilderness_terrains(void)
1019 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1020 feat_permanent, MAX_FEAT_IN_TERRAIN);
1022 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1023 feat_floor, MAX_FEAT_IN_TERRAIN);
1025 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1026 feat_deep_water, 12,
1027 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1029 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1031 feat_shallow_water, 12,
1034 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1036 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1041 feat_shallow_water, 4,
1042 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1044 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1050 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1052 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1058 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1060 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1065 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1067 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1070 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1072 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1073 feat_shallow_lava, 14,
1075 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1077 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1079 feat_shallow_lava, 3,
1081 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1083 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1089 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1094 * @brief 荒野から広域マップへの切り替え処理 /
1095 * Initialize arrays for wilderness terrains
1096 * @param encount 襲撃時TRUE
1097 * @return 切り替えが行われた場合はTRUEを返す。
1099 bool change_wild_mode(player_type *creature_ptr, bool encount)
1101 generate_encounter = encount;
1103 /* It is in the middle of changing map */
1104 if (creature_ptr->leaving) return FALSE;
1106 if (lite_town || vanilla_town)
1108 msg_print(_("荒野なんてない。", "No global map."));
1112 if (creature_ptr->wild_mode)
1114 /* Save the location in the global map */
1115 creature_ptr->wilderness_x = creature_ptr->x;
1116 creature_ptr->wilderness_y = creature_ptr->y;
1118 /* Give first move to the player */
1119 creature_ptr->energy_need = 0;
1121 /* Go back to the ordinary map */
1122 creature_ptr->wild_mode = FALSE;
1123 creature_ptr->leaving = TRUE;
1127 bool have_pet = FALSE;
1128 for (int i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1130 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1132 if (!monster_is_valid(m_ptr)) continue;
1133 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1134 if (MON_CSLEEP(m_ptr)) continue;
1135 if (m_ptr->cdis > MAX_SIGHT) continue;
1136 if (!is_hostile(m_ptr)) continue;
1137 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1138 "You cannot enter global map, since there is some monsters nearby!"));
1139 free_turn(creature_ptr);
1145 concptr msg = _("ペットを置いて広域マップに入りますか?",
1146 "Do you leave your pets behind? ");
1148 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1150 free_turn(creature_ptr);
1155 take_turn(creature_ptr, 1000);
1157 /* Remember the position */
1158 creature_ptr->oldpx = creature_ptr->x;
1159 creature_ptr->oldpy = creature_ptr->y;
1161 /* Cancel hex spelling */
1162 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1164 /* Cancel any special action */
1165 set_action(creature_ptr, ACTION_NONE);
1167 /* Go into the global map */
1168 creature_ptr->wild_mode = TRUE;
1169 creature_ptr->leaving = TRUE;