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

unix.superglobalmegacorp.com

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