OSDN Git Service

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