Annotation of 43BSDReno/games/trek/setup.c, revision 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[] = "@(#)setup.c    5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: # include      "trek.h"
        !            25: # include      "getpar.h"
        !            26: 
        !            27: /*
        !            28: **  INITIALIZE THE GAME
        !            29: **
        !            30: **     The length, skill, and password are read, and the game
        !            31: **     is initialized.  It is far too difficult to describe all
        !            32: **     that goes on in here, but it is all straight-line code;
        !            33: **     give it a look.
        !            34: **
        !            35: **     Game restart and tournament games are handled here.
        !            36: */
        !            37: 
        !            38: struct cvntab  Lentab[] =
        !            39: {
        !            40:        "s",            "hort",                 (int (*)())1,           0,
        !            41:        "m",            "edium",                (int (*)())2,           0,
        !            42:        "l",            "ong",                  (int (*)())4,           0,
        !            43:        "restart",      "",                     0,              0,
        !            44:        0
        !            45: };
        !            46: 
        !            47: struct cvntab  Skitab[] =
        !            48: {
        !            49:        "n",            "ovice",                (int (*)())1,           0,
        !            50:        "f",            "air",                  (int (*)())2,           0,
        !            51:        "g",            "ood",                  (int (*)())3,           0,
        !            52:        "e",            "xpert",                (int (*)())4,           0,
        !            53:        "c",            "ommodore",             (int (*)())5,           0,
        !            54:        "i",            "mpossible",            (int (*)())6,           0,
        !            55:        0
        !            56: };
        !            57: 
        !            58: setup()
        !            59: {
        !            60:        struct cvntab           *r;
        !            61:        register int            i, j;
        !            62:        double                  f;
        !            63:        int                     d;
        !            64:        int                     fd;
        !            65:        int                     klump;
        !            66:        int                     ix, iy;
        !            67:        register struct quad    *q;
        !            68:        struct event            *e;
        !            69: 
        !            70:        while (1)
        !            71:        {
        !            72:                r = getcodpar("What length game", Lentab);
        !            73:                Game.length = (int) r->value;
        !            74:                if (Game.length == 0)
        !            75:                {
        !            76:                        if (restartgame())
        !            77:                                continue;
        !            78:                        return;
        !            79:                }
        !            80:                break;
        !            81:        }
        !            82:        r = getcodpar("What skill game", Skitab);
        !            83:        Game.skill = (int) r->value;
        !            84:        Game.tourn = 0;
        !            85:        getstrpar("Enter a password", Game.passwd, 14, 0);
        !            86:        if (sequal(Game.passwd, "tournament"))
        !            87:        {
        !            88:                getstrpar("Enter tournament code", Game.passwd, 14, 0);
        !            89:                Game.tourn = 1;
        !            90:                d = 0;
        !            91:                for (i = 0; Game.passwd[i]; i++)
        !            92:                        d += Game.passwd[i] << i;
        !            93:                srand(d);
        !            94:        }
        !            95:        Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
        !            96:        if (Game.skill == 6)
        !            97:                Param.bases = Now.bases = 1;
        !            98:        Param.time = Now.time = 6.0 * Game.length + 2.0;
        !            99:        i = Game.skill;
        !           100:        j = Game.length;
        !           101:        Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
        !           102:        if (Param.klings < i * j * 5)
        !           103:                Param.klings = Now.klings = i * j * 5;
        !           104:        if (Param.klings <= i)          /* numerical overflow problems */
        !           105:                Param.klings = Now.klings = 127;
        !           106:        Param.energy = Ship.energy = 5000;
        !           107:        Param.torped = Ship.torped = 10;
        !           108:        Ship.ship = ENTERPRISE;
        !           109:        Ship.shipname = "Enterprise";
        !           110:        Param.shield = Ship.shield = 1500;
        !           111:        Param.resource = Now.resource = Param.klings * Param.time;
        !           112:        Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
        !           113:        Param.crew = Ship.crew = 387;
        !           114:        Param.brigfree = Ship.brigfree = 400;
        !           115:        Ship.shldup = 1;
        !           116:        Ship.cond = GREEN;
        !           117:        Ship.warp = 5.0;
        !           118:        Ship.warp2 = 25.0;
        !           119:        Ship.warp3 = 125.0;
        !           120:        Ship.sinsbad = 0;
        !           121:        Ship.cloaked = 0;
        !           122:        Param.date = Now.date = (ranf(20) + 20) * 100;
        !           123:        f = Game.skill;
        !           124:        f = log(f + 0.5);
        !           125:        for (i = 0; i < NDEV; i++)
        !           126:                if (Device[i].name[0] == '*')
        !           127:                        Param.damfac[i] = 0;
        !           128:                else
        !           129:                        Param.damfac[i] = f;
        !           130:        /* these probabilities must sum to 1000 */
        !           131:        Param.damprob[WARP] = 70;       /* warp drive            7.0% */
        !           132:        Param.damprob[SRSCAN] = 110;    /* short range scanners 11.0% */
        !           133:        Param.damprob[LRSCAN] = 110;    /* long range scanners  11.0% */
        !           134:        Param.damprob[PHASER] = 125;    /* phasers              12.5% */
        !           135:        Param.damprob[TORPED] = 125;    /* photon torpedoes     12.5% */
        !           136:        Param.damprob[IMPULSE] = 75;    /* impulse engines       7.5% */
        !           137:        Param.damprob[SHIELD] = 150;    /* shield control       15.0% */
        !           138:        Param.damprob[COMPUTER] = 20;   /* computer              2.0% */
        !           139:        Param.damprob[SSRADIO] = 35;    /* subspace radio        3.5% */
        !           140:        Param.damprob[LIFESUP] = 30;    /* life support          3.0% */
        !           141:        Param.damprob[SINS] = 20;       /* navigation system     2.0% */
        !           142:        Param.damprob[CLOAK] = 50;      /* cloaking device       5.0% */
        !           143:        Param.damprob[XPORTER] = 80;    /* transporter           8.0% */
        !           144:        /* check to see that I didn't blow it */
        !           145:        for (i = j = 0; i < NDEV; i++)
        !           146:                j += Param.damprob[i];
        !           147:        if (j != 1000)
        !           148:                syserr("Device probabilities sum to %d", j);
        !           149:        Param.dockfac = 0.5;
        !           150:        Param.regenfac = (5 - Game.skill) * 0.05;
        !           151:        if (Param.regenfac < 0.0)
        !           152:                Param.regenfac = 0.0;
        !           153:        Param.warptime = 10;
        !           154:        Param.stopengy = 50;
        !           155:        Param.shupengy = 40;
        !           156:        i = Game.skill;
        !           157:        Param.klingpwr = 100 + 150 * i;
        !           158:        if (i >= 6)
        !           159:                Param.klingpwr += 150;
        !           160:        Param.phasfac = 0.8;
        !           161:        Param.hitfac = 0.5;
        !           162:        Param.klingcrew = 200;
        !           163:        Param.srndrprob = 0.0035;
        !           164:        Param.moveprob[KM_OB] = 45;
        !           165:        Param.movefac[KM_OB] = .09;
        !           166:        Param.moveprob[KM_OA] = 40;
        !           167:        Param.movefac[KM_OA] = -0.05;
        !           168:        Param.moveprob[KM_EB] = 40;
        !           169:        Param.movefac[KM_EB] = 0.075;
        !           170:        Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
        !           171:        Param.movefac[KM_EA] = -0.06 * Game.skill;
        !           172:        Param.moveprob[KM_LB] = 0;
        !           173:        Param.movefac[KM_LB] = 0.0;
        !           174:        Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
        !           175:        Param.movefac[KM_LA] = 0.25;
        !           176:        Param.eventdly[E_SNOVA] = 0.5;
        !           177:        Param.eventdly[E_LRTB] = 25.0;
        !           178:        Param.eventdly[E_KATSB] = 1.0;
        !           179:        Param.eventdly[E_KDESB] = 3.0;
        !           180:        Param.eventdly[E_ISSUE] = 1.0;
        !           181:        Param.eventdly[E_SNAP] = 0.5;
        !           182:        Param.eventdly[E_ENSLV] = 0.5;
        !           183:        Param.eventdly[E_REPRO] = 2.0;
        !           184:        Param.navigcrud[0] = 1.50;
        !           185:        Param.navigcrud[1] = 0.75;
        !           186:        Param.cloakenergy = 1000;
        !           187:        Param.energylow = 1000;
        !           188:        for (i = 0; i < MAXEVENTS; i++)
        !           189:        {
        !           190:                e = &Event[i];
        !           191:                e->date = 1e50;
        !           192:                e->evcode = 0;
        !           193:        }
        !           194:        xsched(E_SNOVA, 1, 0, 0, 0);
        !           195:        xsched(E_LRTB, Param.klings, 0, 0, 0);
        !           196:        xsched(E_KATSB, 1, 0, 0, 0);
        !           197:        xsched(E_ISSUE, 1, 0, 0, 0);
        !           198:        xsched(E_SNAP, 1, 0, 0, 0);
        !           199:        Ship.sectx = ranf(NSECTS);
        !           200:        Ship.secty = ranf(NSECTS);
        !           201:        Game.killk = Game.kills = Game.killb = 0;
        !           202:        Game.deaths = Game.negenbar = 0;
        !           203:        Game.captives = 0;
        !           204:        Game.killinhab = 0;
        !           205:        Game.helps = 0;
        !           206:        Game.killed = 0;
        !           207:        Game.snap = 0;
        !           208:        Move.endgame = 0;
        !           209: 
        !           210:        /* setup stars */
        !           211:        for (i = 0; i < NQUADS; i++)
        !           212:                for (j = 0; j < NQUADS; j++)
        !           213:                {
        !           214:                        q = &Quad[i][j];
        !           215:                        q->klings = q->bases = 0;
        !           216:                        q->scanned = -1;
        !           217:                        q->stars = ranf(9) + 1;
        !           218:                        q->holes = ranf(3) - q->stars / 5;
        !           219:                        q->qsystemname = 0;
        !           220:                }
        !           221: 
        !           222:        /* select inhabited starsystems */
        !           223:        for (d = 1; d < NINHAB; d++)
        !           224:        {
        !           225:                do
        !           226:                {
        !           227:                        i = ranf(NQUADS);
        !           228:                        j = ranf(NQUADS);
        !           229:                        q = &Quad[i][j];
        !           230:                } while (q->qsystemname);
        !           231:                q->qsystemname = d;
        !           232:        }
        !           233: 
        !           234:        /* position starbases */
        !           235:        for (i = 0; i < Param.bases; i++)
        !           236:        {
        !           237:                while (1)
        !           238:                {
        !           239:                        ix = ranf(NQUADS);
        !           240:                        iy = ranf(NQUADS);
        !           241:                        q = &Quad[ix][iy];
        !           242:                        if (q->bases > 0)
        !           243:                                continue;
        !           244:                        break;
        !           245:                }
        !           246:                q->bases = 1;
        !           247:                Now.base[i].x = ix;
        !           248:                Now.base[i].y = iy;
        !           249:                q->scanned = 1001;
        !           250:                /* start the Enterprise near starbase */
        !           251:                if (i == 0)
        !           252:                {
        !           253:                        Ship.quadx = ix;
        !           254:                        Ship.quady = iy;
        !           255:                }
        !           256:        }
        !           257: 
        !           258:        /* position klingons */
        !           259:        for (i = Param.klings; i > 0; )
        !           260:        {
        !           261:                klump = ranf(4) + 1;
        !           262:                if (klump > i)
        !           263:                        klump = i;
        !           264:                while (1)
        !           265:                {
        !           266:                        ix = ranf(NQUADS);
        !           267:                        iy = ranf(NQUADS);
        !           268:                        q = &Quad[ix][iy];
        !           269:                        if (q->klings + klump > MAXKLQUAD)
        !           270:                                continue;
        !           271:                        q->klings += klump;
        !           272:                        i -= klump;
        !           273:                        break;
        !           274:                }
        !           275:        }
        !           276: 
        !           277:        /* initialize this quadrant */
        !           278:        printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
        !           279:        if (Param.bases > 1)
        !           280:                printf("s");
        !           281:        printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
        !           282:        for (i = 1; i < Param.bases; i++)
        !           283:                printf(", %d,%d", Now.base[i].x, Now.base[i].y);
        !           284:        printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);
        !           285:        Move.free = 0;
        !           286:        initquad(0);
        !           287:        srscan(1);
        !           288:        attack(0);
        !           289: }

unix.superglobalmegacorp.com

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