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