Annotation of 42BSD/games/trek/setup.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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