Annotation of 43BSD/games/trek/snova.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 Regents of the University of California.
        !             3:  * All rights reserved.  The Berkeley software License Agreement
        !             4:  * specifies the terms and conditions for redistribution.
        !             5:  */
        !             6: 
        !             7: #ifndef lint
        !             8: static char sccsid[] = "@(#)snova.c    5.1 (Berkeley) 5/30/85";
        !             9: #endif not lint
        !            10: 
        !            11: # include      "trek.h"
        !            12: 
        !            13: /*
        !            14: **  CAUSE SUPERNOVA TO OCCUR
        !            15: **
        !            16: **     A supernova occurs.  If 'ix' < 0, a random quadrant is chosen;
        !            17: **     otherwise, the current quadrant is taken, and (ix, iy) give
        !            18: **     the sector quadrants of the star which is blowing up.
        !            19: **
        !            20: **     If the supernova turns out to be in the quadrant you are in,
        !            21: **     you go into "emergency override mode", which tries to get you
        !            22: **     out of the quadrant as fast as possible.  However, if you
        !            23: **     don't have enough fuel, or if you by chance run into something,
        !            24: **     or some such thing, you blow up anyway.  Oh yeh, if you are
        !            25: **     within two sectors of the star, there is nothing that can
        !            26: **     be done for you.
        !            27: **
        !            28: **     When a star has gone supernova, the quadrant becomes uninhab-
        !            29: **     itable for the rest of eternity, i.e., the game.  If you ever
        !            30: **     try stopping in such a quadrant, you will go into emergency
        !            31: **     override mode.
        !            32: */
        !            33: 
        !            34: snova(x, y)
        !            35: int    x, y;
        !            36: {
        !            37:        int                     qx, qy;
        !            38:        register int            ix, iy;
        !            39:        int                     f;
        !            40:        int                     dx, dy;
        !            41:        int                     n;
        !            42:        register struct quad    *q;
        !            43: 
        !            44:        f = 0;
        !            45:        ix = x;
        !            46:        if (ix < 0)
        !            47:        {
        !            48:                /* choose a quadrant */
        !            49:                while (1)
        !            50:                {
        !            51:                        qx = ranf(NQUADS);
        !            52:                        qy = ranf(NQUADS);
        !            53:                        q = &Quad[qx][qy];
        !            54:                        if (q->stars > 0)
        !            55:                                break;
        !            56:                }
        !            57:                if (Ship.quadx == qx && Ship.quady == qy)
        !            58:                {
        !            59:                        /* select a particular star */
        !            60:                        n = ranf(q->stars);
        !            61:                        for (ix = 0; ix < NSECTS; ix++)
        !            62:                        {
        !            63:                                for (iy = 0; iy < NSECTS; iy++)
        !            64:                                        if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
        !            65:                                                if ((n -= 1) <= 0)
        !            66:                                                        break;
        !            67:                                if (n <= 0)
        !            68:                                        break;
        !            69:                        }
        !            70:                        f = 1;
        !            71:                }
        !            72:        }
        !            73:        else
        !            74:        {
        !            75:                /* current quadrant */
        !            76:                iy = y;
        !            77:                qx = Ship.quadx;
        !            78:                qy = Ship.quady;
        !            79:                q = &Quad[qx][qy];
        !            80:                f = 1;
        !            81:        }
        !            82:        if (f)
        !            83:        {
        !            84:                /* supernova is in same quadrant as Enterprise */
        !            85:                printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
        !            86:                dx = ix - Ship.sectx;
        !            87:                dy = iy - Ship.secty;
        !            88:                if (dx * dx + dy * dy <= 2)
        !            89:                {
        !            90:                        printf("***  Emergency override attem");
        !            91:                        sleep(1);
        !            92:                        printf("\n");
        !            93:                        lose(L_SNOVA);
        !            94:                }
        !            95:                q->scanned = 1000;
        !            96:        }
        !            97:        else
        !            98:        {
        !            99:                if (!damaged(SSRADIO))
        !           100:                {
        !           101:                        q->scanned = 1000;
        !           102:                        printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
        !           103:                        printf("  in quadrant %d,%d.  Caution is advised\n", qx, qy);
        !           104:                }
        !           105:        }
        !           106: 
        !           107:        /* clear out the supernova'ed quadrant */
        !           108:        dx = q->klings;
        !           109:        dy = q->stars;
        !           110:        Now.klings -= dx;
        !           111:        if (x >= 0)
        !           112:        {
        !           113:                /* Enterprise caused supernova */
        !           114:                Game.kills += dy;
        !           115:                if (q->bases)
        !           116:                        killb(qx, qy, -1);
        !           117:                Game.killk += dx;
        !           118:        }
        !           119:        else
        !           120:                if (q->bases)
        !           121:                        killb(qx, qy, 0);
        !           122:        killd(qx, qy, (x >= 0));
        !           123:        q->stars = -1;
        !           124:        q->klings = 0;
        !           125:        if (Now.klings <= 0)
        !           126:        {
        !           127:                printf("Lucky devil, that supernova destroyed the last klingon\n");
        !           128:                win();
        !           129:        }
        !           130:        return;
        !           131: }

unix.superglobalmegacorp.com

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