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"
39 wilderness_type **wilderness;
41 bool generate_encounter;
45 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
46 * @param feat_type 非一様確率を再現するための要素数100の配列
47 * @param prob 元の確率テーブル
50 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
52 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
54 lim[0] = prob[0].percent;
55 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
56 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
58 for (i = 0; i < 100; i++)
60 while (i == lim[cur]) cur++;
61 feat_type[i] = prob[cur].feat;
66 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
67 * / Fill the arrays of floors and walls in the good proportions
71 void set_floor_and_wall(DUNGEON_IDX type)
73 DUNGEON_IDX cur_type = 255;
77 if (cur_type == type) return;
80 d_ptr = &d_info[type];
82 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
83 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
85 feat_wall_outer = d_ptr->outer_wall;
86 feat_wall_inner = d_ptr->inner_wall;
87 feat_wall_solid = d_ptr->outer_wall;
92 * @brief プラズマフラクタル的地形生成の再帰中間処理
93 * / Helper for plasma generation.
101 * @param depth_max 深みの最大値
104 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)
107 * Average the four corners & perturb it a bit.
108 * tmp is a random int +/- rough
110 FEAT_IDX tmp2 = rough*2 + 1;
111 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
113 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
115 /* Division always rounds down, so we round up again */
116 if (((x1 + x2 + x3 + x4) % 4) > 1)
120 if (avg < 0) avg = 0;
121 if (avg > depth_max) avg = depth_max;
123 /* Set the new value. */
124 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
129 * @brief プラズマフラクタル的地形生成の再帰末端処理
130 * / Helper for plasma generation.
131 * @param x1 中間末端部1の重み
132 * @param x2 中間末端部2の重み
133 * @param x3 中間末端部3の重み
134 * @param xmid 最終末端部座標X
135 * @param ymid 最終末端部座標Y
137 * @param depth_max 深みの最大値
140 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)
143 * Average the three corners & perturb it a bit.
144 * tmp is a random int +/- rough
146 FEAT_IDX tmp2 = rough * 2 + 1;
147 FEAT_IDX tmp = randint0(tmp2) - rough;
149 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
151 /* Division always rounds down, so we round up again */
152 if ((x1 + x2 + x3) % 3) avg++;
155 if (avg < 0) avg = 0;
156 if (avg > depth_max) avg = depth_max;
158 /* Set the new value. */
159 floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
164 * @brief プラズマフラクタル的地形生成の開始処理
165 * / Helper for plasma generation.
166 * @param x1 処理範囲の左上X座標
167 * @param y1 処理範囲の左上Y座標
168 * @param x2 処理範囲の右下X座標
169 * @param y2 処理範囲の右下Y座標
170 * @param depth_max 深みの最大値
175 * A generic function to generate the plasma fractal.
176 * Note that it uses ``cave_feat'' as temporary storage.
177 * The values in ``cave_feat'' after this function
178 * are NOT actual features; They are raw heights which
179 * need to be converted to features.
182 static void plasma_recursive(floor_type *floor_ptr, POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
185 POSITION xmid = (x2 - x1) / 2 + x1;
186 POSITION ymid = (y2 - y1) / 2 + y1;
189 if (x1 + 1 == x2) return;
191 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,
192 floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
194 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,
195 xmid, y1, rough, depth_max);
197 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,
198 x2, ymid, rough, depth_max);
200 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,
201 xmid, y2, rough, depth_max);
203 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,
204 x1, ymid, rough, depth_max);
207 /* Recurse the four quadrants */
208 plasma_recursive(floor_ptr, x1, y1, xmid, ymid, depth_max, rough);
209 plasma_recursive(floor_ptr, xmid, y1, x2, ymid, depth_max, rough);
210 plasma_recursive(floor_ptr, x1, ymid, xmid, y2, depth_max, rough);
211 plasma_recursive(floor_ptr, xmid, ymid, x2, y2, depth_max, rough);
215 #define MAX_FEAT_IN_TERRAIN 18
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 border, bool corner)
233 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
234 FEAT_IDX roughness = 1; /* The roughness of the level. */
235 u32b state_backup[4];
240 /* The outer wall is easy */
241 if (terrain == TERRAIN_EDGE)
243 /* Create level background */
244 for (y1 = 0; y1 < MAX_HGT; y1++)
246 for (x1 = 0; x1 < MAX_WID; x1++)
248 floor_ptr->grid_array[y1][x1].feat = feat_permanent;
252 /* We are done already */
257 /* Hack -- Backup the RNG state */
258 Rand_state_backup(state_backup);
260 /* Hack -- Induce consistant flavors */
261 Rand_state_set(seed);
265 /* Create level background */
266 for (y1 = 0; y1 < MAX_HGT; y1++)
268 for (x1 = 0; x1 < MAX_WID; x1++)
270 floor_ptr->grid_array[y1][x1].feat = table_size / 2;
276 * Initialize the four corners
277 * ToDo: calculate the medium height of the adjacent
278 * terrains for every corner.
280 floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
281 floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
282 floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
283 floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
287 /* Hack -- preserve four corners */
288 s16b north_west = floor_ptr->grid_array[1][1].feat;
289 s16b south_west = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
290 s16b north_east = floor_ptr->grid_array[1][MAX_WID - 2].feat;
291 s16b south_east = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
293 /* x1, y1, x2, y2, num_depths, roughness */
294 plasma_recursive(floor_ptr, 1, 1, MAX_WID-2, MAX_HGT-2, table_size-1, roughness);
296 /* Hack -- copyback four corners */
297 floor_ptr->grid_array[1][1].feat = north_west;
298 floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
299 floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
300 floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
302 for (y1 = 1; y1 < MAX_HGT - 1; y1++)
304 for (x1 = 1; x1 < MAX_WID - 1; x1++)
306 floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][floor_ptr->grid_array[y1][x1].feat];
310 else /* Hack -- only four corners */
312 floor_ptr->grid_array[1][1].feat = terrain_table[terrain][floor_ptr->grid_array[1][1].feat];
313 floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][floor_ptr->grid_array[MAX_HGT - 2][1].feat];
314 floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][floor_ptr->grid_array[1][MAX_WID - 2].feat];
315 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];
318 /* Hack -- Restore the RNG state */
319 Rand_state_restore(state_backup);
325 * @brief 荒野フロア生成のメインルーチン /
326 * Load a town or generate a terrain level using "plasma" fractals.
329 * @param border 広域マップの辺部分としての生成ならばTRUE
330 * @param corner 広域マップの角部分としての生成ならばTRUE
334 * x and y are the coordinates of the area in the wilderness.
335 * Border and corner are optimization flags to speed up the
336 * generation of the fractal terrain.
337 * If border is set then only the border of the terrain should
338 * be generated (for initializing the border structure).
339 * If corner is set then only the corners of the area are needed.
342 static void generate_area(floor_type *floor_ptr, POSITION y, POSITION x, bool border, bool corner)
346 /* Number of the town (if any) */
347 p_ptr->town_num = wilderness[y][x].town;
349 /* Set the base level */
350 floor_ptr->base_level = wilderness[y][x].level;
352 /* Set the dungeon level */
353 floor_ptr->dun_level = 0;
355 /* Set the monster generation level */
356 floor_ptr->monster_level = floor_ptr->base_level;
358 /* Set the object generation level */
359 floor_ptr->object_level = floor_ptr->base_level;
362 /* Create the town */
365 /* Reset the buildings */
368 /* Initialize the town */
370 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
372 init_flags = INIT_CREATE_DUNGEON;
374 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
376 if (!corner && !border) p_ptr->visit |= (1L << (p_ptr->town_num - 1));
380 int terrain = wilderness[y][x].terrain;
381 u32b seed = wilderness[y][x].seed;
383 generate_wilderness_area(floor_ptr, terrain, seed, border, corner);
386 if (!corner && !wilderness[y][x].town)
389 * Place roads in the wilderness
390 * ToDo: make the road a bit more interresting
392 if (wilderness[y][x].road)
394 floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
396 if (wilderness[y-1][x].road)
399 for (y1 = 1; y1 < MAX_HGT/2; y1++)
402 floor_ptr->grid_array[y1][x1].feat = feat_floor;
406 if (wilderness[y+1][x].road)
409 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
412 floor_ptr->grid_array[y1][x1].feat = feat_floor;
416 if (wilderness[y][x+1].road)
419 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
422 floor_ptr->grid_array[y1][x1].feat = feat_floor;
426 if (wilderness[y][x-1].road)
429 for (x1 = 1; x1 < MAX_WID/2; x1++)
432 floor_ptr->grid_array[y1][x1].feat = feat_floor;
438 if (wilderness[y][x].entrance && !wilderness[y][x].town && (p_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER)))
441 u32b state_backup[4];
443 /* Hack -- Backup the RNG state */
444 Rand_state_backup(state_backup);
446 /* Hack -- Induce consistant flavors */
447 Rand_state_set(wilderness[y][x].seed);
449 dy = rand_range(6, floor_ptr->height - 6);
450 dx = rand_range(6, floor_ptr->width - 6);
452 floor_ptr->grid_array[dy][dx].feat = feat_entrance;
453 floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
455 /* Hack -- Restore the RNG state */
456 Rand_state_restore(state_backup);
462 * Border of the wilderness area
464 static border_type border;
469 * Build the wilderness area outside of the town.
470 * @todo 広域マップは恒常生成にする予定、player_typeによる処理分岐は最終的に排除する。
473 void wilderness_gen(player_type *creature_ptr, floor_type *floor_ptr)
481 floor_ptr->height = MAX_HGT;
482 floor_ptr->width = MAX_WID;
484 /* Assume illegal panel */
485 panel_row_min = floor_ptr->height;
486 panel_col_min = floor_ptr->width;
488 process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
489 x = creature_ptr->wilderness_x;
490 y = creature_ptr->wilderness_y;
491 get_mon_num_prep(get_monster_hook(), NULL);
494 generate_area(floor_ptr, y - 1, x, TRUE, FALSE);
496 for (i = 1; i < MAX_WID - 1; i++)
498 border.north[i] = floor_ptr->grid_array[MAX_HGT - 2][i].feat;
502 generate_area(floor_ptr, y + 1, x, TRUE, FALSE);
504 for (i = 1; i < MAX_WID - 1; i++)
506 border.south[i] = floor_ptr->grid_array[1][i].feat;
510 generate_area(floor_ptr, y, x - 1, TRUE, FALSE);
512 for (i = 1; i < MAX_HGT - 1; i++)
514 border.west[i] = floor_ptr->grid_array[i][MAX_WID - 2].feat;
518 generate_area(floor_ptr, y, x + 1, TRUE, FALSE);
520 for (i = 1; i < MAX_HGT - 1; i++)
522 border.east[i] = floor_ptr->grid_array[i][1].feat;
525 /* North west corner */
526 generate_area(floor_ptr, y - 1, x - 1, FALSE, TRUE);
527 border.north_west = floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
529 /* North east corner */
530 generate_area(floor_ptr, y - 1, x + 1, FALSE, TRUE);
531 border.north_east = floor_ptr->grid_array[MAX_HGT - 2][1].feat;
533 /* South west corner */
534 generate_area(floor_ptr, y + 1, x - 1, FALSE, TRUE);
535 border.south_west = floor_ptr->grid_array[1][MAX_WID - 2].feat;
537 /* South east corner */
538 generate_area(floor_ptr, y + 1, x + 1, FALSE, TRUE);
539 border.south_east = floor_ptr->grid_array[1][1].feat;
542 /* Create terrain of the current area */
543 generate_area(floor_ptr, y, x, FALSE, FALSE);
546 /* Special boundary walls -- North */
547 for (i = 0; i < MAX_WID; i++)
549 floor_ptr->grid_array[0][i].feat = feat_permanent;
550 floor_ptr->grid_array[0][i].mimic = border.north[i];
553 /* Special boundary walls -- South */
554 for (i = 0; i < MAX_WID; i++)
556 floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
557 floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
560 /* Special boundary walls -- West */
561 for (i = 0; i < MAX_HGT; i++)
563 floor_ptr->grid_array[i][0].feat = feat_permanent;
564 floor_ptr->grid_array[i][0].mimic = border.west[i];
567 /* Special boundary walls -- East */
568 for (i = 0; i < MAX_HGT; i++)
570 floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
571 floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
574 /* North west corner */
575 floor_ptr->grid_array[0][0].mimic = border.north_west;
577 /* North east corner */
578 floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
580 /* South west corner */
581 floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
583 /* South east corner */
584 floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
586 /* Light up or darken the area */
587 for (y = 0; y < floor_ptr->height; y++)
589 for (x = 0; x < floor_ptr->width; x++)
591 g_ptr = &floor_ptr->grid_array[y][x];
596 g_ptr->info |= (CAVE_GLOW);
598 /* Hack -- Memorize lit grids if allowed */
599 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
603 /* Feature code (applying "mimic" field) */
604 f_ptr = &f_info[get_feat_mimic(g_ptr)];
606 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
607 !have_flag(f_ptr->flags, FF_ENTRANCE))
610 g_ptr->info &= ~(CAVE_GLOW);
612 /* Darken "boring" features */
613 if (!have_flag(f_ptr->flags, FF_REMEMBER))
615 /* Forget the grid */
616 g_ptr->info &= ~(CAVE_MARK);
619 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
622 g_ptr->info |= (CAVE_GLOW);
624 /* Hack -- Memorize lit grids if allowed */
625 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
631 if (creature_ptr->teleport_town)
633 for (y = 0; y < floor_ptr->height; y++)
635 for (x = 0; x < floor_ptr->width; x++)
637 g_ptr = &floor_ptr->grid_array[y][x];
639 /* Seeing true feature code (ignore mimic) */
640 f_ptr = &f_info[g_ptr->feat];
642 if (have_flag(f_ptr->flags, FF_BLDG))
644 if ((f_ptr->subtype == 4) || ((creature_ptr->town_num == 1) && (f_ptr->subtype == 0)))
646 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
647 creature_ptr->oldpy = y;
648 creature_ptr->oldpx = x;
653 creature_ptr->teleport_town = FALSE;
656 else if (creature_ptr->leaving_dungeon)
658 for (y = 0; y < floor_ptr->height; y++)
660 for (x = 0; x < floor_ptr->width; x++)
662 g_ptr = &floor_ptr->grid_array[y][x];
664 if (cave_have_flag_grid(g_ptr, FF_ENTRANCE))
666 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
667 creature_ptr->oldpy = y;
668 creature_ptr->oldpx = x;
672 creature_ptr->teleport_town = FALSE;
675 player_place(creature_ptr, creature_ptr->oldpy, creature_ptr->oldpx);
677 lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
679 /* Make some residents */
680 for (i = 0; i < lim; i++)
684 if (!(generate_encounter || (one_in_(2) && (!creature_ptr->town_num))))
685 mode |= PM_ALLOW_SLEEP;
687 /* Make a resident */
688 (void)alloc_monster(generate_encounter ? 0 : 3, mode);
691 if(generate_encounter) creature_ptr->ambush_flag = TRUE;
692 generate_encounter = FALSE;
694 /* Fill the arrays of floors and walls in the good proportions */
695 set_floor_and_wall(0);
697 /* Set rewarded quests to finished */
698 for (i = 0; i < max_q_idx; i++)
700 if (quest[i].status == QUEST_STATUS_REWARDED)
701 quest[i].status = QUEST_STATUS_FINISHED;
705 static s16b conv_terrain2feat[MAX_WILDERNESS];
708 * @brief 広域マップの生成(簡易処理版) /
709 * Build the wilderness area. -DG-
712 void wilderness_gen_small(player_type *creature_ptr, floor_type *floor_ptr)
716 /* To prevent stupid things */
717 for (i = 0; i < MAX_WID; i++)
718 for (j = 0; j < MAX_HGT; j++)
720 floor_ptr->grid_array[j][i].feat = feat_permanent;
723 process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
726 for (i = 0; i < current_world_ptr->max_wild_x; i++)
727 for (j = 0; j < current_world_ptr->max_wild_y; j++)
729 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
731 floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
732 floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
734 else if (wilderness[j][i].road) floor_ptr->grid_array[j][i].feat = feat_floor;
735 else if (wilderness[j][i].entrance && (creature_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
737 floor_ptr->grid_array[j][i].feat = feat_entrance;
738 floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
740 else floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
742 floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
745 floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
746 floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
748 if (floor_ptr->height > MAX_HGT) floor_ptr->height = MAX_HGT;
749 if (floor_ptr->width > MAX_WID) floor_ptr->width = MAX_WID;
751 /* Assume illegal panel */
752 panel_row_min = floor_ptr->height;
753 panel_col_min = floor_ptr->width;
755 creature_ptr->x = creature_ptr->wilderness_x;
756 creature_ptr->y = creature_ptr->wilderness_y;
757 creature_ptr->town_num = 0;
761 typedef struct wilderness_grid wilderness_grid;
763 struct wilderness_grid
765 int terrain; /* Terrain type */
766 TOWN_IDX town; /* Town number */
767 DEPTH level; /* Level of the wilderness */
768 byte road; /* Road */
769 char name[32]; /* Name of the town/wilderness */
773 static wilderness_grid w_letter[255];
777 * @brief w_info.txtのデータ解析 /
778 * Parse a sub-file of the "extra info"
779 * @param buf 読み取ったデータ行のバッファ
781 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
783 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
784 * @param y 広域マップの高さを返す参照ポインタ
785 * @param x 広域マップの幅を返す参照ポインタ
788 errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
796 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 */
855 /* Acquire the text */
858 /* Length of the text */
861 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
864 wilderness[*y][*x].terrain = w_letter[id].terrain;
865 wilderness[*y][*x].level = w_letter[id].level;
866 wilderness[*y][*x].town = w_letter[id].town;
867 wilderness[*y][*x].road = w_letter[id].road;
868 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
876 /* Process "W:P:<x>:<y> - starting position in the wilderness */
879 if ((p_ptr->wilderness_x == 0) &&
880 (p_ptr->wilderness_y == 0))
882 if (tokenize(buf+4, 2, zz, 0) == 2)
884 p_ptr->wilderness_y = atoi(zz[0]);
885 p_ptr->wilderness_x = atoi(zz[1]);
887 if ((p_ptr->wilderness_x < 1) ||
888 (p_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
889 (p_ptr->wilderness_y < 1) ||
890 (p_ptr->wilderness_y > current_world_ptr->max_wild_y))
892 return (PARSE_ERROR_OUT_OF_BOUNDS);
897 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
906 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
909 for (i = 1; i < current_world_ptr->max_d_idx; i++)
911 if (!d_info[i].maxdepth) continue;
912 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte_hack)i;
913 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
914 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
924 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
925 * Generate the random seeds for the wilderness
928 void seed_wilderness(void)
932 /* Init wilderness seeds */
933 for (x = 0; x < current_world_ptr->max_wild_x; x++)
935 for (y = 0; y < current_world_ptr->max_wild_y; y++)
937 wilderness[y][x].seed = randint0(0x10000000);
938 wilderness[y][x].entrance = 0;
945 * Pointer to wilderness_type
947 typedef wilderness_type *wilderness_type_ptr;
951 * @brief ゲーム開始時の荒野初期化メインルーチン /
952 * Initialize wilderness array
955 errr init_wilderness(void)
959 /* Allocate the wilderness (two-dimension array) */
960 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
961 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
963 /* Init the other pointers */
964 for (i = 1; i < current_world_ptr->max_wild_y; i++)
965 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
967 generate_encounter = FALSE;
973 * @brief 荒野の地勢設定を初期化する /
974 * Initialize wilderness array
975 * @param terrain 初期化したい地勢ID
976 * @param feat_global 基本的な地形ID
977 * @param fmt 地勢内の地形数を参照するための独自フォーマット
980 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
989 /* Begin the varargs stuff */
992 /* Wilderness terrains on global map */
993 conv_terrain2feat[terrain] = feat_global;
995 /* Wilderness terrains on local map */
996 for (p = fmt; *p; p++)
1002 feat = (s16b)va_arg(vp, int);
1003 num = va_arg(vp, int);
1006 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1007 terrain_table[terrain][cur] = feat;
1008 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1014 plog_fmt("Format error");
1017 if (cur < MAX_FEAT_IN_TERRAIN)
1019 plog_fmt("Too few parameters");
1022 /* End the varargs stuff */
1028 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1029 * Initialize arrays for wilderness terrains
1032 void init_wilderness_terrains(void)
1034 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1035 feat_permanent, MAX_FEAT_IN_TERRAIN);
1037 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1038 feat_floor, MAX_FEAT_IN_TERRAIN);
1040 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1041 feat_deep_water, 12,
1042 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1044 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1046 feat_shallow_water, 12,
1049 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1051 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1056 feat_shallow_water, 4,
1057 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1059 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1065 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1067 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1073 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1075 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1080 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1082 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1085 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1087 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1088 feat_shallow_lava, 14,
1090 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1092 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1094 feat_shallow_lava, 3,
1096 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1098 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1104 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1108 * @brief 荒野から広域マップへの切り替え処理 /
1109 * Initialize arrays for wilderness terrains
1110 * @param encount 襲撃時TRUE
1111 * @return 切り替えが行われた場合はTRUEを返す。
1113 bool change_wild_mode(player_type *creature_ptr, bool encount)
1116 bool have_pet = FALSE;
1117 generate_encounter = encount;
1119 /* It is in the middle of changing map */
1120 if (creature_ptr->leaving) return FALSE;
1123 if (lite_town || vanilla_town)
1125 msg_print(_("荒野なんてない。", "No global map."));
1129 if (creature_ptr->wild_mode)
1131 /* Save the location in the global map */
1132 creature_ptr->wilderness_x = creature_ptr->x;
1133 creature_ptr->wilderness_y = creature_ptr->y;
1135 /* Give first move to the player */
1136 creature_ptr->energy_need = 0;
1138 /* Go back to the ordinary map */
1139 creature_ptr->wild_mode = FALSE;
1140 creature_ptr->leaving = TRUE;
1146 for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1148 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1150 if (!monster_is_valid(m_ptr)) continue;
1151 if (is_pet(m_ptr) && i != creature_ptr->riding) have_pet = TRUE;
1152 if (MON_CSLEEP(m_ptr)) continue;
1153 if (m_ptr->cdis > MAX_SIGHT) continue;
1154 if (!is_hostile(m_ptr)) continue;
1155 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1156 "You cannot enter global map, since there is some monsters nearby!"));
1157 free_turn(creature_ptr);
1163 concptr msg = _("ペットを置いて広域マップに入りますか?",
1164 "Do you leave your pets behind? ");
1166 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1168 free_turn(creature_ptr);
1173 take_turn(creature_ptr, 1000);
1175 /* Remember the position */
1176 creature_ptr->oldpx = creature_ptr->x;
1177 creature_ptr->oldpy = creature_ptr->y;
1179 /* Cancel hex spelling */
1180 if (hex_spelling_any(creature_ptr)) stop_hex_spell_all(creature_ptr);
1182 /* Cancel any special action */
1183 set_action(creature_ptr, ACTION_NONE);
1185 /* Go into the global map */
1186 creature_ptr->wild_mode = TRUE;
1187 creature_ptr->leaving = TRUE;