[BACK]Return to outside.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / xrogue

Annotation of early-roguelike/xrogue/outside.c, Revision 1.1.1.1

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

CVSweb