OSDN Git Service

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