Sun May 24 20:39:43 2009 UTC ()
KNF: fix formatting of preprocessor directives


(dholland)
diff -r1.8 -r1.9 src/games/trek/capture.c
diff -r1.8 -r1.9 src/games/trek/events.c
diff -r1.8 -r1.9 src/games/trek/externs.c
diff -r1.8 -r1.9 src/games/trek/schedule.c
diff -r1.6 -r1.7 src/games/trek/damaged.c
diff -r1.6 -r1.7 src/games/trek/klmove.c
diff -r1.12 -r1.13 src/games/trek/dumpgame.c
diff -r1.12 -r1.13 src/games/trek/trek.h
diff -r1.14 -r1.15 src/games/trek/main.c
diff -r1.7 -r1.8 src/games/trek/move.c
diff -r1.7 -r1.8 src/games/trek/systemname.c
diff -r1.11 -r1.12 src/games/trek/phaser.c

cvs diff -r1.8 -r1.9 src/games/trek/capture.c (switch to unified diff)

--- src/games/trek/capture.c 2009/05/24 19:18:44 1.8
+++ src/games/trek/capture.c 2009/05/24 20:39:43 1.9
@@ -1,136 +1,136 @@ @@ -1,136 +1,136 @@
1/* $NetBSD: capture.c,v 1.8 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: capture.c,v 1.9 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)capture.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)capture.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: capture.c,v 1.8 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: capture.c,v 1.9 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include "trek.h" 42#include "trek.h"
43 43
44/* 44/*
45** Ask a Klingon To Surrender 45** Ask a Klingon To Surrender
46** 46**
47** (Fat chance) 47** (Fat chance)
48** 48**
49** The Subspace Radio is needed to ask a Klingon if he will kindly 49** The Subspace Radio is needed to ask a Klingon if he will kindly
50** surrender. A random Klingon from the ones in the quadrant is 50** surrender. A random Klingon from the ones in the quadrant is
51** chosen. 51** chosen.
52** 52**
53** The Klingon is requested to surrender. The probability of this 53** The Klingon is requested to surrender. The probability of this
54** is a function of that Klingon's remaining power, our power, 54** is a function of that Klingon's remaining power, our power,
55** etc. 55** etc.
56*/ 56*/
57 57
58/*ARGSUSED*/ 58/*ARGSUSED*/
59void 59void
60capture(int v __unused) 60capture(int v __unused)
61{ 61{
62 int i; 62 int i;
63 struct kling *k; 63 struct kling *k;
64 double x; 64 double x;
65 65
66 /* check for not cloaked */ 66 /* check for not cloaked */
67 if (Ship.cloaked) 67 if (Ship.cloaked)
68 { 68 {
69 printf("Ship-ship communications out when cloaked\n"); 69 printf("Ship-ship communications out when cloaked\n");
70 return; 70 return;
71 } 71 }
72 if (damaged(SSRADIO)) { 72 if (damaged(SSRADIO)) {
73 out(SSRADIO); 73 out(SSRADIO);
74 return; 74 return;
75 } 75 }
76 /* find out if there are any at all */ 76 /* find out if there are any at all */
77 if (Etc.nkling <= 0) 77 if (Etc.nkling <= 0)
78 { 78 {
79 printf("Uhura: Getting no response, sir\n"); 79 printf("Uhura: Getting no response, sir\n");
80 return; 80 return;
81 } 81 }
82 82
83 /* if there is more than one Klingon, find out which one */ 83 /* if there is more than one Klingon, find out which one */
84 k = selectklingon(); 84 k = selectklingon();
85 Move.free = 0; 85 Move.free = 0;
86 Move.time = 0.05; 86 Move.time = 0.05;
87 87
88 /* check out that Klingon */ 88 /* check out that Klingon */
89 k->srndreq++; 89 k->srndreq++;
90 x = Param.klingpwr; 90 x = Param.klingpwr;
91 x *= Ship.energy; 91 x *= Ship.energy;
92 x /= k->power * Etc.nkling; 92 x /= k->power * Etc.nkling;
93 x *= Param.srndrprob; 93 x *= Param.srndrprob;
94 i = x; 94 i = x;
95# ifdef xTRACE 95#ifdef xTRACE
96 if (Trace) 96 if (Trace)
97 printf("Prob = %d (%.4f)\n", i, x); 97 printf("Prob = %d (%.4f)\n", i, x);
98# endif 98#endif
99 if (i > ranf(100)) 99 if (i > ranf(100))
100 { 100 {
101 /* guess what, he surrendered!!! */ 101 /* guess what, he surrendered!!! */
102 printf("Klingon at %d,%d surrenders\n", k->x, k->y); 102 printf("Klingon at %d,%d surrenders\n", k->x, k->y);
103 i = ranf(Param.klingcrew); 103 i = ranf(Param.klingcrew);
104 if ( i > 0 ) 104 if ( i > 0 )
105 printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i); 105 printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i);
106 if (i > Ship.brigfree) 106 if (i > Ship.brigfree)
107 i = Ship.brigfree; 107 i = Ship.brigfree;
108 Ship.brigfree -= i; 108 Ship.brigfree -= i;
109 printf("%d captives taken\n", i); 109 printf("%d captives taken\n", i);
110 killk(k->x, k->y); 110 killk(k->x, k->y);
111 return; 111 return;
112 } 112 }
113 113
114 /* big surprise, he refuses to surrender */ 114 /* big surprise, he refuses to surrender */
115 printf("Fat chance, captain\n"); 115 printf("Fat chance, captain\n");
116 return; 116 return;
117} 117}
118 118
119 119
120/* 120/*
121** SELECT A KLINGON 121** SELECT A KLINGON
122** 122**
123** Cruddy, just takes one at random. Should ask the captain. 123** Cruddy, just takes one at random. Should ask the captain.
124*/ 124*/
125 125
126struct kling * 126struct kling *
127selectklingon(void) 127selectklingon(void)
128{ 128{
129 int i; 129 int i;
130 130
131 if (Etc.nkling < 2) 131 if (Etc.nkling < 2)
132 i = 0; 132 i = 0;
133 else 133 else
134 i = ranf(Etc.nkling); 134 i = ranf(Etc.nkling);
135 return (&Etc.klingon[i]); 135 return (&Etc.klingon[i]);
136} 136}

cvs diff -r1.8 -r1.9 src/games/trek/events.c (switch to unified diff)

