/usr/games often isn't in root's path
[unix-history] / usr / src / games / trek / kill.c
CommitLineData
9758240b
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
e9fb6bea
KB
3 * All rights reserved.
4 *
b2e7427f 5 * %sccs.include.redist.c%
9758240b
KM
6 */
7
060604f0 8#ifndef lint
b2e7427f 9static char sccsid[] = "@(#)kill.c 5.4 (Berkeley) %G%";
e9fb6bea 10#endif /* not lint */
060604f0
KM
11
12# include "trek.h"
13
14/*
15** KILL KILL KILL !!!
16**
17** This file handles the killing off of almost anything.
18*/
19
20/*
21** Handle a Klingon's death
22**
23** The Klingon at the sector given by the parameters is killed
24** and removed from the Klingon list. Notice that it is not
25** removed from the event list; this is done later, when the
26** the event is to be caught. Also, the time left is recomputed,
27** and the game is won if that was the last klingon.
28*/
29
30killk(ix, iy)
31int ix, iy;
32{
33 register int i, j;
34
35 printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy);
36
37 /* remove the scoundrel */
06d69904 38 Now.klings -= 1;
060604f0 39 Sect[ix][iy] = EMPTY;
06d69904 40 Quad[Ship.quadx][Ship.quady].klings -= 1;
060604f0 41 /* %%% IS THIS SAFE???? %%% */
06d69904
KL
42 Quad[Ship.quadx][Ship.quady].scanned -= 100;
43 Game.killk += 1;
060604f0
KM
44
45 /* find the Klingon in the Klingon list */
46 for (i = 0; i < Etc.nkling; i++)
47 if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y)
48 {
49 /* purge him from the list */
06d69904 50 Etc.nkling -= 1;
060604f0
KM
51 for (; i < Etc.nkling; i++)
52 bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]);
53 break;
54 }
55
56 /* find out if that was the last one */
57 if (Now.klings <= 0)
58 win();
59
60 /* recompute time left */
61 Now.time = Now.resource / Now.klings;
62 return;
63}
64
65
66/*
67** handle a starbase's death
68*/
69
70killb(qx, qy)
71int qx, qy;
72{
73 register struct quad *q;
74 register struct xy *b;
75
76 q = &Quad[qx][qy];
77
78 if (q->bases <= 0)
79 return;
80 if (!damaged(SSRADIO))
81 /* then update starchart */
82 if (q->scanned < 1000)
06d69904 83 q->scanned -= 10;
060604f0
KM
84 else
85 if (q->scanned > 1000)
86 q->scanned = -1;
87 q->bases = 0;
06d69904 88 Now.bases -= 1;
060604f0
KM
89 for (b = Now.base; ; b++)
90 if (qx == b->x && qy == b->y)
91 break;
92 bmove(&Now.base[Now.bases], b, sizeof *b);
93 if (qx == Ship.quadx && qy == Ship.quady)
94 {
95 Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
96 if (Ship.cond == DOCKED)
97 undock();
98 printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
99 }
100 else
101 {
102 if (!damaged(SSRADIO))
103 {
104 printf("Uhura: Starfleet command reports that the starbase in\n");
105 printf(" quadrant %d,%d has been destroyed\n", qx, qy);
106 }
107 else
108 schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0);
109 }
110}
111
112
113/**
114 ** kill an inhabited starsystem
115 **/
116
117kills(x, y, f)
118int x, y; /* quad coords if f == 0, else sector coords */
119int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */
120{
121 register struct quad *q;
122 register struct event *e;
123 register char *name;
06d69904 124 char *systemname();
060604f0
KM
125
126 if (f)
127 {
128 /* current quadrant */
129 q = &Quad[Ship.quadx][Ship.quady];
130 Sect[x][y] = EMPTY;
131 name = systemname(q);
132 if (name == 0)
133 return;
134 printf("Inhabited starsystem %s at %d,%d destroyed\n",
135 name, x, y);
136 if (f < 0)
06d69904 137 Game.killinhab += 1;
060604f0
KM
138 }
139 else
140 {
141 /* different quadrant */
142 q = &Quad[x][y];
143 }
06d69904 144 if (q->qsystemname & Q_DISTRESSED)
060604f0
KM
145 {
146 /* distressed starsystem */
06d69904 147 e = &Event[q->qsystemname & Q_SYSTEM];
060604f0
KM
148 printf("Distress call for %s invalidated\n",
149 Systemname[e->systemname]);
150 unschedule(e);
151 }
06d69904
KL
152 q->qsystemname = 0;
153 q->stars -= 1;
060604f0
KM
154}
155
156
157/**
158 ** "kill" a distress call
159 **/
160
161killd(x, y, f)
162int x, y; /* quadrant coordinates */
163int f; /* set if user is to be informed */
164{
165 register struct event *e;
166 register int i;
167 register struct quad *q;
168
169 q = &Quad[x][y];
170 for (i = 0; i < MAXEVENTS; i++)
171 {
172 e = &Event[i];
173 if (e->x != x || e->y != y)
174 continue;
175 switch (e->evcode)
176 {
177 case E_KDESB:
178 if (f)
179 {
180 printf("Distress call for starbase in %d,%d nullified\n",
181 x, y);
182 unschedule(e);
183 }
184 break;
185
186 case E_ENSLV:
187 case E_REPRO:
188 if (f)
189 {
190 printf("Distress call for %s in quadrant %d,%d nullified\n",
191 Systemname[e->systemname], x, y);
06d69904 192 q->qsystemname = e->systemname;
060604f0
KM
193 unschedule(e);
194 }
195 else
196 {
06d69904 197 e->evcode |= E_GHOST;
060604f0
KM
198 }
199 }
200 }
201}