Home | History | Annotate | Line # | Download | only in trek
kill.c revision 1.7
      1 /*	$NetBSD: kill.c,v 1.7 2003/08/07 09:37:52 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     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
     17  *    without specific prior written permission.
     18  *
     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
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     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
     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
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 #if 0
     35 static char sccsid[] = "@(#)kill.c	8.1 (Berkeley) 5/31/93";
     36 #else
     37 __RCSID("$NetBSD: kill.c,v 1.7 2003/08/07 09:37:52 agc Exp $");
     38 #endif
     39 #endif /* not lint */
     40 
     41 #include <stdio.h>
     42 #include "trek.h"
     43 
     44 /*
     45 **  KILL KILL KILL !!!
     46 **
     47 **	This file handles the killing off of almost anything.
     48 */
     49 
     50 /*
     51 **  Handle a Klingon's death
     52 **
     53 **	The Klingon at the sector given by the parameters is killed
     54 **	and removed from the Klingon list.  Notice that it is not
     55 **	removed from the event list; this is done later, when the
     56 **	the event is to be caught.  Also, the time left is recomputed,
     57 **	and the game is won if that was the last klingon.
     58 */
     59 
     60 void
     61 killk(ix, iy)
     62 int	ix, iy;
     63 {
     64 	int		i;
     65 
     66 	printf("   *** Klingon at %d,%d destroyed ***\n", ix, iy);
     67 
     68 	/* remove the scoundrel */
     69 	Now.klings -= 1;
     70 	Sect[ix][iy] = EMPTY;
     71 	Quad[Ship.quadx][Ship.quady].klings -= 1;
     72 	/* %%% IS THIS SAFE???? %%% */
     73 	Quad[Ship.quadx][Ship.quady].scanned -= 100;
     74 	Game.killk += 1;
     75 
     76 	/* find the Klingon in the Klingon list */
     77 	for (i = 0; i < Etc.nkling; i++)
     78 		if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y)
     79 		{
     80 			/* purge him from the list */
     81 			Etc.nkling -= 1;
     82 			for (; i < Etc.nkling; i++)
     83 				Etc.klingon[i] = Etc.klingon[i+1];
     84 			break;
     85 		}
     86 
     87 	/* find out if that was the last one */
     88 	if (Now.klings <= 0)
     89 		win();
     90 
     91 	/* recompute time left */
     92 	Now.time = Now.resource / Now.klings;
     93 	return;
     94 }
     95 
     96 
     97 /*
     98 **  handle a starbase's death
     99 */
    100 
    101 void
    102 killb(qx, qy)
    103 int	qx, qy;
    104 {
    105 	struct quad	*q;
    106 	struct xy	*b;
    107 
    108 	q = &Quad[qx][qy];
    109 
    110 	if (q->bases <= 0)
    111 		return;
    112 	if (!damaged(SSRADIO)) {
    113 		/* then update starchart */
    114 		if (q->scanned < 1000)
    115 			q->scanned -= 10;
    116 		else
    117 			if (q->scanned > 1000)
    118 				q->scanned = -1;
    119 	}
    120 	q->bases = 0;
    121 	Now.bases -= 1;
    122 	for (b = Now.base; ; b++)
    123 		if (qx == b->x && qy == b->y)
    124 			break;
    125 	*b = Now.base[Now.bases];
    126 	if (qx == Ship.quadx && qy == Ship.quady)
    127 	{
    128 		Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
    129 		if (Ship.cond == DOCKED)
    130 			undock(0);
    131 		printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
    132 	}
    133 	else
    134 	{
    135 		if (!damaged(SSRADIO))
    136 		{
    137 			printf("Uhura: Starfleet command reports that the starbase in\n");
    138 			printf("   quadrant %d,%d has been destroyed\n", qx, qy);
    139 		}
    140 		else
    141 			schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0);
    142 	}
    143 }
    144 
    145 
    146 /**
    147  **	kill an inhabited starsystem
    148  **/
    149 
    150 void
    151 kills(x, y, f)
    152 int	x, y;	/* quad coords if f == 0, else sector coords */
    153 int	f;	/* f != 0 -- this quad;  f < 0 -- Enterprise's fault */
    154 {
    155 	struct quad	*q;
    156 	struct event	*e;
    157 	const char	*name;
    158 
    159 	if (f)
    160 	{
    161 		/* current quadrant */
    162 		q = &Quad[Ship.quadx][Ship.quady];
    163 		Sect[x][y] = EMPTY;
    164 		name = systemname(q);
    165 		if (name == 0)
    166 			return;
    167 		printf("Inhabited starsystem %s at %d,%d destroyed\n",
    168 			name, x, y);
    169 		if (f < 0)
    170 			Game.killinhab += 1;
    171 	}
    172 	else
    173 	{
    174 		/* different quadrant */
    175 		q = &Quad[x][y];
    176 	}
    177 	if (q->qsystemname & Q_DISTRESSED)
    178 	{
    179 		/* distressed starsystem */
    180 		e = &Event[q->qsystemname & Q_SYSTEM];
    181 		printf("Distress call for %s invalidated\n",
    182 			Systemname[e->systemname]);
    183 		unschedule(e);
    184 	}
    185 	q->qsystemname = 0;
    186 	q->stars -= 1;
    187 }
    188 
    189 
    190 /**
    191  **	"kill" a distress call
    192  **/
    193 
    194 void
    195 killd(x, y, f)
    196 int	x, y;		/* quadrant coordinates */
    197 int	f;		/* set if user is to be informed */
    198 {
    199 	struct event	*e;
    200 	int		i;
    201 	struct quad	*q;
    202 
    203 	q = &Quad[x][y];
    204 	for (i = 0; i < MAXEVENTS; i++)
    205 	{
    206 		e = &Event[i];
    207 		if (e->x != x || e->y != y)
    208 			continue;
    209 		switch (e->evcode)
    210 		{
    211 		  case E_KDESB:
    212 			if (f)
    213 			{
    214 				printf("Distress call for starbase in %d,%d nullified\n",
    215 					x, y);
    216 				unschedule(e);
    217 			}
    218 			break;
    219 
    220 		  case E_ENSLV:
    221 		  case E_REPRO:
    222 			if (f)
    223 			{
    224 				printf("Distress call for %s in quadrant %d,%d nullified\n",
    225 					Systemname[e->systemname], x, y);
    226 				q->qsystemname = e->systemname;
    227 				unschedule(e);
    228 			}
    229 			else
    230 			{
    231 				e->evcode |= E_GHOST;
    232 			}
    233 		}
    234 	}
    235 }
    236