pl_6.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* $NetBSD: pl_6.c,v 1.11 2003/08/07 09:37:44 agc Exp $ */
  2. /*
  3. * Copyright (c) 1983, 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[] = "@(#)pl_6.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: pl_6.c,v 1.11 2003/08/07 09:37:44 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <signal.h>
  39. #include "extern.h"
  40. #include "player.h"
  41. static int turned(void);
  42. void
  43. repair(void)
  44. {
  45. char c;
  46. char *repairs;
  47. struct shipspecs *ptr = mc;
  48. int count;
  49. #define FIX(x, m) (m - ptr->x > count \
  50. ? (ptr->x += count, count = 0) : (count -= m - ptr->x, ptr->x = m))
  51. if (repaired || loaded || fired || changed || turned()) {
  52. Msg("No hands free to repair");
  53. return;
  54. }
  55. c = sgetch("Repair (hull, guns, rigging)? ", (struct ship *)0, 1);
  56. switch (c) {
  57. case 'h':
  58. repairs = &mf->RH;
  59. break;
  60. case 'g':
  61. repairs = &mf->RG;
  62. break;
  63. case 'r':
  64. repairs = &mf->RR;
  65. break;
  66. default:
  67. Msg("Avast heaving!");
  68. return;
  69. }
  70. if (++*repairs >= 3) {
  71. count = 2;
  72. switch (c) {
  73. case 'h': {
  74. int max = ptr->guns/4;
  75. if (ptr->hull < max) {
  76. FIX(hull, max);
  77. Write(W_HULL, ms, ptr->hull, 0, 0, 0);
  78. }
  79. break;
  80. }
  81. case 'g':
  82. if (ptr->gunL < ptr->gunR) {
  83. int max = ptr->guns/5 - ptr->carL;
  84. if (ptr->gunL < max) {
  85. FIX(gunL, max);
  86. Write(W_GUNL, ms, ptr->gunL,
  87. ptr->carL, 0, 0);
  88. }
  89. } else {
  90. int max = ptr->guns/5 - ptr->carR;
  91. if (ptr->gunR < max) {
  92. FIX(gunR, max);
  93. Write(W_GUNR, ms, ptr->gunR,
  94. ptr->carR, 0, 0);
  95. }
  96. }
  97. break;
  98. case 'r':
  99. #define X 2
  100. if (ptr->rig4 >= 0 && ptr->rig4 < X) {
  101. FIX(rig4, X);
  102. Write(W_RIG4, ms, ptr->rig4, 0, 0, 0);
  103. }
  104. if (count && ptr->rig3 < X) {
  105. FIX(rig3, X);
  106. Write(W_RIG3, ms, ptr->rig3, 0, 0, 0);
  107. }
  108. if (count && ptr->rig2 < X) {
  109. FIX(rig2, X);
  110. Write(W_RIG2, ms, ptr->rig2, 0, 0, 0);
  111. }
  112. if (count && ptr->rig1 < X) {
  113. FIX(rig1, X);
  114. Write(W_RIG1, ms, ptr->rig1, 0, 0, 0);
  115. }
  116. break;
  117. }
  118. if (count == 2) {
  119. Msg("Repairs completed.");
  120. *repairs = 2;
  121. } else {
  122. *repairs = 0;
  123. blockalarm();
  124. draw_stat();
  125. unblockalarm();
  126. }
  127. }
  128. blockalarm();
  129. draw_slot();
  130. unblockalarm();
  131. repaired = 1;
  132. }
  133. static int
  134. turned(void)
  135. {
  136. char *p;
  137. for (p = movebuf; *p; p++)
  138. if (*p == 'r' || *p == 'l')
  139. return 1;
  140. return 0;
  141. }
  142. void
  143. loadplayer(void)
  144. {
  145. char c;
  146. int loadL, loadR, ready, load;
  147. if (!mc->crew3) {
  148. Msg("Out of crew");
  149. return;
  150. }
  151. loadL = mf->loadL;
  152. loadR = mf->loadR;
  153. if (!loadL && !loadR) {
  154. c = sgetch("Load which broadside (left or right)? ",
  155. (struct ship *)0, 1);
  156. if (c == 'r')
  157. loadL = 1;
  158. else
  159. loadR = 1;
  160. }
  161. if ((!loadL && loadR) || (loadL && !loadR)) {
  162. c = sgetch("Reload with (round, double, chain, grape)? ",
  163. (struct ship *)0, 1);
  164. switch (c) {
  165. case 'r':
  166. load = L_ROUND;
  167. ready = 0;
  168. break;
  169. case 'd':
  170. load = L_DOUBLE;
  171. ready = R_DOUBLE;
  172. break;
  173. case 'c':
  174. load = L_CHAIN;
  175. ready = 0;
  176. break;
  177. case 'g':
  178. load = L_GRAPE;
  179. ready = 0;
  180. break;
  181. default:
  182. Msg("Broadside not loaded.");
  183. return;
  184. }
  185. if (!loadR) {
  186. mf->loadR = load;
  187. mf->readyR = ready|R_LOADING;
  188. } else {
  189. mf->loadL = load;
  190. mf->readyL = ready|R_LOADING;
  191. }
  192. loaded = 1;
  193. }
  194. }