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