comparison xrogue/outside.c @ 133:e6179860cb76

Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 21 Apr 2015 08:55:20 -0400
parents
children f54901b9c39b
comparison
equal deleted inserted replaced
124:d10fc4a065ac 133:e6179860cb76
1 /*
2 outside.c - functions for dealing with the "outside" level
3
4 XRogue: Expeditions into the Dungeons of Doom
5 Copyright (C) 1991 Robert Pietkivitch
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
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 void
43 do_terrain(basey, basex, deltay, deltax, fresh)
44 int basey, basex, deltay, deltax;
45 bool fresh;
46 {
47 register int cury, curx; /* Current y and x positions */
48
49 /* Lay out the boundary */
50 for (cury=1; cury<lines-2; cury++) { /* Vertical "walls" */
51 mvaddch(cury, 0, VERTWALL);
52 mvaddch(cury, cols-1, VERTWALL);
53 }
54 for (curx=0; curx<cols; curx++) { /* Horizontal "walls" */
55 mvaddch(1, curx, HORZWALL);
56 mvaddch(lines-3, curx, HORZWALL);
57 }
58
59 /* If we are not continuing, let's start out with a line of terrain */
60 if (fresh) {
61 char ch; /* Next char to add */
62
63 /* Move to the starting point (should be (1, 0)) */
64 move(basey, basex);
65 curx = basex;
66
67 /* Start with some random terrain */
68 if (basex == 0) {
69 ch = rnd_terrain();
70 addch(ch);
71 }
72 else ch = mvinch(basey, basex);
73
74 curx += deltax;
75
76 /* Fill in the rest of the line */
77 while (curx > 0 && curx < cols-1) {
78 /* Put in the next piece */
79 ch = get_terrain(ch, '\0', '\0', '\0');
80 mvaddch(basey, curx, ch);
81 curx += deltax;
82 }
83
84 basey++; /* Advance to next line */
85 }
86
87 /* Fill in the rest of the lines */
88 cury = basey;
89 while (cury > 1 && cury < lines - 3) {
90 curx = basex;
91 while (curx > 0 && curx < cols-1) {
92 register char left, top_left, top, top_right;
93 register int left_pos, top_pos;
94
95 /* Get the surrounding terrain */
96 left_pos = curx - deltax;
97 top_pos = cury - deltay;
98
99 left = mvinch(cury, left_pos);
100 top_left = mvinch(top_pos, left_pos);
101 top = mvinch(top_pos, curx);
102 top_right = mvinch(top_pos, curx + deltax);
103
104 /* Put the piece of terrain on the map */
105 mvaddch(cury, curx, get_terrain(left, top_left, top, top_right));
106
107 /* Get the next x coordinate */
108 curx += deltax;
109 }
110
111 /* Get the next y coordinate */
112 cury += deltay;
113 }
114 /* The deeper we go.. */
115 if (level > 40) genmonsters(20, (bool) 0);
116 else if (level > 10) genmonsters(15, (bool) 0);
117 else genmonsters(10, (bool) 0);
118
119 /* sometimes they're real angry */
120 if (rnd(100) < 65) {
121 /* protect good guys */
122 if (player.t_ctype == C_PALADIN ||
123 player.t_ctype == C_RANGER || player.t_ctype == C_MONK) {
124 aggravate(TRUE, FALSE);
125 }
126 else {
127 aggravate(TRUE, TRUE);
128 }
129 }
130 }
131
132 /*
133 * do_paths:
134 * draw at least a single path-way through the terrain
135 */
136
137 /*
138 * rnd_terrain:
139 * return a weighted, random type of outside terrain
140 */
141
142 char
143 rnd_terrain()
144 {
145 int chance = rnd(100);
146
147 /* Meadow is most likely */
148 if (chance < 40) return(FLOOR);
149
150 /* Next comes forest */
151 if (chance < 65) return(FOREST);
152
153 /* Then comes lakes */
154 if (chance < 85) return(POOL);
155
156 /* Finally, mountains */
157 return(WALL);
158 }
159
160
161 /*
162 * get_terrain:
163 * return a terrain weighted by what is surrounding
164 */
165
166 char
167 get_terrain(one, two, three, four)
168 char one, two, three, four;
169 {
170 register int i;
171 int forest = 0, mountain = 0, lake = 0, meadow = 0, total = 0;
172 char surrounding[4];
173
174 surrounding[0] = one;
175 surrounding[1] = two;
176 surrounding[2] = three;
177 surrounding[3] = four;
178
179 for (i=0; i<4; i++)
180 switch (surrounding[i]) {
181 case FOREST:
182 forest++;
183 total++;
184
185 when WALL:
186 mountain++;
187 total++;
188
189 when POOL:
190 lake++;
191 total++;
192
193 when FLOOR:
194 meadow++;
195 total++;
196 }
197
198 /* Should we continue mountain? */
199 if (rnd(total+1) < mountain) return(WALL);
200
201 /* Should we continue lakes? */
202 if (rnd(total+1) < lake) return(POOL);
203
204 /* Should we continue meadow? */
205 if (rnd(total+1) < meadow) return(FLOOR);
206
207 /* Should we continue forest? */
208 if (rnd(total+2) < forest) return(FOREST);
209
210 /* Return something random */
211 return(rnd_terrain());
212 }
213
214 /*
215 * lake_check:
216 * Determine if the player would drown
217 */
218
219 /*UNUSED*/
220 /* void
221 * lake_check(place)
222 * register coord *place;
223 * {
224 * }
225 */
226