destruct.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* $NetBSD: destruct.c,v 1.7 2003/08/07 09:37:50 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[] = "@(#)destruct.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: destruct.c,v 1.7 2003/08/07 09:37:50 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include "trek.h"
  42. #include "getpar.h"
  43. /*
  44. ** Self Destruct Sequence
  45. **
  46. ** The computer starts up the self destruct sequence. Obviously,
  47. ** if the computer is out nothing can happen. You get a countdown
  48. ** and a request for password. This must match the password that
  49. ** you entered at the start of the game.
  50. **
  51. ** You get to destroy things when you blow up; hence, it is
  52. ** possible to win the game by destructing if you take the last
  53. ** Klingon with you.
  54. **
  55. ** By the way, the \032 in the message is a ^Z, which is because
  56. ** the terminal in my office is an ADM-3, which uses that char-
  57. ** acter to clear the screen. I also stick in a \014 (form feed)
  58. ** because that clears some other screens.
  59. **
  60. ** Uses trace flag 41
  61. */
  62. /*ARGSUSED*/
  63. void
  64. destruct(v)
  65. int v __attribute__((__unused__));
  66. {
  67. char checkpass[15];
  68. int i, j;
  69. double zap;
  70. if (damaged(COMPUTER)) {
  71. out(COMPUTER);
  72. return;
  73. }
  74. printf("\n\07 --- WORKING ---\07\n");
  75. sleep(3);
  76. /* output the count 10 9 8 7 6 */
  77. for (i = 10; i > 5; i--)
  78. {
  79. for (j = 10; j > i; j--)
  80. printf(" ");
  81. printf("%d\n", i);
  82. sleep(1);
  83. }
  84. /* check for password on new line only */
  85. skiptonl(0);
  86. getstrpar("Enter password verification", checkpass, 14, 0);
  87. sleep(2);
  88. if (strcmp(checkpass, Game.passwd) != 0) {
  89. printf("Self destruct sequence aborted\n");
  90. return;
  91. }
  92. printf("Password verified; self destruct sequence continues:\n");
  93. sleep(2);
  94. /* output count 5 4 3 2 1 0 */
  95. for (i = 5; i >= 0; i--)
  96. {
  97. sleep(1);
  98. for (j = 5; j > i; j--)
  99. printf(" ");
  100. printf("%d\n", i);
  101. }
  102. sleep(2);
  103. printf("\032\014***** %s destroyed *****\n", Ship.shipname);
  104. Game.killed = 1;
  105. /* let's see what we can blow up!!!! */
  106. zap = 20.0 * Ship.energy;
  107. Game.deaths += Ship.crew;
  108. for (i = 0; i < Etc.nkling; )
  109. {
  110. if (Etc.klingon[i].power * Etc.klingon[i].dist <= zap)
  111. killk(Etc.klingon[i].x, Etc.klingon[i].y);
  112. else
  113. i++;
  114. }
  115. /* if we didn't kill the last Klingon (detected by killk), */
  116. /* then we lose.... */
  117. lose(L_DSTRCT);
  118. }