kill.c 5.4 KB

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