--- src/games/trek/events.c 2008/01/28 01:15:55 1.8
+++ src/games/trek/events.c 2009/05/24 20:39:43 1.9
@@ -1,474 +1,474 @@ @@ -1,474 +1,474 @@
1/* $NetBSD: events.c,v 1.8 2008/01/28 01:15:55 dholland Exp $ */ 1/* $NetBSD: events.c,v 1.9 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)events.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)events.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: events.c,v 1.8 2008/01/28 01:15:55 dholland Exp $"); 37__RCSID("$NetBSD: events.c,v 1.9 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <string.h> 42#include <string.h>
43#include <math.h> 43#include <math.h>
44#include "getpar.h" 44#include "getpar.h"
45#include "trek.h" 45#include "trek.h"
46 46
47/* 47/*
48** CAUSE TIME TO ELAPSE 48** CAUSE TIME TO ELAPSE
49** 49**
50** This routine does a hell of a lot. It elapses time, eats up 50** This routine does a hell of a lot. It elapses time, eats up
51** energy, regenerates energy, processes any events that occur, 51** energy, regenerates energy, processes any events that occur,
52** and so on. 52** and so on.
53** 53**
54** 'timewarp' is set if called in a time warp. 54** 'timewarp' is set if called in a time warp.
55*/ 55*/
56 56
57int 57int
58events(int timewarp) 58events(int timewarp)
59{ 59{
60 int i; 60 int i;
61 char *p; 61 char *p;
62 int j = 0; 62 int j = 0;
63 struct kling *k; 63 struct kling *k;
64 double rtime; 64 double rtime;
65 double xdate; 65 double xdate;
66 double idate; 66 double idate;
67 struct event *ev = NULL; 67 struct event *ev = NULL;
68 int ix, iy; 68 int ix, iy;
69 struct quad *q; 69 struct quad *q;
70 struct event *e; 70 struct event *e;
71 int evnum; 71 int evnum;
72 int restcancel; 72 int restcancel;
73 73
74 /* if nothing happened, just allow for any Klingons killed */ 74 /* if nothing happened, just allow for any Klingons killed */
75 if (Move.time <= 0.0) 75 if (Move.time <= 0.0)
76 { 76 {
77 Now.time = Now.resource / Now.klings; 77 Now.time = Now.resource / Now.klings;
78 return (0); 78 return (0);
79 } 79 }
80 80
81 /* indicate that the cloaking device is now working */ 81 /* indicate that the cloaking device is now working */
82 Ship.cloakgood = 1; 82 Ship.cloakgood = 1;
83 83
84 /* idate is the initial date */ 84 /* idate is the initial date */
85 idate = Now.date; 85 idate = Now.date;
86 86
87 /* schedule attacks if resting too long */ 87 /* schedule attacks if resting too long */
88 if (Move.time > 0.5 && Move.resting) 88 if (Move.time > 0.5 && Move.resting)
89 schedule(E_ATTACK, 0.5, 0, 0, 0); 89 schedule(E_ATTACK, 0.5, 0, 0, 0);
90 90
91 /* scan the event list */ 91 /* scan the event list */
92 while (1) 92 while (1)
93 { 93 {
94 restcancel = 0; 94 restcancel = 0;
95 evnum = -1; 95 evnum = -1;
96 /* xdate is the date of the current event */ 96 /* xdate is the date of the current event */
97 xdate = idate + Move.time; 97 xdate = idate + Move.time;
98 98
99 /* find the first event that has happened */ 99 /* find the first event that has happened */
100 for (i = 0; i < MAXEVENTS; i++) 100 for (i = 0; i < MAXEVENTS; i++)
101 { 101 {
102 e = &Event[i]; 102 e = &Event[i];
103 if (e->evcode == 0 || (e->evcode & E_GHOST)) 103 if (e->evcode == 0 || (e->evcode & E_GHOST))
104 continue; 104 continue;
105 if (e->date < xdate) 105 if (e->date < xdate)
106 { 106 {
107 xdate = e->date; 107 xdate = e->date;
108 ev = e; 108 ev = e;
109 evnum = i; 109 evnum = i;
110 } 110 }
111 } 111 }
112 e = ev; 112 e = ev;
113 113
114 /* find the time between events */ 114 /* find the time between events */
115 rtime = xdate - Now.date; 115 rtime = xdate - Now.date;
116 116
117 /* decrement the magic "Federation Resources" pseudo-variable */ 117 /* decrement the magic "Federation Resources" pseudo-variable */
118 Now.resource -= Now.klings * rtime; 118 Now.resource -= Now.klings * rtime;
119 /* and recompute the time left */ 119 /* and recompute the time left */
120 Now.time = Now.resource / Now.klings; 120 Now.time = Now.resource / Now.klings;
121 121
122 /* move us up to the next date */ 122 /* move us up to the next date */
123 Now.date = xdate; 123 Now.date = xdate;
124 124
125 /* check for out of time */ 125 /* check for out of time */
126 if (Now.time <= 0.0) 126 if (Now.time <= 0.0)
127 lose(L_NOTIME); 127 lose(L_NOTIME);
128# ifdef xTRACE 128#ifdef xTRACE
129 if (evnum >= 0 && Trace) 129 if (evnum >= 0 && Trace)
130 printf("xdate = %.2f, evcode %d params %d %d %d\n", 130 printf("xdate = %.2f, evcode %d params %d %d %d\n",
131 xdate, e->evcode, e->x, e->y, e->systemname); 131 xdate, e->evcode, e->x, e->y, e->systemname);
132# endif 132#endif
133 133
134 /* if evnum < 0, no events occurred */ 134 /* if evnum < 0, no events occurred */
135 if (evnum < 0) 135 if (evnum < 0)
136 break; 136 break;
137 137
138 /* otherwise one did. Find out what it is */ 138 /* otherwise one did. Find out what it is */
139 switch (e->evcode & E_EVENT) 139 switch (e->evcode & E_EVENT)
140 { 140 {
141 141
142 case E_SNOVA: /* supernova */ 142 case E_SNOVA: /* supernova */
143 /* cause the supernova to happen */ 143 /* cause the supernova to happen */
144 snova(-1, 0); 144 snova(-1, 0);
145 /* and schedule the next one */ 145 /* and schedule the next one */
146 xresched(e, E_SNOVA, 1); 146 xresched(e, E_SNOVA, 1);
147 break; 147 break;
148 148
149 case E_LRTB: /* long range tractor beam */ 149 case E_LRTB: /* long range tractor beam */
150 /* schedule the next one */ 150 /* schedule the next one */
151 xresched(e, E_LRTB, Now.klings); 151 xresched(e, E_LRTB, Now.klings);
152 /* LRTB cannot occur if we are docked */ 152 /* LRTB cannot occur if we are docked */
153 if (Ship.cond != DOCKED) 153 if (Ship.cond != DOCKED)
154 { 154 {
155 /* pick a new quadrant */ 155 /* pick a new quadrant */
156 i = ranf(Now.klings) + 1; 156 i = ranf(Now.klings) + 1;
157 for (ix = 0; ix < NQUADS; ix++) 157 for (ix = 0; ix < NQUADS; ix++)
158 { 158 {
159 for (iy = 0; iy < NQUADS; iy++) 159 for (iy = 0; iy < NQUADS; iy++)
160 { 160 {
161 q = &Quad[ix][iy]; 161 q = &Quad[ix][iy];
162 if (q->stars >= 0) 162 if (q->stars >= 0)
163 if ((i -= q->klings) <= 0) 163 if ((i -= q->klings) <= 0)
164 break; 164 break;
165 } 165 }
166 if (i <= 0) 166 if (i <= 0)
167 break; 167 break;
168 } 168 }
169 169
170 /* test for LRTB to same quadrant */ 170 /* test for LRTB to same quadrant */
171 if (Ship.quadx == ix && Ship.quady == iy) 171 if (Ship.quadx == ix && Ship.quady == iy)
172 break; 172 break;
173 173
174 /* nope, dump him in the new quadrant */ 174 /* nope, dump him in the new quadrant */
175 Ship.quadx = ix; 175 Ship.quadx = ix;
176 Ship.quady = iy; 176 Ship.quady = iy;
177 printf("\n%s caught in long range tractor beam\n", Ship.shipname); 177 printf("\n%s caught in long range tractor beam\n", Ship.shipname);
178 printf("*** Pulled to quadrant %d,%d\n", Ship.quadx, Ship.quady); 178 printf("*** Pulled to quadrant %d,%d\n", Ship.quadx, Ship.quady);
179 Ship.sectx = ranf(NSECTS); 179 Ship.sectx = ranf(NSECTS);
180 Ship.secty = ranf(NSECTS); 180 Ship.secty = ranf(NSECTS);
181 initquad(0); 181 initquad(0);
182 /* truncate the move time */ 182 /* truncate the move time */
183 Move.time = xdate - idate; 183 Move.time = xdate - idate;
184 } 184 }
185 break; 185 break;
186 186
187 case E_KATSB: /* Klingon attacks starbase */ 187 case E_KATSB: /* Klingon attacks starbase */
188 /* if out of bases, forget it */ 188 /* if out of bases, forget it */
189 if (Now.bases <= 0) 189 if (Now.bases <= 0)
190 { 190 {
191 unschedule(e); 191 unschedule(e);
192 break; 192 break;
193 } 193 }
194 194
195 /* check for starbase and Klingons in same quadrant */ 195 /* check for starbase and Klingons in same quadrant */
196 for (i = 0; i < Now.bases; i++) 196 for (i = 0; i < Now.bases; i++)
197 { 197 {
198 ix = Now.base[i].x; 198 ix = Now.base[i].x;
199 iy = Now.base[i].y; 199 iy = Now.base[i].y;
200 /* see if a Klingon exists in this quadrant */ 200 /* see if a Klingon exists in this quadrant */
201 q = &Quad[ix][iy]; 201 q = &Quad[ix][iy];
202 if (q->klings <= 0) 202 if (q->klings <= 0)
203 continue; 203 continue;
204 204
205 /* see if already distressed */ 205 /* see if already distressed */
206 for (j = 0; j < MAXEVENTS; j++) 206 for (j = 0; j < MAXEVENTS; j++)
207 { 207 {
208 e = &Event[j]; 208 e = &Event[j];
209 if ((e->evcode & E_EVENT) != E_KDESB) 209 if ((e->evcode & E_EVENT) != E_KDESB)
210 continue; 210 continue;
211 if (e->x == ix && e->y == iy) 211 if (e->x == ix && e->y == iy)
212 break; 212 break;
213 } 213 }
214 if (j < MAXEVENTS) 214 if (j < MAXEVENTS)
215 continue; 215 continue;
216 216
217 /* got a potential attack */ 217 /* got a potential attack */
218 break; 218 break;
219 } 219 }
220 e = ev; 220 e = ev;
221 if (i >= Now.bases) 221 if (i >= Now.bases)
222 { 222 {
223 /* not now; wait a while and see if some Klingons move in */ 223 /* not now; wait a while and see if some Klingons move in */
224 reschedule(e, 0.5 + 3.0 * franf()); 224 reschedule(e, 0.5 + 3.0 * franf());
225 break; 225 break;
226 } 226 }
227 /* schedule a new attack, and a destruction of the base */ 227 /* schedule a new attack, and a destruction of the base */
228 xresched(e, E_KATSB, 1); 228 xresched(e, E_KATSB, 1);
229 e = xsched(E_KDESB, 1, ix, iy, 0); 229 e = xsched(E_KDESB, 1, ix, iy, 0);
230 230
231 /* report it if we can */ 231 /* report it if we can */
232 if (!damaged(SSRADIO)) 232 if (!damaged(SSRADIO))
233 { 233 {
234 printf("\nUhura: Captain, we have received a distress signal\n"); 234 printf("\nUhura: Captain, we have received a distress signal\n");
235 printf(" from the starbase in quadrant %d,%d.\n", 235 printf(" from the starbase in quadrant %d,%d.\n",
236 ix, iy); 236 ix, iy);
237 restcancel++; 237 restcancel++;
238 } 238 }
239 else 239 else
240 /* SSRADIO out, make it so we can't see the distress call */ 240 /* SSRADIO out, make it so we can't see the distress call */
241 /* but it's still there!!! */ 241 /* but it's still there!!! */
242 e->evcode |= E_HIDDEN; 242 e->evcode |= E_HIDDEN;
243 break; 243 break;
244 244
245 case E_KDESB: /* Klingon destroys starbase */ 245 case E_KDESB: /* Klingon destroys starbase */
246 unschedule(e); 246 unschedule(e);
247 q = &Quad[e->x][e->y]; 247 q = &Quad[e->x][e->y];
248 /* if the base has mysteriously gone away, or if the Klingon 248 /* if the base has mysteriously gone away, or if the Klingon
249 got tired and went home, ignore this event */ 249 got tired and went home, ignore this event */
250 if (q->bases <=0 || q->klings <= 0) 250 if (q->bases <=0 || q->klings <= 0)
251 break; 251 break;
252 /* are we in the same quadrant? */ 252 /* are we in the same quadrant? */
253 if (e->x == Ship.quadx && e->y == Ship.quady) 253 if (e->x == Ship.quadx && e->y == Ship.quady)
254 { 254 {
255 /* yep, kill one in this quadrant */ 255 /* yep, kill one in this quadrant */
256 printf("\nSpock: "); 256 printf("\nSpock: ");
257 killb(Ship.quadx, Ship.quady); 257 killb(Ship.quadx, Ship.quady);
258 } 258 }
259 else 259 else
260 /* kill one in some other quadrant */ 260 /* kill one in some other quadrant */
261 killb(e->x, e->y); 261 killb(e->x, e->y);
262 break; 262 break;
263 263
264 case E_ISSUE: /* issue a distress call */ 264 case E_ISSUE: /* issue a distress call */
265 xresched(e, E_ISSUE, 1); 265 xresched(e, E_ISSUE, 1);
266 /* if we already have too many, throw this one away */ 266 /* if we already have too many, throw this one away */
267 if (Ship.distressed >= MAXDISTR) 267 if (Ship.distressed >= MAXDISTR)
268 break; 268 break;
269 /* try a whole bunch of times to find something suitable */ 269 /* try a whole bunch of times to find something suitable */
270 for (i = 0; i < 100; i++) 270 for (i = 0; i < 100; i++)
271 { 271 {
272 ix = ranf(NQUADS); 272 ix = ranf(NQUADS);
273 iy = ranf(NQUADS); 273 iy = ranf(NQUADS);
274 q = &Quad[ix][iy]; 274 q = &Quad[ix][iy];
275 /* need a quadrant which is not the current one, 275 /* need a quadrant which is not the current one,
276 which has some stars which are inhabited and 276 which has some stars which are inhabited and
277 not already under attack, which is not 277 not already under attack, which is not
278 supernova'ed, and which has some Klingons in it */ 278 supernova'ed, and which has some Klingons in it */
279 if (!((ix == Ship.quadx && iy == Ship.quady) || q->stars < 0 || 279 if (!((ix == Ship.quadx && iy == Ship.quady) || q->stars < 0 ||
280 (q->qsystemname & Q_DISTRESSED) || 280 (q->qsystemname & Q_DISTRESSED) ||
281 (q->qsystemname & Q_SYSTEM) == 0 || q->klings <= 0)) 281 (q->qsystemname & Q_SYSTEM) == 0 || q->klings <= 0))
282 break; 282 break;
283 } 283 }
284 if (i >= 100) 284 if (i >= 100)
285 /* can't seem to find one; ignore this call */ 285 /* can't seem to find one; ignore this call */
286 break; 286 break;
287 287
288 /* got one!! Schedule its enslavement */ 288 /* got one!! Schedule its enslavement */
289 Ship.distressed++; 289 Ship.distressed++;
290 e = xsched(E_ENSLV, 1, ix, iy, q->qsystemname); 290 e = xsched(E_ENSLV, 1, ix, iy, q->qsystemname);
291 q->qsystemname = (e - Event) | Q_DISTRESSED; 291 q->qsystemname = (e - Event) | Q_DISTRESSED;
292 292
293 /* tell the captain about it if we can */ 293 /* tell the captain about it if we can */
294 if (!damaged(SSRADIO)) 294 if (!damaged(SSRADIO))
295 { 295 {
296 printf("\nUhura: Captain, starsystem %s in quadrant %d,%d is under attack\n", 296 printf("\nUhura: Captain, starsystem %s in quadrant %d,%d is under attack\n",
297 Systemname[e->systemname], ix, iy); 297 Systemname[e->systemname], ix, iy);
298 restcancel++; 298 restcancel++;
299 } 299 }
300 else 300 else
301 /* if we can't tell him, make it invisible */ 301 /* if we can't tell him, make it invisible */
302 e->evcode |= E_HIDDEN; 302 e->evcode |= E_HIDDEN;
303 break; 303 break;
304 304
305 case E_ENSLV: /* starsystem is enslaved */ 305 case E_ENSLV: /* starsystem is enslaved */
306 unschedule(e); 306 unschedule(e);
307 /* see if current distress call still active */ 307 /* see if current distress call still active */
308 q = &Quad[e->x][e->y]; 308 q = &Quad[e->x][e->y];
309 if (q->klings <= 0) 309 if (q->klings <= 0)
310 { 310 {
311 /* no Klingons, clean up */ 311 /* no Klingons, clean up */
312 /* restore the system name */ 312 /* restore the system name */
313 q->qsystemname = e->systemname; 313 q->qsystemname = e->systemname;
314 break; 314 break;
315 } 315 }
316 316
317 /* play stork and schedule the first baby */ 317 /* play stork and schedule the first baby */
318 e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(), e->x, e->y, e->systemname); 318 e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(), e->x, e->y, e->systemname);
319 319
320 /* report the disaster if we can */ 320 /* report the disaster if we can */
321 if (!damaged(SSRADIO)) 321 if (!damaged(SSRADIO))
322 { 322 {
323 printf("\nUhura: We've lost contact with starsystem %s\n", 323 printf("\nUhura: We've lost contact with starsystem %s\n",
324 Systemname[e->systemname]); 324 Systemname[e->systemname]);
325 printf(" in quadrant %d,%d.\n", 325 printf(" in quadrant %d,%d.\n",
326 e->x, e->y); 326 e->x, e->y);
327 } 327 }
328 else 328 else
329 e->evcode |= E_HIDDEN; 329 e->evcode |= E_HIDDEN;
330 break; 330 break;
331 331
332 case E_REPRO: /* Klingon reproduces */ 332 case E_REPRO: /* Klingon reproduces */
333 /* see if distress call is still active */ 333 /* see if distress call is still active */
334 q = &Quad[e->x][e->y]; 334 q = &Quad[e->x][e->y];
335 if (q->klings <= 0) 335 if (q->klings <= 0)
336 { 336 {
337 unschedule(e); 337 unschedule(e);
338 q->qsystemname = e->systemname; 338 q->qsystemname = e->systemname;
339 break; 339 break;
340 } 340 }
341 xresched(e, E_REPRO, 1); 341 xresched(e, E_REPRO, 1);
342 /* reproduce one Klingon */ 342 /* reproduce one Klingon */
343 ix = e->x; 343 ix = e->x;
344 iy = e->y; 344 iy = e->y;
345 if (Now.klings == 127) 345 if (Now.klings == 127)
346 break; /* full right now */ 346 break; /* full right now */
347 if (q->klings >= MAXKLQUAD) 347 if (q->klings >= MAXKLQUAD)
348 { 348 {
349 /* this quadrant not ok, pick an adjacent one */ 349 /* this quadrant not ok, pick an adjacent one */
350 for (i = ix - 1; i <= ix + 1; i++) 350 for (i = ix - 1; i <= ix + 1; i++)
351 { 351 {
352 if (i < 0 || i >= NQUADS) 352 if (i < 0 || i >= NQUADS)
353 continue; 353 continue;
354 for (j = iy - 1; j <= iy + 1; j++) 354 for (j = iy - 1; j <= iy + 1; j++)
355 { 355 {
356 if (j < 0 || j >= NQUADS) 356 if (j < 0 || j >= NQUADS)
357 continue; 357 continue;
358 q = &Quad[i][j]; 358 q = &Quad[i][j];
359 /* check for this quad ok (not full & no snova) */ 359 /* check for this quad ok (not full & no snova) */
360 if (q->klings >= MAXKLQUAD || q->stars < 0) 360 if (q->klings >= MAXKLQUAD || q->stars < 0)
361 continue; 361 continue;
362 break; 362 break;
363 } 363 }
364 if (j <= iy + 1) 364 if (j <= iy + 1)
365 break; 365 break;
366 } 366 }
367 if (j > iy + 1) 367 if (j > iy + 1)
368 /* cannot create another yet */ 368 /* cannot create another yet */
369 break; 369 break;
370 ix = i; 370 ix = i;
371 iy = j; 371 iy = j;
372 } 372 }
373 /* deliver the child */ 373 /* deliver the child */
374 q->klings++; 374 q->klings++;
375 Now.klings++; 375 Now.klings++;
376 if (ix == Ship.quadx && iy == Ship.quady) 376 if (ix == Ship.quadx && iy == Ship.quady)
377 { 377 {
378 /* we must position Klingon */ 378 /* we must position Klingon */
379 sector(&ix, &iy); 379 sector(&ix, &iy);
380 Sect[ix][iy] = KLINGON; 380 Sect[ix][iy] = KLINGON;
381 k = &Etc.klingon[Etc.nkling++]; 381 k = &Etc.klingon[Etc.nkling++];
382 k->x = ix; 382 k->x = ix;
383 k->y = iy; 383 k->y = iy;
384 k->power = Param.klingpwr; 384 k->power = Param.klingpwr;
385 k->srndreq = 0; 385 k->srndreq = 0;
386 compkldist(Etc.klingon[0].dist == Etc.klingon[0].avgdist ? 0 : 1); 386 compkldist(Etc.klingon[0].dist == Etc.klingon[0].avgdist ? 0 : 1);
387 } 387 }
388 388
389 /* recompute time left */ 389 /* recompute time left */
390 Now.time = Now.resource / Now.klings; 390 Now.time = Now.resource / Now.klings;
391 break; 391 break;
392 392
393 case E_SNAP: /* take a snapshot of the galaxy */ 393 case E_SNAP: /* take a snapshot of the galaxy */
394 xresched(e, E_SNAP, 1); 394 xresched(e, E_SNAP, 1);
395 p = (char *) Etc.snapshot; 395 p = (char *) Etc.snapshot;
396 memcpy(p, Quad, sizeof (Quad)); 396 memcpy(p, Quad, sizeof (Quad));
397 p += sizeof(Quad); 397 p += sizeof(Quad);
398 memcpy(p, Event, sizeof (Event)); 398 memcpy(p, Event, sizeof (Event));
399 p += sizeof(Event); 399 p += sizeof(Event);
400 memcpy(p, &Now, sizeof (Now)); 400 memcpy(p, &Now, sizeof (Now));
401 Game.snap = 1; 401 Game.snap = 1;
402 break; 402 break;
403 403
404 case E_ATTACK: /* Klingons attack during rest period */ 404 case E_ATTACK: /* Klingons attack during rest period */
405 if (!Move.resting) 405 if (!Move.resting)
406 { 406 {
407 unschedule(e); 407 unschedule(e);
408 break; 408 break;
409 } 409 }
410 attack(1); 410 attack(1);
411 reschedule(e, 0.5); 411 reschedule(e, 0.5);
412 break; 412 break;
413 413
414 case E_FIXDV: 414 case E_FIXDV:
415 i = e->systemname; 415 i = e->systemname;
416 unschedule(e); 416 unschedule(e);
417 417
418 /* de-damage the device */ 418 /* de-damage the device */
419 printf("%s reports repair work on the %s finished.\n", 419 printf("%s reports repair work on the %s finished.\n",
420 Device[i].person, Device[i].name); 420 Device[i].person, Device[i].name);
421 421
422 /* handle special processing upon fix */ 422 /* handle special processing upon fix */
423 switch (i) 423 switch (i)
424 { 424 {
425 425
426 case LIFESUP: 426 case LIFESUP:
427 Ship.reserves = Param.reserves; 427 Ship.reserves = Param.reserves;
428 break; 428 break;
429 429
430 case SINS: 430 case SINS:
431 if (Ship.cond == DOCKED) 431 if (Ship.cond == DOCKED)
432 break; 432 break;
433 printf("Spock has tried to recalibrate your Space Internal Navigation System,\n"); 433 printf("Spock has tried to recalibrate your Space Internal Navigation System,\n");
434 printf(" but he has no standard base to calibrate to. Suggest you get\n"); 434 printf(" but he has no standard base to calibrate to. Suggest you get\n");
435 printf(" to a starbase immediately so that you can properly recalibrate.\n"); 435 printf(" to a starbase immediately so that you can properly recalibrate.\n");
436 Ship.sinsbad = 1; 436 Ship.sinsbad = 1;
437 break; 437 break;
438 438
439 case SSRADIO: 439 case SSRADIO:
440 restcancel = dumpssradio(); 440 restcancel = dumpssradio();
441 break; 441 break;
442 } 442 }
443 break; 443 break;
444 444
445 default: 445 default:
446 break; 446 break;
447 } 447 }
448 448
449 if (restcancel && Move.resting && getynpar("Spock: Shall we cancel our rest period")) 449 if (restcancel && Move.resting && getynpar("Spock: Shall we cancel our rest period"))
450 Move.time = xdate - idate; 450 Move.time = xdate - idate;
451 451
452 } 452 }
453 453
454 /* unschedule an attack during a rest period */ 454 /* unschedule an attack during a rest period */
455 if ((e = Now.eventptr[E_ATTACK]) != NULL) 455 if ((e = Now.eventptr[E_ATTACK]) != NULL)
456 unschedule(e); 456 unschedule(e);
457 457
458 if (!timewarp) 458 if (!timewarp)
459 { 459 {
460 /* eat up energy if cloaked */ 460 /* eat up energy if cloaked */
461 if (Ship.cloaked) 461 if (Ship.cloaked)
462 Ship.energy -= Param.cloakenergy * Move.time; 462 Ship.energy -= Param.cloakenergy * Move.time;
463 463
464 /* regenerate resources */ 464 /* regenerate resources */
465 rtime = 1.0 - exp(-Param.regenfac * Move.time); 465 rtime = 1.0 - exp(-Param.regenfac * Move.time);
466 Ship.shield += (Param.shield - Ship.shield) * rtime; 466 Ship.shield += (Param.shield - Ship.shield) * rtime;
467 Ship.energy += (Param.energy - Ship.energy) * rtime; 467 Ship.energy += (Param.energy - Ship.energy) * rtime;
468 468
469 /* decrement life support reserves */ 469 /* decrement life support reserves */
470 if (damaged(LIFESUP) && Ship.cond != DOCKED) 470 if (damaged(LIFESUP) && Ship.cond != DOCKED)
471 Ship.reserves -= Move.time; 471 Ship.reserves -= Move.time;
472 } 472 }
473 return (0); 473 return (0);
474} 474}

cvs diff -r1.8 -r1.9 src/games/trek/externs.c (switch to unified diff)

