dock.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* $NetBSD: dock.c,v 1.6 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[] = "@(#)dock.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: dock.c,v 1.6 2003/08/07 09:37:50 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include <stdio.h>
  39. #include "trek.h"
  40. /*
  41. ** DOCK TO STARBASE
  42. **
  43. ** The starship is docked to a starbase. For this to work you
  44. ** must be adjacent to a starbase.
  45. **
  46. ** You get your supplies replenished and your captives are
  47. ** disembarked. Note that your score is updated now, not when
  48. ** you actually take the captives.
  49. **
  50. ** Any repairs that need to be done are rescheduled to take
  51. ** place sooner. This provides for the faster repairs when you
  52. ** are docked.
  53. */
  54. /*ARGSUSED*/
  55. void
  56. dock(v)
  57. int v __attribute__((__unused__));
  58. {
  59. int i, j;
  60. int ok;
  61. struct event *e;
  62. if (Ship.cond == DOCKED) {
  63. printf("Chekov: But captain, we are already docked\n");
  64. return;
  65. }
  66. /* check for ok to dock, i.e., adjacent to a starbase */
  67. ok = 0;
  68. for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++)
  69. {
  70. if (i < 0 || i >= NSECTS)
  71. continue;
  72. for (j = Ship.secty - 1; j <= Ship.secty + 1; j++)
  73. {
  74. if (j < 0 || j >= NSECTS)
  75. continue;
  76. if (Sect[i][j] == BASE)
  77. {
  78. ok++;
  79. break;
  80. }
  81. }
  82. }
  83. if (!ok) {
  84. printf("Chekov: But captain, we are not adjacent to a starbase.\n");
  85. return;
  86. }
  87. /* restore resources */
  88. Ship.energy = Param.energy;
  89. Ship.torped = Param.torped;
  90. Ship.shield = Param.shield;
  91. Ship.crew = Param.crew;
  92. Game.captives += Param.brigfree - Ship.brigfree;
  93. Ship.brigfree = Param.brigfree;
  94. /* reset ship's defenses */
  95. Ship.shldup = 0;
  96. Ship.cloaked = 0;
  97. Ship.cond = DOCKED;
  98. Ship.reserves = Param.reserves;
  99. /* recalibrate space inertial navigation system */
  100. Ship.sinsbad = 0;
  101. /* output any saved radio messages */
  102. dumpssradio();
  103. /* reschedule any device repairs */
  104. for (i = 0; i < MAXEVENTS; i++)
  105. {
  106. e = &Event[i];
  107. if (e->evcode != E_FIXDV)
  108. continue;
  109. reschedule(e, (e->date - Now.date) * Param.dockfac);
  110. }
  111. return;
  112. }
  113. /*
  114. ** LEAVE A STARBASE
  115. **
  116. ** This is the inverse of dock(). The main function it performs
  117. ** is to reschedule any damages so that they will take longer.
  118. */
  119. /*ARGSUSED*/
  120. void
  121. undock(v)
  122. int v __attribute__((__unused__));
  123. {
  124. struct event *e;
  125. int i;
  126. if (Ship.cond != DOCKED)
  127. {
  128. printf("Sulu: Pardon me captain, but we are not docked.\n");
  129. return;
  130. }
  131. Ship.cond = GREEN;
  132. Move.free = 0;
  133. /* reschedule device repair times (again) */
  134. for (i = 0; i < MAXEVENTS; i++)
  135. {
  136. e = &Event[i];
  137. if (e->evcode != E_FIXDV)
  138. continue;
  139. reschedule(e, (e->date - Now.date) / Param.dockfac);
  140. }
  141. return;
  142. }