OSDN Git Service

[Refactor] #38993 floor_type 構造体作成。 / Create floor_type structure.
[hengband/hengband.git] / src / floor-streams.c
1 /*!
2  * @file streams.c
3  * @brief ダンジョン生成に利用する関数群 / Used by dungeon generation.
4  * @date 2014/07/15
5  * @author
6  * <pre>
7  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8  * This software may be copied and distributed for educational, research,
9  * and not for profit purposes provided that this copyright and statement
10  * are included in all such copies.  Other copyrights may also apply.
11  * </pre>
12  * @details
13  * Purpose:  This file holds all the
14  * functions that are applied to a level after the rest has been
15  * generated, ie streams and level destruction.
16  */
17
18 #include "angband.h"
19 #include "generate.h"
20 #include "floor-streams.h"
21 #include "grid.h"
22 #include "feature.h"
23
24
25 /*!
26  * @brief 再帰フラクタルアルゴリズムによりダンジョン内に川を配置する /
27  * Recursive fractal algorithm to place water through the dungeon.
28  * @param x1 起点x座標
29  * @param y1 起点y座標
30  * @param x2 終点x座標
31  * @param y2 終点y座標
32  * @param feat1 中央部地形ID
33  * @param feat2 境界部地形ID
34  * @param width 基本幅
35  * @return なし
36  */
37 static void recursive_river(POSITION x1, POSITION y1, POSITION x2, POSITION y2, FEAT_IDX feat1, FEAT_IDX feat2, POSITION width)
38 {
39         POSITION dx, dy, length, l, x, y;
40         POSITION changex, changey;
41         POSITION ty, tx;
42         bool done;
43         grid_type *g_ptr;
44
45         length = distance(x1, y1, x2, y2);
46
47         if (length > 4)
48         {
49                 /*
50                  * Divide path in half and call routine twice.
51                  * There is a small chance of splitting the river
52                  */
53                 dx = (x2 - x1) / 2;
54                 dy = (y2 - y1) / 2;
55
56                 if (dy != 0)
57                 {
58                         /* perturbation perpendicular to path */
59                         changex = randint1(abs(dy)) * 2 - abs(dy);
60                 }
61                 else
62                 {
63                         changex = 0;
64                 }
65
66                 if (dx != 0)
67                 {
68                         /* perturbation perpendicular to path */
69                         changey = randint1(abs(dx)) * 2 - abs(dx);
70                 }
71                 else
72                 {
73                         changey = 0;
74                 }
75
76                 if (!in_bounds(y1 + dy + changey, x1 + dx + changex))
77                 {
78                         changex = 0;
79                         changey = 0;
80                 }
81
82                 /* construct river out of two smaller ones */
83                 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
84                 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
85
86                 /* Split the river some of the time - junctions look cool */
87                 if (one_in_(DUN_WAT_CHG) && (width > 0))
88                 {
89                         recursive_river(x1 + dx + changex, y1 + dy + changey,
90                                         x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
91                                         feat1, feat2, width - 1);
92                 }
93         }
94         else
95         {
96                 /* Actually build the river */
97                 for (l = 0; l < length; l++)
98                 {
99                         x = x1 + l * (x2 - x1) / length;
100                         y = y1 + l * (y2 - y1) / length;
101
102                         done = FALSE;
103
104                         while (!done)
105                         {
106                                 for (ty = y - width - 1; ty <= y + width + 1; ty++)
107                                 {
108                                         for (tx = x - width - 1; tx <= x + width + 1; tx++)
109                                         {
110                                                 if (!in_bounds2(ty, tx)) continue;
111
112                                                 g_ptr = &current_floor->grid_array[ty][tx];
113
114                                                 if (g_ptr->feat == feat1) continue;
115                                                 if (g_ptr->feat == feat2) continue;
116
117                                                 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
118
119                                                 /* Do not convert permanent features */
120                                                 if (cave_perma_grid(g_ptr)) continue;
121
122                                                 /*
123                                                  * Clear previous contents, add feature
124                                                  * The border mainly gets feat2, while the center gets feat1
125                                                  */
126                                                 if (distance(ty, tx, y, x) > width)
127                                                         g_ptr->feat = feat2;
128                                                 else
129                                                         g_ptr->feat = feat1;
130
131                                                 /* Clear garbage of hidden trap or door */
132                                                 g_ptr->mimic = 0;
133
134                                                 /* Lava terrain glows */
135                                                 if (have_flag(f_info[feat1].flags, FF_LAVA))
136                                                 {
137                                                         if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) g_ptr->info |= CAVE_GLOW;
138                                                 }
139
140                                                 /* Hack -- don't teleport here */
141                                                 g_ptr->info |= CAVE_ICKY;
142                                         }
143                                 }
144
145                                 done = TRUE;
146                         }
147                 }
148         }
149 }
150
151
152 /*!
153  * @brief ランダムに川/溶岩流をダンジョンに配置する /
154  * Places water /lava through dungeon.
155  * @param feat1 中央部地形ID
156  * @param feat2 境界部地形ID
157  * @return なし
158  */
159 void add_river(IDX feat1, IDX feat2)
160 {
161         POSITION y2, x2;
162         POSITION y1 = 0, x1 = 0;
163         POSITION wid;
164
165
166         /* Hack -- Choose starting point */
167         y2 = randint1(cur_hgt / 2 - 2) + cur_hgt / 2;
168         x2 = randint1(cur_wid / 2 - 2) + cur_wid / 2;
169
170         /* Hack -- Choose ending point somewhere on boundary */
171         switch(randint1(4))
172         {
173                 case 1:
174                 {
175                         /* top boundary */
176                         x1 = randint1(cur_wid-2)+1;
177                         y1 = 1;
178                         break;
179                 }
180                 case 2:
181                 {
182                         /* left boundary */
183                         x1 = 1;
184                         y1 = randint1(cur_hgt-2)+1;
185                         break;
186                 }
187                 case 3:
188                 {
189                         /* right boundary */
190                         x1 = cur_wid-1;
191                         y1 = randint1(cur_hgt-2)+1;
192                         break;
193                 }
194                 case 4:
195                 {
196                         /* bottom boundary */
197                         x1 = randint1(cur_wid-2)+1;
198                         y1 = cur_hgt-1;
199                         break;
200                 }
201         }
202
203         wid = randint1(DUN_WAT_RNG);
204         recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
205
206         /* Hack - Save the location as a "room" */
207         if (dun->cent_n < CENT_MAX)
208         {
209                 dun->cent[dun->cent_n].y = y2;
210                 dun->cent[dun->cent_n].x = x2;
211                 dun->cent_n++;
212         }
213 }
214
215
216 /*!
217  * @brief ダンジョンの壁部にストリーマー(地質の変化)を与える /
218  * Places "streamers" of rock through dungeon
219  * @param feat ストリーマー地形ID
220  * @param chance 生成密度
221  * @return なし
222  * @details
223  * <pre>
224  * Note that their are actually six different terrain features used
225  * to represent streamers.  Three each of magma and quartz, one for
226  * basic vein, one with hidden gold, and one with known gold.  The
227  * hidden gold types are currently unused.
228  * </pre>
229  */
230 void build_streamer(IDX feat, int chance)
231 {
232         int             i, tx, ty;
233         int             y, x, dir;
234         int dummy = 0;
235
236         grid_type *g_ptr;
237         feature_type *f_ptr;
238
239         feature_type *streamer_ptr = &f_info[feat];
240         bool streamer_is_wall = have_flag(streamer_ptr->flags, FF_WALL) && !have_flag(streamer_ptr->flags, FF_PERMANENT);
241         bool streamer_may_have_gold = have_flag(streamer_ptr->flags, FF_MAY_HAVE_GOLD);
242
243         /* Hack -- Choose starting point */
244         y = rand_spread(cur_hgt / 2, cur_hgt / 6);
245         x = rand_spread(cur_wid / 2, cur_wid / 6);
246
247         /* Choose a random compass direction */
248         dir = randint0(8);
249
250         /* Place streamer into dungeon */
251         while (dummy < SAFE_MAX_ATTEMPTS)
252         {
253                 dummy++;
254
255                 /* One grid per density */
256                 for (i = 0; i < DUN_STR_DEN; i++)
257                 {
258                         int d = DUN_STR_RNG;
259
260                         /* Pick a nearby grid */
261                         while (1)
262                         {
263                                 ty = rand_spread(y, d);
264                                 tx = rand_spread(x, d);
265                                 if (!in_bounds2(ty, tx)) continue;
266                                 break;
267                         }
268                         g_ptr = &current_floor->grid_array[ty][tx];
269                         f_ptr = &f_info[g_ptr->feat];
270
271                         if (have_flag(f_ptr->flags, FF_MOVE) && (have_flag(f_ptr->flags, FF_WATER) || have_flag(f_ptr->flags, FF_LAVA)))
272                                 continue;
273
274                         /* Do not convert permanent features */
275                         if (have_flag(f_ptr->flags, FF_PERMANENT)) continue;
276
277                         /* Only convert "granite" walls */
278                         if (streamer_is_wall)
279                         {
280                                 if (!is_extra_grid(g_ptr) && !is_inner_grid(g_ptr) && !is_outer_grid(g_ptr) && !is_solid_grid(g_ptr)) continue;
281                                 if (is_closed_door(g_ptr->feat)) continue;
282                         }
283
284                         if (g_ptr->m_idx && !(have_flag(streamer_ptr->flags, FF_PLACE) && monster_can_cross_terrain(feat, &r_info[m_list[g_ptr->m_idx].r_idx], 0)))
285                         {
286                                 /* Delete the monster (if any) */
287                                 delete_monster(ty, tx);
288                         }
289
290                         if (g_ptr->o_idx && !have_flag(streamer_ptr->flags, FF_DROP))
291                         {
292                                 OBJECT_IDX this_o_idx, next_o_idx = 0;
293
294                                 /* Scan all objects in the grid */
295                                 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
296                                 {
297                                         object_type *o_ptr = &o_list[this_o_idx];
298
299                                         /* Acquire next object */
300                                         next_o_idx = o_ptr->next_o_idx;
301
302                                         /* Hack -- Preserve unknown artifacts */
303                                         if (object_is_fixed_artifact(o_ptr))
304                                         {
305                                                 /* Mega-Hack -- Preserve the artifact */
306                                                 a_info[o_ptr->name1].cur_num = 0;
307
308                                                 if (cheat_peek)
309                                                 {
310                                                         GAME_TEXT o_name[MAX_NLEN];
311                                                         object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
312                                                         msg_format(_("伝説のアイテム (%s) はストリーマーにより削除された。",
313                                                                 "Artifact (%s) was deleted by streamer."), o_name);
314                                                 }
315                                         }
316                                         else if (cheat_peek && o_ptr->art_name)
317                                         {
318                                                 msg_print(_("ランダム・アーティファクトの1つはストリーマーにより削除された。",
319                                                         "One of the random artifacts was deleted by streamer."));
320                                         }
321                                 }
322
323                                 delete_object(ty, tx);
324                         }
325
326                         /* Clear previous contents, add proper vein type */
327                         g_ptr->feat = feat;
328
329                         /* Paranoia: Clear mimic field */
330                         g_ptr->mimic = 0;
331
332                         if (streamer_may_have_gold)
333                         {
334                                 /* Hack -- Add some known treasure */
335                                 if (one_in_(chance))
336                                 {
337                                         cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
338                                 }
339
340                                 /* Hack -- Add some hidden treasure */
341                                 else if (one_in_(chance / 4))
342                                 {
343                                         cave_alter_feat(ty, tx, FF_MAY_HAVE_GOLD);
344                                         cave_alter_feat(ty, tx, FF_ENSECRET);
345                                 }
346                         }
347                 }
348
349                 if (dummy >= SAFE_MAX_ATTEMPTS)
350                 {
351                         msg_print_wizard(CHEAT_DUNGEON, _("地形のストリーマー処理に失敗しました。", "Failed to place streamer."));
352                         return;
353                 }
354
355                 /* Advance the streamer */
356                 y += ddy[cdd[dir]];
357                 x += ddx[cdd[dir]];
358
359                 if(one_in_(10))
360                 {
361                         if(one_in_(2)) dir = (dir + 1) % 8;
362                         else dir = (dir > 0) ? dir - 1 : 7; 
363                 }
364
365                 /* Quit before leaving the dungeon */
366                 if (!in_bounds(y, x)) break;
367         }
368 }
369
370
371 /*!
372  * @brief ダンジョンの指定位置近辺に森林を配置する /
373  * Places "streamers" of rock through dungeon
374  * @param x 指定X座標
375  * @param y 指定Y座標
376  * @return なし
377  * @details
378  * <pre>
379  * Put trees near a hole in the dungeon roof  (rubble on ground + up stairway)
380  * This happens in real world lava tubes.
381  * </pre>
382  */
383 void place_trees(POSITION x, POSITION y)
384 {
385         int i, j;
386         grid_type *g_ptr;
387
388         /* place trees/ rubble in ovalish distribution */
389         for (i = x - 3; i < x + 4; i++)
390         {
391                 for (j = y - 3; j < y + 4; j++)
392                 {
393                         if (!in_bounds(j, i)) continue;
394                         g_ptr = &current_floor->grid_array[j][i];
395
396                         if (g_ptr->info & CAVE_ICKY) continue;
397                         if (g_ptr->o_idx) continue;
398
399                         /* Want square to be in the circle and accessable. */
400                         if ((distance(j, i, y, x) < 4) && !cave_perma_grid(g_ptr))
401                         {
402                                 /*
403                                  * Clear previous contents, add feature
404                                  * The border mainly gets trees, while the center gets rubble
405                                  */
406                                 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
407                                 {
408                                         if (randint1(100) < 75)
409                                                 current_floor->grid_array[j][i].feat = feat_tree;
410                                 }
411                                 else
412                                 {
413                                         current_floor->grid_array[j][i].feat = feat_rubble;
414                                 }
415
416                                 /* Clear garbage of hidden trap or door */
417                                 g_ptr->mimic = 0;
418
419                                 /* Light area since is open above */
420                                 if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) current_floor->grid_array[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
421                         }
422                 }
423         }
424
425         /* No up stairs in ironman mode */
426         if (!ironman_downward && one_in_(3))
427         {
428                 /* up stair */
429                 current_floor->grid_array[y][x].feat = feat_up_stair;
430         }
431 }
432
433
434 /*!
435  * @brief ダンジョンに*破壊*済み地形ランダムに施す /
436  * Build a destroyed level
437  * @return なし
438  */
439 void destroy_level(void)
440 {
441         POSITION y1, x1;
442         int n;
443
444         /* Note destroyed levels */
445         msg_print_wizard(CHEAT_DUNGEON, _("階に*破壊*の痕跡を生成しました。", "Destroyed Level."));
446
447         /* Drop a few epi-centers (usually about two) */
448         for (n = 0; n < randint1(5); n++)
449         {
450                 /* Pick an epi-center */
451                 x1 = rand_range(5, cur_wid - 1 - 5);
452                 y1 = rand_range(5, cur_hgt - 1 - 5);
453
454                 (void)destroy_area(y1, x1, 15, TRUE);
455         }
456 }