--- src/games/trek/externs.c 2003/08/07 09:37:51 1.8
+++ src/games/trek/externs.c 2009/05/24 20:39:43 1.9
@@ -1,117 +1,117 @@ @@ -1,117 +1,117 @@
1/* $NetBSD: externs.c,v 1.8 2003/08/07 09:37:51 agc Exp $ */ 1/* $NetBSD: externs.c,v 1.9 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)externs.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)externs.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: externs.c,v 1.8 2003/08/07 09:37:51 agc Exp $"); 37__RCSID("$NetBSD: externs.c,v 1.9 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "trek.h" 41#include "trek.h"
42 42
43/* 43/*
44** global variable definitions 44** global variable definitions
45*/ 45*/
46 46
47const struct device Device[NDEV] = 47const struct device Device[NDEV] =
48{ 48{
49 { "warp drive", "Scotty" }, 49 { "warp drive", "Scotty" },
50 { "S.R. scanners", "Scotty" }, 50 { "S.R. scanners", "Scotty" },
51 { "L.R. scanners", "Scotty" }, 51 { "L.R. scanners", "Scotty" },
52 { "phasers", "Sulu" }, 52 { "phasers", "Sulu" },
53 { "photon tubes", "Sulu" }, 53 { "photon tubes", "Sulu" },
54 { "impulse engines", "Scotty" }, 54 { "impulse engines", "Scotty" },
55 { "shield control", "Sulu" }, 55 { "shield control", "Sulu" },
56 { "computer", "Spock" }, 56 { "computer", "Spock" },
57 { "subspace radio", "Uhura" }, 57 { "subspace radio", "Uhura" },
58 { "life support", "Scotty" }, 58 { "life support", "Scotty" },
59 { "navigation system", "Chekov" }, 59 { "navigation system", "Chekov" },
60 { "cloaking device", "Scotty" }, 60 { "cloaking device", "Scotty" },
61 { "transporter", "Scotty" }, 61 { "transporter", "Scotty" },
62 { "shuttlecraft", "Scotty" }, 62 { "shuttlecraft", "Scotty" },
63 { "*ERR 14*", "Nobody" }, 63 { "*ERR 14*", "Nobody" },
64 { "*ERR 15*", "Nobody" } 64 { "*ERR 15*", "Nobody" }
65}; 65};
66 66
67const char *const Systemname[NINHAB] = 67const char *const Systemname[NINHAB] =
68{ 68{
69 "ERROR", 69 "ERROR",
70 "Talos IV", 70 "Talos IV",
71 "Rigel III", 71 "Rigel III",
72 "Deneb VII", 72 "Deneb VII",
73 "Canopus V", 73 "Canopus V",
74 "Icarus I", 74 "Icarus I",
75 "Prometheus II", 75 "Prometheus II",
76 "Omega VII", 76 "Omega VII",
77 "Elysium I", 77 "Elysium I",
78 "Scalos IV", 78 "Scalos IV",
79 "Procyon IV", 79 "Procyon IV",
80 "Arachnid I", 80 "Arachnid I",
81 "Argo VIII", 81 "Argo VIII",
82 "Triad III", 82 "Triad III",
83 "Echo IV", 83 "Echo IV",
84 "Nimrod III", 84 "Nimrod III",
85 "Nemisis IV", 85 "Nemisis IV",
86 "Centarurus I", 86 "Centarurus I",
87 "Kronos III", 87 "Kronos III",
88 "Spectros V", 88 "Spectros V",
89 "Beta III", 89 "Beta III",
90 "Gamma Tranguli VI", 90 "Gamma Tranguli VI",
91 "Pyris III", 91 "Pyris III",
92 "Triachus", 92 "Triachus",
93 "Marcus XII", 93 "Marcus XII",
94 "Kaland", 94 "Kaland",
95 "Ardana", 95 "Ardana",
96 "Stratos", 96 "Stratos",
97 "Eden", 97 "Eden",
98 "Arrikis", 98 "Arrikis",
99 "Epsilon Eridani IV", 99 "Epsilon Eridani IV",
100 "Exo III" 100 "Exo III"
101}; 101};
102 102
103struct quad Quad[NQUADS][NQUADS]; 103struct quad Quad[NQUADS][NQUADS];
104 104
105/* current sector map */ 105/* current sector map */
106char Sect[NSECTS][NSECTS]; 106char Sect[NSECTS][NSECTS];
107 107
108struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */ 108struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */
109 109
110struct Ship_struct Ship; 110struct Ship_struct Ship;
111struct Game_struct Game; 111struct Game_struct Game;
112struct Move_struct Move; 112struct Move_struct Move;
113struct Param_struct Param; 113struct Param_struct Param;
114struct Now_struct Now; 114struct Now_struct Now;
115struct Etc_struct Etc; 115struct Etc_struct Etc;
116 116
117int Trace; 117int Trace;

cvs diff -r1.8 -r1.9 src/games/trek/schedule.c (switch to unified diff)

--- src/games/trek/schedule.c 2009/05/24 19:18:44 1.8
+++ src/games/trek/schedule.c 2009/05/24 20:39:43 1.9
@@ -1,172 +1,172 @@ @@ -1,172 +1,172 @@
1/* $NetBSD: schedule.c,v 1.8 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: schedule.c,v 1.9 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: schedule.c,v 1.8 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: schedule.c,v 1.9 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <math.h> 42#include <math.h>
43#include <err.h> 43#include <err.h>
44#include <limits.h> 44#include <limits.h>
45#include "trek.h" 45#include "trek.h"
46 46
47/* 47/*
48** SCHEDULE AN EVENT 48** SCHEDULE AN EVENT
49** 49**
50** An event of type 'type' is scheduled for time NOW + 'offset' 50** An event of type 'type' is scheduled for time NOW + 'offset'
51** into the first available slot. 'x', 'y', and 'z' are 51** into the first available slot. 'x', 'y', and 'z' are
52** considered the attributes for this event. 52** considered the attributes for this event.
53** 53**
54** The address of the slot is returned. 54** The address of the slot is returned.
55*/ 55*/
56 56
57struct event * 57struct event *
58schedule(int type, double offset, int x, int y, int z) 58schedule(int type, double offset, int x, int y, int z)
59{ 59{
60 struct event *e; 60 struct event *e;
61 int i; 61 int i;
62 double date; 62 double date;
63 63
64 date = Now.date + offset; 64 date = Now.date + offset;
65 for (i = 0; i < MAXEVENTS; i++) 65 for (i = 0; i < MAXEVENTS; i++)
66 { 66 {
67 e = &Event[i]; 67 e = &Event[i];
68 if (e->evcode) 68 if (e->evcode)
69 continue; 69 continue;
70 /* got a slot */ 70 /* got a slot */
71# ifdef xTRACE 71#ifdef xTRACE
72 if (Trace) 72 if (Trace)
73 printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n", 73 printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
74 type, date, i, x, y, z); 74 type, date, i, x, y, z);
75# endif 75#endif
76 e->evcode = type; 76 e->evcode = type;
77 e->date = date; 77 e->date = date;
78 e->x = x; 78 e->x = x;
79 e->y = y; 79 e->y = y;
80 e->systemname = z; 80 e->systemname = z;
81 Now.eventptr[type & ~E_GHOST] = e; 81 Now.eventptr[type & ~E_GHOST] = e;
82 return (e); 82 return (e);
83 } 83 }
84 errx(1, "Cannot schedule event %d parm %d %d %d", type, x, y, z); 84 errx(1, "Cannot schedule event %d parm %d %d %d", type, x, y, z);
85} 85}
86 86
87 87
88/* 88/*
89** RESCHEDULE AN EVENT 89** RESCHEDULE AN EVENT
90** 90**
91** The event pointed to by 'e' is rescheduled to the current 91** The event pointed to by 'e' is rescheduled to the current
92** time plus 'offset'. 92** time plus 'offset'.
93*/ 93*/
94 94
95void 95void
96reschedule(struct event *e1, double offset) 96reschedule(struct event *e1, double offset)
97{ 97{
98 double date; 98 double date;
99 struct event *e; 99 struct event *e;
100 100
101 e = e1; 101 e = e1;
102 102
103 date = Now.date + offset; 103 date = Now.date + offset;
104 e->date = date; 104 e->date = date;
105# ifdef xTRACE 105#ifdef xTRACE
106 if (Trace) 106 if (Trace)
107 printf("reschedule: type %d parm %d %d %d @ %.2f\n", 107 printf("reschedule: type %d parm %d %d %d @ %.2f\n",
108 e->evcode, e->x, e->y, e->systemname, date); 108 e->evcode, e->x, e->y, e->systemname, date);
109# endif 109#endif
110 return; 110 return;
111} 111}
112 112
113 113
114/* 114/*
115** UNSCHEDULE AN EVENT 115** UNSCHEDULE AN EVENT
116** 116**
117** The event at slot 'e' is deleted. 117** The event at slot 'e' is deleted.
118*/ 118*/
119 119
120void 120void
121unschedule(struct event *e1) 121unschedule(struct event *e1)
122{ 122{
123 struct event *e; 123 struct event *e;
124 124
125 e = e1; 125 e = e1;
126 126
127# ifdef xTRACE 127#ifdef xTRACE
128 if (Trace) 128 if (Trace)
129 printf("unschedule: type %d @ %.2f parm %d %d %d\n", 129 printf("unschedule: type %d @ %.2f parm %d %d %d\n",
130 e->evcode, e->date, e->x, e->y, e->systemname); 130 e->evcode, e->date, e->x, e->y, e->systemname);
131# endif 131#endif
132 Now.eventptr[e->evcode & E_EVENT] = 0; 132 Now.eventptr[e->evcode & E_EVENT] = 0;
133 e->date = TOOLARGE; 133 e->date = TOOLARGE;
134 e->evcode = 0; 134 e->evcode = 0;
135 return; 135 return;
136} 136}
137 137
138 138
139/* 139/*
140** Abreviated schedule routine 140** Abreviated schedule routine
141** 141**
142** Parameters are the event index and a factor for the time 142** Parameters are the event index and a factor for the time
143** figure. 143** figure.
144*/ 144*/
145 145
146struct event * 146struct event *
147xsched(int ev1, int factor, int x, int y, int z) 147xsched(int ev1, int factor, int x, int y, int z)
148{ 148{
149 int ev; 149 int ev;
150 150
151 ev = ev1; 151 ev = ev1;
152 return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z)); 152 return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
153} 153}
154 154
155 155
156/* 156/*
157** Simplified reschedule routine 157** Simplified reschedule routine
158** 158**
159** Parameters are the event index, the initial date, and the 159** Parameters are the event index, the initial date, and the
160** division factor. Look at the code to see what really happens. 160** division factor. Look at the code to see what really happens.
161*/ 161*/
162 162
163void 163void
164xresched(struct event *e1, int ev1, int factor) 164xresched(struct event *e1, int ev1, int factor)
165{ 165{
166 int ev; 166 int ev;
167 struct event *e; 167 struct event *e;
168 168
169 ev = ev1; 169 ev = ev1;
170 e = e1; 170 e = e1;
171 reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor); 171 reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
172} 172}

cvs diff -r1.6 -r1.7 src/games/trek/damaged.c (switch to unified diff)

--- src/games/trek/damaged.c 2009/05/24 19:18:44 1.6
+++ src/games/trek/damaged.c 2009/05/24 20:39:43 1.7
@@ -1,70 +1,70 @@ @@ -1,70 +1,70 @@
1/* $NetBSD: damaged.c,v 1.6 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: damaged.c,v 1.7 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)damaged.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)damaged.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: damaged.c,v 1.6 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: damaged.c,v 1.7 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "trek.h" 41#include "trek.h"
42 42
43/* DAMAGED -- check for device damaged 43/* DAMAGED -- check for device damaged
44** 44**
45** This is a boolean function which returns non-zero if the 45** This is a boolean function which returns non-zero if the
46** specified device is broken. It does this by checking the 46** specified device is broken. It does this by checking the
47** event list for a "device fix" action on that device. 47** event list for a "device fix" action on that device.
48*/ 48*/
49 49
50int 50int
51damaged(int dev) 51damaged(int dev)
52{ 52{
53 int d; 53 int d;
54 struct event *e; 54 struct event *e;
55 int i; 55 int i;
56 56
57 d = dev; 57 d = dev;
58 58
59 for (i = 0; i < MAXEVENTS; i++) 59 for (i = 0; i < MAXEVENTS; i++)
60 { 60 {
61 e = &Event[i]; 61 e = &Event[i];
62 if (e->evcode != E_FIXDV) 62 if (e->evcode != E_FIXDV)
63 continue; 63 continue;
64 if (e->systemname == d) 64 if (e->systemname == d)
65 return (1); 65 return (1);
66 } 66 }
67 67
68 /* device fix not in event list -- device must not be broken */ 68 /* device fix not in event list -- device must not be broken */
69 return (0); 69 return (0);
70} 70}

cvs diff -r1.6 -r1.7 src/games/trek/klmove.c (switch to unified diff)

--- src/games/trek/klmove.c 2009/05/24 19:18:44 1.6
+++ src/games/trek/klmove.c 2009/05/24 20:39:43 1.7
@@ -1,186 +1,186 @@ @@ -1,186 +1,186 @@
1/* $NetBSD: klmove.c,v 1.6 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: klmove.c,v 1.7 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)klmove.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)klmove.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: klmove.c,v 1.6 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: klmove.c,v 1.7 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include "trek.h" 42#include "trek.h"
43 43
44/* 44/*
45** Move Klingons Around 45** Move Klingons Around
46** 46**
47** This is a largely incomprehensible block of code that moves 47** This is a largely incomprehensible block of code that moves
48** Klingons around in a quadrant. It was written in a very 48** Klingons around in a quadrant. It was written in a very
49** "program as you go" fashion, and is a prime candidate for 49** "program as you go" fashion, and is a prime candidate for
50** rewriting. 50** rewriting.
51** 51**
52** The flag `fl' is zero before an attack, one after an attack, 52** The flag `fl' is zero before an attack, one after an attack,
53** and two if you are leaving a quadrant. This serves to 53** and two if you are leaving a quadrant. This serves to
54** change the probability and distance that it moves. 54** change the probability and distance that it moves.
55** 55**
56** Basically, what it will try to do is to move a certain number 56** Basically, what it will try to do is to move a certain number
57** of steps either toward you or away from you. It will avoid 57** of steps either toward you or away from you. It will avoid
58** stars whenever possible. Nextx and nexty are the next 58** stars whenever possible. Nextx and nexty are the next
59** sector to move to on a per-Klingon basis; they are roughly 59** sector to move to on a per-Klingon basis; they are roughly
60** equivalent to Ship.sectx and Ship.secty for the starship. Lookx and 60** equivalent to Ship.sectx and Ship.secty for the starship. Lookx and
61** looky are the sector that you are going to look at to see 61** looky are the sector that you are going to look at to see
62** if you can move their. Dx and dy are the increment. Fudgex 62** if you can move their. Dx and dy are the increment. Fudgex
63** and fudgey are the things you change around to change your 63** and fudgey are the things you change around to change your
64** course around stars. 64** course around stars.
65*/ 65*/
66 66
67void 67void
68klmove(int fl) 68klmove(int fl)
69{ 69{
70 int n; 70 int n;
71 struct kling *k; 71 struct kling *k;
72 double dx, dy; 72 double dx, dy;
73 int nextx, nexty; 73 int nextx, nexty;
74 int lookx, looky; 74 int lookx, looky;
75 int motion; 75 int motion;
76 int fudgex, fudgey; 76 int fudgex, fudgey;
77 int qx, qy; 77 int qx, qy;
78 double bigger; 78 double bigger;
79 int i; 79 int i;
80 80
81# ifdef xTRACE 81#ifdef xTRACE
82 if (Trace) 82 if (Trace)
83 printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling); 83 printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling);
84# endif 84#endif
85 for (n = 0; n < Etc.nkling; n++) 85 for (n = 0; n < Etc.nkling; n++)
86 { 86 {
87 k = &Etc.klingon[n]; 87 k = &Etc.klingon[n];
88 i = 100; 88 i = 100;
89 if (fl) 89 if (fl)
90 i = 100.0 * k->power / Param.klingpwr; 90 i = 100.0 * k->power / Param.klingpwr;
91 if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl]) 91 if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl])
92 continue; 92 continue;
93 /* compute distance to move */ 93 /* compute distance to move */
94 motion = ranf(75) - 25; 94 motion = ranf(75) - 25;
95 motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl]; 95 motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl];
96 /* compute direction */ 96 /* compute direction */
97 dx = Ship.sectx - k->x + ranf(3) - 1; 97 dx = Ship.sectx - k->x + ranf(3) - 1;
98 dy = Ship.secty - k->y + ranf(3) - 1; 98 dy = Ship.secty - k->y + ranf(3) - 1;
99 bigger = dx; 99 bigger = dx;
100 if (dy > bigger) 100 if (dy > bigger)
101 bigger = dy; 101 bigger = dy;
102 if (bigger == 0.0) 102 if (bigger == 0.0)
103 bigger = 1.0; 103 bigger = 1.0;
104 dx = dx / bigger + 0.5; 104 dx = dx / bigger + 0.5;
105 dy = dy / bigger + 0.5; 105 dy = dy / bigger + 0.5;
106 if (motion < 0) 106 if (motion < 0)
107 { 107 {
108 motion = -motion; 108 motion = -motion;
109 dx = -dx; 109 dx = -dx;
110 dy = -dy; 110 dy = -dy;
111 } 111 }
112 fudgex = fudgey = 1; 112 fudgex = fudgey = 1;
113 /* try to move the klingon */ 113 /* try to move the klingon */
114 nextx = k->x; 114 nextx = k->x;
115 nexty = k->y; 115 nexty = k->y;
116 for (; motion > 0; motion--) 116 for (; motion > 0; motion--)
117 { 117 {
118 lookx = nextx + dx; 118 lookx = nextx + dx;
119 looky = nexty + dy; 119 looky = nexty + dy;
120 if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS) 120 if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS)
121 { 121 {
122 /* new quadrant */ 122 /* new quadrant */
123 qx = Ship.quadx; 123 qx = Ship.quadx;
124 qy = Ship.quady; 124 qy = Ship.quady;
125 if (lookx < 0) 125 if (lookx < 0)
126 qx -= 1; 126 qx -= 1;
127 else 127 else
128 if (lookx >= NSECTS) 128 if (lookx >= NSECTS)
129 qx += 1; 129 qx += 1;
130 if (looky < 0) 130 if (looky < 0)
131 qy -= 1; 131 qy -= 1;
132 else 132 else
133 if (looky >= NSECTS) 133 if (looky >= NSECTS)
134 qy += 1; 134 qy += 1;
135 if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS || 135 if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS ||
136 Quad[qx][qy].stars < 0 || Quad[qx][qy].klings > MAXKLQUAD - 1) 136 Quad[qx][qy].stars < 0 || Quad[qx][qy].klings > MAXKLQUAD - 1)
137 break; 137 break;
138 if (!damaged(SRSCAN)) 138 if (!damaged(SRSCAN))
139 { 139 {
140 printf("Klingon at %d,%d escapes to quadrant %d,%d\n", 140 printf("Klingon at %d,%d escapes to quadrant %d,%d\n",
141 k->x, k->y, qx, qy); 141 k->x, k->y, qx, qy);
142 motion = Quad[qx][qy].scanned; 142 motion = Quad[qx][qy].scanned;
143 if (motion >= 0 && motion < 1000) 143 if (motion >= 0 && motion < 1000)
144 Quad[qx][qy].scanned += 100; 144 Quad[qx][qy].scanned += 100;
145 motion = Quad[Ship.quadx][Ship.quady].scanned; 145 motion = Quad[Ship.quadx][Ship.quady].scanned;
146 if (motion >= 0 && motion < 1000) 146 if (motion >= 0 && motion < 1000)
147 Quad[Ship.quadx][Ship.quady].scanned -= 100; 147 Quad[Ship.quadx][Ship.quady].scanned -= 100;
148 } 148 }
149 Sect[k->x][k->y] = EMPTY; 149 Sect[k->x][k->y] = EMPTY;
150 Quad[qx][qy].klings += 1; 150 Quad[qx][qy].klings += 1;
151 Etc.nkling -= 1; 151 Etc.nkling -= 1;
152 *k = Etc.klingon[Etc.nkling]; 152 *k = Etc.klingon[Etc.nkling];
153 Quad[Ship.quadx][Ship.quady].klings -= 1; 153 Quad[Ship.quadx][Ship.quady].klings -= 1;
154 k = 0; 154 k = 0;
155 break; 155 break;
156 } 156 }
157 if (Sect[lookx][looky] != EMPTY) 157 if (Sect[lookx][looky] != EMPTY)
158 { 158 {
159 lookx = nextx + fudgex; 159 lookx = nextx + fudgex;
160 if (lookx < 0 || lookx >= NSECTS) 160 if (lookx < 0 || lookx >= NSECTS)
161 lookx = nextx + dx; 161 lookx = nextx + dx;
162 if (Sect[lookx][looky] != EMPTY) 162 if (Sect[lookx][looky] != EMPTY)
163 { 163 {
164 fudgex = -fudgex; 164 fudgex = -fudgex;
165 looky = nexty + fudgey; 165 looky = nexty + fudgey;
166 if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY) 166 if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY)
167 { 167 {
168 fudgey = -fudgey; 168 fudgey = -fudgey;
169 break; 169 break;
170 } 170 }
171 } 171 }
172 } 172 }
173 nextx = lookx; 173 nextx = lookx;
174 nexty = looky; 174 nexty = looky;
175 } 175 }
176 if (k && (k->x != nextx || k->y != nexty)) 176 if (k && (k->x != nextx || k->y != nexty))
177 { 177 {
178 if (!damaged(SRSCAN)) 178 if (!damaged(SRSCAN))
179 printf("Klingon at %d,%d moves to %d,%d\n", 179 printf("Klingon at %d,%d moves to %d,%d\n",
180 k->x, k->y, nextx, nexty); 180 k->x, k->y, nextx, nexty);
181 Sect[k->x][k->y] = EMPTY; 181 Sect[k->x][k->y] = EMPTY;
182 Sect[k->x = nextx][k->y = nexty] = KLINGON; 182 Sect[k->x = nextx][k->y = nexty] = KLINGON;
183 } 183 }
184 } 184 }
185 compkldist(0); 185 compkldist(0);
186} 186}

