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