2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)setup.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/trek/setup.c,v 1.6 1999/11/30 03:49:54 billf Exp $
31 * $DragonFly: src/games/trek/setup.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
38 ** INITIALIZE THE GAME
40 ** The length, skill, and password are read, and the game
41 ** is initialized. It is far too difficult to describe all
42 ** that goes on in here, but it is all straight-line code;
45 ** Game restart and tournament games are handled here.
48 struct cvntab Lentab
[] = {
49 { "s", "hort", (cmdfun
)1, 0 },
50 { "m", "edium", (cmdfun
)2, 0 },
51 { "l", "ong", (cmdfun
)4, 0 },
52 { "restart", "", NULL
, 0 },
53 { NULL
, NULL
, NULL
, 0 }
56 struct cvntab Skitab
[] = {
57 { "n", "ovice", (cmdfun
)1, 0 },
58 { "f", "air", (cmdfun
)2, 0 },
59 { "g", "ood", (cmdfun
)3, 0 },
60 { "e", "xpert", (cmdfun
)4, 0 },
61 { "c", "ommodore", (cmdfun
)5, 0 },
62 { "i", "mpossible", (cmdfun
)6, 0 },
63 { NULL
, NULL
, NULL
, 0 }
79 r
= getcodpar("What length game", Lentab
);
80 Game
.length
= (long) r
->value
;
81 if (Game
.length
== 0) {
88 r
= getcodpar("What skill game", Skitab
);
89 Game
.skill
= (long) r
->value
;
91 getstrpar("Enter a password", Game
.passwd
, 14, 0);
92 if (sequal(Game
.passwd
, "tournament")) {
93 getstrpar("Enter tournament code", Game
.passwd
, 14, 0);
96 for (i
= 0; Game
.passwd
[i
]; i
++)
97 d
+= Game
.passwd
[i
] << i
;
100 Param
.bases
= Now
.bases
= ranf(6 - Game
.skill
) + 2;
102 Param
.bases
= Now
.bases
= 1;
103 Param
.time
= Now
.time
= 6.0 * Game
.length
+ 2.0;
106 Param
.klings
= Now
.klings
= i
* j
* 3.5 * (franf() + 0.75);
107 if (Param
.klings
< i
* j
* 5)
108 Param
.klings
= Now
.klings
= i
* j
* 5;
109 if (Param
.klings
<= i
) /* numerical overflow problems */
110 Param
.klings
= Now
.klings
= 127;
111 Param
.energy
= Ship
.energy
= 5000;
112 Param
.torped
= Ship
.torped
= 10;
113 Ship
.ship
= ENTERPRISE
;
114 Ship
.shipname
= "Enterprise";
115 Param
.shield
= Ship
.shield
= 1500;
116 Param
.resource
= Now
.resource
= Param
.klings
* Param
.time
;
117 Param
.reserves
= Ship
.reserves
= (6 - Game
.skill
) * 2.0;
118 Param
.crew
= Ship
.crew
= 387;
119 Param
.brigfree
= Ship
.brigfree
= 400;
127 Param
.date
= Now
.date
= (ranf(20) + 20) * 100;
130 for (i
= 0; i
< NDEV
; i
++)
131 if (Device
[i
].name
[0] == '*')
135 /* these probabilities must sum to 1000 */
136 Param
.damprob
[WARP
] = 70; /* warp drive 7.0% */
137 Param
.damprob
[SRSCAN
] = 110; /* short range scanners 11.0% */
138 Param
.damprob
[LRSCAN
] = 110; /* long range scanners 11.0% */
139 Param
.damprob
[PHASER
] = 125; /* phasers 12.5% */
140 Param
.damprob
[TORPED
] = 125; /* photon torpedoes 12.5% */
141 Param
.damprob
[IMPULSE
] = 75; /* impulse engines 7.5% */
142 Param
.damprob
[SHIELD
] = 150; /* shield control 15.0% */
143 Param
.damprob
[COMPUTER
] = 20; /* computer 2.0% */
144 Param
.damprob
[SSRADIO
] = 35; /* subspace radio 3.5% */
145 Param
.damprob
[LIFESUP
] = 30; /* life support 3.0% */
146 Param
.damprob
[SINS
] = 20; /* navigation system 2.0% */
147 Param
.damprob
[CLOAK
] = 50; /* cloaking device 5.0% */
148 Param
.damprob
[XPORTER
] = 80; /* transporter 8.0% */
149 /* check to see that I didn't blow it */
150 for (i
= j
= 0; i
< NDEV
; i
++)
151 j
+= Param
.damprob
[i
];
153 syserr("Device probabilities sum to %d", j
);
155 Param
.regenfac
= (5 - Game
.skill
) * 0.05;
156 if (Param
.regenfac
< 0.0)
157 Param
.regenfac
= 0.0;
162 Param
.klingpwr
= 100 + 150 * i
;
164 Param
.klingpwr
+= 150;
167 Param
.klingcrew
= 200;
168 Param
.srndrprob
= 0.0035;
169 Param
.moveprob
[KM_OB
] = 45;
170 Param
.movefac
[KM_OB
] = .09;
171 Param
.moveprob
[KM_OA
] = 40;
172 Param
.movefac
[KM_OA
] = -0.05;
173 Param
.moveprob
[KM_EB
] = 40;
174 Param
.movefac
[KM_EB
] = 0.075;
175 Param
.moveprob
[KM_EA
] = 25 + 5 * Game
.skill
;
176 Param
.movefac
[KM_EA
] = -0.06 * Game
.skill
;
177 Param
.moveprob
[KM_LB
] = 0;
178 Param
.movefac
[KM_LB
] = 0.0;
179 Param
.moveprob
[KM_LA
] = 10 + 10 * Game
.skill
;
180 Param
.movefac
[KM_LA
] = 0.25;
181 Param
.eventdly
[E_SNOVA
] = 0.5;
182 Param
.eventdly
[E_LRTB
] = 25.0;
183 Param
.eventdly
[E_KATSB
] = 1.0;
184 Param
.eventdly
[E_KDESB
] = 3.0;
185 Param
.eventdly
[E_ISSUE
] = 1.0;
186 Param
.eventdly
[E_SNAP
] = 0.5;
187 Param
.eventdly
[E_ENSLV
] = 0.5;
188 Param
.eventdly
[E_REPRO
] = 2.0;
189 Param
.navigcrud
[0] = 1.50;
190 Param
.navigcrud
[1] = 0.75;
191 Param
.cloakenergy
= 1000;
192 Param
.energylow
= 1000;
193 for (i
= 0; i
< MAXEVENTS
; i
++) {
198 xsched(E_SNOVA
, 1, 0, 0, 0);
199 xsched(E_LRTB
, Param
.klings
, 0, 0, 0);
200 xsched(E_KATSB
, 1, 0, 0, 0);
201 xsched(E_ISSUE
, 1, 0, 0, 0);
202 xsched(E_SNAP
, 1, 0, 0, 0);
203 Ship
.sectx
= ranf(NSECTS
);
204 Ship
.secty
= ranf(NSECTS
);
205 Game
.killk
= Game
.kills
= Game
.killb
= 0;
206 Game
.deaths
= Game
.negenbar
= 0;
215 for (i
= 0; i
< NQUADS
; i
++) {
216 for (j
= 0; j
< NQUADS
; j
++) {
218 q
->klings
= q
->bases
= 0;
220 q
->stars
= ranf(9) + 1;
221 q
->holes
= ranf(3) - q
->stars
/ 5;
226 /* select inhabited starsystems */
227 for (d
= 1; d
< NINHAB
; d
++) {
232 } while (q
->qsystemname
);
236 /* position starbases */
237 for (i
= 0; i
< Param
.bases
; i
++) {
250 /* start the Enterprise near starbase */
257 /* position klingons */
258 for (i
= Param
.klings
; i
> 0; ) {
266 if (q
->klings
+ klump
> MAXKLQUAD
)
274 /* initialize this quadrant */
275 printf("%d Klingons\n%d starbase", Param
.klings
, Param
.bases
);
278 printf(" at %d,%d", Now
.base
[0].x
, Now
.base
[0].y
);
279 for (i
= 1; i
< Param
.bases
; i
++)
280 printf(", %d,%d", Now
.base
[i
].x
, Now
.base
[i
].y
);
281 printf("\nIt takes %d units to kill a Klingon\n", Param
.klingpwr
);