cvs diff -r1.12 -r1.13 src/games/trek/dumpgame.c (switch to unified diff)

--- src/games/trek/dumpgame.c 2009/05/24 19:18:44 1.12
+++ src/games/trek/dumpgame.c 2009/05/24 20:39:43 1.13
@@ -1,176 +1,176 @@ @@ -1,176 +1,176 @@
1/* $NetBSD: dumpgame.c,v 1.12 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: dumpgame.c,v 1.13 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)dumpgame.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)dumpgame.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: dumpgame.c,v 1.12 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: dumpgame.c,v 1.13 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <err.h> 42#include <err.h>
43#include <unistd.h> 43#include <unistd.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include "trek.h" 45#include "trek.h"
46 46
47/*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/ 47/*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/
48# define VERSION 2 48#define VERSION 2
49 49
50struct dump 50struct dump
51{ 51{
52 char *area; 52 char *area;
53 int count; 53 int count;
54}; 54};
55 55
56static int readdump(int); 56static int readdump(int);
57 57
58 58
59struct dump Dump_template[] = 59struct dump Dump_template[] =
60{ 60{
61 { (char *)&Ship, sizeof (Ship) }, 61 { (char *)&Ship, sizeof (Ship) },
62 { (char *)&Now, sizeof (Now) }, 62 { (char *)&Now, sizeof (Now) },
63 { (char *)&Param, sizeof (Param) }, 63 { (char *)&Param, sizeof (Param) },
64 { (char *)&Etc, sizeof (Etc) }, 64 { (char *)&Etc, sizeof (Etc) },
65 { (char *)&Game, sizeof (Game) }, 65 { (char *)&Game, sizeof (Game) },
66 { (char *)Sect, sizeof (Sect) }, 66 { (char *)Sect, sizeof (Sect) },
67 { (char *)Quad, sizeof (Quad) }, 67 { (char *)Quad, sizeof (Quad) },
68 { (char *)&Move, sizeof (Move) }, 68 { (char *)&Move, sizeof (Move) },
69 { (char *)Event, sizeof (Event) }, 69 { (char *)Event, sizeof (Event) },
70 { NULL, 0 } 70 { NULL, 0 }
71}; 71};
72 72
73/* 73/*
74** DUMP GAME 74** DUMP GAME
75** 75**
76** This routine dumps the game onto the file "trek.dump". The 76** This routine dumps the game onto the file "trek.dump". The
77** first two bytes of the file are a version number, which 77** first two bytes of the file are a version number, which
78** reflects whether this image may be used. Obviously, it must 78** reflects whether this image may be used. Obviously, it must
79** change as the size, content, or order of the data structures 79** change as the size, content, or order of the data structures
80** output change. 80** output change.
81*/ 81*/
82 82
83/*ARGSUSED*/ 83/*ARGSUSED*/
84void 84void
85dumpgame(int v __unused) 85dumpgame(int v __unused)
86{ 86{
87 int version; 87 int version;
88 int fd; 88 int fd;
89 struct dump *d; 89 struct dump *d;
90 int i; 90 int i;
91 91
92 if ((fd = creat("trek.dump", 0644)) < 0) { 92 if ((fd = creat("trek.dump", 0644)) < 0) {
93 warn("cannot open `trek.dump'"); 93 warn("cannot open `trek.dump'");
94 return; 94 return;
95 } 95 }
96 version = VERSION; 96 version = VERSION;
97 write(fd, &version, sizeof version); 97 write(fd, &version, sizeof version);
98 98
99 /* output the main data areas */ 99 /* output the main data areas */
100 for (d = Dump_template; d->area; d++) 100 for (d = Dump_template; d->area; d++)
101 { 101 {
102 write(fd, &d->area, sizeof d->area); 102 write(fd, &d->area, sizeof d->area);
103 i = d->count; 103 i = d->count;
104 write(fd, d->area, i); 104 write(fd, d->area, i);
105 } 105 }
106 106
107 close(fd); 107 close(fd);
108} 108}
109 109
110 110
111/* 111/*
112** RESTORE GAME 112** RESTORE GAME
113** 113**
114** The game is restored from the file "trek.dump". In order for 114** The game is restored from the file "trek.dump". In order for
115** this to succeed, the file must exist and be readable, must 115** this to succeed, the file must exist and be readable, must
116** have the correct version number, and must have all the appro- 116** have the correct version number, and must have all the appro-
117** priate data areas. 117** priate data areas.
118** 118**
119** Return value is zero for success, one for failure. 119** Return value is zero for success, one for failure.
120*/ 120*/
121 121
122int 122int
123restartgame(void) 123restartgame(void)
124{ 124{
125 int fd; 125 int fd;
126 int version; 126 int version;
127 127
128 if ((fd = open("trek.dump", O_RDONLY)) < 0 || 128 if ((fd = open("trek.dump", O_RDONLY)) < 0 ||
129 read(fd, &version, sizeof version) != sizeof version || 129 read(fd, &version, sizeof version) != sizeof version ||
130 version != VERSION || 130 version != VERSION ||
131 readdump(fd)) 131 readdump(fd))
132 { 132 {
133 printf("cannot restart\n"); 133 printf("cannot restart\n");
134 if (fd >= 0) 134 if (fd >= 0)
135 close(fd); 135 close(fd);
136 return (1); 136 return (1);
137 } 137 }
138 138
139 close(fd); 139 close(fd);
140 return (0); 140 return (0);
141} 141}
142 142
143 143
144/* 144/*
145** READ DUMP 145** READ DUMP
146** 146**
147** This is the business end of restartgame(). It reads in the 147** This is the business end of restartgame(). It reads in the
148** areas. 148** areas.
149** 149**
150** Returns zero for success, one for failure. 150** Returns zero for success, one for failure.
151*/ 151*/
152 152
153static int 153static int
154readdump(int fd1) 154readdump(int fd1)
155{ 155{
156 int fd; 156 int fd;
157 struct dump *d; 157 struct dump *d;
158 int i; 158 int i;
159 long junk; 159 long junk;
160 160
161 fd = fd1; 161 fd = fd1;
162 162
163 for (d = Dump_template; d->area; d++) 163 for (d = Dump_template; d->area; d++)
164 { 164 {
165 if (read(fd, &junk, sizeof junk) != (sizeof junk)) 165 if (read(fd, &junk, sizeof junk) != (sizeof junk))
166 return (1); 166 return (1);
167 if ((char *)junk != d->area) 167 if ((char *)junk != d->area)
168 return (1); 168 return (1);
169 i = d->count; 169 i = d->count;
170 if (read(fd, d->area, i) != i) 170 if (read(fd, d->area, i) != i)
171 return (1); 171 return (1);
172 } 172 }
173 173
174 /* make quite certain we are at EOF */ 174 /* make quite certain we are at EOF */
175 return (read(fd, &junk, 1)); 175 return (read(fd, &junk, 1));
176} 176}

cvs diff -r1.12 -r1.13 src/games/trek/trek.h (switch to unified diff)

