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