Annotation of researchv10no/games/trek/snova.c, revision 1.1.1.1

1.1       root        1: # include      "trek.h"
                      2: 
                      3: /**
                      4:  **    cause supernova to occur
                      5:  **/
                      6: 
                      7: snova(x, y)
                      8: int    x, y;
                      9: {
                     10:        int                     qx, qy;
                     11:        register int            ix, iy;
                     12:        int                     f;
                     13:        int                     dx, dy;
                     14:        int                     n;
                     15:        register QUAD           *q;
                     16: 
                     17:        f = 0;
                     18:        ix = x;
                     19:        if (ix < 0)
                     20:        {
                     21:                /* choose a quadrant */
                     22:                while (1)
                     23:                {
                     24:                        qx = ranf(NQUADS);
                     25:                        qy = ranf(NQUADS);
                     26:                        q = &Quad[qx][qy];
                     27:                        if (q->stars > 0)
                     28:                                break;
                     29:                }
                     30:                if (Quadx == qx && Quady == qy)
                     31:                {
                     32:                        /* select a particular star */
                     33:                        n = ranf(q->stars);
                     34:                        for (ix = 0; ix < NSECTS; ix++)
                     35:                        {
                     36:                                for (iy = 0; iy < NSECTS; iy++)
                     37:                                        if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
                     38:                                                if ((n =- 1) <= 0)
                     39:                                                        break;
                     40:                                if (n <= 0)
                     41:                                        break;
                     42:                        }
                     43:                        f = 1;
                     44:                }
                     45:        }
                     46:        else
                     47:        {
                     48:                /* current quadrant */
                     49:                iy = y;
                     50:                qx = Quadx;
                     51:                qy = Quady;
                     52:                q = &Quad[qx][qy];
                     53:                f = 1;
                     54:        }
                     55:        if (f)
                     56:        {
                     57:                /* supernova is in same quadrant as Enterprise */
                     58:                printf(" *** RED ALERT: supernova occuring at %d,%d", ix, iy);
                     59:                dx = ix - Sectx;
                     60:                dy = iy - Secty;
                     61:                if (dx * dx + dy * dy <= 2)
                     62:                {
                     63:                        printf(" *** Emergency override attempt");
                     64:                        sleep(4);
                     65:                        printf("\n");
                     66:                        lose(L_SNOVA);
                     67:                }
                     68:                printf("\n");
                     69:                q->scanned = 1000;
                     70:                kills(ix, iy, x >= 0 ? -1 : 1);
                     71:                Nkling = 0;
                     72:        }
                     73:        else
                     74:        {
                     75:                if (!Damage[SSRADIO])
                     76:                {
                     77:                        q->scanned = 1000;
                     78:                        printf("Uhura: Starfleet Command reports a supernova in quadrant %d,%d\n", qx, qy);
                     79:                }
                     80:                kills(qx, qy, 0);
                     81:        }
                     82: 
                     83:        /* clear out the supernova'ed quadrant */
                     84:        dx = q->qkling;
                     85:        dy = q->stars;
                     86:        Status.kling =- dx;
                     87:        if (x >= 0)
                     88:        {
                     89:                /* Enterprise caused supernova */
                     90:                Game.kills =+ dy;
                     91:                if (q->bases) {
                     92:                        killb(qx, qy); Game.killb++;
                     93:                }
                     94:                Game.gkillk =+ dx;
                     95:        }
                     96:        else
                     97:                if (q->bases) {
                     98:                        killb(qx, qy);
                     99:                }
                    100:        q->stars = -1;
                    101:        q->qkling = 0;
                    102:        if (Status.kling <= 0)
                    103:        {
                    104:                printf("Lucky devil, that supernova destroyed the last klingon\n");
                    105:                win();
                    106:        }
                    107:        return;
                    108: }

unix.superglobalmegacorp.com

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