Annotation of 43BSDReno/games/trek/initquad.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted provided
                      6:  * that: (1) source distributions retain this entire copyright notice and
                      7:  * comment, and (2) distributions including binaries display the following
                      8:  * acknowledgement:  ``This product includes software developed by the
                      9:  * University of California, Berkeley and its contributors'' in the
                     10:  * documentation or other materials provided with the distribution and in
                     11:  * all advertising materials mentioning features or use of this software.
                     12:  * Neither the name of the University nor the names of its contributors may
                     13:  * be used to endorse or promote products derived from this software without
                     14:  * specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)initquad.c 5.4 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: # include      "trek.h"
                     25: 
                     26: /*
                     27: **  Paramize Quadrant Upon Entering
                     28: **
                     29: **     A quadrant is initialized from the information held in the
                     30: **     Quad matrix.  Basically, everything is just initialized
                     31: **     randomly, except for the starship, which goes into a fixed
                     32: **     sector.
                     33: **
                     34: **     If there are Klingons in the quadrant, the captain is informed
                     35: **     that the condition is RED, and he is given a chance to put
                     36: **     his shields up if the computer is working.
                     37: **
                     38: **     The flag `f' is set to disable the check for condition red.
                     39: **     This mode is used in situations where you know you are going
                     40: **     to be docked, i.e., abandon() and help().
                     41: */
                     42: 
                     43: initquad(f)
                     44: int    f;
                     45: {
                     46:        register int            i, j;
                     47:        int                     rx, ry;
                     48:        int                     nbases, nstars;
                     49:        register struct quad    *q;
                     50:        int                     nholes;
                     51: 
                     52:        q = &Quad[Ship.quadx][Ship.quady];
                     53: 
                     54:        /* ignored supernova'ed quadrants (this is checked again later anyway */
                     55:        if (q->stars < 0)
                     56:                return;
                     57:        Etc.nkling = q->klings;
                     58:        nbases = q->bases;
                     59:        nstars = q->stars;
                     60:        nholes = q->holes;
                     61: 
                     62:        /* have we blundered into a battle zone w/ shields down? */
                     63:        if (Etc.nkling > 0 && !f)
                     64:        {
                     65:                printf("Condition RED\n");
                     66:                Ship.cond = RED;
                     67:                if (!damaged(COMPUTER))
                     68:                        shield(1);
                     69:        }
                     70: 
                     71:        /* clear out the quadrant */
                     72:        for (i = 0; i < NSECTS; i++)
                     73:                for (j = 0; j < NSECTS; j++)
                     74:                        Sect[i][j] = EMPTY;
                     75: 
                     76:        /* initialize Enterprise */
                     77:        Sect[Ship.sectx][Ship.secty] = Ship.ship;
                     78: 
                     79:        /* initialize Klingons */
                     80:        for (i = 0; i < Etc.nkling; i++)
                     81:        {
                     82:                sector(&rx, &ry);
                     83:                Sect[rx][ry] = KLINGON;
                     84:                Etc.klingon[i].x = rx;
                     85:                Etc.klingon[i].y = ry;
                     86:                Etc.klingon[i].power = Param.klingpwr;
                     87:                Etc.klingon[i].srndreq = 0;
                     88:        }
                     89:        compkldist(1);
                     90: 
                     91:        /* initialize star base */
                     92:        if (nbases > 0)
                     93:        {
                     94:                sector(&rx, &ry);
                     95:                Sect[rx][ry] = BASE;
                     96:                Etc.starbase.x = rx;
                     97:                Etc.starbase.y = ry;
                     98:        }
                     99: 
                    100:        /* initialize inhabited starsystem */
                    101:        if (q->qsystemname != 0)
                    102:        {
                    103:                sector(&rx, &ry);
                    104:                Sect[rx][ry] = INHABIT;
                    105:                nstars -= 1;
                    106:        }
                    107: 
                    108:        /* initialize black holes */
                    109:        for (i = 0; i < nholes; i++)
                    110:        {
                    111:                sector(&rx, &ry);
                    112:                Sect[rx][ry] = HOLE;
                    113:        }
                    114: 
                    115:        /* initialize stars */
                    116:        for (i = 0; i < nstars; i++)
                    117:        {
                    118:                sector(&rx, &ry);
                    119:                Sect[rx][ry] = STAR;
                    120:        }
                    121:        Move.newquad = 1;
                    122: }
                    123: 
                    124: 
                    125: sector(x, y)
                    126: int    *x, *y;
                    127: {
                    128:        register int            i, j;
                    129: 
                    130:        do
                    131:        {
                    132:                i = ranf(NSECTS);
                    133:                j = ranf(NSECTS);
                    134:        } while (Sect[i][j] != EMPTY);
                    135:        *x = i;
                    136:        *y = j;
                    137:        return;
                    138: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.