1 /* @(#)setup.c 8.1 (Berkeley) 5/31/93 */
2 /* $NetBSD: setup.c,v 1.13 2009/05/25 00:37:27 dholland Exp $ */
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 ** INITIALIZE THE GAME
46 ** The length, skill, and password are read, and the game
47 ** is initialized. It is far too difficult to describe all
48 ** that goes on in here, but it is all straight-line code;
51 ** Game restart and tournament games are handled here.
54 const struct cvntab Lentab
[] = {
55 { "s", "hort", (cmdfun
)1, 0 },
56 { "m", "edium", (cmdfun
)2, 0 },
57 { "l", "ong", (cmdfun
)4, 0 },
58 { "restart", "", (cmdfun
)0, 0 },
59 { NULL
, NULL
, NULL
, 0 }
62 const struct cvntab Skitab
[] = {
63 { "n", "ovice", (cmdfun
)1, 0 },
64 { "f", "air", (cmdfun
)2, 0 },
65 { "g", "ood", (cmdfun
)3, 0 },
66 { "e", "xpert", (cmdfun
)4, 0 },
67 { "c", "ommodore", (cmdfun
)5, 0 },
68 { "i", "mpossible", (cmdfun
)6, 0 },
69 { NULL
, NULL
, NULL
, 0 }
75 const struct cvntab
*r
;
85 r
= getcodpar("What length game", Lentab
);
86 Game
.length
= (long) r
->value
;
87 if (Game
.length
== 0) {
94 r
= getcodpar("What skill game", Skitab
);
95 Game
.skill
= (long) r
->value
;
97 getstrpar("Enter a password", Game
.passwd
, 14, 0);
98 if (strcmp(Game
.passwd
, "tournament") == 0) {
99 getstrpar("Enter tournament code", Game
.passwd
, 14, 0);
102 for (i
= 0; Game
.passwd
[i
]; i
++)
103 d
+= Game
.passwd
[i
] << i
;
106 Param
.bases
= Now
.bases
= ranf(6 - Game
.skill
) + 2;
108 Param
.bases
= Now
.bases
= 1;
109 Param
.time
= Now
.time
= 6.0 * Game
.length
+ 2.0;
112 Param
.klings
= Now
.klings
= i
* j
* 3.5 * (franf() + 0.75);
113 if (Param
.klings
< i
* j
* 5)
114 Param
.klings
= Now
.klings
= i
* j
* 5;
115 if (Param
.klings
<= i
) /* numerical overflow problems */
116 Param
.klings
= Now
.klings
= 127;
117 Param
.energy
= Ship
.energy
= 5000;
118 Param
.torped
= Ship
.torped
= 10;
119 Ship
.ship
= ENTERPRISE
;
120 Ship
.shipname
= "Enterprise";
121 Param
.shield
= Ship
.shield
= 1500;
122 Param
.resource
= Now
.resource
= Param
.klings
* Param
.time
;
123 Param
.reserves
= Ship
.reserves
= (6 - Game
.skill
) * 2.0;
124 Param
.crew
= Ship
.crew
= 387;
125 Param
.brigfree
= Ship
.brigfree
= 400;
133 Param
.date
= Now
.date
= (ranf(20) + 20) * 100;
136 for (i
= 0; i
< NDEV
; i
++)
137 if (Device
[i
].name
[0] == '*')
141 /* these probabilities must sum to 1000 */
142 Param
.damprob
[WARP
] = 70; /* warp drive 7.0% */
143 Param
.damprob
[SRSCAN
] = 110; /* short range scanners 11.0% */
144 Param
.damprob
[LRSCAN
] = 110; /* long range scanners 11.0% */
145 Param
.damprob
[PHASER
] = 125; /* phasers 12.5% */
146 Param
.damprob
[TORPED
] = 125; /* photon torpedoes 12.5% */
147 Param
.damprob
[IMPULSE
] = 75; /* impulse engines 7.5% */
148 Param
.damprob
[SHIELD
] = 150; /* shield control 15.0% */
149 Param
.damprob
[COMPUTER
] = 20; /* computer 2.0% */
150 Param
.damprob
[SSRADIO
] = 35; /* subspace radio 3.5% */
151 Param
.damprob
[LIFESUP
] = 30; /* life support 3.0% */
152 Param
.damprob
[SINS
] = 20; /* navigation system 2.0% */
153 Param
.damprob
[CLOAK
] = 50; /* cloaking device 5.0% */
154 Param
.damprob
[XPORTER
] = 80; /* transporter 8.0% */
155 /* check to see that I didn't blow it */
156 for (i
= j
= 0; i
< NDEV
; i
++)
157 j
+= Param
.damprob
[i
];
159 errx(1, "Device probabilities sum to %d", j
);
161 Param
.regenfac
= (5 - Game
.skill
) * 0.05;
162 if (Param
.regenfac
< 0.0)
163 Param
.regenfac
= 0.0;
168 Param
.klingpwr
= 100 + 150 * i
;
170 Param
.klingpwr
+= 150;
173 Param
.klingcrew
= 200;
174 Param
.srndrprob
= 0.0035;
175 Param
.moveprob
[KM_OB
] = 45;
176 Param
.movefac
[KM_OB
] = .09;
177 Param
.moveprob
[KM_OA
] = 40;
178 Param
.movefac
[KM_OA
] = -0.05;
179 Param
.moveprob
[KM_EB
] = 40;
180 Param
.movefac
[KM_EB
] = 0.075;
181 Param
.moveprob
[KM_EA
] = 25 + 5 * Game
.skill
;
182 Param
.movefac
[KM_EA
] = -0.06 * Game
.skill
;
183 Param
.moveprob
[KM_LB
] = 0;
184 Param
.movefac
[KM_LB
] = 0.0;
185 Param
.moveprob
[KM_LA
] = 10 + 10 * Game
.skill
;
186 Param
.movefac
[KM_LA
] = 0.25;
187 Param
.eventdly
[E_SNOVA
] = 0.5;
188 Param
.eventdly
[E_LRTB
] = 25.0;
189 Param
.eventdly
[E_KATSB
] = 1.0;
190 Param
.eventdly
[E_KDESB
] = 3.0;
191 Param
.eventdly
[E_ISSUE
] = 1.0;
192 Param
.eventdly
[E_SNAP
] = 0.5;
193 Param
.eventdly
[E_ENSLV
] = 0.5;
194 Param
.eventdly
[E_REPRO
] = 2.0;
195 Param
.navigcrud
[0] = 1.50;
196 Param
.navigcrud
[1] = 0.75;
197 Param
.cloakenergy
= 1000;
198 Param
.energylow
= 1000;
199 for (i
= 0; i
< MAXEVENTS
; i
++) {
204 xsched(E_SNOVA
, 1, 0, 0, 0);
205 xsched(E_LRTB
, Param
.klings
, 0, 0, 0);
206 xsched(E_KATSB
, 1, 0, 0, 0);
207 xsched(E_ISSUE
, 1, 0, 0, 0);
208 xsched(E_SNAP
, 1, 0, 0, 0);
209 Ship
.sectx
= ranf(NSECTS
);
210 Ship
.secty
= ranf(NSECTS
);
211 Game
.killk
= Game
.kills
= Game
.killb
= 0;
212 Game
.deaths
= Game
.negenbar
= 0;
221 for (i
= 0; i
< NQUADS
; i
++) {
222 for (j
= 0; j
< NQUADS
; j
++) {
225 q
->klings
= q
->bases
= 0;
227 q
->stars
= ranf(9) + 1;
230 q
->holes
= q
->holes
> s5
? q
->holes
- s5
: 0;
235 /* select inhabited starsystems */
236 for (d
= 1; d
< NINHAB
; d
++) {
241 } while (q
->qsystemname
);
245 /* position starbases */
246 for (i
= 0; i
< Param
.bases
; i
++) {
259 /* start the Enterprise near starbase */
266 /* position klingons */
267 for (i
= Param
.klings
; i
> 0; ) {
275 if (q
->klings
+ klump
> MAXKLQUAD
)
283 /* initialize this quadrant */
284 printf("%d Klingons\n%d starbase", Param
.klings
, Param
.bases
);
287 printf(" at %d,%d", Now
.base
[0].x
, Now
.base
[0].y
);
288 for (i
= 1; i
< Param
.bases
; i
++)
289 printf(", %d,%d", Now
.base
[i
].x
, Now
.base
[i
].y
);
290 printf("\nIt takes %d units to kill a Klingon\n", Param
.klingpwr
);