1 /* $NetBSD: setup.c,v 1.4 1995/04/24 12:26:06 cgd Exp $ */ 2 3 /* 4 * Copyright (c) 1980, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93"; 39 #else 40 static char rcsid[] = "$NetBSD: setup.c,v 1.4 1995/04/24 12:26:06 cgd Exp $"; 41 #endif 42 #endif /* not lint */ 43 44 # include "trek.h" 45 # include "getpar.h" 46 47 /* 48 ** INITIALIZE THE GAME 49 ** 50 ** The length, skill, and password are read, and the game 51 ** is initialized. It is far too difficult to describe all 52 ** that goes on in here, but it is all straight-line code; 53 ** give it a look. 54 ** 55 ** Game restart and tournament games are handled here. 56 */ 57 58 struct cvntab Lentab[] = 59 { 60 "s", "hort", (int (*)())1, 0, 61 "m", "edium", (int (*)())2, 0, 62 "l", "ong", (int (*)())4, 0, 63 "restart", "", 0, 0, 64 0 65 }; 66 67 struct cvntab Skitab[] = 68 { 69 "n", "ovice", (int (*)())1, 0, 70 "f", "air", (int (*)())2, 0, 71 "g", "ood", (int (*)())3, 0, 72 "e", "xpert", (int (*)())4, 0, 73 "c", "ommodore", (int (*)())5, 0, 74 "i", "mpossible", (int (*)())6, 0, 75 0 76 }; 77 78 setup() 79 { 80 struct cvntab *r; 81 register int i, j; 82 double f; 83 int d; 84 int fd; 85 int klump; 86 int ix, iy; 87 register struct quad *q; 88 struct event *e; 89 90 while (1) 91 { 92 r = getcodpar("What length game", Lentab); 93 Game.length = (long) r->value; 94 if (Game.length == 0) 95 { 96 if (restartgame()) 97 continue; 98 return; 99 } 100 break; 101 } 102 r = getcodpar("What skill game", Skitab); 103 Game.skill = (long) r->value; 104 Game.tourn = 0; 105 getstrpar("Enter a password", Game.passwd, 14, 0); 106 if (sequal(Game.passwd, "tournament")) 107 { 108 getstrpar("Enter tournament code", Game.passwd, 14, 0); 109 Game.tourn = 1; 110 d = 0; 111 for (i = 0; Game.passwd[i]; i++) 112 d += Game.passwd[i] << i; 113 srand(d); 114 } 115 Param.bases = Now.bases = ranf(6 - Game.skill) + 2; 116 if (Game.skill == 6) 117 Param.bases = Now.bases = 1; 118 Param.time = Now.time = 6.0 * Game.length + 2.0; 119 i = Game.skill; 120 j = Game.length; 121 Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75); 122 if (Param.klings < i * j * 5) 123 Param.klings = Now.klings = i * j * 5; 124 if (Param.klings <= i) /* numerical overflow problems */ 125 Param.klings = Now.klings = 127; 126 Param.energy = Ship.energy = 5000; 127 Param.torped = Ship.torped = 10; 128 Ship.ship = ENTERPRISE; 129 Ship.shipname = "Enterprise"; 130 Param.shield = Ship.shield = 1500; 131 Param.resource = Now.resource = Param.klings * Param.time; 132 Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0; 133 Param.crew = Ship.crew = 387; 134 Param.brigfree = Ship.brigfree = 400; 135 Ship.shldup = 1; 136 Ship.cond = GREEN; 137 Ship.warp = 5.0; 138 Ship.warp2 = 25.0; 139 Ship.warp3 = 125.0; 140 Ship.sinsbad = 0; 141 Ship.cloaked = 0; 142 Param.date = Now.date = (ranf(20) + 20) * 100; 143 f = Game.skill; 144 f = log(f + 0.5); 145 for (i = 0; i < NDEV; i++) 146 if (Device[i].name[0] == '*') 147 Param.damfac[i] = 0; 148 else 149 Param.damfac[i] = f; 150 /* these probabilities must sum to 1000 */ 151 Param.damprob[WARP] = 70; /* warp drive 7.0% */ 152 Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */ 153 Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */ 154 Param.damprob[PHASER] = 125; /* phasers 12.5% */ 155 Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */ 156 Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */ 157 Param.damprob[SHIELD] = 150; /* shield control 15.0% */ 158 Param.damprob[COMPUTER] = 20; /* computer 2.0% */ 159 Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */ 160 Param.damprob[LIFESUP] = 30; /* life support 3.0% */ 161 Param.damprob[SINS] = 20; /* navigation system 2.0% */ 162 Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */ 163 Param.damprob[XPORTER] = 80; /* transporter 8.0% */ 164 /* check to see that I didn't blow it */ 165 for (i = j = 0; i < NDEV; i++) 166 j += Param.damprob[i]; 167 if (j != 1000) 168 syserr("Device probabilities sum to %d", j); 169 Param.dockfac = 0.5; 170 Param.regenfac = (5 - Game.skill) * 0.05; 171 if (Param.regenfac < 0.0) 172 Param.regenfac = 0.0; 173 Param.warptime = 10; 174 Param.stopengy = 50; 175 Param.shupengy = 40; 176 i = Game.skill; 177 Param.klingpwr = 100 + 150 * i; 178 if (i >= 6) 179 Param.klingpwr += 150; 180 Param.phasfac = 0.8; 181 Param.hitfac = 0.5; 182 Param.klingcrew = 200; 183 Param.srndrprob = 0.0035; 184 Param.moveprob[KM_OB] = 45; 185 Param.movefac[KM_OB] = .09; 186 Param.moveprob[KM_OA] = 40; 187 Param.movefac[KM_OA] = -0.05; 188 Param.moveprob[KM_EB] = 40; 189 Param.movefac[KM_EB] = 0.075; 190 Param.moveprob[KM_EA] = 25 + 5 * Game.skill; 191 Param.movefac[KM_EA] = -0.06 * Game.skill; 192 Param.moveprob[KM_LB] = 0; 193 Param.movefac[KM_LB] = 0.0; 194 Param.moveprob[KM_LA] = 10 + 10 * Game.skill; 195 Param.movefac[KM_LA] = 0.25; 196 Param.eventdly[E_SNOVA] = 0.5; 197 Param.eventdly[E_LRTB] = 25.0; 198 Param.eventdly[E_KATSB] = 1.0; 199 Param.eventdly[E_KDESB] = 3.0; 200 Param.eventdly[E_ISSUE] = 1.0; 201 Param.eventdly[E_SNAP] = 0.5; 202 Param.eventdly[E_ENSLV] = 0.5; 203 Param.eventdly[E_REPRO] = 2.0; 204 Param.navigcrud[0] = 1.50; 205 Param.navigcrud[1] = 0.75; 206 Param.cloakenergy = 1000; 207 Param.energylow = 1000; 208 for (i = 0; i < MAXEVENTS; i++) 209 { 210 e = &Event[i]; 211 e->date = 1e50; 212 e->evcode = 0; 213 } 214 xsched(E_SNOVA, 1, 0, 0, 0); 215 xsched(E_LRTB, Param.klings, 0, 0, 0); 216 xsched(E_KATSB, 1, 0, 0, 0); 217 xsched(E_ISSUE, 1, 0, 0, 0); 218 xsched(E_SNAP, 1, 0, 0, 0); 219 Ship.sectx = ranf(NSECTS); 220 Ship.secty = ranf(NSECTS); 221 Game.killk = Game.kills = Game.killb = 0; 222 Game.deaths = Game.negenbar = 0; 223 Game.captives = 0; 224 Game.killinhab = 0; 225 Game.helps = 0; 226 Game.killed = 0; 227 Game.snap = 0; 228 Move.endgame = 0; 229 230 /* setup stars */ 231 for (i = 0; i < NQUADS; i++) 232 for (j = 0; j < NQUADS; j++) 233 { 234 q = &Quad[i][j]; 235 q->klings = q->bases = 0; 236 q->scanned = -1; 237 q->stars = ranf(9) + 1; 238 q->holes = ranf(3) - q->stars / 5; 239 q->qsystemname = 0; 240 } 241 242 /* select inhabited starsystems */ 243 for (d = 1; d < NINHAB; d++) 244 { 245 do 246 { 247 i = ranf(NQUADS); 248 j = ranf(NQUADS); 249 q = &Quad[i][j]; 250 } while (q->qsystemname); 251 q->qsystemname = d; 252 } 253 254 /* position starbases */ 255 for (i = 0; i < Param.bases; i++) 256 { 257 while (1) 258 { 259 ix = ranf(NQUADS); 260 iy = ranf(NQUADS); 261 q = &Quad[ix][iy]; 262 if (q->bases > 0) 263 continue; 264 break; 265 } 266 q->bases = 1; 267 Now.base[i].x = ix; 268 Now.base[i].y = iy; 269 q->scanned = 1001; 270 /* start the Enterprise near starbase */ 271 if (i == 0) 272 { 273 Ship.quadx = ix; 274 Ship.quady = iy; 275 } 276 } 277 278 /* position klingons */ 279 for (i = Param.klings; i > 0; ) 280 { 281 klump = ranf(4) + 1; 282 if (klump > i) 283 klump = i; 284 while (1) 285 { 286 ix = ranf(NQUADS); 287 iy = ranf(NQUADS); 288 q = &Quad[ix][iy]; 289 if (q->klings + klump > MAXKLQUAD) 290 continue; 291 q->klings += klump; 292 i -= klump; 293 break; 294 } 295 } 296 297 /* initialize this quadrant */ 298 printf("%d Klingons\n%d starbase", Param.klings, Param.bases); 299 if (Param.bases > 1) 300 printf("s"); 301 printf(" at %d,%d", Now.base[0].x, Now.base[0].y); 302 for (i = 1; i < Param.bases; i++) 303 printf(", %d,%d", Now.base[i].x, Now.base[i].y); 304 printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr); 305 Move.free = 0; 306 initquad(0); 307 srscan(1); 308 attack(0); 309 } 310