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.
18 #include "realm-hex.h"
19 #include "player-status.h"
21 #include "monster-status.h"
23 #include "dungeon-file.h"
29 wilderness_type **wilderness;
33 * @brief 地形生成確率を決める要素100の配列を確率テーブルから作成する
34 * @param feat_type 非一様確率を再現するための要素数100の配列
35 * @param prob 元の確率テーブル
38 static void set_floor_and_wall_aux(s16b feat_type[100], feat_prob prob[DUNGEON_FEAT_PROB_NUM])
40 int lim[DUNGEON_FEAT_PROB_NUM], cur = 0, i;
42 lim[0] = prob[0].percent;
43 for (i = 1; i < DUNGEON_FEAT_PROB_NUM; i++) lim[i] = lim[i - 1] + prob[i].percent;
44 if (lim[DUNGEON_FEAT_PROB_NUM - 1] < 100) lim[DUNGEON_FEAT_PROB_NUM - 1] = 100;
46 for (i = 0; i < 100; i++)
48 while (i == lim[cur]) cur++;
49 feat_type[i] = prob[cur].feat;
54 * @brief ダンジョンの地形を指定確率に応じて各マスへランダムに敷き詰める
55 * / Fill the arrays of floors and walls in the good proportions
59 void set_floor_and_wall(DUNGEON_IDX type)
61 DUNGEON_IDX cur_type = 255;
65 if (cur_type == type) return;
68 d_ptr = &d_info[type];
70 set_floor_and_wall_aux(feat_ground_type, d_ptr->floor);
71 set_floor_and_wall_aux(feat_wall_type, d_ptr->fill);
73 feat_wall_outer = d_ptr->outer_wall;
74 feat_wall_inner = d_ptr->inner_wall;
75 feat_wall_solid = d_ptr->outer_wall;
80 * @brief プラズマフラクタル的地形生成の再帰中間処理
81 * / Helper for plasma generation.
89 * @param depth_max 深みの最大値
92 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)
95 * Average the four corners & perturb it a bit.
96 * tmp is a random int +/- rough
98 FEAT_IDX tmp2 = rough*2 + 1;
99 FEAT_IDX tmp = randint1(tmp2) - (rough + 1);
101 FEAT_IDX avg = ((x1 + x2 + x3 + x4) / 4) + tmp;
103 /* Division always rounds down, so we round up again */
104 if (((x1 + x2 + x3 + x4) % 4) > 1)
108 if (avg < 0) avg = 0;
109 if (avg > depth_max) avg = depth_max;
111 /* Set the new value. */
112 current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
117 * @brief プラズマフラクタル的地形生成の再帰末端処理
118 * / Helper for plasma generation.
119 * @param x1 中間末端部1の重み
120 * @param x2 中間末端部2の重み
121 * @param x3 中間末端部3の重み
122 * @param xmid 最終末端部座標X
123 * @param ymid 最終末端部座標Y
125 * @param depth_max 深みの最大値
128 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)
131 * Average the three corners & perturb it a bit.
132 * tmp is a random int +/- rough
134 FEAT_IDX tmp2 = rough * 2 + 1;
135 FEAT_IDX tmp = randint0(tmp2) - rough;
137 FEAT_IDX avg = ((x1 + x2 + x3) / 3) + tmp;
139 /* Division always rounds down, so we round up again */
140 if ((x1 + x2 + x3) % 3) avg++;
143 if (avg < 0) avg = 0;
144 if (avg > depth_max) avg = depth_max;
146 /* Set the new value. */
147 current_floor_ptr->grid_array[ymid][xmid].feat = (FEAT_IDX)avg;
152 * @brief プラズマフラクタル的地形生成の開始処理
153 * / Helper for plasma generation.
154 * @param x1 処理範囲の左上X座標
155 * @param y1 処理範囲の左上Y座標
156 * @param x2 処理範囲の右下X座標
157 * @param y2 処理範囲の右下Y座標
158 * @param depth_max 深みの最大値
163 * A generic function to generate the plasma fractal.
164 * Note that it uses ``cave_feat'' as temporary storage.
165 * The values in ``cave_feat'' after this function
166 * are NOT actual features; They are raw heights which
167 * need to be converted to features.
170 static void plasma_recursive(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX depth_max, FEAT_IDX rough)
173 POSITION xmid = (x2 - x1) / 2 + x1;
174 POSITION ymid = (y2 - y1) / 2 + y1;
177 if (x1 + 1 == x2) return;
179 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,
180 current_floor_ptr->grid_array[y2][x2].feat, xmid, ymid, rough, depth_max);
182 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,
183 xmid, y1, rough, depth_max);
185 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,
186 x2, ymid, rough, depth_max);
188 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,
189 xmid, y2, rough, depth_max);
191 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,
192 x1, ymid, rough, depth_max);
195 /* Recurse the four quadrants */
196 plasma_recursive(x1, y1, xmid, ymid, depth_max, rough);
197 plasma_recursive(xmid, y1, x2, ymid, depth_max, rough);
198 plasma_recursive(x1, ymid, xmid, y2, depth_max, rough);
199 plasma_recursive(xmid, ymid, x2, y2, depth_max, rough);
203 #define MAX_FEAT_IN_TERRAIN 18
206 * The default table in terrain level generation.
208 static s16b terrain_table[MAX_WILDERNESS][MAX_FEAT_IN_TERRAIN];
211 * @brief 荒野フロア生成のサブルーチン
212 * @param terrain 荒野地形ID
213 * @param seed 乱数の固定シード
215 * @param corner 広域マップの角部分としての生成ならばTRUE
218 static void generate_wilderness_area(int terrain, u32b seed, bool border, bool corner)
221 int table_size = sizeof(terrain_table[0]) / sizeof(s16b);
222 FEAT_IDX roughness = 1; /* The roughness of the level. */
223 u32b state_backup[4];
228 /* The outer wall is easy */
229 if (terrain == TERRAIN_EDGE)
231 /* Create level background */
232 for (y1 = 0; y1 < MAX_HGT; y1++)
234 for (x1 = 0; x1 < MAX_WID; x1++)
236 current_floor_ptr->grid_array[y1][x1].feat = feat_permanent;
240 /* We are done already */
245 /* Hack -- Backup the RNG state */
246 Rand_state_backup(state_backup);
248 /* Hack -- Induce consistant flavors */
249 Rand_state_set(seed);
253 /* Create level background */
254 for (y1 = 0; y1 < MAX_HGT; y1++)
256 for (x1 = 0; x1 < MAX_WID; x1++)
258 current_floor_ptr->grid_array[y1][x1].feat = table_size / 2;
264 * Initialize the four corners
265 * ToDo: calculate the medium height of the adjacent
266 * terrains for every corner.
268 current_floor_ptr->grid_array[1][1].feat = (s16b)randint0(table_size);
269 current_floor_ptr->grid_array[MAX_HGT-2][1].feat = (s16b)randint0(table_size);
270 current_floor_ptr->grid_array[1][MAX_WID-2].feat = (s16b)randint0(table_size);
271 current_floor_ptr->grid_array[MAX_HGT-2][MAX_WID-2].feat = (s16b)randint0(table_size);
275 /* Hack -- preserve four corners */
276 s16b north_west = current_floor_ptr->grid_array[1][1].feat;
277 s16b south_west = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
278 s16b north_east = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
279 s16b south_east = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
281 /* x1, y1, x2, y2, num_depths, roughness */
282 plasma_recursive(1, 1, MAX_WID-2, MAX_HGT-2, table_size-1, roughness);
284 /* Hack -- copyback four corners */
285 current_floor_ptr->grid_array[1][1].feat = north_west;
286 current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = south_west;
287 current_floor_ptr->grid_array[1][MAX_WID - 2].feat = north_east;
288 current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat = south_east;
290 for (y1 = 1; y1 < MAX_HGT - 1; y1++)
292 for (x1 = 1; x1 < MAX_WID - 1; x1++)
294 current_floor_ptr->grid_array[y1][x1].feat = terrain_table[terrain][current_floor_ptr->grid_array[y1][x1].feat];
298 else /* Hack -- only four corners */
300 current_floor_ptr->grid_array[1][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][1].feat];
301 current_floor_ptr->grid_array[MAX_HGT - 2][1].feat = terrain_table[terrain][current_floor_ptr->grid_array[MAX_HGT - 2][1].feat];
302 current_floor_ptr->grid_array[1][MAX_WID - 2].feat = terrain_table[terrain][current_floor_ptr->grid_array[1][MAX_WID - 2].feat];
303 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];
306 /* Hack -- Restore the RNG state */
307 Rand_state_restore(state_backup);
313 * @brief 荒野フロア生成のメインルーチン /
314 * Load a town or generate a terrain level using "plasma" fractals.
317 * @param border 広域マップの辺部分としての生成ならばTRUE
318 * @param corner 広域マップの角部分としての生成ならばTRUE
322 * x and y are the coordinates of the area in the wilderness.
323 * Border and corner are optimization flags to speed up the
324 * generation of the fractal terrain.
325 * If border is set then only the border of the terrain should
326 * be generated (for initializing the border structure).
327 * If corner is set then only the corners of the area are needed.
330 static void generate_area(POSITION y, POSITION x, bool border, bool corner)
334 /* Number of the town (if any) */
335 p_ptr->town_num = wilderness[y][x].town;
337 /* Set the base level */
338 current_floor_ptr->base_level = wilderness[y][x].level;
340 /* Set the dungeon level */
341 current_floor_ptr->dun_level = 0;
343 /* Set the monster generation level */
344 current_floor_ptr->monster_level = current_floor_ptr->base_level;
346 /* Set the object generation level */
347 current_floor_ptr->object_level = current_floor_ptr->base_level;
350 /* Create the town */
353 /* Reset the buildings */
356 /* Initialize the town */
358 init_flags = INIT_CREATE_DUNGEON | INIT_ONLY_FEATURES;
360 init_flags = INIT_CREATE_DUNGEON;
362 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
364 if (!corner && !border) p_ptr->visit |= (1L << (p_ptr->town_num - 1));
368 int terrain = wilderness[y][x].terrain;
369 u32b seed = wilderness[y][x].seed;
371 generate_wilderness_area(terrain, seed, border, corner);
374 if (!corner && !wilderness[y][x].town)
377 * Place roads in the wilderness
378 * ToDo: make the road a bit more interresting
380 if (wilderness[y][x].road)
382 current_floor_ptr->grid_array[MAX_HGT/2][MAX_WID/2].feat = feat_floor;
384 if (wilderness[y-1][x].road)
387 for (y1 = 1; y1 < MAX_HGT/2; y1++)
390 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
394 if (wilderness[y+1][x].road)
397 for (y1 = MAX_HGT/2; y1 < MAX_HGT - 1; y1++)
400 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
404 if (wilderness[y][x+1].road)
407 for (x1 = MAX_WID/2; x1 < MAX_WID - 1; x1++)
410 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
414 if (wilderness[y][x-1].road)
417 for (x1 = 1; x1 < MAX_WID/2; x1++)
420 current_floor_ptr->grid_array[y1][x1].feat = feat_floor;
426 if (wilderness[y][x].entrance && !wilderness[y][x].town && (p_ptr->total_winner || !(d_info[wilderness[y][x].entrance].flags1 & DF1_WINNER)))
429 u32b state_backup[4];
431 /* Hack -- Backup the RNG state */
432 Rand_state_backup(state_backup);
434 /* Hack -- Induce consistant flavors */
435 Rand_state_set(wilderness[y][x].seed);
437 dy = rand_range(6, current_floor_ptr->height - 6);
438 dx = rand_range(6, current_floor_ptr->width - 6);
440 current_floor_ptr->grid_array[dy][dx].feat = feat_entrance;
441 current_floor_ptr->grid_array[dy][dx].special = wilderness[y][x].entrance;
443 /* Hack -- Restore the RNG state */
444 Rand_state_restore(state_backup);
450 * Border of the wilderness area
452 static border_type border;
457 * Build the wilderness area outside of the town.
460 void wilderness_gen(void)
468 current_floor_ptr->height = MAX_HGT;
469 current_floor_ptr->width = MAX_WID;
471 /* Assume illegal panel */
472 panel_row_min = current_floor_ptr->height;
473 panel_col_min = current_floor_ptr->width;
475 /* Init the wilderness */
477 process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
479 x = p_ptr->wilderness_x;
480 y = p_ptr->wilderness_y;
481 get_mon_num_prep(get_monster_hook(), NULL);
484 generate_area(y - 1, x, TRUE, FALSE);
486 for (i = 1; i < MAX_WID - 1; i++)
488 border.north[i] = current_floor_ptr->grid_array[MAX_HGT - 2][i].feat;
492 generate_area(y + 1, x, TRUE, FALSE);
494 for (i = 1; i < MAX_WID - 1; i++)
496 border.south[i] = current_floor_ptr->grid_array[1][i].feat;
500 generate_area(y, x - 1, TRUE, FALSE);
502 for (i = 1; i < MAX_HGT - 1; i++)
504 border.west[i] = current_floor_ptr->grid_array[i][MAX_WID - 2].feat;
508 generate_area(y, x + 1, TRUE, FALSE);
510 for (i = 1; i < MAX_HGT - 1; i++)
512 border.east[i] = current_floor_ptr->grid_array[i][1].feat;
515 /* North west corner */
516 generate_area(y - 1, x - 1, FALSE, TRUE);
517 border.north_west = current_floor_ptr->grid_array[MAX_HGT - 2][MAX_WID - 2].feat;
519 /* North east corner */
520 generate_area(y - 1, x + 1, FALSE, TRUE);
521 border.north_east = current_floor_ptr->grid_array[MAX_HGT - 2][1].feat;
523 /* South west corner */
524 generate_area(y + 1, x - 1, FALSE, TRUE);
525 border.south_west = current_floor_ptr->grid_array[1][MAX_WID - 2].feat;
527 /* South east corner */
528 generate_area(y + 1, x + 1, FALSE, TRUE);
529 border.south_east = current_floor_ptr->grid_array[1][1].feat;
532 /* Create terrain of the current area */
533 generate_area(y, x, FALSE, FALSE);
536 /* Special boundary walls -- North */
537 for (i = 0; i < MAX_WID; i++)
539 current_floor_ptr->grid_array[0][i].feat = feat_permanent;
540 current_floor_ptr->grid_array[0][i].mimic = border.north[i];
543 /* Special boundary walls -- South */
544 for (i = 0; i < MAX_WID; i++)
546 current_floor_ptr->grid_array[MAX_HGT - 1][i].feat = feat_permanent;
547 current_floor_ptr->grid_array[MAX_HGT - 1][i].mimic = border.south[i];
550 /* Special boundary walls -- West */
551 for (i = 0; i < MAX_HGT; i++)
553 current_floor_ptr->grid_array[i][0].feat = feat_permanent;
554 current_floor_ptr->grid_array[i][0].mimic = border.west[i];
557 /* Special boundary walls -- East */
558 for (i = 0; i < MAX_HGT; i++)
560 current_floor_ptr->grid_array[i][MAX_WID - 1].feat = feat_permanent;
561 current_floor_ptr->grid_array[i][MAX_WID - 1].mimic = border.east[i];
564 /* North west corner */
565 current_floor_ptr->grid_array[0][0].mimic = border.north_west;
567 /* North east corner */
568 current_floor_ptr->grid_array[0][MAX_WID - 1].mimic = border.north_east;
570 /* South west corner */
571 current_floor_ptr->grid_array[MAX_HGT - 1][0].mimic = border.south_west;
573 /* South east corner */
574 current_floor_ptr->grid_array[MAX_HGT - 1][MAX_WID - 1].mimic = border.south_east;
576 /* Light up or darken the area */
577 for (y = 0; y < current_floor_ptr->height; y++)
579 for (x = 0; x < current_floor_ptr->width; x++)
581 g_ptr = ¤t_floor_ptr->grid_array[y][x];
586 g_ptr->info |= (CAVE_GLOW);
588 /* Hack -- Memorize lit grids if allowed */
589 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
593 /* Feature code (applying "mimic" field) */
594 f_ptr = &f_info[get_feat_mimic(g_ptr)];
596 if (!is_mirror_grid(g_ptr) && !have_flag(f_ptr->flags, FF_QUEST_ENTER) &&
597 !have_flag(f_ptr->flags, FF_ENTRANCE))
600 g_ptr->info &= ~(CAVE_GLOW);
602 /* Darken "boring" features */
603 if (!have_flag(f_ptr->flags, FF_REMEMBER))
605 /* Forget the grid */
606 g_ptr->info &= ~(CAVE_MARK);
609 else if (have_flag(f_ptr->flags, FF_ENTRANCE))
612 g_ptr->info |= (CAVE_GLOW);
614 /* Hack -- Memorize lit grids if allowed */
615 if (view_perma_grids) g_ptr->info |= (CAVE_MARK);
621 if (p_ptr->teleport_town)
623 for (y = 0; y < current_floor_ptr->height; y++)
625 for (x = 0; x < current_floor_ptr->width; x++)
627 g_ptr = ¤t_floor_ptr->grid_array[y][x];
629 /* Seeing true feature code (ignore mimic) */
630 f_ptr = &f_info[g_ptr->feat];
632 if (have_flag(f_ptr->flags, FF_BLDG))
634 if ((f_ptr->subtype == 4) || ((p_ptr->town_num == 1) && (f_ptr->subtype == 0)))
636 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
643 p_ptr->teleport_town = FALSE;
646 else if (p_ptr->leaving_dungeon)
648 for (y = 0; y < current_floor_ptr->height; y++)
650 for (x = 0; x < current_floor_ptr->width; x++)
652 g_ptr = ¤t_floor_ptr->grid_array[y][x];
654 if (cave_have_flag_grid(g_ptr, FF_ENTRANCE))
656 if (g_ptr->m_idx) delete_monster_idx(g_ptr->m_idx);
662 p_ptr->teleport_town = FALSE;
665 player_place(p_ptr->oldpy, p_ptr->oldpx);
666 /* p_ptr->leaving_dungeon = FALSE;*/
668 lim = (generate_encounter == TRUE) ? 40 : MIN_M_ALLOC_TN;
670 /* Make some residents */
671 for (i = 0; i < lim; i++)
675 if (!(generate_encounter || (one_in_(2) && (!p_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) p_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 (i = 0; i < max_q_idx; i++)
691 if (quest[i].status == QUEST_STATUS_REWARDED)
692 quest[i].status = QUEST_STATUS_FINISHED;
697 static s16b conv_terrain2feat[MAX_WILDERNESS];
700 * @brief 広域マップの生成(簡易処理版) /
701 * Build the wilderness area. -DG-
704 void wilderness_gen_small(void)
708 /* To prevent stupid things */
709 for (i = 0; i < MAX_WID; i++)
710 for (j = 0; j < MAX_HGT; j++)
712 current_floor_ptr->grid_array[j][i].feat = feat_permanent;
715 /* Init the wilderness */
716 process_dungeon_file("w_info.txt", 0, 0, current_world_ptr->max_wild_y, current_world_ptr->max_wild_x);
719 for (i = 0; i < current_world_ptr->max_wild_x; i++)
720 for (j = 0; j < current_world_ptr->max_wild_y; j++)
722 if (wilderness[j][i].town && (wilderness[j][i].town != NO_TOWN))
724 current_floor_ptr->grid_array[j][i].feat = (s16b)feat_town;
725 current_floor_ptr->grid_array[j][i].special = (s16b)wilderness[j][i].town;
727 else if (wilderness[j][i].road) current_floor_ptr->grid_array[j][i].feat = feat_floor;
728 else if (wilderness[j][i].entrance && (p_ptr->total_winner || !(d_info[wilderness[j][i].entrance].flags1 & DF1_WINNER)))
730 current_floor_ptr->grid_array[j][i].feat = feat_entrance;
731 current_floor_ptr->grid_array[j][i].special = (byte)wilderness[j][i].entrance;
733 else current_floor_ptr->grid_array[j][i].feat = conv_terrain2feat[wilderness[j][i].terrain];
735 current_floor_ptr->grid_array[j][i].info |= (CAVE_GLOW | CAVE_MARK);
738 current_floor_ptr->height = (s16b) current_world_ptr->max_wild_y;
739 current_floor_ptr->width = (s16b) current_world_ptr->max_wild_x;
741 if (current_floor_ptr->height > MAX_HGT) current_floor_ptr->height = MAX_HGT;
742 if (current_floor_ptr->width > MAX_WID) current_floor_ptr->width = MAX_WID;
744 /* Assume illegal panel */
745 panel_row_min = current_floor_ptr->height;
746 panel_col_min = current_floor_ptr->width;
748 /* Place the player */
749 p_ptr->x = p_ptr->wilderness_x;
750 p_ptr->y = p_ptr->wilderness_y;
756 typedef struct wilderness_grid wilderness_grid;
758 struct wilderness_grid
760 int terrain; /* Terrain type */
761 TOWN_IDX town; /* Town number */
762 DEPTH level; /* Level of the wilderness */
763 byte road; /* Road */
764 char name[32]; /* Name of the town/wilderness */
768 static wilderness_grid w_letter[255];
772 * @brief w_info.txtのデータ解析 /
773 * Parse a sub-file of the "extra info"
774 * @param buf 読み取ったデータ行のバッファ
776 * @param xmin 広域地形マップを読み込みたいx座標の開始位置
778 * @param xmax 広域地形マップを読み込みたいx座標の終了位置
779 * @param y 広域マップの高さを返す参照ポインタ
780 * @param x 広域マップの幅を返す参照ポインタ
783 errr parse_line_wilderness(char *buf, int ymin, int xmin, int ymax, int xmax, int *y, int *x)
791 if (!(buf[0] == 'W')) return (PARSE_ERROR_GENERIC);
795 /* Process "W:F:<letter>:<terrain>:<town>:<road>:<name> */
808 if ((num = tokenize(buf+4, 6, zz, 0)) > 1)
810 int index = zz[0][0];
813 w_letter[index].terrain = atoi(zz[1]);
815 w_letter[index].terrain = 0;
818 w_letter[index].level = (s16b)atoi(zz[2]);
820 w_letter[index].level = 0;
823 w_letter[index].town = (TOWN_IDX)atoi(zz[3]);
825 w_letter[index].town = 0;
828 w_letter[index].road = (byte_hack)atoi(zz[4]);
830 w_letter[index].road = 0;
833 strcpy(w_letter[index].name, zz[5]);
835 w_letter[index].name[0] = 0;
840 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
846 /* Process "W:D:<layout> */
847 /* Layout of the wilderness */
850 /* Acquire the text */
853 /* Length of the text */
856 for (*x = xmin, i = 0; ((*x < xmax) && (i < len)); (*x)++, s++, i++)
859 wilderness[*y][*x].terrain = w_letter[id].terrain;
860 wilderness[*y][*x].level = w_letter[id].level;
861 wilderness[*y][*x].town = w_letter[id].town;
862 wilderness[*y][*x].road = w_letter[id].road;
863 strcpy(town_info[w_letter[id].town].name, w_letter[id].name);
871 /* Process "W:P:<x>:<y> - starting position in the wilderness */
874 if ((p_ptr->wilderness_x == 0) &&
875 (p_ptr->wilderness_y == 0))
877 if (tokenize(buf+4, 2, zz, 0) == 2)
879 p_ptr->wilderness_y = atoi(zz[0]);
880 p_ptr->wilderness_x = atoi(zz[1]);
882 if ((p_ptr->wilderness_x < 1) ||
883 (p_ptr->wilderness_x > current_world_ptr->max_wild_x) ||
884 (p_ptr->wilderness_y < 1) ||
885 (p_ptr->wilderness_y > current_world_ptr->max_wild_y))
887 return (PARSE_ERROR_OUT_OF_BOUNDS);
892 return (PARSE_ERROR_TOO_FEW_ARGUMENTS);
901 return (PARSE_ERROR_UNDEFINED_DIRECTIVE);
904 for (i = 1; i < max_d_idx; i++)
906 if (!d_info[i].maxdepth) continue;
907 wilderness[d_info[i].dy][d_info[i].dx].entrance = (byte_hack)i;
908 if (!wilderness[d_info[i].dy][d_info[i].dx].town)
909 wilderness[d_info[i].dy][d_info[i].dx].level = d_info[i].mindepth;
919 * @brief ゲーム開始時に各荒野フロアの乱数シードを指定する /
920 * Generate the random seeds for the wilderness
923 void seed_wilderness(void)
927 /* Init wilderness seeds */
928 for (x = 0; x < current_world_ptr->max_wild_x; x++)
930 for (y = 0; y < current_world_ptr->max_wild_y; y++)
932 wilderness[y][x].seed = randint0(0x10000000);
933 wilderness[y][x].entrance = 0;
940 * Pointer to wilderness_type
942 typedef wilderness_type *wilderness_type_ptr;
946 * @brief ゲーム開始時の荒野初期化メインルーチン /
947 * Initialize wilderness array
950 errr init_wilderness(void)
954 /* Allocate the wilderness (two-dimension array) */
955 C_MAKE(wilderness, current_world_ptr->max_wild_y, wilderness_type_ptr);
956 C_MAKE(wilderness[0], current_world_ptr->max_wild_x * current_world_ptr->max_wild_y, wilderness_type);
958 /* Init the other pointers */
959 for (i = 1; i < current_world_ptr->max_wild_y; i++)
960 wilderness[i] = wilderness[0] + i * current_world_ptr->max_wild_x;
962 generate_encounter = FALSE;
968 * @brief 荒野の地勢設定を初期化する /
969 * Initialize wilderness array
970 * @param terrain 初期化したい地勢ID
971 * @param feat_global 基本的な地形ID
972 * @param fmt 地勢内の地形数を参照するための独自フォーマット
975 static void init_terrain_table(int terrain, s16b feat_global, concptr fmt, ...)
984 /* Begin the varargs stuff */
987 /* Wilderness terrains on global map */
988 conv_terrain2feat[terrain] = feat_global;
990 /* Wilderness terrains on local map */
991 for (p = fmt; *p; p++)
997 feat = (s16b)va_arg(vp, int);
998 num = va_arg(vp, int);
1001 for (; (cur < lim) && (cur < MAX_FEAT_IN_TERRAIN); cur++)
1002 terrain_table[terrain][cur] = feat;
1003 if (cur >= MAX_FEAT_IN_TERRAIN) break;
1009 plog_fmt("Format error");
1012 if (cur < MAX_FEAT_IN_TERRAIN)
1014 plog_fmt("Too few parameters");
1017 /* End the varargs stuff */
1023 * @brief 荒野の地勢設定全体を初期化するメインルーチン /
1024 * Initialize arrays for wilderness terrains
1027 void init_wilderness_terrains(void)
1029 init_terrain_table(TERRAIN_EDGE, feat_permanent, "a",
1030 feat_permanent, MAX_FEAT_IN_TERRAIN);
1032 init_terrain_table(TERRAIN_TOWN, feat_town, "a",
1033 feat_floor, MAX_FEAT_IN_TERRAIN);
1035 init_terrain_table(TERRAIN_DEEP_WATER, feat_deep_water, "ab",
1036 feat_deep_water, 12,
1037 feat_shallow_water, MAX_FEAT_IN_TERRAIN - 12);
1039 init_terrain_table(TERRAIN_SHALLOW_WATER, feat_shallow_water, "abcde",
1041 feat_shallow_water, 12,
1044 feat_grass, MAX_FEAT_IN_TERRAIN - 17);
1046 init_terrain_table(TERRAIN_SWAMP, feat_swamp, "abcdef",
1051 feat_shallow_water, 4,
1052 feat_swamp, MAX_FEAT_IN_TERRAIN - 11);
1054 init_terrain_table(TERRAIN_DIRT, feat_dirt, "abcdef",
1060 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1062 init_terrain_table(TERRAIN_GRASS, feat_grass, "abcdef",
1068 feat_tree, MAX_FEAT_IN_TERRAIN - 16);
1070 init_terrain_table(TERRAIN_TREES, feat_tree, "abcde",
1075 feat_grass, MAX_FEAT_IN_TERRAIN - 16);
1077 init_terrain_table(TERRAIN_DESERT, feat_dirt, "abc",
1080 feat_grass, MAX_FEAT_IN_TERRAIN - 15);
1082 init_terrain_table(TERRAIN_SHALLOW_LAVA, feat_shallow_lava, "abc",
1083 feat_shallow_lava, 14,
1085 feat_mountain, MAX_FEAT_IN_TERRAIN - 17);
1087 init_terrain_table(TERRAIN_DEEP_LAVA, feat_deep_lava, "abcd",
1089 feat_shallow_lava, 3,
1091 feat_mountain, MAX_FEAT_IN_TERRAIN - 16);
1093 init_terrain_table(TERRAIN_MOUNTAIN, feat_mountain, "abcdef",
1099 feat_mountain, MAX_FEAT_IN_TERRAIN - 8);
1103 * @brief 荒野から広域マップへの切り替え処理 /
1104 * Initialize arrays for wilderness terrains
1105 * @return 切り替えが行われた場合はTRUEを返す。
1107 bool change_wild_mode(void)
1110 bool have_pet = FALSE;
1112 /* It is in the middle of changing map */
1113 if (p_ptr->leaving) return FALSE;
1116 if (lite_town || vanilla_town)
1118 msg_print(_("荒野なんてない。", "No global map."));
1122 if (p_ptr->wild_mode)
1124 /* Save the location in the global map */
1125 p_ptr->wilderness_x = p_ptr->x;
1126 p_ptr->wilderness_y = p_ptr->y;
1128 /* Give first move to the player */
1129 p_ptr->energy_need = 0;
1131 /* Go back to the ordinary map */
1132 p_ptr->wild_mode = FALSE;
1133 p_ptr->leaving = TRUE;
1139 for (i = 1; i < m_max; i++)
1141 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1143 if (!monster_is_valid(m_ptr)) 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;
1148 msg_print(_("敵がすぐ近くにいるときは広域マップに入れない!",
1149 "You cannot enter global map, since there is some monsters nearby!"));
1156 concptr msg = _("ペットを置いて広域マップに入りますか?",
1157 "Do you leave your pets behind? ");
1159 if (!get_check_strict(msg, CHECK_OKAY_CANCEL))
1166 take_turn(p_ptr, 1000);
1168 /* Remember the position */
1169 p_ptr->oldpx = p_ptr->x;
1170 p_ptr->oldpy = p_ptr->y;
1172 /* Cancel hex spelling */
1173 if (hex_spelling_any()) stop_hex_spell_all();
1175 /* Cancel any special action */
1176 set_action(ACTION_NONE);
1178 /* Go into the global map */
1179 p_ptr->wild_mode = TRUE;
1180 p_ptr->leaving = TRUE;