--- src/games/trek/trek.h 2009/03/31 18:48:16 1.12
+++ src/games/trek/trek.h 2009/05/24 20:39:43 1.13
@@ -1,527 +1,527 @@ @@ -1,527 +1,527 @@
1/* $NetBSD: trek.h,v 1.12 2009/03/31 18:48:16 christos Exp $ */ 1/* $NetBSD: trek.h,v 1.13 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * @(#)trek.h 8.1 (Berkeley) 5/31/93 31 * @(#)trek.h 8.1 (Berkeley) 5/31/93
32 */ 32 */
33 33
34/* 34/*
35** Global Declarations 35** Global Declarations
36** 36**
37** Virtually all non-local variable declarations are made in this 37** Virtually all non-local variable declarations are made in this
38** file. Exceptions are those things which are initialized, which 38** file. Exceptions are those things which are initialized, which
39** are defined in "externs.c", and things which are local to one 39** are defined in "externs.c", and things which are local to one
40** program file. 40** program file.
41** 41**
42** So far as I know, nothing in here must be preinitialized to 42** So far as I know, nothing in here must be preinitialized to
43** zero. 43** zero.
44*/ 44*/
45 45
46/* external function definitions */ 46/* external function definitions */
47 47
48/********************* GALAXY **************************/ 48/********************* GALAXY **************************/
49 49
50/* galactic parameters */ 50/* galactic parameters */
51# define NSECTS 10 /* dimensions of quadrant in sectors */ 51#define NSECTS 10 /* dimensions of quadrant in sectors */
52# define NQUADS 8 /* dimension of galazy in quadrants */ 52#define NQUADS 8 /* dimension of galazy in quadrants */
53# define NINHAB 32 /* number of quadrants which are inhabited */ 53#define NINHAB 32 /* number of quadrants which are inhabited */
54 54
55struct quad /* definition for each quadrant */ 55struct quad /* definition for each quadrant */
56{ 56{
57 unsigned char bases; /* number of bases in this quadrant */ 57 unsigned char bases; /* number of bases in this quadrant */
58 char klings; /* number of Klingons in this quadrant */ 58 char klings; /* number of Klingons in this quadrant */
59 char holes; /* number of black holes in this quadrant */ 59 char holes; /* number of black holes in this quadrant */
60 int scanned; /* star chart entry (see below) */ 60 int scanned; /* star chart entry (see below) */
61 short stars; /* number of stars in this quadrant */ 61 short stars; /* number of stars in this quadrant */
62 char qsystemname; /* starsystem name (see below) */ 62 char qsystemname; /* starsystem name (see below) */
63}; 63};
64 64
65# define Q_DISTRESSED 0200 65#define Q_DISTRESSED 0200
66# define Q_SYSTEM 077 66#define Q_SYSTEM 077
67 67
68/* systemname conventions: 68/* systemname conventions:
69 * 1 -> NINHAB index into Systemname table for live system. 69 * 1 -> NINHAB index into Systemname table for live system.
70 * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM 70 * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM
71 * is the index into the Event table which will 71 * is the index into the Event table which will
72 * have the system name 72 * have the system name
73 * 0 dead or nonexistent starsystem 73 * 0 dead or nonexistent starsystem
74 * 74 *
75 * starchart ("scanned") conventions: 75 * starchart ("scanned") conventions:
76 * 0 -> 999 taken as is 76 * 0 -> 999 taken as is
77 * -1 not yet scanned ("...") 77 * -1 not yet scanned ("...")
78 * 1000 supernova ("///") 78 * 1000 supernova ("///")
79 * 1001 starbase + ??? (".1.") 79 * 1001 starbase + ??? (".1.")
80*/ 80*/
81 81
82/* ascii names of systems */ 82/* ascii names of systems */
83extern const char *const Systemname[NINHAB]; 83extern const char *const Systemname[NINHAB];
84 84
85/* quadrant definition */ 85/* quadrant definition */
86extern struct quad Quad[NQUADS][NQUADS]; 86extern struct quad Quad[NQUADS][NQUADS];
87 87
88/* defines for sector map (below) */ 88/* defines for sector map (below) */
89# define EMPTY '.' 89#define EMPTY '.'
90# define STAR '*' 90#define STAR '*'
91# define BASE '#' 91#define BASE '#'
92# define ENTERPRISE 'E' 92#define ENTERPRISE 'E'
93# define QUEENE 'Q' 93#define QUEENE 'Q'
94# define KLINGON 'K' 94#define KLINGON 'K'
95# define INHABIT '@' 95#define INHABIT '@'
96# define HOLE ' ' 96#define HOLE ' '
97 97
98/* current sector map */ 98/* current sector map */
99extern char Sect[NSECTS][NSECTS]; 99extern char Sect[NSECTS][NSECTS];
100 100
101 101
102 102
103/************************ DEVICES ******************************/ 103/************************ DEVICES ******************************/
104 104
105# define NDEV 16 /* max number of devices */ 105#define NDEV 16 /* max number of devices */
106 106
107/* device tokens */ 107/* device tokens */
108# define WARP 0 /* warp engines */ 108#define WARP 0 /* warp engines */
109# define SRSCAN 1 /* short range scanners */ 109#define SRSCAN 1 /* short range scanners */
110# define LRSCAN 2 /* long range scanners */ 110#define LRSCAN 2 /* long range scanners */
111# define PHASER 3 /* phaser control */ 111#define PHASER 3 /* phaser control */
112# define TORPED 4 /* photon torpedo control */ 112#define TORPED 4 /* photon torpedo control */
113# define IMPULSE 5 /* impulse engines */ 113#define IMPULSE 5 /* impulse engines */
114# define SHIELD 6 /* shield control */ 114#define SHIELD 6 /* shield control */
115# define COMPUTER 7 /* on board computer */ 115#define COMPUTER 7 /* on board computer */
116# define SSRADIO 8 /* subspace radio */ 116#define SSRADIO 8 /* subspace radio */
117# define LIFESUP 9 /* life support systems */ 117#define LIFESUP 9 /* life support systems */
118# define SINS 10 /* Space Inertial Navigation System */ 118#define SINS 10 /* Space Inertial Navigation System */
119# define CLOAK 11 /* cloaking device */ 119#define CLOAK 11 /* cloaking device */
120# define XPORTER 12 /* transporter */ 120#define XPORTER 12 /* transporter */
121# define SHUTTLE 13 /* shuttlecraft */ 121#define SHUTTLE 13 /* shuttlecraft */
122 122
123/* device names */ 123/* device names */
124struct device 124struct device
125{ 125{
126 const char *name; /* device name */ 126 const char *name; /* device name */
127 const char *person; /* the person who fixes it */ 127 const char *person; /* the person who fixes it */
128}; 128};
129 129
130extern const struct device Device[NDEV]; 130extern const struct device Device[NDEV];
131 131
132/*************************** EVENTS ****************************/ 132/*************************** EVENTS ****************************/
133 133
134# define NEVENTS 12 /* number of different event types */ 134#define NEVENTS 12 /* number of different event types */
135 135
136# define E_LRTB 1 /* long range tractor beam */ 136#define E_LRTB 1 /* long range tractor beam */
137# define E_KATSB 2 /* Klingon attacks starbase */ 137#define E_KATSB 2 /* Klingon attacks starbase */
138# define E_KDESB 3 /* Klingon destroys starbase */ 138#define E_KDESB 3 /* Klingon destroys starbase */
139# define E_ISSUE 4 /* distress call is issued */ 139#define E_ISSUE 4 /* distress call is issued */
140# define E_ENSLV 5 /* Klingons enslave a quadrant */ 140#define E_ENSLV 5 /* Klingons enslave a quadrant */
141# define E_REPRO 6 /* a Klingon is reproduced */ 141#define E_REPRO 6 /* a Klingon is reproduced */
142# define E_FIXDV 7 /* fix a device */ 142#define E_FIXDV 7 /* fix a device */
143# define E_ATTACK 8 /* Klingon attack during rest period */ 143#define E_ATTACK 8 /* Klingon attack during rest period */
144# define E_SNAP 9 /* take a snapshot for time warp */ 144#define E_SNAP 9 /* take a snapshot for time warp */
145# define E_SNOVA 10 /* supernova occurs */ 145#define E_SNOVA 10 /* supernova occurs */
146 146
147# define E_GHOST 0100 /* ghost of a distress call if ssradio out */ 147#define E_GHOST 0100 /* ghost of a distress call if ssradio out */
148# define E_HIDDEN 0200 /* event that is unreportable because ssradio out */ 148#define E_HIDDEN 0200 /* event unreportable because ssradio out */
149# define E_EVENT 077 /* mask to get event code */ 149#define E_EVENT 077 /* mask to get event code */
150 150
151struct event 151struct event
152{ 152{
153 unsigned char x, y; /* coordinates */ 153 unsigned char x, y; /* coordinates */
154 double date; /* trap stardate */ 154 double date; /* trap stardate */
155 char evcode; /* event type */ 155 char evcode; /* event type */
156 unsigned char systemname; /* starsystem name */ 156 unsigned char systemname; /* starsystem name */
157}; 157};
158/* systemname conventions: 158/* systemname conventions:
159 * 1 -> NINHAB index into Systemname table for reported distress calls 159 * 1 -> NINHAB index into Systemname table for reported distress calls
160 * 160 *
161 * evcode conventions: 161 * evcode conventions:
162 * 1 -> NEVENTS-1 event type 162 * 1 -> NEVENTS-1 event type
163 * + E_HIDDEN unreported (SSradio out) 163 * + E_HIDDEN unreported (SSradio out)
164 * + E_GHOST actually already expired 164 * + E_GHOST actually already expired
165 * 0 unallocated 165 * 0 unallocated
166 */ 166 */
167 167
168# define MAXEVENTS 25 /* max number of concurrently pending events */ 168#define MAXEVENTS 25 /* max number of concurrently pending events */
169 169
170extern struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */ 170extern struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */
171 171
172/***************************** KLINGONS *******************************/ 172/***************************** KLINGONS *******************************/
173 173
174struct kling 174struct kling
175{ 175{
176 unsigned char x, y; /* coordinates */ 176 unsigned char x, y; /* coordinates */
177 int power; /* power left */ 177 int power; /* power left */
178 double dist; /* distance to Enterprise */ 178 double dist; /* distance to Enterprise */
179 double avgdist; /* average over this move */ 179 double avgdist; /* average over this move */
180 char srndreq; /* set if surrender has been requested */ 180 char srndreq; /* set if surrender has been requested */
181}; 181};
182 182
183# define MAXKLQUAD 9 /* maximum klingons per quadrant */ 183#define MAXKLQUAD 9 /* maximum klingons per quadrant */
184 184
185/********************** MISCELLANEOUS ***************************/ 185/********************** MISCELLANEOUS ***************************/
186 186
187/* condition codes */ 187/* condition codes */
188# define GREEN 0 188#define GREEN 0
189# define DOCKED 1 189#define DOCKED 1
190# define YELLOW 2 190#define YELLOW 2
191# define RED 3 191#define RED 3
192 192
193/* starbase coordinates */ 193/* starbase coordinates */
194# define MAXBASES 9 /* maximum number of starbases in galaxy */ 194#define MAXBASES 9 /* maximum number of starbases in galaxy */
195 195
196/* distress calls */ 196/* distress calls */
197# define MAXDISTR 5 /* maximum concurrent distress calls */ 197#define MAXDISTR 5 /* maximum concurrent distress calls */
198 198
199/* phaser banks */ 199/* phaser banks */
200# define NBANKS 6 /* number of phaser banks */ 200#define NBANKS 6 /* number of phaser banks */
201 201
202struct xy 202struct xy
203{ 203{
204 unsigned char x, y; /* coordinates */ 204 unsigned char x, y; /* coordinates */
205}; 205};
206 206
207 207
208/* 208/*
209 * note that much of the stuff in the following structs CAN NOT 209 * note that much of the stuff in the following structs CAN NOT
210 * be moved around!!!! 210 * be moved around!!!!
211 */ 211 */
212 212
213 213
214/* information regarding the state of the starship */ 214/* information regarding the state of the starship */
215struct Ship_struct 215struct Ship_struct
216{ 216{
217 double warp; /* warp factor */ 217 double warp; /* warp factor */
218 double warp2; /* warp factor squared */ 218 double warp2; /* warp factor squared */
219 double warp3; /* warp factor cubed */ 219 double warp3; /* warp factor cubed */
220 char shldup; /* shield up flag */ 220 char shldup; /* shield up flag */
221 char cloaked; /* set if cloaking device on */ 221 char cloaked; /* set if cloaking device on */
222 int energy; /* starship's energy */ 222 int energy; /* starship's energy */
223 int shield; /* energy in shields */ 223 int shield; /* energy in shields */
224 double reserves; /* life support reserves */ 224 double reserves; /* life support reserves */
225 int crew; /* ship's complement */ 225 int crew; /* ship's complement */
226 int brigfree; /* space left in brig */ 226 int brigfree; /* space left in brig */
227 char torped; /* torpedoes */ 227 char torped; /* torpedoes */
228 char cloakgood; /* set if we have moved */ 228 char cloakgood; /* set if we have moved */
229 int quadx; /* quadrant x coord */ 229 int quadx; /* quadrant x coord */
230 int quady; /* quadrant y coord */ 230 int quady; /* quadrant y coord */
231 int sectx; /* sector x coord */ 231 int sectx; /* sector x coord */
232 int secty; /* sector y coord */ 232 int secty; /* sector y coord */
233 unsigned char cond; /* condition code */ 233 unsigned char cond; /* condition code */
234 char sinsbad; /* Space Inertial Navigation System condition */ 234 char sinsbad; /* Space Inertial Navigation System condition */
235 const char *shipname; /* name of current starship */ 235 const char *shipname; /* name of current starship */
236 char ship; /* current starship */ 236 char ship; /* current starship */
237 int distressed; /* number of distress calls */ 237 int distressed; /* number of distress calls */
238}; 238};
239extern struct Ship_struct Ship; 239extern struct Ship_struct Ship;
240 240
241/* sinsbad is set if SINS is working but not calibrated */ 241/* sinsbad is set if SINS is working but not calibrated */
242 242
243/* game related information, mostly scoring */ 243/* game related information, mostly scoring */
244struct Game_struct 244struct Game_struct
245{ 245{
246 int killk; /* number of klingons killed */ 246 int killk; /* number of klingons killed */
247 int deaths; /* number of deaths onboard Enterprise */ 247 int deaths; /* number of deaths onboard Enterprise */
248 char negenbar; /* number of hits on negative energy barrier */ 248 char negenbar; /* number of hits on negative energy barrier */
249 char killb; /* number of starbases killed */ 249 char killb; /* number of starbases killed */
250 int kills; /* number of stars killed */ 250 int kills; /* number of stars killed */
251 char skill; /* skill rating of player */ 251 char skill; /* skill rating of player */
252 char length; /* length of game */ 252 char length; /* length of game */
253 char killed; /* set if you were killed */ 253 char killed; /* set if you were killed */
254 char killinhab; /* number of inhabited starsystems killed */ 254 char killinhab; /* number of inhabited starsystems killed */
255 char tourn; /* set if a tournament game */ 255 char tourn; /* set if a tournament game */
256 char passwd[15]; /* game password */ 256 char passwd[15]; /* game password */
257 char snap; /* set if snapshot taken */ 257 char snap; /* set if snapshot taken */
258 char helps; /* number of help calls */ 258 char helps; /* number of help calls */
259 int captives; /* total number of captives taken */ 259 int captives; /* total number of captives taken */
260}; 260};
261extern struct Game_struct Game; 261extern struct Game_struct Game;
262 262
263/* per move information */ 263/* per move information */
264struct Move_struct 264struct Move_struct
265{ 265{
266 char free; /* set if a move is free */ 266 char free; /* set if a move is free */
267 char endgame; /* end of game flag */ 267 char endgame; /* end of game flag */
268 char shldchg; /* set if shields changed this move */ 268 char shldchg; /* set if shields changed this move */
269 char newquad; /* set if just entered this quadrant */ 269 char newquad; /* set if just entered this quadrant */
270 char resting; /* set if this move is a rest */ 270 char resting; /* set if this move is a rest */
271 double time; /* time used this move */ 271 double time; /* time used this move */
272}; 272};
273extern struct Move_struct Move; 273extern struct Move_struct Move;
274 274
275/* parametric information */ 275/* parametric information */
276struct Param_struct 276struct Param_struct
277{ 277{
278 unsigned char bases; /* number of starbases */ 278 unsigned char bases; /* number of starbases */
279 char klings; /* number of klingons */ 279 char klings; /* number of klingons */
280 double date; /* stardate */ 280 double date; /* stardate */
281 double time; /* time left */ 281 double time; /* time left */
282 double resource; /* Federation resources */ 282 double resource; /* Federation resources */
283 int energy; /* starship's energy */ 283 int energy; /* starship's energy */
284 int shield; /* energy in shields */ 284 int shield; /* energy in shields */
285 double reserves; /* life support reserves */ 285 double reserves; /* life support reserves */
286 int crew; /* size of ship's complement */ 286 int crew; /* size of ship's complement */
287 int brigfree; /* max possible number of captives */ 287 int brigfree; /* max possible number of captives */
288 char torped; /* photon torpedos */ 288 char torped; /* photon torpedos */
289 double damfac[NDEV]; /* damage factor */ 289 double damfac[NDEV]; /* damage factor */
290 double dockfac; /* docked repair time factor */ 290 double dockfac; /* docked repair time factor */
291 double regenfac; /* regeneration factor */ 291 double regenfac; /* regeneration factor */
292 int stopengy; /* energy to do emergency stop */ 292 int stopengy; /* energy to do emergency stop */
293 int shupengy; /* energy to put up shields */ 293 int shupengy; /* energy to put up shields */
294 int klingpwr; /* Klingon initial power */ 294 int klingpwr; /* Klingon initial power */
295 int warptime; /* time chewer multiplier */ 295 int warptime; /* time chewer multiplier */
296 double phasfac; /* Klingon phaser power eater factor */ 296 double phasfac; /* Klingon phaser power eater factor */
297 char moveprob[6]; /* probability that a Klingon moves */ 297 char moveprob[6]; /* probability that a Klingon moves */
298 double movefac[6]; /* Klingon move distance multiplier */ 298 double movefac[6]; /* Klingon move distance multiplier */
299 double eventdly[NEVENTS]; /* event time multipliers */ 299 double eventdly[NEVENTS]; /* event time multipliers */
300 double navigcrud[2]; /* navigation crudup factor */ 300 double navigcrud[2]; /* navigation crudup factor */
301 int cloakenergy; /* cloaking device energy per stardate */ 301 int cloakenergy; /* cloaking device energy per stardate */
302 double damprob[NDEV]; /* damage probability */ 302 double damprob[NDEV]; /* damage probability */
303 double hitfac; /* Klingon attack factor */ 303 double hitfac; /* Klingon attack factor */
304 int klingcrew; /* number of Klingons in a crew */ 304 int klingcrew; /* number of Klingons in a crew */
305 double srndrprob; /* surrender probability */ 305 double srndrprob; /* surrender probability */
306 int energylow; /* low energy mark (cond YELLOW) */ 306 int energylow; /* low energy mark (cond YELLOW) */
307}; 307};
308extern struct Param_struct Param; 308extern struct Param_struct Param;
309 309
310/* Sum of damage probabilities must add to 1000 */ 310/* Sum of damage probabilities must add to 1000 */
311 311
312/* other information kept in a snapshot */ 312/* other information kept in a snapshot */
313struct Now_struct 313struct Now_struct
314{ 314{
315 unsigned char bases; /* number of starbases */ 315 unsigned char bases; /* number of starbases */
316 char klings; /* number of klingons */ 316 char klings; /* number of klingons */
317 double date; /* stardate */ 317 double date; /* stardate */
318 double time; /* time left */ 318 double time; /* time left */
319 double resource; /* Federation resources */ 319 double resource; /* Federation resources */
320 char distressed; /* number of currently distressed quadrants */ 320 char distressed; /* number of currently distressed quadrants */
321 struct event *eventptr[NEVENTS]; /* pointer to event structs */ 321 struct event *eventptr[NEVENTS]; /* pointer to event structs */
322 struct xy base[MAXBASES]; /* locations of starbases */ 322 struct xy base[MAXBASES]; /* locations of starbases */
323}; 323};
324extern struct Now_struct Now; 324extern struct Now_struct Now;
325 325
326/* Other stuff, not dumped in a snapshot */ 326/* Other stuff, not dumped in a snapshot */
327struct Etc_struct 327struct Etc_struct
328{ 328{
329 struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */ 329 struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */
330 short nkling; /* number of Klingons in this sector */ 330 short nkling; /* number of Klingons in this sector */
331 /* < 0 means automatic override mode */ 331 /* < 0 means automatic override mode */
332 char fast; /* set if speed > 300 baud */ 332 char fast; /* set if speed > 300 baud */
333 struct xy starbase; /* starbase in current quadrant */ 333 struct xy starbase; /* starbase in current quadrant */
334 char snapshot[sizeof Quad + sizeof Event + sizeof Now]; /* snapshot for time warp */ 334 char snapshot[sizeof Quad + sizeof Event + sizeof Now]; /* snapshot for time warp */
335 char statreport; /* set to get a status report on a srscan */ 335 char statreport; /* set to get a status report on a srscan */
336}; 336};
337extern struct Etc_struct Etc; 337extern struct Etc_struct Etc;
338 338
339/* 339/*
340 * eventptr is a pointer to the event[] entry of the last 340 * eventptr is a pointer to the event[] entry of the last
341 * scheduled event of each type. Zero if no such event scheduled. 341 * scheduled event of each type. Zero if no such event scheduled.
342 */ 342 */
343 343
344/* Klingon move indicies */ 344/* Klingon move indicies */
345# define KM_OB 0 /* Old quadrant, Before attack */ 345#define KM_OB 0 /* Old quadrant, Before attack */
346# define KM_OA 1 /* Old quadrant, After attack */ 346#define KM_OA 1 /* Old quadrant, After attack */
347# define KM_EB 2 /* Enter quadrant, Before attack */ 347#define KM_EB 2 /* Enter quadrant, Before attack */
348# define KM_EA 3 /* Enter quadrant, After attack */ 348#define KM_EA 3 /* Enter quadrant, After attack */
349# define KM_LB 4 /* Leave quadrant, Before attack */ 349#define KM_LB 4 /* Leave quadrant, Before attack */
350# define KM_LA 5 /* Leave quadrant, After attack */ 350#define KM_LA 5 /* Leave quadrant, After attack */
351 351
352/* you lose codes */ 352/* you lose codes */
353# define L_NOTIME 1 /* ran out of time */ 353#define L_NOTIME 1 /* ran out of time */
354# define L_NOENGY 2 /* ran out of energy */ 354#define L_NOENGY 2 /* ran out of energy */
355# define L_DSTRYD 3 /* destroyed by a Klingon */ 355#define L_DSTRYD 3 /* destroyed by a Klingon */
356# define L_NEGENB 4 /* ran into the negative energy barrier */ 356#define L_NEGENB 4 /* ran into the negative energy barrier */
357# define L_SUICID 5 /* destroyed in a nova */ 357#define L_SUICID 5 /* destroyed in a nova */
358# define L_SNOVA 6 /* destroyed in a supernova */ 358#define L_SNOVA 6 /* destroyed in a supernova */
359# define L_NOLIFE 7 /* life support died (so did you) */ 359#define L_NOLIFE 7 /* life support died (so did you) */
360# define L_NOHELP 8 /* you could not be rematerialized */ 360#define L_NOHELP 8 /* you could not be rematerialized */
361# define L_TOOFAST 9 /* pretty stupid going at warp 10 */ 361#define L_TOOFAST 9 /* pretty stupid going at warp 10 */
362# define L_STAR 10 /* ran into a star */ 362#define L_STAR 10 /* ran into a star */
363# define L_DSTRCT 11 /* self destructed */ 363#define L_DSTRCT 11 /* self destructed */
364# define L_CAPTURED 12 /* captured by Klingons */ 364#define L_CAPTURED 12 /* captured by Klingons */
365# define L_NOCREW 13 /* you ran out of crew */ 365#define L_NOCREW 13 /* you ran out of crew */
366 366
367/****************** COMPILE OPTIONS ***********************/ 367/****************** COMPILE OPTIONS ***********************/
368 368
369/* Trace info */ 369/* Trace info */
370# define xTRACE 1 370#define xTRACE 1
371extern int Trace; 371extern int Trace;
372 372
373# define TOOLARGE (DBL_MAX / 2) /* < DOUBLE_MAX for everyone */ 373#define TOOLARGE (DBL_MAX / 2) /* < DOUBLE_MAX for everyone */
374 374
375/* abandon.c */ 375/* abandon.c */
376void abandon(int); 376void abandon(int);
377 377
378/* attack.c */ 378/* attack.c */
379void attack(int); 379void attack(int);
380 380
381/* autover.c */ 381/* autover.c */
382void autover(void); 382void autover(void);
383 383
384/* capture.c */ 384/* capture.c */
385void capture(int); 385void capture(int);
386struct kling *selectklingon(void); 386struct kling *selectklingon(void);
387 387
388/* cgetc.c */ 388/* cgetc.c */
389char cgetc(int); 389char cgetc(int);
390 390
391/* check_out.c */ 391/* check_out.c */
392int check_out(int); 392int check_out(int);
393 393
394/* checkcond.c */ 394/* checkcond.c */
395void checkcond(void); 395void checkcond(void);
396 396
397/* compkl.c */ 397/* compkl.c */
398void compkldist(int); 398void compkldist(int);
399 399
400/* computer.c */ 400/* computer.c */
401void computer(int); 401void computer(int);
402 402
403/* damage.c */ 403/* damage.c */
404void damage(int, double); 404void damage(int, double);
405 405
406/* damaged.c */ 406/* damaged.c */
407int damaged(int); 407int damaged(int);
408 408
409/* dcrept.c */ 409/* dcrept.c */
410void dcrept(int); 410void dcrept(int);
411 411
412/* destruct.c */ 412/* destruct.c */
413void destruct(int); 413void destruct(int);
414 414
415/* dock.c */ 415/* dock.c */
416void dock(int); 416void dock(int);
417void undock(int); 417void undock(int);
418 418
419/* dumpgame.c */ 419/* dumpgame.c */
420void dumpgame(int); 420void dumpgame(int);
421int restartgame(void); 421int restartgame(void);
422 422
423/* dumpme.c */ 423/* dumpme.c */
424void dumpme(int); 424void dumpme(int);
425 425
426/* dumpssradio.c */ 426/* dumpssradio.c */
427int dumpssradio(void); 427int dumpssradio(void);
428 428
429/* events.c */ 429/* events.c */
430int events(int); 430int events(int);
431 431
432/* externs.c */ 432/* externs.c */
433 433
434/* getcodi.c */ 434/* getcodi.c */
435int getcodi(int *, double *); 435int getcodi(int *, double *);
436 436
437/* help.c */ 437/* help.c */
438void help(int); 438void help(int);
439 439
440/* impulse.c */ 440/* impulse.c */
441void impulse(int); 441void impulse(int);
442 442
443/* initquad.c */ 443/* initquad.c */
444void initquad(int); 444void initquad(int);
445void sector(int *, int *); 445void sector(int *, int *);
446 446
447/* kill.c */ 447/* kill.c */
448void killk(int, int ); 448void killk(int, int );
449void killb(int, int ); 449void killb(int, int );
450void kills(int, int , int); 450void kills(int, int , int);
451void killd(int, int , int); 451void killd(int, int , int);
452 452
453/* klmove.c */ 453/* klmove.c */
454void klmove(int); 454void klmove(int);
455 455
456/* lose.c */ 456/* lose.c */
457void lose(int) __attribute__((__noreturn__)); 457void lose(int) __attribute__((__noreturn__));
458 458
459/* lrscan.c */ 459/* lrscan.c */
460void lrscan(int); 460void lrscan(int);
461 461
462/* move.c */ 462/* move.c */
463double move(int, int, double, double); 463double move(int, int, double, double);
464 464
465/* nova.c */ 465/* nova.c */
466void nova(int, int ); 466void nova(int, int );
467 467
468/* out.c */ 468/* out.c */
469void out(int); 469void out(int);
470 470
471/* phaser.c */ 471/* phaser.c */
472void phaser(int); 472void phaser(int);
473 473
474/* play.c */ 474/* play.c */
475void myreset(int) __attribute__((__noreturn__)); 475void myreset(int) __attribute__((__noreturn__));
476void play(void) __attribute__((__noreturn__)); 476void play(void) __attribute__((__noreturn__));
477 477
478/* ram.c */ 478/* ram.c */
479void ram(int, int ); 479void ram(int, int );
480 480
481/* ranf.c */ 481/* ranf.c */
482int ranf(int); 482int ranf(int);
483double franf(void); 483double franf(void);
484 484
485/* rest.c */ 485/* rest.c */
486void rest(int); 486void rest(int);
487 487
488/* schedule.c */ 488/* schedule.c */
489struct event *schedule(int, double, int, int , int); 489struct event *schedule(int, double, int, int , int);
490void reschedule(struct event *, double); 490void reschedule(struct event *, double);
491void unschedule(struct event *); 491void unschedule(struct event *);
492struct event *xsched(int, int, int, int , int ); 492struct event *xsched(int, int, int, int , int );
493void xresched(struct event *, int, int); 493void xresched(struct event *, int, int);
494 494
495/* score.c */ 495/* score.c */
496long score(void); 496long score(void);
497 497
498/* setup.c */ 498/* setup.c */
499void setup(void); 499void setup(void);
500 500
501/* setwarp.c */ 501/* setwarp.c */
502void setwarp(int); 502void setwarp(int);
503 503
504/* shield.c */ 504/* shield.c */
505void shield(int); 505void shield(int);
506 506
507/* snova.c */ 507/* snova.c */
508void snova(int, int ); 508void snova(int, int );
509 509
510/* srscan.c */ 510/* srscan.c */
511void srscan(int); 511void srscan(int);
512 512
513/* systemname.c */ 513/* systemname.c */
514const char *systemname(const struct quad *); 514const char *systemname(const struct quad *);
515 515
516/* torped.c */ 516/* torped.c */
517void torped(int); 517void torped(int);
518 518
519/* visual.c */ 519/* visual.c */
520void visual(int); 520void visual(int);
521 521
522/* warp.c */ 522/* warp.c */
523void dowarp(int); 523void dowarp(int);
524void warp(int, int, double); 524void warp(int, int, double);
525 525
526/* win.c */ 526/* win.c */
527void win(void) __attribute__((__noreturn__)); 527void win(void) __attribute__((__noreturn__));

