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