shield.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* $NetBSD: shield.c,v 1.8 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[] = "@(#)shield.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: shield.c,v 1.8 2003/08/07 09:37:54 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include "trek.h"
  40. #include "getpar.h"
  41. /*
  42. ** SHIELD AND CLOAKING DEVICE CONTROL
  43. **
  44. ** 'f' is one for auto shield up (in case of Condition RED),
  45. ** zero for shield control, and negative one for cloaking
  46. ** device control.
  47. **
  48. ** Called with an 'up' or 'down' on the same line, it puts
  49. ** the shields/cloak into the specified mode. Otherwise it
  50. ** reports to the user the current mode, and asks if she wishes
  51. ** to change.
  52. **
  53. ** This is not a free move. Hits that occur as a result of
  54. ** this move appear as though the shields are half up/down,
  55. ** so you get partial hits.
  56. */
  57. const struct cvntab Udtab[] =
  58. {
  59. { "u", "p", (cmdfun)1, 0 },
  60. { "d", "own", (cmdfun)0, 0 },
  61. { NULL, NULL, NULL, 0 }
  62. };
  63. void
  64. shield(f)
  65. int f;
  66. {
  67. int i;
  68. const struct cvntab *r;
  69. char s[100];
  70. const char *device, *dev2, *dev3;
  71. int ind;
  72. char *stat;
  73. if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
  74. return;
  75. if (f < 0)
  76. {
  77. /* cloaking device */
  78. if (Ship.ship == QUEENE) {
  79. printf("Ye Faire Queene does not have the cloaking device.\n");
  80. return;
  81. }
  82. device = "Cloaking device";
  83. dev2 = "is";
  84. ind = CLOAK;
  85. dev3 = "it";
  86. stat = &Ship.cloaked;
  87. }
  88. else
  89. {
  90. /* shields */
  91. device = "Shields";
  92. dev2 = "are";
  93. dev3 = "them";
  94. ind = SHIELD;
  95. stat = &Ship.shldup;
  96. }
  97. if (damaged(ind))
  98. {
  99. if (f <= 0)
  100. out(ind);
  101. return;
  102. }
  103. if (Ship.cond == DOCKED)
  104. {
  105. printf("%s %s down while docked\n", device, dev2);
  106. return;
  107. }
  108. if (f <= 0 && !testnl())
  109. {
  110. r = getcodpar("Up or down", Udtab);
  111. i = (long) r->value;
  112. }
  113. else
  114. {
  115. if (*stat)
  116. (void)sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3);
  117. else
  118. (void)sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3);
  119. if (!getynpar(s))
  120. return;
  121. i = !*stat;
  122. }
  123. if (*stat == i)
  124. {
  125. printf("%s already ", device);
  126. if (i)
  127. printf("up\n");
  128. else
  129. printf("down\n");
  130. return;
  131. }
  132. if (i) {
  133. if (f >= 0)
  134. Ship.energy -= Param.shupengy;
  135. else
  136. Ship.cloakgood = 0;
  137. }
  138. Move.free = 0;
  139. if (f >= 0)
  140. Move.shldchg = 1;
  141. *stat = i;
  142. return;
  143. }