cvs diff -r1.14 -r1.15 src/games/trek/main.c (switch to unified diff)

--- src/games/trek/main.c 2009/05/24 19:18:44 1.14
+++ src/games/trek/main.c 2009/05/24 20:39:43 1.15
@@ -1,251 +1,251 @@ @@ -1,251 +1,251 @@
1/* $NetBSD: main.c,v 1.14 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: main.c,v 1.15 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1980, 1993\ 34__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
35 The Regents of the University of California. All rights reserved."); 35 The Regents of the University of California. All rights reserved.");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#ifndef lint 38#ifndef lint
39#if 0 39#if 0
40static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; 40static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
41#else 41#else
42__RCSID("$NetBSD: main.c,v 1.14 2009/05/24 19:18:44 dholland Exp $"); 42__RCSID("$NetBSD: main.c,v 1.15 2009/05/24 20:39:43 dholland Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#include <stdio.h> 46#include <stdio.h>
47#include <setjmp.h> 47#include <setjmp.h>
48#include <termios.h> 48#include <termios.h>
49#include <stdlib.h> 49#include <stdlib.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <err.h> 51#include <err.h>
52#include <time.h> 52#include <time.h>
53#include <sys/types.h> 53#include <sys/types.h>
54#include "trek.h" 54#include "trek.h"
55#include "getpar.h" 55#include "getpar.h"
56 56
57# define PRIO 00 /* default priority */ 57#define PRIO 00 /* default priority */
58 58
59uid_t Mother = 51 + (51 << 8); 59uid_t Mother = 51 + (51 << 8);
60 60
61/* 61/*
62** #### ##### # #### ##### #### ##### # # 62** #### ##### # #### ##### #### ##### # #
63** # # # # # # # # # # # # 63** # # # # # # # # # # # #
64** ### # ##### #### # #### ### ### 64** ### # ##### #### # #### ### ###
65** # # # # # # # # # # # # 65** # # # # # # # # # # # #
66** #### # # # # # # # # ##### # # 66** #### # # # # # # # # ##### # #
67** 67**
68** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help 68** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
69** from Jeff Poskanzer and Pete Rubinstein. 69** from Jeff Poskanzer and Pete Rubinstein.
70** 70**
71** I also want to thank everyone here at Berkeley who 71** I also want to thank everyone here at Berkeley who
72** where crazy enough to play the undebugged game. I want to 72** where crazy enough to play the undebugged game. I want to
73** particularly thank Nick Whyte, who made considerable 73** particularly thank Nick Whyte, who made considerable
74** suggestions regarding the content of the game. Why, I'll 74** suggestions regarding the content of the game. Why, I'll
75** never forget the time he suggested the name for the 75** never forget the time he suggested the name for the
76** "capture" command. 76** "capture" command.
77** 77**
78** Please send comments, questions, and suggestions about this 78** Please send comments, questions, and suggestions about this
79** game to: 79** game to:
80** Eric P. Allman 80** Eric P. Allman
81** Project INGRES 81** Project INGRES
82** Electronics Research Laboratory 82** Electronics Research Laboratory
83** Cory Hall 83** Cory Hall
84** University of California 84** University of California
85** Berkeley, California 94720 85** Berkeley, California 94720
86** 86**
87** If you make ANY changes in the game, I sure would like to 87** If you make ANY changes in the game, I sure would like to
88** know about them. It is sort of an ongoing project for me, 88** know about them. It is sort of an ongoing project for me,
89** and I very much want to put in any bug fixes and improvements 89** and I very much want to put in any bug fixes and improvements
90** that you might come up with. 90** that you might come up with.
91** 91**
92** FORTRASH version by Kay R. Fisher (DEC) "and countless others". 92** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
93** That was adapted from the "original BASIC program" (ha!) by 93** That was adapted from the "original BASIC program" (ha!) by
94** Mike Mayfield (Centerline Engineering). 94** Mike Mayfield (Centerline Engineering).
95** 95**
96** Additional inspiration taken from FORTRAN version by 96** Additional inspiration taken from FORTRAN version by
97** David Matuszek and Paul Reynolds which runs on the CDC 97** David Matuszek and Paul Reynolds which runs on the CDC
98** 7600 at Lawrence Berkeley Lab, maintained there by 98** 7600 at Lawrence Berkeley Lab, maintained there by
99** Andy Davidson. This version is also available at LLL 99** Andy Davidson. This version is also available at LLL
100** and at LMSC. In all fairness, this version was the 100** and at LMSC. In all fairness, this version was the
101** major inspiration for this version of the game (trans- 101** major inspiration for this version of the game (trans-
102** lation: I ripped off a whole lot of code). 102** lation: I ripped off a whole lot of code).
103** 103**
104** Minor other input from the "Battelle Version 7A" by Joe Miller 104** Minor other input from the "Battelle Version 7A" by Joe Miller
105** (Graphics Systems Group, Battelle-Columbus Labs) and 105** (Graphics Systems Group, Battelle-Columbus Labs) and
106** Ross Pavlac (Systems Programmer, Battelle Memorial 106** Ross Pavlac (Systems Programmer, Battelle Memorial
107** Institute). That version was written in December '74 107** Institute). That version was written in December '74
108** and extensively modified June '75. It was adapted 108** and extensively modified June '75. It was adapted
109** from the FTN version by Ron Williams of CDC Sunnyvale, 109** from the FTN version by Ron Williams of CDC Sunnyvale,
110** which was adapted from the Basic version distributed 110** which was adapted from the Basic version distributed
111** by DEC. It also had "neat stuff swiped" from T. T. 111** by DEC. It also had "neat stuff swiped" from T. T.
112** Terry and Jim Korp (University of Texas), Hicks (Penn 112** Terry and Jim Korp (University of Texas), Hicks (Penn
113** U.), and Rick Maus (Georgia Tech). Unfortunately, it 113** U.), and Rick Maus (Georgia Tech). Unfortunately, it
114** was not as readable as it could have been and so the 114** was not as readable as it could have been and so the
115** translation effort was severely hampered. None the 115** translation effort was severely hampered. None the
116** less, I got the idea of inhabited starsystems from this 116** less, I got the idea of inhabited starsystems from this
117** version. 117** version.
118** 118**
119** Permission is given for use, copying, and modification of 119** Permission is given for use, copying, and modification of
120** all or part of this program and related documentation, 120** all or part of this program and related documentation,
121** provided that all reference to the authors are maintained. 121** provided that all reference to the authors are maintained.
122** 122**
123** 123**
124********************************************************************** 124**********************************************************************
125** 125**
126** NOTES TO THE MAINTAINER: 126** NOTES TO THE MAINTAINER:
127** 127**
128** There is a compilation option xTRACE which must be set for any 128** There is a compilation option xTRACE which must be set for any
129** trace information to be generated. It is probably defined in 129** trace information to be generated. It is probably defined in
130** the version that you get. It can be removed, however, if you 130** the version that you get. It can be removed, however, if you
131** have trouble finding room in core. 131** have trouble finding room in core.
132** 132**
133** Many things in trek are not as clear as they might be, but are 133** Many things in trek are not as clear as they might be, but are
134** done to reduce space. I compile with the -f and -O flags. I 134** done to reduce space. I compile with the -f and -O flags. I
135** am constrained to running with non-separated I/D space, since 135** am constrained to running with non-separated I/D space, since
136** we don't have doubleing point hardware here; even if we did, I 136** we don't have doubleing point hardware here; even if we did, I
137** would like trek to be available to the large number of people 137** would like trek to be available to the large number of people
138** who either have an 11/40 or do not have FP hardware. I also 138** who either have an 11/40 or do not have FP hardware. I also
139** found it desirable to make the code run reentrant, so this 139** found it desirable to make the code run reentrant, so this
140** added even more space constraints. 140** added even more space constraints.
141** 141**
142** I use the portable C library to do my I/O. This is done be- 142** I use the portable C library to do my I/O. This is done be-
143** cause I wanted the game easily transportable to other C 143** cause I wanted the game easily transportable to other C
144** implementations, and because I was too lazy to do the doubleing 144** implementations, and because I was too lazy to do the doubleing
145** point input myself. Little did I know. The portable C library 145** point input myself. Little did I know. The portable C library
146** released by Bell Labs has more bugs than you would believe, so 146** released by Bell Labs has more bugs than you would believe, so
147** I ended up rewriting the whole blessed thing. Trek excercises 147** I ended up rewriting the whole blessed thing. Trek excercises
148** many of the bugs in it, as well as bugs in some of the section 148** many of the bugs in it, as well as bugs in some of the section
149** III UNIX routines. We have fixed them here. One main problem 149** III UNIX routines. We have fixed them here. One main problem
150** was a bug in alloc() that caused it to always ask for a large 150** was a bug in alloc() that caused it to always ask for a large
151** hunk of memory, which worked fine unless you were almost out, 151** hunk of memory, which worked fine unless you were almost out,
152** which I inevitably was. If you want the code for all of this 152** which I inevitably was. If you want the code for all of this
153** stuff, it is also available through me. 153** stuff, it is also available through me.
154** 154**
155*********************************************************************** 155***********************************************************************
156*/ 156*/
157 157
158jmp_buf env; 158jmp_buf env;
159 159
160int main(int, char **); 160int main(int, char **);
161 161
162int 162int
163main(int argc, char **argv) 163main(int argc, char **argv)
164{ 164{
165 time_t curtime; 165 time_t curtime;
166 long vect; 166 long vect;
167 char opencode; 167 char opencode;
168 int prio; 168 int prio;
169 int ac; 169 int ac;
170 char **av; 170 char **av;
171 struct termios argp; 171 struct termios argp;
172 172
173 /* Revoke setgid privileges */ 173 /* Revoke setgid privileges */
174 setgid(getgid()); 174 setgid(getgid());
175 175
176 av = argv; 176 av = argv;
177 ac = argc; 177 ac = argc;
178 av++; 178 av++;
179 time(&curtime); 179 time(&curtime);
180 vect = (long) curtime; 180 vect = (long) curtime;
181 srand(vect); 181 srand(vect);
182 opencode = 'w'; 182 opencode = 'w';
183 prio = PRIO; 183 prio = PRIO;
184 184
185 if (tcgetattr(1, &argp) == 0) 185 if (tcgetattr(1, &argp) == 0)
186 { 186 {
187 if (cfgetispeed(&argp) < B1200) 187 if (cfgetispeed(&argp) < B1200)
188 Etc.fast++; 188 Etc.fast++;
189 } 189 }
190 190
191 while (ac > 1 && av[0][0] == '-') 191 while (ac > 1 && av[0][0] == '-')
192 { 192 {
193 switch (av[0][1]) 193 switch (av[0][1])
194 { 194 {
195 case 'a': /* append to log file */ 195 case 'a': /* append to log file */
196 opencode = 'a'; 196 opencode = 'a';
197 break; 197 break;
198 198
199 case 'f': /* set fast mode */ 199 case 'f': /* set fast mode */
200 Etc.fast++; 200 Etc.fast++;
201 break; 201 break;
202 202
203 case 's': /* set slow mode */ 203 case 's': /* set slow mode */
204 Etc.fast = 0; 204 Etc.fast = 0;
205 break; 205 break;
206 206
207# ifdef xTRACE 207#ifdef xTRACE
208 case 't': /* trace */ 208 case 't': /* trace */
209 if (getuid() != Mother) 209 if (getuid() != Mother)
210 goto badflag; 210 goto badflag;
211 Trace++; 211 Trace++;
212 break; 212 break;
213# endif 213#endif
214 214
215 case 'p': /* set priority */ 215 case 'p': /* set priority */
216 if (getuid() != Mother) 216 if (getuid() != Mother)
217 goto badflag; 217 goto badflag;
218 prio = atoi(av[0] + 2); 218 prio = atoi(av[0] + 2);
219 break; 219 break;
220 220
221 default: 221 default:
222 badflag: 222 badflag:
223 printf("Invalid option: %s\n", av[0]); 223 printf("Invalid option: %s\n", av[0]);
224 224
225 } 225 }
226 ac--; 226 ac--;
227 av++; 227 av++;
228 } 228 }
229 if (ac > 2) 229 if (ac > 2)
230 errx(1, "arg count"); 230 errx(1, "arg count");
231 /* 231 /*
232 if (ac > 1) 232 if (ac > 1)
233 f_log = fopen(av[0], opencode); 233 f_log = fopen(av[0], opencode);
234 */ 234 */
235 235
236 printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n"); 236 printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
237 237
238 if (setjmp(env)) 238 if (setjmp(env))
239 { 239 {
240 if ( !getynpar("Another game") ) 240 if ( !getynpar("Another game") )
241 exit(0); 241 exit(0);
242 } 242 }
243 do 243 do
244 { 244 {
245 setup(); 245 setup();
246 play(); 246 play();
247 } while (getynpar("Another game")); 247 } while (getynpar("Another game"));
248 248
249 fflush(stdout); 249 fflush(stdout);
250 return 0; 250 return 0;
251} 251}

