comparison arogue7/outside.c @ 125:adfa37e67084

Import Advanced Rogue 7.7 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Fri, 08 May 2015 15:24:40 -0400
parents
children f9ef86cf22b2
comparison
equal deleted inserted replaced
124:d10fc4a065ac 125:adfa37e67084
1 /*
2 * outside.c - functions for dealing with the "outside" level
3 *
4 * Advanced Rogue
5 * Copyright (C) 1984, 1985, 1986 Michael Morgan, Ken Dalka and AT&T
6 * All rights reserved.
7 *
8 * Based on "Rogue: Exploring the Dungeons of Doom"
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * All rights reserved.
11 *
12 * See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include "curses.h"
16 #include "rogue.h"
17
18 extern char rnd_terrain(), get_terrain();
19
20 /*
21 * init_terrain:
22 * Get the single "outside room" set up correctly
23 */
24
25 void
26 init_terrain()
27 {
28 register struct room *rp;
29
30 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
31 rp->r_flags = ISGONE; /* kill all rooms */
32 rp->r_fires = NULL; /* no fires */
33 }
34 rp = &rooms[0]; /* point to only room */
35 rp->r_flags = ISDARK; /* outside is always dark */
36 rp->r_pos.x = 0; /* room fills whole screen */
37 rp->r_pos.y = 1;
38 rp->r_max.x = cols;
39 rp->r_max.y = lines - 3;
40 }
41
42
43
44 void
45 do_terrain(basey, basex, deltay, deltax, fresh)
46 int basey, basex, deltay, deltax;
47 bool fresh;
48 {
49 register cury, curx; /* Current y and x positions */
50
51 /* Lay out the boundary */
52 for (cury=1; cury<lines-2; cury++) { /* Vertical "walls" */
53 mvaddch(cury, 0, '|');
54 mvaddch(cury, cols-1, '|');
55 }
56 for (curx=0; curx<cols; curx++) { /* Horizontal "walls" */
57 mvaddch(1, curx, '-');
58 mvaddch(lines-3, curx, '-');
59 }
60
61 /* If we are not continuing, let's start out with a line of terrain */
62 if (fresh) {
63 char ch; /* Next char to add */
64
65 /* Move to the starting point (should be (1, 0)) */
66 move(basey, basex);
67 curx = basex;
68
69 /* Start with some random terrain */
70 if (basex == 0) {
71 ch = rnd_terrain();
72 addch(ch);
73 }
74 else ch = CCHAR( mvinch(basey, basex) );
75
76 curx += deltax;
77
78 /* Fill in the rest of the line */
79 while (curx > 0 && curx < cols-1) {
80 /* Put in the next piece */
81 ch = get_terrain(ch, '\0', '\0', '\0');
82 mvaddch(basey, curx, ch);
83 curx += deltax;
84 }
85
86 basey++; /* Advance to next line */
87 }
88
89 /* Fill in the rest of the lines */
90 cury = basey;
91 while (cury > 1 && cury < lines - 3) {
92 curx = basex;
93 while (curx > 0 && curx < cols-1) {
94 register char left, top_left, top, top_right;
95 register int left_pos, top_pos;
96
97 /* Get the surrounding terrain */
98 left_pos = curx - deltax;
99 top_pos = cury - deltay;
100
101 left = CCHAR( mvinch(cury, left_pos) );
102 top_left = CCHAR( mvinch(top_pos, left_pos) );
103 top = CCHAR( mvinch(top_pos, curx) );
104 top_right = CCHAR( mvinch(top_pos, curx + deltax) );
105
106 /* Put the piece of terrain on the map */
107 mvaddch(cury, curx, get_terrain(left, top_left, top, top_right));
108
109 /* Get the next x coordinate */
110 curx += deltax;
111 }
112
113 /* Get the next y coordinate */
114 cury += deltay;
115 }
116 genmonsters(5, (bool) 0);
117 }
118
119
120 /*
121 * do_paths:
122 * draw at least a single path-way through the terrain
123 */
124
125
126 /*
127 * rnd_terrain:
128 * return a weighted, random type of outside terrain
129 */
130
131 char
132 rnd_terrain()
133 {
134 int chance = rnd(100);
135
136 /* Forest is most likely */
137 if (chance < 60) return(FOREST);
138
139 /* Next comes meadow */
140 if (chance < 90) return(FLOOR);
141
142 /* Then comes lakes */
143 if (chance < 97) return(POOL);
144
145 /* Finally, mountains */
146 return(WALL);
147 }
148
149
150 /*
151 * get_terrain:
152 * return a terrain weighted by what is surrounding
153 */
154
155 char
156 get_terrain(one, two, three, four)
157 char one, two, three, four;
158 {
159 register int i;
160 int forest = 0, mountain = 0, lake = 0, meadow = 0, total = 0;
161 char surrounding[4];
162
163 surrounding[0] = one;
164 surrounding[1] = two;
165 surrounding[2] = three;
166 surrounding[3] = four;
167
168 for (i=0; i<4; i++)
169 switch (surrounding[i]) {
170 case FOREST:
171 forest++;
172 total++;
173
174 when WALL:
175 mountain++;
176 total++;
177
178 when POOL:
179 lake++;
180 total++;
181
182 when FLOOR:
183 meadow++;
184 total++;
185 }
186
187 /* Should we continue mountain? */
188 if (rnd(total+1) < mountain) return(WALL);
189
190 /* Should we continue lakes? */
191 if (rnd(total+1) < lake) return(POOL);
192
193 /* Should we continue meadow? */
194 if (rnd(total+1) < meadow) return(FLOOR);
195
196 /* Should we continue forest? */
197 if (rnd(total+2) < forest) return(FOREST);
198
199 /* Return something random */
200 return(rnd_terrain());
201 }
202
203
204 /*
205 * lake_check:
206 * Determine if the player would drown
207 */
208
209 void
210 lake_check(place)
211 coord *place;
212 {
213 }