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

Defined functions

killd defined in line 160; used 2 times
kills defined in line 116; used 2 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 796
Valid CSS Valid XHTML 1.0 Strict