cvs diff -r1.7 -r1.8 src/games/trek/move.c (switch to unified diff)

--- src/games/trek/move.c 2009/05/24 19:18:44 1.7
+++ src/games/trek/move.c 2009/05/24 20:39:43 1.8
@@ -1,232 +1,232 @@ @@ -1,232 +1,232 @@
1/* $NetBSD: move.c,v 1.7 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: move.c,v 1.8 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: move.c,v 1.7 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: move.c,v 1.8 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <math.h> 42#include <math.h>
43#include "trek.h" 43#include "trek.h"
44 44
45/* 45/*
46** Move Under Warp or Impulse Power 46** Move Under Warp or Impulse Power
47** 47**
48** `Ramflag' is set if we are to be allowed to ram stars, 48** `Ramflag' is set if we are to be allowed to ram stars,
49** Klingons, etc. This is passed from warp(), which gets it from 49** Klingons, etc. This is passed from warp(), which gets it from
50** either play() or ram(). Course is the course (0 -> 360) at 50** either play() or ram(). Course is the course (0 -> 360) at
51** which we want to move. `Speed' is the speed we 51** which we want to move. `Speed' is the speed we
52** want to go, and `time' is the expected time. It 52** want to go, and `time' is the expected time. It
53** can get cut short if a long range tractor beam is to occur. We 53** can get cut short if a long range tractor beam is to occur. We
54** cut short the move so that the user doesn't get docked time and 54** cut short the move so that the user doesn't get docked time and
55** energy for distance which he didn't travel. 55** energy for distance which he didn't travel.
56** 56**
57** We check the course through the current quadrant to see that he 57** We check the course through the current quadrant to see that he
58** doesn't run into anything. After that, though, space sort of 58** doesn't run into anything. After that, though, space sort of
59** bends around him. Note that this puts us in the awkward posi- 59** bends around him. Note that this puts us in the awkward posi-
60** tion of being able to be dropped into a sector which is com- 60** tion of being able to be dropped into a sector which is com-
61** pletely surrounded by stars. Oh Well. 61** pletely surrounded by stars. Oh Well.
62** 62**
63** If the SINS (Space Inertial Navigation System) is out, we ran- 63** If the SINS (Space Inertial Navigation System) is out, we ran-
64** domize the course accordingly before ever starting to move. 64** domize the course accordingly before ever starting to move.
65** We will still move in a straight line. 65** We will still move in a straight line.
66** 66**
67** Note that if your computer is out, you ram things anyway. In 67** Note that if your computer is out, you ram things anyway. In
68** other words, if your computer and sins are both out, you're in 68** other words, if your computer and sins are both out, you're in
69** potentially very bad shape. 69** potentially very bad shape.
70** 70**
71** Klingons get a chance to zap you as you leave the quadrant. 71** Klingons get a chance to zap you as you leave the quadrant.
72** By the way, they also try to follow you (heh heh). 72** By the way, they also try to follow you (heh heh).
73** 73**
74** Return value is the actual amount of time used. 74** Return value is the actual amount of time used.
75** 75**
76** 76**
77** Uses trace flag 4. 77** Uses trace flag 4.
78*/ 78*/
79 79
80double 80double
81move(int ramflag, int course, double time, double speed) 81move(int ramflag, int course, double time, double speed)
82{ 82{
83 double angle; 83 double angle;
84 double x, y, dx, dy; 84 double x, y, dx, dy;
85 int ix = 0, iy = 0; 85 int ix = 0, iy = 0;
86 double bigger; 86 double bigger;
87 int n; 87 int n;
88 int i; 88 int i;
89 double dist; 89 double dist;
90 double sectsize; 90 double sectsize;
91 double xn; 91 double xn;
92 double evtime; 92 double evtime;
93 93
94# ifdef xTRACE 94#ifdef xTRACE
95 if (Trace) 95 if (Trace)
96 printf("move: ramflag %d course %d time %.2f speed %.2f\n", 96 printf("move: ramflag %d course %d time %.2f speed %.2f\n",
97 ramflag, course, time, speed); 97 ramflag, course, time, speed);
98# endif 98#endif
99 sectsize = NSECTS; 99 sectsize = NSECTS;
100 /* initialize delta factors for move */ 100 /* initialize delta factors for move */
101 angle = course * 0.0174532925; 101 angle = course * 0.0174532925;
102 if (damaged(SINS)) 102 if (damaged(SINS))
103 angle += Param.navigcrud[1] * (franf() - 0.5); 103 angle += Param.navigcrud[1] * (franf() - 0.5);
104 else 104 else
105 if (Ship.sinsbad) 105 if (Ship.sinsbad)
106 angle += Param.navigcrud[0] * (franf() - 0.5); 106 angle += Param.navigcrud[0] * (franf() - 0.5);
107 dx = -cos(angle); 107 dx = -cos(angle);
108 dy = sin(angle); 108 dy = sin(angle);
109 bigger = fabs(dx); 109 bigger = fabs(dx);
110 dist = fabs(dy); 110 dist = fabs(dy);
111 if (dist > bigger) 111 if (dist > bigger)
112 bigger = dist; 112 bigger = dist;
113 dx /= bigger; 113 dx /= bigger;
114 dy /= bigger; 114 dy /= bigger;
115 115
116 /* check for long range tractor beams */ 116 /* check for long range tractor beams */
117 /**** TEMPORARY CODE == DEBUGGING ****/ 117 /**** TEMPORARY CODE == DEBUGGING ****/
118 evtime = Now.eventptr[E_LRTB]->date - Now.date; 118 evtime = Now.eventptr[E_LRTB]->date - Now.date;
119# ifdef xTRACE 119#ifdef xTRACE
120 if (Trace) 120 if (Trace)
121 printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n", 121 printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
122 Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode, 122 Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode,
123 Now.eventptr[E_LRTB]->date, evtime); 123 Now.eventptr[E_LRTB]->date, evtime);
124# endif 124#endif
125 if (time > evtime && Etc.nkling < 3) 125 if (time > evtime && Etc.nkling < 3)
126 { 126 {
127 /* then we got a LRTB */ 127 /* then we got a LRTB */
128 evtime += 0.005; 128 evtime += 0.005;
129 time = evtime; 129 time = evtime;
130 } 130 }
131 else 131 else
132 evtime = -1.0e50; 132 evtime = -1.0e50;
133 dist = time * speed; 133 dist = time * speed;
134 134
135 /* move within quadrant */ 135 /* move within quadrant */
136 Sect[Ship.sectx][Ship.secty] = EMPTY; 136 Sect[Ship.sectx][Ship.secty] = EMPTY;
137 x = Ship.sectx + 0.5; 137 x = Ship.sectx + 0.5;
138 y = Ship.secty + 0.5; 138 y = Ship.secty + 0.5;
139 xn = NSECTS * dist * bigger; 139 xn = NSECTS * dist * bigger;
140 n = xn + 0.5; 140 n = xn + 0.5;
141# ifdef xTRACE 141#ifdef xTRACE
142 if (Trace) 142 if (Trace)
143 printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n); 143 printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
144# endif 144#endif
145 Move.free = 0; 145 Move.free = 0;
146 146
147 for (i = 0; i < n; i++) 147 for (i = 0; i < n; i++)
148 { 148 {
149 ix = (x += dx); 149 ix = (x += dx);
150 iy = (y += dy); 150 iy = (y += dy);
151# ifdef xTRACE 151#ifdef xTRACE
152 if (Trace) 152 if (Trace)
153 printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y); 153 printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
154# endif 154#endif
155 if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) 155 if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize)
156 { 156 {
157 /* enter new quadrant */ 157 /* enter new quadrant */
158 dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn; 158 dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
159 dy = Ship.quady * NSECTS + Ship.secty + dy * xn; 159 dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
160 if (dx < 0.0) 160 if (dx < 0.0)
161 ix = -1; 161 ix = -1;
162 else 162 else
163 ix = dx + 0.5; 163 ix = dx + 0.5;
164 if (dy < 0.0) 164 if (dy < 0.0)
165 iy = -1; 165 iy = -1;
166 else 166 else
167 iy = dy + 0.5; 167 iy = dy + 0.5;
168# ifdef xTRACE 168#ifdef xTRACE
169 if (Trace) 169 if (Trace)
170 printf("New quad: ix = %d, iy = %d\n", ix, iy); 170 printf("New quad: ix = %d, iy = %d\n", ix, iy);
171# endif 171#endif
172 Ship.sectx = x; 172 Ship.sectx = x;
173 Ship.secty = y; 173 Ship.secty = y;
174 compkldist(0); 174 compkldist(0);
175 Move.newquad = 2; 175 Move.newquad = 2;
176 attack(0); 176 attack(0);
177 checkcond(); 177 checkcond();
178 Ship.quadx = ix / NSECTS; 178 Ship.quadx = ix / NSECTS;
179 Ship.quady = iy / NSECTS; 179 Ship.quady = iy / NSECTS;
180 Ship.sectx = ix % NSECTS; 180 Ship.sectx = ix % NSECTS;
181 Ship.secty = iy % NSECTS; 181 Ship.secty = iy % NSECTS;
182 if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || 182 if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
183 Ship.quady >= NQUADS) { 183 Ship.quady >= NQUADS) {
184 if (!damaged(COMPUTER)) { 184 if (!damaged(COMPUTER)) {
185 dumpme(0); 185 dumpme(0);
186 } else 186 } else
187 lose(L_NEGENB); 187 lose(L_NEGENB);
188 } 188 }
189 initquad(0); 189 initquad(0);
190 n = 0; 190 n = 0;
191 break; 191 break;
192 } 192 }
193 if (Sect[ix][iy] != EMPTY) 193 if (Sect[ix][iy] != EMPTY)
194 { 194 {
195 /* we just hit something */ 195 /* we just hit something */
196 if (!damaged(COMPUTER) && ramflag <= 0) 196 if (!damaged(COMPUTER) && ramflag <= 0)
197 { 197 {
198 ix = x - dx; 198 ix = x - dx;
199 iy = y - dy; 199 iy = y - dy;
200 printf("Computer reports navigation error; %s stopped at %d,%d\n", 200 printf("Computer reports navigation error; %s stopped at %d,%d\n",
201 Ship.shipname, ix, iy); 201 Ship.shipname, ix, iy);
202 Ship.energy -= Param.stopengy * speed; 202 Ship.energy -= Param.stopengy * speed;
203 break; 203 break;
204 } 204 }
205 /* test for a black hole */ 205 /* test for a black hole */
206 if (Sect[ix][iy] == HOLE) 206 if (Sect[ix][iy] == HOLE)
207 { 207 {
208 /* get dumped elsewhere in the galaxy */ 208 /* get dumped elsewhere in the galaxy */
209 dumpme(1); 209 dumpme(1);
210 initquad(0); 210 initquad(0);
211 n = 0; 211 n = 0;
212 break; 212 break;
213 } 213 }
214 ram(ix, iy); 214 ram(ix, iy);
215 break; 215 break;
216 } 216 }
217 } 217 }
218 if (n > 0) 218 if (n > 0)
219 { 219 {
220 dx = Ship.sectx - ix; 220 dx = Ship.sectx - ix;
221 dy = Ship.secty - iy; 221 dy = Ship.secty - iy;
222 dist = sqrt(dx * dx + dy * dy) / NSECTS; 222 dist = sqrt(dx * dx + dy * dy) / NSECTS;
223 time = dist / speed; 223 time = dist / speed;
224 if (evtime > time) 224 if (evtime > time)
225 time = evtime; /* spring the LRTB trap */ 225 time = evtime; /* spring the LRTB trap */
226 Ship.sectx = ix; 226 Ship.sectx = ix;
227 Ship.secty = iy; 227 Ship.secty = iy;
228 } 228 }
229 Sect[Ship.sectx][Ship.secty] = Ship.ship; 229 Sect[Ship.sectx][Ship.secty] = Ship.ship;
230 compkldist(0); 230 compkldist(0);
231 return (time); 231 return (time);
232} 232}

cvs diff -r1.7 -r1.8 src/games/trek/systemname.c (switch to unified diff)

--- src/games/trek/systemname.c 2009/05/24 19:18:44 1.7
+++ src/games/trek/systemname.c 2009/05/24 20:39:43 1.8
@@ -1,70 +1,70 @@ @@ -1,70 +1,70 @@
1/* $NetBSD: systemname.c,v 1.7 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: systemname.c,v 1.8 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)systemname.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)systemname.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: systemname.c,v 1.7 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: systemname.c,v 1.8 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41# include "trek.h" 41#include "trek.h"
42 42
43/* 43/*
44** RETRIEVE THE STARSYSTEM NAME 44** RETRIEVE THE STARSYSTEM NAME
45** 45**
46** Very straightforward, this routine just gets the starsystem 46** Very straightforward, this routine just gets the starsystem
47** name. It returns zero if none in the specified quadrant 47** name. It returns zero if none in the specified quadrant
48** (which, by the way, is passed it). 48** (which, by the way, is passed it).
49** 49**
50** This routine knows all about such things as distressed 50** This routine knows all about such things as distressed
51** starsystems, etc. 51** starsystems, etc.
52*/ 52*/
53 53
54const char * 54const char *
55systemname(const struct quad *q1) 55systemname(const struct quad *q1)
56{ 56{
57 const struct quad *q; 57 const struct quad *q;
58 int i; 58 int i;
59 59
60 q = q1; 60 q = q1;
61 61
62 i = q->qsystemname; 62 i = q->qsystemname;
63 if (i & Q_DISTRESSED) 63 if (i & Q_DISTRESSED)
64 i = Event[i & Q_SYSTEM].systemname; 64 i = Event[i & Q_SYSTEM].systemname;
65 65
66 i &= Q_SYSTEM; 66 i &= Q_SYSTEM;
67 if (i == 0) 67 if (i == 0)
68 return (0); 68 return (0);
69 return (Systemname[i]); 69 return (Systemname[i]);
70} 70}

cvs diff -r1.11 -r1.12 src/games/trek/phaser.c (switch to unified diff)

