OSDN Git Service

c_ptr->mimic のコードさらにバグ取り。地形を操作する各コマンド disarm,
[hengband/hengband.git] / src / streams.c
1 /*
2  * File: streams.c
3  * Purpose: Used by dungeon generation. This file holds all the
4  * functions that are applied to a level after the rest has been
5  * generated, ie streams and level destruction.
6  */
7
8 /*
9  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
10  *
11  * This software may be copied and distributed for educational, research, and
12  * not for profit purposes provided that this copyright and statement are
13  * included in all such copies.
14  */
15
16 #include "angband.h"
17 #include "generate.h"
18 #include "streams.h"
19 #include "grid.h"
20
21
22 /*
23  * Recursive fractal algorithm to place water through the dungeon.
24  */
25 static void recursive_river(int x1, int y1, int x2, int y2, int feat1, int feat2, int width)
26 {
27         int dx, dy, length, l, x, y;
28         int changex, changey;
29         int ty, tx;
30         bool done;
31         cave_type *c_ptr;
32
33         length = distance(x1, y1, x2, y2);
34
35         if (length > 4)
36         {
37                 /*
38                  * Divide path in half and call routine twice.
39                  * There is a small chance of splitting the river
40                  */
41                 dx = (x2 - x1) / 2;
42                 dy = (y2 - y1) / 2;
43
44                 if (dy != 0)
45                 {
46                         /* perturbation perpendicular to path */
47                         changex = randint1(abs(dy)) * 2 - abs(dy);
48                 }
49                 else
50                 {
51                         changex = 0;
52                 }
53
54                 if (dx != 0)
55                 {
56                         /* perturbation perpendicular to path */
57                         changey = randint1(abs(dx)) * 2 - abs(dx);
58                 }
59                 else
60                 {
61                         changey = 0;
62                 }
63
64                 if (!in_bounds(y1 + dy + changey, x1 + dx + changex))
65                 {
66                         changex = 0;
67                         changey = 0;
68                 }
69
70                 /* construct river out of two smaller ones */
71                 recursive_river(x1, y1, x1 + dx + changex, y1 + dy + changey, feat1, feat2, width);
72                 recursive_river(x1 + dx + changex, y1 + dy + changey, x2, y2, feat1, feat2, width);
73
74                 /* Split the river some of the time - junctions look cool */
75                 if (one_in_(DUN_WAT_CHG) && (width > 0))
76                 {
77                         recursive_river(x1 + dx + changex, y1 + dy + changey,
78                                         x1 + 8 * (dx + changex), y1 + 8 * (dy + changey),
79                                         feat1, feat2, width - 1);
80                 }
81         }
82         else
83         {
84                 /* Actually build the river */
85                 for (l = 0; l < length; l++)
86                 {
87                         x = x1 + l * (x2 - x1) / length;
88                         y = y1 + l * (y2 - y1) / length;
89
90                         done = FALSE;
91
92                         while (!done)
93                         {
94                                 for (ty = y - width - 1; ty <= y + width + 1; ty++)
95                                 {
96                                         for (tx = x - width - 1; tx <= x + width + 1; tx++)
97                                         {
98                                                 if (!in_bounds(ty, tx)) continue;
99
100                                                 c_ptr = &cave[ty][tx];
101
102                                                 if (c_ptr->feat == feat1) continue;
103                                                 if (c_ptr->feat == feat2) continue;
104
105                                                 if (distance(ty, tx, y, x) > rand_spread(width, 1)) continue;
106
107                                                 /* Do not convert permanent features */
108                                                 if (cave_perma_grid(c_ptr) && (c_ptr->feat != FEAT_MOUNTAIN)) continue;
109
110                                                 /*
111                                                  * Clear previous contents, add feature
112                                                  * The border mainly gets feat2, while the center gets feat1
113                                                  */
114                                                 if (distance(ty, tx, y, x) > width)
115                                                         c_ptr->feat = feat2;
116                                                 else
117                                                         c_ptr->feat = feat1;
118
119                                                 /* Clear garbage of hidden trap or door */
120                                                 c_ptr->mimic = 0;
121
122                                                 /* Lava terrain glows */
123                                                 if ((feat1 == FEAT_DEEP_LAVA) ||  (feat1 == FEAT_SHAL_LAVA))
124                                                 {
125                                                         c_ptr->info |= CAVE_GLOW;
126                                                 }
127
128                                                 /* Hack -- don't teleport here */
129                                                 c_ptr->info |= CAVE_ICKY;
130                                         }
131                                 }
132
133                                 done = TRUE;
134                         }
135                 }
136         }
137 }
138
139
140 /*
141  * Places water /lava through dungeon.
142  */
143 void add_river(int feat1, int feat2)
144 {
145         int y2, x2;
146         int y1 = 0, x1 = 0;
147         int wid;
148
149
150         /* Hack -- Choose starting point */
151         y2 = randint1(cur_hgt / 2 - 2) + cur_hgt / 2;
152         x2 = randint1(cur_wid / 2 - 2) + cur_wid / 2;
153
154         /* Hack -- Choose ending point somewhere on boundary */
155         switch(randint1(4))
156         {
157                 case 1:
158                 {
159                         /* top boundary */
160                         x1 = randint1(cur_wid-2)+1;
161                         y1 = 1;
162                         break;
163                 }
164                 case 2:
165                 {
166                         /* left boundary */
167                         x1 = 1;
168                         y1 = randint1(cur_hgt-2)+1;
169                         break;
170                 }
171                 case 3:
172                 {
173                         /* right boundary */
174                         x1 = cur_wid-1;
175                         y1 = randint1(cur_hgt-2)+1;
176                         break;
177                 }
178                 case 4:
179                 {
180                         /* bottom boundary */
181                         x1 = randint1(cur_wid-2)+1;
182                         y1 = cur_hgt-1;
183                         break;
184                 }
185         }
186
187         wid = randint1(DUN_WAT_RNG);
188         recursive_river(x1, y1, x2, y2, feat1, feat2, wid);
189
190         /* Hack - Save the location as a "room" */
191         if (dun->cent_n < CENT_MAX)
192         {
193                 dun->cent[dun->cent_n].y = y2;
194                 dun->cent[dun->cent_n].x = x2;
195                 dun->cent_n++;
196         }
197 }
198
199
200 /*
201  * Places "streamers" of rock through dungeon
202  *
203  * Note that their are actually six different terrain features used
204  * to represent streamers.  Three each of magma and quartz, one for
205  * basic vein, one with hidden gold, and one with known gold.  The
206  * hidden gold types are currently unused.
207  */
208 void build_streamer(int feat, int chance)
209 {
210         int             i, tx, ty;
211         int             y, x, dir;
212         int dummy = 0;
213         bool treasure = FALSE;
214
215         cave_type *c_ptr;
216
217         /* Hack -- Choose starting point */
218         y = rand_spread(cur_hgt / 2, 10);
219         x = rand_spread(cur_wid / 2, 15);
220
221         /* Choose a random compass direction */
222         dir = ddd[randint0(8)];
223
224         /* Place streamer into dungeon */
225         while (dummy < SAFE_MAX_ATTEMPTS)
226         {
227                 dummy++;
228
229                 /* One grid per density */
230                 for (i = 0; i < DUN_STR_DEN; i++)
231                 {
232                         int d = DUN_STR_RNG;
233
234                         /* Pick a nearby grid */
235                         while (1)
236                         {
237                                 ty = rand_spread(y, d);
238                                 tx = rand_spread(x, d);
239                                 if (!in_bounds(ty, tx)) continue;
240                                 break;
241                         }
242
243                         /* Access the grid */
244                         c_ptr = &cave[ty][tx];
245
246                         if ((c_ptr->feat >= FEAT_DEEP_WATER) && (c_ptr->feat <= FEAT_SHAL_LAVA)) continue;
247                         if ((c_ptr->feat >= FEAT_PERM_EXTRA) && (c_ptr->feat <= FEAT_PERM_SOLID)) continue;
248
249                         /* Only convert "granite" walls */
250                         if ((feat >= FEAT_MAGMA) && (feat <= FEAT_WALL_SOLID))
251                         {
252                                 if (!is_extra_grid(c_ptr) && !is_inner_grid(c_ptr) && !is_outer_grid(c_ptr) && !is_solid_grid(c_ptr)) continue;
253                                 if (is_closed_door(c_ptr->feat)) continue;
254                                 if ((feat == FEAT_MAGMA) || (feat == FEAT_QUARTZ)) treasure = TRUE;
255                         }
256                         else
257                         {
258                                 if (cave_perma_grid(c_ptr) && (c_ptr->feat != FEAT_MOUNTAIN)) continue;
259                         }
260
261                         /* Clear previous contents, add proper vein type */
262                         c_ptr->feat = feat;
263
264                         /* Paranoia: Clear mimic field */
265                         c_ptr->mimic = 0;
266
267                         /* Hack -- Add some (known) treasure */
268                         if (treasure && one_in_(chance)) c_ptr->feat += 0x04;
269                 }
270
271                 if (dummy >= SAFE_MAX_ATTEMPTS)
272                 {
273                         if (cheat_room)
274                         {
275 #ifdef JP
276 msg_print("·Ù¹ð¡ª¥¹¥È¥ê¡¼¥Þ¡¼¤òÇÛÃ֤Ǥ­¤Þ¤»¤ó¡ª");
277 #else
278                                 msg_print("Warning! Could not place streamer!");
279 #endif
280
281                         }
282                         return;
283                 }
284
285
286                 /* Advance the streamer */
287                 y += ddy[dir];
288                 x += ddx[dir];
289
290                 /* Quit before leaving the dungeon */
291                 if (!in_bounds(y, x)) break;
292         }
293 }
294
295
296 /*
297  * Put trees near a hole in the dungeon roof  (rubble on ground + up stairway)
298  * This happens in real world lava tubes.
299  */
300 void place_trees(int x, int y)
301 {
302         int i, j;
303         cave_type *c_ptr;
304
305         /* place trees/ rubble in ovalish distribution */
306         for (i = x - 3; i < x + 4; i++)
307         {
308                 for (j = y - 3; j < y + 4; j++)
309                 {
310                         if (!in_bounds(j, i)) continue;
311                         c_ptr = &cave[j][i];
312
313                         if (c_ptr->info & CAVE_ICKY) continue;
314                         if (c_ptr->o_idx) continue;
315
316                         /* Want square to be in the circle and accessable. */
317                         if ((distance(j, i, y, x) < 4) && !cave_perma_grid(c_ptr))
318                         {
319                                 /*
320                                  * Clear previous contents, add feature
321                                  * The border mainly gets trees, while the center gets rubble
322                                  */
323                                 if ((distance(j, i, y, x) > 1) || (randint1(100) < 25))
324                                 {
325                                         if (randint1(100) < 75)
326                                                 cave[j][i].feat = FEAT_TREES;
327                                 }
328                                 else
329                                 {
330                                         cave[j][i].feat = FEAT_RUBBLE;
331                                 }
332
333                                 /* Clear garbage of hidden trap or door */
334                                 c_ptr->mimic = 0;
335
336                                 /* Light area since is open above */
337                                 cave[j][i].info |= (CAVE_GLOW | CAVE_ROOM);
338                         }
339                 }
340         }
341
342         /* No up stairs in ironman mode */
343         if (!ironman_downward && one_in_(3))
344         {
345                 /* up stair */
346                 cave[y][x].feat = FEAT_LESS;
347         }
348 }
349
350
351 /*
352  * Build a destroyed level
353  */
354 void destroy_level(void)
355 {
356         int y1, x1, y, x, k, t, n;
357
358         cave_type *c_ptr;
359
360         /* Note destroyed levels */
361 #ifdef JP
362 if (cheat_room) msg_print("Ç˲õ¤µ¤ì¤¿³¬");
363 #else
364         if (cheat_room) msg_print("Destroyed Level");
365 #endif
366
367
368         /* Drop a few epi-centers (usually about two) */
369         for (n = 0; n < randint1(5); n++)
370         {
371                 /* Pick an epi-center */
372                 x1 = rand_range(5, cur_wid - 1 - 5);
373                 y1 = rand_range(5, cur_hgt - 1 - 5);
374
375                 /* Big area of affect */
376                 for (y = (y1 - 15); y <= (y1 + 15); y++)
377                 {
378                         for (x = (x1 - 15); x <= (x1 + 15); x++)
379                         {
380                                 /* Skip illegal grids */
381                                 if (!in_bounds(y, x)) continue;
382
383                                 /* Extract the distance */
384                                 k = distance(y1, x1, y, x);
385
386                                 /* Stay in the circle of death */
387                                 if (k >= 16) continue;
388
389                                 /* Delete the monster (if any) */
390                                 delete_monster(y, x);
391
392                                 /* Access the grid */
393                                 c_ptr = &cave[y][x];
394
395                                 /* Destroy valid grids */
396                                 if (cave_valid_grid(c_ptr))
397                                 {
398                                         /* Delete objects */
399                                         delete_object(y, x);
400
401                                         /* Wall (or floor) type */
402                                         t = randint0(200);
403
404                                         /* Granite */
405                                         if (t < 20)
406                                         {
407                                                 /* Create granite wall */
408                                                 place_extra_grid(c_ptr);
409                                         }
410
411                                         /* Quartz */
412                                         else if (t < 70)
413                                         {
414                                                 /* Create quartz vein */
415                                                 c_ptr->feat = FEAT_QUARTZ;
416                                         }
417
418                                         /* Magma */
419                                         else if (t < 100)
420                                         {
421                                                 /* Create magma vein */
422                                                 c_ptr->feat = FEAT_MAGMA;
423                                         }
424
425                                         /* Floor */
426                                         else
427                                         {
428                                                 /* Create floor */
429                                                 place_floor_grid(c_ptr);
430                                         }
431
432                                         /* Clear garbage of hidden trap or door */
433                                         c_ptr->mimic = 0;
434
435                                         /* No longer part of a room or vault */
436                                         c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
437
438                                         /* No longer illuminated or known */
439                                         c_ptr->info &= ~(CAVE_MARK | CAVE_GLOW);
440                                 }
441                         }
442                 }
443         }
444 }