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.
16 #include "realm-hex.h"
17 #include "player-status.h"
21 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
22 * @param feat_type 非一様確率を再現するための要素数100の配列
23 * @param prob 元の確率テーブル
26 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
28 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
30 lim[0] = prob[0].percent;
31 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
34 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
36 for (i = 0; i < 100; i++)
38 while (i == lim[cur]) cur++;
39 feat_type[i] = prob[cur].feat;
44 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
45 * / Fill the arrays of floors and walls in the good proportions
49 void set_floor_and_wall(DUNGEON_IDX type)
51 DUNGEON_IDX cur_type = 255;
55 if (cur_type == type) return;
58 d_ptr = &d_info[type];
60 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
61 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
63 feat_wall_outer = d_ptr->outer_wall;
64 feat_wall_inner = d_ptr->inner_wall;
65 feat_wall_solid = d_ptr->outer_wall;
70 * @brief プラズマフラクタル的地形生成の再帰中間処理
71 * / Helper for plasma generation.
79 * @param depth_max 深みの最大値
82 static void perturb_point_mid(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, FEAT_IDX x4, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
85 * Average the four corners & perturb it a bit.
86 * tmp is a random int +/- rough
88 FEAT_IDX tmp2 = rough*2 + 1;
89 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
91 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
93 /* Division always rounds down, so we round up again */
94 if (((x1 + x2 + x3 + x4) % 4) > 1)
99 if (avg > depth_max) avg = depth_max;
101 /* Set the new value. */
102 current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
107 * @brief プラズマフラクタル的地形生成の再帰末端処理
108 * / Helper for plasma generation.
109 * @param x1 中間末端部1の重み
110 * @param x2 中間末端部2の重み
111 * @param x3 中間末端部3の重み
112 * @param xmid 最終末端部座標X
113 * @param ymid 最終末端部座標Y
115 * @param depth_max 深みの最大値
118 static void perturb_point_end(FEAT_IDX x1, FEAT_IDX x2, FEAT_IDX x3, POSITION xmid, POSITION ymid, FEAT_IDX rough, FEAT_IDX depth_max)
121 * Average the three corners & perturb it a bit.
122 * tmp is a random int +/- rough
124 FEAT_IDX tmp2 = rough * 2 + 1;
125 FEAT_IDX tmp = randint0(tmp2) - rough;
127 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
129 /* Division always rounds down, so we round up again */
130 if ((x1 + x2 + x3) % 3) avg++;
133 if (avg < 0) avg = 0;
134 if (avg > depth_max) avg = depth_max;
136 /* Set the new value. */
137 current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
142 * @brief プラズマフラクタル的地形生成の開始処理
143 * / Helper for plasma generation.
144 * @param x1 処理範囲の左上X座標
145 * @param y1 処理範囲の左上Y座標
146 * @param x2 処理範囲の右下X座標
147 * @param y2 処理範囲の右下Y座標
148 * @param depth_max 深みの最大値
153 * A generic function to generate the plasma fractal.
154 * Note that it uses ``cave_feat'' as temporary storage.
155 * The values in ``cave_feat'' after this function
156 * are NOT actual features; They are raw heights which
157 * need to be converted to features.
160 static void plasma_recursive(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
163 POSITION xmid = (x2 - x1) / 2 + x1;
164 POSITION ymid = (y2 - y1) / 2 + y1;
167 if (x1 + 1 == x2) return;
169 perturb_point_mid(current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[y1][x2].feat,
170 current_floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
172 perturb_point_end(current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[y1][x2].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
173 xmid, y1, rough, depth_max);
175 perturb_point_end(current_floor_ptr->grid_array[y1][x2].feat, current_floor_ptr->grid_array[y2][x2].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
176 x2, ymid, rough, depth_max);
178 perturb_point_end(current_floor_ptr->grid_array[y2][x2].feat, current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
179 xmid, y2, rough, depth_max);
181 perturb_point_end(current_floor_ptr->grid_array[y2][x1].feat, current_floor_ptr->grid_array[y1][x1].feat, current_floor_ptr->grid_array[ymid][xmid].feat,
182 x1, ymid, rough, depth_max);
185 /* Recurse the four quadrants */
186 plasma_recursive(x1, y1, xmid, ymid, depth_max, rough);
187 plasma_recursive(xmid, y1, x2, ymid, depth_max, rough);
188 plasma_recursive(x1, ymid, xmid, y2, depth_max, rough);
189 plasma_recursive(xmid, ymid, x2, y2, depth_max, rough);
193 #define MAX_FEAT_IN_TERRAIN 18
196 * The default table in terrain level generation.
198 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
201 * @brief 荒野フロア生成のサブルーチン
202 * @param terrain 荒野地形ID
203 * @param seed 乱数の固定シード
205 * @param corner 広域マップの角部分としての生成ならばTRUE
208 static void generate_wilderness_area(int terrain, u32b seed, bool border, bool corner)
211 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
212 FEAT_IDX roughness = 1; /* The roughness of the level. */
213 u32b state_backup[4];
218 /* The outer wall is easy */
219 if (terrain == TERRAIN_EDGE)
221 /* Create level background */
222 for (y1 = 0; y1 < MAX_HGT; y1++)
224 for (x1 = 0; x1 < MAX_WID; x1++)
226 current_floor_ptr->grid_array[y1][x1].feat = feat_permanent;
230 /* We are done already */
235 /* Hack -- Backup the RNG state */
236 Rand_state_backup(state_backup);
238 /* Hack -- Induce consistant flavors */
239 Rand_state_set(seed);
243 /* Create level background */
244 for (y1 = 0; y1 < MAX_HGT; y1++)
246 for (x1 = 0; x1 < MAX_WID; x1++)
248 current_floor_ptr->grid_array[y1][x1].feat = table_size / 2;
254 * Initialize the four corners
255 * ToDo: calculate the medium height of the adjacent
256 * terrains for every corner.
258 current_floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
259 current_floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
260 current_floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
261 current_floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
265 /* Hack -- preserve four corners */
266 s16b north_west = current_floor_ptr->grid_array[1][1].feat;
267 s16b south_west = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
268 s16b north_east = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
269 s16b south_east = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
271 /* x1, y1, x2, y2, num_depths, roughness */
272 plasma_recursive(1, 1, MAX_WID-2, MAX_HGT-2, table_size-1, roughness);
274 /* Hack -- copyback four corners */
275 current_floor_ptr->grid_array[1][1].feat = north_west;
276 current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
277 current_floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
278 current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
280 for (y1 = 1; y1 < MAX_HGT - 1; y1++)
282 for (x1 = 1; x1 < MAX_WID - 1; x1++)
284 current_floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][current_floor_ptr->grid_array[y1][x1].feat];
288 else /* Hack -- only four corners */
290 current_floor_ptr->grid_array[1][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][1].feat];
291 current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[MAX_HGT - 2][1].feat];
292 current_floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][MAX_WID - 2].feat];
293 current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = terrain_table[terrain][current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat];
296 /* Hack -- Restore the RNG state */
297 Rand_state_restore(state_backup);
303 * @brief 荒野フロア生成のメインルーチン /
304 * Load a town or generate a terrain level using "plasma" fractals.
307 * @param border 広域マップの辺部分としての生成ならばTRUE
308 * @param corner 広域マップの角部分としての生成ならばTRUE
312 * x and y are the coordinates of the area in the wilderness.
313 * Border and corner are optimization flags to speed up the
314 * generation of the fractal terrain.
315 * If border is set then only the border of the terrain should
316 * be generated (for initializing the border structure).
317 * If corner is set then only the corners of the area are needed.
320 static void generate_area(POSITION y, POSITION x, bool border, bool corner)
324 /* Number of the town (if any) */
325 p_ptr->town_num = wilderness[y][x].town;
327 /* Set the base level */
328 current_floor_ptr->base_level = wilderness[y][x].level;
330 /* Set the dungeon level */
331 current_floor_ptr->dun_level = 0;
333 /* Set the monster generation level */
334 monster_level = current_floor_ptr->base_level;
336 /* Set the object generation level */
337 object_level = current_floor_ptr->base_level;
340 /* Create the town */
343 /* Reset the buildings */
346 /* Initialize the town */
348 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
350 init_flags = INIT_CREATE_DUNGEON;
352 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
354 if (!corner && !border) p_ptr->visit |= (1L << (p_ptr->town_num - 1));
358 int terrain = wilderness[y][x].terrain;
359 u32b seed = wilderness[y][x].seed;
361 generate_wilderness_area(terrain, seed, border, corner);
364 if (!corner && !wilderness[y][x].town)
367 * Place roads in the wilderness
368 * ToDo: make the road a bit more interresting
370 if (wilderness[y][x].road)
372 current_floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
374 if (wilderness[y-1][x].road)
377 for (y1 = 1; y1 < MAX_HGT/2; y1++)
380 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
384 if (wilderness[y+1][x].road)
387 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
390 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
394 if (wilderness[y][x+1].road)
397 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
400 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
404 if (wilderness[y][x-1].road)
407 for (x1 = 1; x1 < MAX_WID/2; x1++)
410 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
416 if (wilderness[y][x].entrance && !wilderness[y][x].town && (p_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER)))
419 u32b state_backup[4];
421 /* Hack -- Backup the RNG state */
422 Rand_state_backup(state_backup);
424 /* Hack -- Induce consistant flavors */
425 Rand_state_set(wilderness[y][x].seed);
427 dy = rand_range(6, cur_hgt - 6);
428 dx = rand_range(6, cur_wid - 6);
430 current_floor_ptr->grid_array[dy][dx].feat = feat_entrance;
431 current_floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
433 /* Hack -- Restore the RNG state */
434 Rand_state_restore(state_backup);
440 * Border of the wilderness area
442 static border_type border;
447 * Build the wilderness area outside of the town.
450 void wilderness_gen(void)
461 /* Assume illegal panel */
462 panel_row_min = cur_hgt;
463 panel_col_min = cur_wid;
465 /* Init the wilderness */
467 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
469 x = p_ptr->wilderness_x;
470 y = p_ptr->wilderness_y;
471 get_mon_num_prep(get_monster_hook(), NULL);
474 generate_area(y - 1, x, TRUE, FALSE);
476 for (i = 1; i < MAX_WID - 1; i++)
478 border.north[i] = current_floor_ptr->grid_array[MAX_HGT - 2][i].feat;
482 generate_area(y + 1, x, TRUE, FALSE);
484 for (i = 1; i < MAX_WID - 1; i++)
486 border.south[i] = current_floor_ptr->grid_array[1][i].feat;
490 generate_area(y, x - 1, TRUE, FALSE);
492 for (i = 1; i < MAX_HGT - 1; i++)
494 border.west[i] = current_floor_ptr->grid_array[i][MAX_WID - 2].feat;
498 generate_area(y, x + 1, TRUE, FALSE);
500 for (i = 1; i < MAX_HGT - 1; i++)
502 border.east[i] = current_floor_ptr->grid_array[i][1].feat;
505 /* North west corner */
506 generate_area(y - 1, x - 1, FALSE, TRUE);
507 border.north_west = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
509 /* North east corner */
510 generate_area(y - 1, x + 1, FALSE, TRUE);
511 border.north_east = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
513 /* South west corner */
514 generate_area(y + 1, x - 1, FALSE, TRUE);
515 border.south_west = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
517 /* South east corner */
518 generate_area(y + 1, x + 1, FALSE, TRUE);
519 border.south_east = current_floor_ptr->grid_array[1][1].feat;
522 /* Create terrain of the current area */
523 generate_area(y, x, FALSE, FALSE);
526 /* Special boundary walls -- North */
527 for (i = 0; i < MAX_WID; i++)
529 current_floor_ptr->grid_array[0][i].feat = feat_permanent;
530 current_floor_ptr->grid_array[0][i].mimic = border.north[i];
533 /* Special boundary walls -- South */
534 for (i = 0; i < MAX_WID; i++)
536 current_floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
537 current_floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
540 /* Special boundary walls -- West */
541 for (i = 0; i < MAX_HGT; i++)
543 current_floor_ptr->grid_array[i][0].feat = feat_permanent;
544 current_floor_ptr->grid_array[i][0].mimic = border.west[i];
547 /* Special boundary walls -- East */
548 for (i = 0; i < MAX_HGT; i++)
550 current_floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
551 current_floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
554 /* North west corner */
555 current_floor_ptr->grid_array[0][0].mimic = border.north_west;
557 /* North east corner */
558 current_floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
560 /* South west corner */
561 current_floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
563 /* South east corner */
564 current_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 < cur_hgt; y++)
569 for (x = 0; x < cur_wid; x++)
571 g_ptr = ¤t_floor_ptr->grid_array[y][x];
576 g_ptr->info |= (CAVE_GLOW);
578 /* Hack -- Memorize lit grids if allowed */
579 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
583 /* Feature code (applying "mimic" field) */
584 f_ptr = &f_info[get_feat_mimic(g_ptr)];
586 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
587 !have_flag(f_ptr->flags, FF_ENTRANCE))
590 g_ptr->info &= ~(CAVE_GLOW);
592 /* Darken "boring" features */
593 if (!have_flag(f_ptr->flags, FF_REMEMBER))
595 /* Forget the grid */
596 g_ptr->info &= ~(CAVE_MARK);
599 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
602 g_ptr->info |= (CAVE_GLOW);
604 /* Hack -- Memorize lit grids if allowed */
605 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
611 if (p_ptr->teleport_town)
613 for (y = 0; y < cur_hgt; y++)
615 for (x = 0; x < cur_wid; x++)
617 g_ptr = ¤t_floor_ptr->grid_array[y][x];
619 /* Seeing true feature code (ignore mimic) */
620 f_ptr = &f_info[g_ptr->feat];
622 if (have_flag(f_ptr->flags, FF_BLDG))
624 if ((f_ptr->subtype == 4) || ((p_ptr->town_num == 1) && (f_ptr->subtype == 0)))
626 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
633 p_ptr->teleport_town = FALSE;
636 else if (p_ptr->leaving_dungeon)
638 for (y = 0; y < cur_hgt; y++)
640 for (x = 0; x < cur_wid; x++)
642 g_ptr = ¤t_floor_ptr->grid_array[y][x];
644 if (cave_have_flag_grid(g_ptr, FF_ENTRANCE))
646 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
652 p_ptr->teleport_town = FALSE;
655 player_place(p_ptr->oldpy, p_ptr->oldpx);
656 /* p_ptr->leaving_dungeon = FALSE;*/
658 lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
660 /* Make some residents */
661 for (i = 0; i < lim; i++)
665 if (!(generate_encounter || (one_in_(2) && (!p_ptr->town_num))))
666 mode |= PM_ALLOW_SLEEP;
668 /* Make a resident */
669 (void)alloc_monster(generate_encounter ? 0 : 3, mode);
672 if(generate_encounter) ambush_flag = TRUE;
673 generate_encounter = FALSE;
675 /* Fill the arrays of floors and walls in the good proportions */
676 set_floor_and_wall(0);
678 /* Set rewarded quests to finished */
679 for (i = 0; i < max_q_idx; i++)
681 if (quest[i].status == QUEST_STATUS_REWARDED)
682 quest[i].status = QUEST_STATUS_FINISHED;
687 static s16b conv_terrain2feat[MAX_WILDERNESS];
690 * @brief 広域マップの生成(簡易処理版) /
691 * Build the wilderness area. -DG-
694 void wilderness_gen_small(void)
698 /* To prevent stupid things */
699 for (i = 0; i < MAX_WID; i++)
700 for (j = 0; j < MAX_HGT; j++)
702 current_floor_ptr->grid_array[j][i].feat = feat_permanent;
705 /* Init the wilderness */
706 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
709 for (i = 0; i < max_wild_x; i++)
710 for (j = 0; j < max_wild_y; j++)
712 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
714 current_floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
715 current_floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
717 else if (wilderness[j][i].road) current_floor_ptr->grid_array[j][i].feat = feat_floor;
718 else if (wilderness[j][i].entrance && (p_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
720 current_floor_ptr->grid_array[j][i].feat = feat_entrance;
721 current_floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
723 else current_floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
725 current_floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
728 cur_hgt = (s16b) max_wild_y;
729 cur_wid = (s16b) max_wild_x;
731 if (cur_hgt > MAX_HGT) cur_hgt = MAX_HGT;
732 if (cur_wid > MAX_WID) cur_wid = MAX_WID;
734 /* Assume illegal panel */
735 panel_row_min = cur_hgt;
736 panel_col_min = cur_wid;
738 /* Place the player */
739 p_ptr->x = p_ptr->wilderness_x;
740 p_ptr->y = p_ptr->wilderness_y;
746 typedef struct wilderness_grid wilderness_grid;
748 struct wilderness_grid
750 int terrain; /* Terrain type */
751 TOWN_IDX town; /* Town number */
752 DEPTH level; /* Level of the wilderness */
753 byte road; /* Road */
754 char name[32]; /* Name of the town/wilderness */
758 static wilderness_grid w_letter[255];
762 * @brief w_info.txtのデータ解析 /
763 * Parse a sub-file of the "extra info"
764 * @param buf 読み取ったデータ行のバッファ
766 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
768 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
769 * @param y 広域マップの高さを返す参照ポインタ
770 * @param x 広域マップの幅を返す参照ポインタ
773 errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
783 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
787 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
800 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
802 int index = zz[0][0];
805 w_letter[index].terrain = atoi(zz[1]);
807 w_letter[index].terrain = 0;
810 w_letter[index].level = (s16b)atoi(zz[2]);
812 w_letter[index].level = 0;
815 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
817 w_letter[index].town = 0;
820 w_letter[index].road = (byte_hack)atoi(zz[4]);
822 w_letter[index].road = 0;
825 strcpy(w_letter[index].name, zz[5]);
827 w_letter[index].name[0] = 0;
832 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
838 /* Process "W:D:<layout> */
839 /* Layout of the wilderness */
842 /* Acquire the text */
845 /* Length of the text */
848 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
851 wilderness[*y][*x].terrain = w_letter[id].terrain;
852 wilderness[*y][*x].level = w_letter[id].level;
853 wilderness[*y][*x].town = w_letter[id].town;
854 wilderness[*y][*x].road = w_letter[id].road;
855 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
863 /* Process "W:P:<x>:<y> - starting position in the wilderness */
866 if ((p_ptr->wilderness_x == 0) &&
867 (p_ptr->wilderness_y == 0))
869 if (tokenize(buf+4, 2, zz, 0) == 2)
871 p_ptr->wilderness_y = atoi(zz[0]);
872 p_ptr->wilderness_x = atoi(zz[1]);
874 if ((p_ptr->wilderness_x < 1) ||
875 (p_ptr->wilderness_x > max_wild_x) ||
876 (p_ptr->wilderness_y < 1) ||
877 (p_ptr->wilderness_y > max_wild_y))
879 return (PARSE_ERROR_OUT_OF_BOUNDS);
884 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
893 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
896 for (i = 1; i < max_d_idx; i++)
898 if (!d_info[i].maxdepth) continue;
899 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte_hack)i;
900 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
901 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
911 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
912 * Generate the random seeds for the wilderness
915 void seed_wilderness(void)
919 /* Init wilderness seeds */
920 for (x = 0; x < max_wild_x; x++)
922 for (y = 0; y < max_wild_y; y++)
924 wilderness[y][x].seed = randint0(0x10000000);
925 wilderness[y][x].entrance = 0;
932 * Pointer to wilderness_type
934 typedef wilderness_type *wilderness_type_ptr;
938 * @brief ゲーム開始時の荒野初期化メインルーチン /
939 * Initialize wilderness array
942 errr init_wilderness(void)
946 /* Allocate the wilderness (two-dimension array) */
947 C_MAKE(wilderness, max_wild_y, wilderness_type_ptr);
948 C_MAKE(wilderness[0], max_wild_x * max_wild_y, wilderness_type);
950 /* Init the other pointers */
951 for (i = 1; i < max_wild_y; i++)
952 wilderness[i] = wilderness[0] + i * max_wild_x;
954 generate_encounter = FALSE;
960 * @brief 荒野の地勢設定を初期化する /
961 * Initialize wilderness array
962 * @param terrain 初期化したい地勢ID
963 * @param feat_global 基本的な地形ID
964 * @param fmt 地勢内の地形数を参照するための独自フォーマット
967 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
976 /* Begin the varargs stuff */
979 /* Wilderness terrains on global map */
980 conv_terrain2feat[terrain] = feat_global;
982 /* Wilderness terrains on local map */
983 for (p = fmt; *p; p++)
989 feat = (s16b)va_arg(vp, int);
990 num = va_arg(vp, int);
993 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
994 terrain_table[terrain][cur] = feat;
995 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1001 plog_fmt("Format error");
1006 if (cur < MAX_FEAT_IN_TERRAIN)
1008 plog_fmt("Too few parameters");
1011 /* End the varargs stuff */
1017 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1018 * Initialize arrays for wilderness terrains
1021 void init_wilderness_terrains(void)
1023 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1024 feat_permanent, MAX_FEAT_IN_TERRAIN);
1026 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1027 feat_floor, MAX_FEAT_IN_TERRAIN);
1029 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1030 feat_deep_water, 12,
1031 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1033 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1035 feat_shallow_water, 12,
1038 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1040 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1045 feat_shallow_water, 4,
1046 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1048 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1054 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1056 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1062 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1064 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1069 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1071 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1074 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1076 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1077 feat_shallow_lava, 14,
1079 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1081 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1083 feat_shallow_lava, 3,
1085 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1087 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1093 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1097 * @brief 荒野から広域マップへの切り替え処理 /
1098 * Initialize arrays for wilderness terrains
1099 * @return 切り替えが行われた場合はTRUEを返す。
1101 bool change_wild_mode(void)
1104 bool have_pet = FALSE;
1106 /* It is in the middle of changing map */
1107 if (p_ptr->leaving) return FALSE;
1110 if (lite_town || vanilla_town)
1113 msg_print("荒野なんてない。");
1115 msg_print("No global map.");
1120 if (p_ptr->wild_mode)
1122 /* Save the location in the global map */
1123 p_ptr->wilderness_x = p_ptr->x;
1124 p_ptr->wilderness_y = p_ptr->y;
1126 /* Give first move to the player */
1127 p_ptr->energy_need = 0;
1129 /* Go back to the ordinary map */
1130 p_ptr->wild_mode = FALSE;
1133 p_ptr->leaving = TRUE;
1139 for (i = 1; i < m_max; i++)
1141 monster_type *m_ptr = &m_list[i];
1143 if (!m_ptr->r_idx) continue;
1144 if (is_pet(m_ptr) && i != p_ptr->riding) have_pet = TRUE;
1145 if (MON_CSLEEP(m_ptr)) continue;
1146 if (m_ptr->cdis > MAX_SIGHT) continue;
1147 if (!is_hostile(m_ptr)) continue;
1149 msg_print("敵がすぐ近くにいるときは広域マップに入れない!");
1151 msg_print("You cannot enter global map, since there is some monsters nearby!");
1160 concptr msg = "ペットを置いて広域マップに入りますか?";
1162 concptr msg = "Do you leave your pets behind? ";
1165 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1173 p_ptr->energy_use = 1000;
1175 /* Remember the position */
1176 p_ptr->oldpx = p_ptr->x;
1177 p_ptr->oldpy = p_ptr->y;
1179 /* Cancel hex spelling */
1180 if (hex_spelling_any()) stop_hex_spell_all();
1182 /* Cancel any special action */
1183 set_action(ACTION_NONE);
1185 /* Go into the global map */
1186 p_ptr->wild_mode = TRUE;
1189 p_ptr->leaving = TRUE;