--- src/games/trek/phaser.c 2009/05/24 19:18:44 1.11
+++ src/games/trek/phaser.c 2009/05/24 20:39:43 1.12
@@ -1,384 +1,384 @@ @@ -1,384 +1,384 @@
1/* $NetBSD: phaser.c,v 1.11 2009/05/24 19:18:44 dholland Exp $ */ 1/* $NetBSD: phaser.c,v 1.12 2009/05/24 20:39:43 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1993 4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34#if 0 34#if 0
35static char sccsid[] = "@(#)phaser.c 8.1 (Berkeley) 5/31/93"; 35static char sccsid[] = "@(#)phaser.c 8.1 (Berkeley) 5/31/93";
36#else 36#else
37__RCSID("$NetBSD: phaser.c,v 1.11 2009/05/24 19:18:44 dholland Exp $"); 37__RCSID("$NetBSD: phaser.c,v 1.12 2009/05/24 20:39:43 dholland Exp $");
38#endif 38#endif
39#endif /* not lint */ 39#endif /* not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
42#include <math.h> 42#include <math.h>
43#include "trek.h" 43#include "trek.h"
44#include "getpar.h" 44#include "getpar.h"
45 45
46/* factors for phaser hits; see description below */ 46/* factors for phaser hits; see description below */
47 47
48# define ALPHA 3.0 /* spread */ 48#define ALPHA 3.0 /* spread */
49# define BETA 3.0 /* franf() */ 49#define BETA 3.0 /* franf() */
50# define GAMMA 0.30 /* cos(angle) */ 50#define GAMMA 0.30 /* cos(angle) */
51# define EPSILON 150.0 /* dist ** 2 */ 51#define EPSILON 150.0 /* dist ** 2 */
52# define OMEGA 10.596 /* overall scaling factor */ 52#define OMEGA 10.596 /* overall scaling factor */
53 53
54/* OMEGA ~= 100 * (ALPHA + 1) * (BETA + 1) / (EPSILON + 1) */ 54/* OMEGA ~= 100 * (ALPHA + 1) * (BETA + 1) / (EPSILON + 1) */
55 55
56/* 56/*
57** Phaser Control 57** Phaser Control
58** 58**
59** There are up to NBANKS phaser banks which may be fired 59** There are up to NBANKS phaser banks which may be fired
60** simultaneously. There are two modes, "manual" and 60** simultaneously. There are two modes, "manual" and
61** "automatic". In manual mode, you specify exactly which 61** "automatic". In manual mode, you specify exactly which
62** direction you want each bank to be aimed, the number 62** direction you want each bank to be aimed, the number
63** of units to fire, and the spread angle. In automatic 63** of units to fire, and the spread angle. In automatic
64** mode, you give only the total number of units to fire. 64** mode, you give only the total number of units to fire.
65** 65**
66** The spread is specified as a number between zero and 66** The spread is specified as a number between zero and
67** one, with zero being minimum spread and one being maximum 67** one, with zero being minimum spread and one being maximum
68** spread. You will normally want zero spread, unless your 68** spread. You will normally want zero spread, unless your
69** short range scanners are out, in which case you probably 69** short range scanners are out, in which case you probably
70** don't know exactly where the Klingons are. In that case, 70** don't know exactly where the Klingons are. In that case,
71** you really don't have any choice except to specify a 71** you really don't have any choice except to specify a
72** fairly large spread. 72** fairly large spread.
73** 73**
74** Phasers spread slightly, even if you specify zero spread. 74** Phasers spread slightly, even if you specify zero spread.
75** 75**
76** Uses trace flag 30 76** Uses trace flag 30
77*/ 77*/
78 78
79struct cvntab Matab[] = 79struct cvntab Matab[] =
80{ 80{
81 { "m", "anual", (cmdfun) 1, 0 }, 81 { "m", "anual", (cmdfun) 1, 0 },
82 { "a", "utomatic", (cmdfun) 0, 0 }, 82 { "a", "utomatic", (cmdfun) 0, 0 },
83 { NULL, NULL, NULL, 0 } 83 { NULL, NULL, NULL, 0 }
84}; 84};
85 85
86struct banks 86struct banks
87{ 87{
88 int units; 88 int units;
89 double angle; 89 double angle;
90 double spread; 90 double spread;
91}; 91};
92 92
93 93
94 94
95/*ARGSUSED*/ 95/*ARGSUSED*/
96void 96void
97phaser(int v __unused) 97phaser(int v __unused)
98{ 98{
99 int i; 99 int i;
100 int j; 100 int j;
101 struct kling *k; 101 struct kling *k;
102 double dx, dy; 102 double dx, dy;
103 double anglefactor, distfactor; 103 double anglefactor, distfactor;
104 struct banks *b; 104 struct banks *b;
105 int manual, flag, extra = 0; 105 int manual, flag, extra = 0;
106 int hit; 106 int hit;
107 double tot; 107 double tot;
108 int n; 108 int n;
109 int hitreqd[NBANKS]; 109 int hitreqd[NBANKS];
110 struct banks bank[NBANKS]; 110 struct banks bank[NBANKS];
111 const struct cvntab *ptr; 111 const struct cvntab *ptr;
112 112
113 if (Ship.cond == DOCKED) { 113 if (Ship.cond == DOCKED) {
114 printf("Phasers cannot fire through starbase shields\n"); 114 printf("Phasers cannot fire through starbase shields\n");
115 return; 115 return;
116 } 116 }
117 if (damaged(PHASER)) { 117 if (damaged(PHASER)) {
118 out(PHASER); 118 out(PHASER);
119 return; 119 return;
120 } 120 }
121 if (Ship.shldup) { 121 if (Ship.shldup) {
122 printf("Sulu: Captain, we cannot fire through shields.\n"); 122 printf("Sulu: Captain, we cannot fire through shields.\n");
123 return; 123 return;
124 } 124 }
125 if (Ship.cloaked) 125 if (Ship.cloaked)
126 { 126 {
127 printf("Sulu: Captain, surely you must realize that we cannot fire\n"); 127 printf("Sulu: Captain, surely you must realize that we cannot fire\n");
128 printf(" phasers with the cloaking device up.\n"); 128 printf(" phasers with the cloaking device up.\n");
129 return; 129 return;
130 } 130 }
131 131
132 /* decide if we want manual or automatic mode */ 132 /* decide if we want manual or automatic mode */
133 manual = 0; 133 manual = 0;
134 if (testnl()) 134 if (testnl())
135 { 135 {
136 if (damaged(COMPUTER)) 136 if (damaged(COMPUTER))
137 { 137 {
138 printf("%s", Device[COMPUTER].name); 138 printf("%s", Device[COMPUTER].name);
139 manual++; 139 manual++;
140 } 140 }
141 else 141 else
142 if (damaged(SRSCAN)) 142 if (damaged(SRSCAN))
143 { 143 {
144 printf("%s", Device[SRSCAN].name); 144 printf("%s", Device[SRSCAN].name);
145 manual++; 145 manual++;
146 } 146 }
147 if (manual) 147 if (manual)
148 printf(" damaged, manual mode selected\n"); 148 printf(" damaged, manual mode selected\n");
149 } 149 }
150 150
151 if (!manual) 151 if (!manual)
152 { 152 {
153 ptr = getcodpar("Manual or automatic", Matab); 153 ptr = getcodpar("Manual or automatic", Matab);
154 manual = (long) ptr->value; 154 manual = (long) ptr->value;
155 } 155 }
156 if (!manual && damaged(COMPUTER)) 156 if (!manual && damaged(COMPUTER))
157 { 157 {
158 printf("Computer damaged, manual selected\n"); 158 printf("Computer damaged, manual selected\n");
159 skiptonl(0); 159 skiptonl(0);
160 manual++; 160 manual++;
161 } 161 }
162 162
163 /* initialize the bank[] array */ 163 /* initialize the bank[] array */
164 flag = 1; 164 flag = 1;
165 for (i = 0; i < NBANKS; i++) 165 for (i = 0; i < NBANKS; i++)
166 bank[i].units = 0; 166 bank[i].units = 0;
167 if (manual) 167 if (manual)
168 { 168 {
169 /* collect manual mode statistics */ 169 /* collect manual mode statistics */
170 while (flag) 170 while (flag)
171 { 171 {
172 printf("%d units available\n", Ship.energy); 172 printf("%d units available\n", Ship.energy);
173 extra = 0; 173 extra = 0;
174 flag = 0; 174 flag = 0;
175 for (i = 0; i < NBANKS; i++) 175 for (i = 0; i < NBANKS; i++)
176 { 176 {
177 b = &bank[i]; 177 b = &bank[i];
178 printf("\nBank %d:\n", i); 178 printf("\nBank %d:\n", i);
179 hit = getintpar("units"); 179 hit = getintpar("units");
180 if (hit < 0) 180 if (hit < 0)
181 return; 181 return;
182 if (hit == 0) 182 if (hit == 0)
183 break; 183 break;
184 extra += hit; 184 extra += hit;
185 if (extra > Ship.energy) 185 if (extra > Ship.energy)
186 { 186 {
187 printf("available energy exceeded. "); 187 printf("available energy exceeded. ");
188 skiptonl(0); 188 skiptonl(0);
189 flag++; 189 flag++;
190 break; 190 break;
191 } 191 }
192 b->units = hit; 192 b->units = hit;
193 hit = getintpar("course"); 193 hit = getintpar("course");
194 if (hit < 0 || hit > 360) 194 if (hit < 0 || hit > 360)
195 return; 195 return;
196 b->angle = hit * 0.0174532925; 196 b->angle = hit * 0.0174532925;
197 b->spread = getfltpar("spread"); 197 b->spread = getfltpar("spread");
198 if (b->spread < 0 || b->spread > 1) 198 if (b->spread < 0 || b->spread > 1)
199 return; 199 return;
200 } 200 }
201 Ship.energy -= extra; 201 Ship.energy -= extra;
202 } 202 }
203 extra = 0; 203 extra = 0;
204 } 204 }
205 else 205 else
206 { 206 {
207 /* automatic distribution of power */ 207 /* automatic distribution of power */
208 if (Etc.nkling <= 0) { 208 if (Etc.nkling <= 0) {
209 printf("Sulu: But there are no Klingons in this quadrant\n"); 209 printf("Sulu: But there are no Klingons in this quadrant\n");
210 return; 210 return;
211 } 211 }
212 printf("Phasers locked on target. "); 212 printf("Phasers locked on target. ");
213 while (flag) 213 while (flag)
214 { 214 {
215 printf("%d units available\n", Ship.energy); 215 printf("%d units available\n", Ship.energy);
216 hit = getintpar("Units to fire"); 216 hit = getintpar("Units to fire");
217 if (hit <= 0) 217 if (hit <= 0)
218 return; 218 return;
219 if (hit > Ship.energy) 219 if (hit > Ship.energy)
220 { 220 {
221 printf("available energy exceeded. "); 221 printf("available energy exceeded. ");
222 skiptonl(0); 222 skiptonl(0);
223 continue; 223 continue;
224 } 224 }
225 flag = 0; 225 flag = 0;
226 Ship.energy -= hit; 226 Ship.energy -= hit;
227 extra = hit; 227 extra = hit;
228 n = Etc.nkling; 228 n = Etc.nkling;
229 if (n > NBANKS) 229 if (n > NBANKS)
230 n = NBANKS; 230 n = NBANKS;
231 tot = n * (n + 1) / 2; 231 tot = n * (n + 1) / 2;
232 for (i = 0; i < n; i++) 232 for (i = 0; i < n; i++)
233 { 233 {
234 k = &Etc.klingon[i]; 234 k = &Etc.klingon[i];
235 b = &bank[i]; 235 b = &bank[i];
236 distfactor = k->dist; 236 distfactor = k->dist;
237 anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON); 237 anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON);
238 anglefactor *= GAMMA; 238 anglefactor *= GAMMA;
239 distfactor = k->power; 239 distfactor = k->power;
240 distfactor /= anglefactor; 240 distfactor /= anglefactor;
241 hitreqd[i] = distfactor + 0.5; 241 hitreqd[i] = distfactor + 0.5;
242 dx = Ship.sectx - k->x; 242 dx = Ship.sectx - k->x;
243 dy = k->y - Ship.secty; 243 dy = k->y - Ship.secty;
244 b->angle = atan2(dy, dx); 244 b->angle = atan2(dy, dx);
245 b->spread = 0.0; 245 b->spread = 0.0;
246 b->units = ((n - i) / tot) * extra; 246 b->units = ((n - i) / tot) * extra;
247# ifdef xTRACE 247#ifdef xTRACE
248 if (Trace) 248 if (Trace)
249 { 249 {
250 printf("b%d hr%d u%d df%.2f af%.2f\n", 250 printf("b%d hr%d u%d df%.2f af%.2f\n",
251 i, hitreqd[i], b->units, 251 i, hitreqd[i], b->units,
252 distfactor, anglefactor); 252 distfactor, anglefactor);
253 } 253 }
254# endif 254#endif
255 extra -= b->units; 255 extra -= b->units;
256 hit = b->units - hitreqd[i]; 256 hit = b->units - hitreqd[i];
257 if (hit > 0) 257 if (hit > 0)
258 { 258 {
259 extra += hit; 259 extra += hit;
260 b->units -= hit; 260 b->units -= hit;
261 } 261 }
262 } 262 }
263 263
264 /* give out any extra energy we might have around */ 264 /* give out any extra energy we might have around */
265 if (extra > 0) 265 if (extra > 0)
266 { 266 {
267 for (i = 0; i < n; i++) 267 for (i = 0; i < n; i++)
268 { 268 {
269 b = &bank[i]; 269 b = &bank[i];
270 hit = hitreqd[i] - b->units; 270 hit = hitreqd[i] - b->units;
271 if (hit <= 0) 271 if (hit <= 0)
272 continue; 272 continue;
273 if (hit >= extra) 273 if (hit >= extra)
274 { 274 {
275 b->units += extra; 275 b->units += extra;
276 extra = 0; 276 extra = 0;
277 break; 277 break;
278 } 278 }
279 b->units = hitreqd[i]; 279 b->units = hitreqd[i];
280 extra -= hit; 280 extra -= hit;
281 } 281 }
282 if (extra > 0) 282 if (extra > 0)
283 printf("%d units overkill\n", extra); 283 printf("%d units overkill\n", extra);
284 } 284 }
285 } 285 }
286 } 286 }
287 287
288# ifdef xTRACE 288#ifdef xTRACE
289 if (Trace) 289 if (Trace)
290 { 290 {
291 for (i = 0; i < NBANKS; i++) 291 for (i = 0; i < NBANKS; i++)
292 { 292 {
293 b = &bank[i]; 293 b = &bank[i];
294 printf("b%d u%d", i, b->units); 294 printf("b%d u%d", i, b->units);
295 if (b->units > 0) 295 if (b->units > 0)
296 printf(" a%.2f s%.2f\n", b->angle, b->spread); 296 printf(" a%.2f s%.2f\n", b->angle, b->spread);
297 else 297 else
298 printf("\n"); 298 printf("\n");
299 } 299 }
300 } 300 }
301# endif 301#endif
302 302
303 /* actually fire the shots */ 303 /* actually fire the shots */
304 Move.free = 0; 304 Move.free = 0;
305 for (i = 0; i < NBANKS; i++) 305 for (i = 0; i < NBANKS; i++)
306 { 306 {
307 b = &bank[i]; 307 b = &bank[i];
308 if (b->units <= 0) 308 if (b->units <= 0)
309 { 309 {
310 continue; 310 continue;
311 } 311 }
312 printf("\nPhaser bank %d fires:\n", i); 312 printf("\nPhaser bank %d fires:\n", i);
313 n = Etc.nkling; 313 n = Etc.nkling;
314 k = Etc.klingon; 314 k = Etc.klingon;
315 for (j = 0; j < n; j++) 315 for (j = 0; j < n; j++)
316 { 316 {
317 if (b->units <= 0) 317 if (b->units <= 0)
318 break; 318 break;
319 /* 319 /*
320 ** The formula for hit is as follows: 320 ** The formula for hit is as follows:
321 ** 321 **
322 ** zap = OMEGA * [(sigma + ALPHA) * (rho + BETA)] 322 ** zap = OMEGA * [(sigma + ALPHA) * (rho + BETA)]
323 ** / (dist ** 2 + EPSILON)] 323 ** / (dist ** 2 + EPSILON)]
324 ** * [cos(delta * sigma) + GAMMA] 324 ** * [cos(delta * sigma) + GAMMA]
325 ** * hit 325 ** * hit
326 ** 326 **
327 ** where sigma is the spread factor, 327 ** where sigma is the spread factor,
328 ** rho is a random number (0 -> 1), 328 ** rho is a random number (0 -> 1),
329 ** GAMMA is a crud factor for angle (essentially 329 ** GAMMA is a crud factor for angle (essentially
330 ** cruds up the spread factor), 330 ** cruds up the spread factor),
331 ** delta is the difference in radians between the 331 ** delta is the difference in radians between the
332 ** angle you are shooting at and the actual 332 ** angle you are shooting at and the actual
333 ** angle of the klingon, 333 ** angle of the klingon,
334 ** ALPHA scales down the significance of sigma, 334 ** ALPHA scales down the significance of sigma,
335 ** BETA scales down the significance of rho, 335 ** BETA scales down the significance of rho,
336 ** OMEGA is the magic number which makes everything 336 ** OMEGA is the magic number which makes everything
337 ** up to "* hit" between zero and one, 337 ** up to "* hit" between zero and one,
338 ** dist is the distance to the klingon 338 ** dist is the distance to the klingon
339 ** hit is the number of units in the bank, and 339 ** hit is the number of units in the bank, and
340 ** zap is the amount of the actual hit. 340 ** zap is the amount of the actual hit.
341 ** 341 **
342 ** Everything up through dist squared should maximize 342 ** Everything up through dist squared should maximize
343 ** at 1.0, so that the distance factor is never 343 ** at 1.0, so that the distance factor is never
344 ** greater than one. Conveniently, cos() is 344 ** greater than one. Conveniently, cos() is
345 ** never greater than one, but the same restric- 345 ** never greater than one, but the same restric-
346 ** tion applies. 346 ** tion applies.
347 */ 347 */
348 distfactor = BETA + franf(); 348 distfactor = BETA + franf();
349 distfactor *= ALPHA + b->spread; 349 distfactor *= ALPHA + b->spread;
350 distfactor *= OMEGA; 350 distfactor *= OMEGA;
351 anglefactor = k->dist; 351 anglefactor = k->dist;
352 distfactor /= anglefactor * anglefactor + EPSILON; 352 distfactor /= anglefactor * anglefactor + EPSILON;
353 distfactor *= b->units; 353 distfactor *= b->units;
354 dx = Ship.sectx - k->x; 354 dx = Ship.sectx - k->x;
355 dy = k->y - Ship.secty; 355 dy = k->y - Ship.secty;
356 anglefactor = atan2(dy, dx) - b->angle; 356 anglefactor = atan2(dy, dx) - b->angle;
357 anglefactor = cos((anglefactor * b->spread) + GAMMA); 357 anglefactor = cos((anglefactor * b->spread) + GAMMA);
358 if (anglefactor < 0.0) 358 if (anglefactor < 0.0)
359 { 359 {
360 k++; 360 k++;
361 continue; 361 continue;
362 } 362 }
363 hit = anglefactor * distfactor + 0.5; 363 hit = anglefactor * distfactor + 0.5;
364 k->power -= hit; 364 k->power -= hit;
365 printf("%d unit hit on Klingon", hit); 365 printf("%d unit hit on Klingon", hit);
366 if (!damaged(SRSCAN)) 366 if (!damaged(SRSCAN))
367 printf(" at %d,%d", k->x, k->y); 367 printf(" at %d,%d", k->x, k->y);
368 printf("\n"); 368 printf("\n");
369 b->units -= hit; 369 b->units -= hit;
370 if (k->power <= 0) 370 if (k->power <= 0)
371 { 371 {
372 killk(k->x, k->y); 372 killk(k->x, k->y);
373 continue; 373 continue;
374 } 374 }
375 k++; 375 k++;
376 } 376 }
377 } 377 }
378 378
379 /* compute overkill */ 379 /* compute overkill */
380 for (i = 0; i < NBANKS; i++) 380 for (i = 0; i < NBANKS; i++)
381 extra += bank[i].units; 381 extra += bank[i].units;
382 if (extra > 0) 382 if (extra > 0)
383 printf("\n%d units expended on empty space\n", extra); 383 printf("\n%d units expended on empty space\n", extra);
384} 384}