nova.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* $NetBSD: nova.c,v 1.6 2003/08/07 09:37:53 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[] = "@(#)nova.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: nova.c,v 1.6 2003/08/07 09:37:53 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include "trek.h"
  40. /*
  41. ** CAUSE A NOVA TO OCCUR
  42. **
  43. ** A nova occurs. It is the result of having a star hit with
  44. ** a photon torpedo. There are several things which may happen.
  45. ** The star may not be affected. It may go nova. It may turn
  46. ** into a black hole. Any (yummy) it may go supernova.
  47. **
  48. ** Stars that go nova cause stars which surround them to undergo
  49. ** the same probabilistic process. Klingons next to them are
  50. ** destroyed. And if the starship is next to it, it gets zapped.
  51. ** If the zap is too much, it gets destroyed.
  52. */
  53. void
  54. nova(x, y)
  55. int x, y;
  56. {
  57. int i, j;
  58. int se;
  59. if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0)
  60. return;
  61. if (ranf(100) < 15)
  62. {
  63. printf("Spock: Star at %d,%d failed to nova.\n", x, y);
  64. return;
  65. }
  66. if (ranf(100) < 5) {
  67. snova(x, y);
  68. return;
  69. }
  70. printf("Spock: Star at %d,%d gone nova\n", x, y);
  71. if (ranf(4) != 0)
  72. Sect[x][y] = EMPTY;
  73. else
  74. {
  75. Sect[x][y] = HOLE;
  76. Quad[Ship.quadx][Ship.quady].holes += 1;
  77. }
  78. Quad[Ship.quadx][Ship.quady].stars -= 1;
  79. Game.kills += 1;
  80. for (i = x - 1; i <= x + 1; i++)
  81. {
  82. if (i < 0 || i >= NSECTS)
  83. continue;
  84. for (j = y - 1; j <= y + 1; j++)
  85. {
  86. if (j < 0 || j >= NSECTS)
  87. continue;
  88. se = Sect[i][j];
  89. switch (se)
  90. {
  91. case EMPTY:
  92. case HOLE:
  93. break;
  94. case KLINGON:
  95. killk(i, j);
  96. break;
  97. case STAR:
  98. nova(i, j);
  99. break;
  100. case INHABIT:
  101. kills(i, j, -1);
  102. break;
  103. case BASE:
  104. killb(i, j);
  105. Game.killb += 1;
  106. break;
  107. case ENTERPRISE:
  108. case QUEENE:
  109. se = 2000;
  110. if (Ship.shldup) {
  111. if (Ship.shield >= se) {
  112. Ship.shield -= se;
  113. se = 0;
  114. } else {
  115. se -= Ship.shield;
  116. Ship.shield = 0;
  117. }
  118. }
  119. Ship.energy -= se;
  120. if (Ship.energy <= 0)
  121. lose(L_SUICID);
  122. break;
  123. default:
  124. printf("Unknown object %c at %d,%d destroyed\n",
  125. se, i, j);
  126. Sect[i][j] = EMPTY;
  127. break;
  128. }
  129. }
  130. }
  131. return;
  132. }