snova.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* $NetBSD: snova.c,v 1.5 2003/08/07 09:37:54 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[] = "@(#)snova.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: snova.c,v 1.5 2003/08/07 09:37:54 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include <unistd.h>
  40. #include "trek.h"
  41. /*
  42. ** CAUSE SUPERNOVA TO OCCUR
  43. **
  44. ** A supernova occurs. If 'ix' < 0, a random quadrant is chosen;
  45. ** otherwise, the current quadrant is taken, and (ix, iy) give
  46. ** the sector quadrants of the star which is blowing up.
  47. **
  48. ** If the supernova turns out to be in the quadrant you are in,
  49. ** you go into "emergency override mode", which tries to get you
  50. ** out of the quadrant as fast as possible. However, if you
  51. ** don't have enough fuel, or if you by chance run into something,
  52. ** or some such thing, you blow up anyway. Oh yeh, if you are
  53. ** within two sectors of the star, there is nothing that can
  54. ** be done for you.
  55. **
  56. ** When a star has gone supernova, the quadrant becomes uninhab-
  57. ** itable for the rest of eternity, i.e., the game. If you ever
  58. ** try stopping in such a quadrant, you will go into emergency
  59. ** override mode.
  60. */
  61. void
  62. snova(x, y)
  63. int x, y;
  64. {
  65. int qx, qy;
  66. int ix, iy = 0;
  67. int f;
  68. int dx, dy;
  69. int n;
  70. struct quad *q;
  71. f = 0;
  72. ix = x;
  73. if (ix < 0)
  74. {
  75. /* choose a quadrant */
  76. while (1)
  77. {
  78. qx = ranf(NQUADS);
  79. qy = ranf(NQUADS);
  80. q = &Quad[qx][qy];
  81. if (q->stars > 0)
  82. break;
  83. }
  84. if (Ship.quadx == qx && Ship.quady == qy)
  85. {
  86. /* select a particular star */
  87. n = ranf(q->stars);
  88. for (ix = 0; ix < NSECTS; ix++)
  89. {
  90. for (iy = 0; iy < NSECTS; iy++)
  91. if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
  92. if ((n -= 1) <= 0)
  93. break;
  94. if (n <= 0)
  95. break;
  96. }
  97. f = 1;
  98. }
  99. }
  100. else
  101. {
  102. /* current quadrant */
  103. iy = y;
  104. qx = Ship.quadx;
  105. qy = Ship.quady;
  106. q = &Quad[qx][qy];
  107. f = 1;
  108. }
  109. if (f)
  110. {
  111. /* supernova is in same quadrant as Enterprise */
  112. printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
  113. dx = ix - Ship.sectx;
  114. dy = iy - Ship.secty;
  115. if (dx * dx + dy * dy <= 2)
  116. {
  117. printf("*** Emergency override attem");
  118. sleep(1);
  119. printf("\n");
  120. lose(L_SNOVA);
  121. }
  122. q->scanned = 1000;
  123. }
  124. else
  125. {
  126. if (!damaged(SSRADIO))
  127. {
  128. q->scanned = 1000;
  129. printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
  130. printf(" in quadrant %d,%d. Caution is advised\n", qx, qy);
  131. }
  132. }
  133. /* clear out the supernova'ed quadrant */
  134. dx = q->klings;
  135. dy = q->stars;
  136. Now.klings -= dx;
  137. if (x >= 0)
  138. {
  139. /* Enterprise caused supernova */
  140. Game.kills += dy;
  141. if (q->bases)
  142. killb(qx, qy);
  143. Game.killk += dx;
  144. }
  145. else
  146. if (q->bases)
  147. killb(qx, qy);
  148. killd(qx, qy, (x >= 0));
  149. q->stars = -1;
  150. q->klings = 0;
  151. if (Now.klings <= 0)
  152. {
  153. printf("Lucky devil, that supernova destroyed the last klingon\n");
  154. win();
  155. }
  156. return;
  157. }