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