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