1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)dock.c 8.1 (Berkeley) 05/31/93";
10 #endif /* not lint */
11
12 # include "trek.h"
13
14 /*
15 ** DOCK TO STARBASE
16 **
17 ** The starship is docked to a starbase. For this to work you
18 ** must be adjacent to a starbase.
19 **
20 ** You get your supplies replenished and your captives are
21 ** disembarked. Note that your score is updated now, not when
22 ** you actually take the captives.
23 **
24 ** Any repairs that need to be done are rescheduled to take
25 ** place sooner. This provides for the faster repairs when you
26 ** are docked.
27 */
28
dock()29 dock()
30 {
31 register int i, j;
32 int ok;
33 register struct event *e;
34
35 if (Ship.cond == DOCKED)
36 return (printf("Chekov: But captain, we are already docked\n"));
37 /* check for ok to dock, i.e., adjacent to a starbase */
38 ok = 0;
39 for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++)
40 {
41 if (i < 0 || i >= NSECTS)
42 continue;
43 for (j = Ship.secty - 1; j <= Ship.secty + 1; j++)
44 {
45 if (j < 0 || j >= NSECTS)
46 continue;
47 if (Sect[i][j] == BASE)
48 {
49 ok++;
50 break;
51 }
52 }
53 }
54 if (!ok)
55 return (printf("Chekov: But captain, we are not adjacent to a starbase.\n"));
56
57 /* restore resources */
58 Ship.energy = Param.energy;
59 Ship.torped = Param.torped;
60 Ship.shield = Param.shield;
61 Ship.crew = Param.crew;
62 Game.captives += Param.brigfree - Ship.brigfree;
63 Ship.brigfree = Param.brigfree;
64
65 /* reset ship's defenses */
66 Ship.shldup = 0;
67 Ship.cloaked = 0;
68 Ship.cond = DOCKED;
69 Ship.reserves = Param.reserves;
70
71 /* recalibrate space inertial navigation system */
72 Ship.sinsbad = 0;
73
74 /* output any saved radio messages */
75 dumpssradio();
76
77 /* reschedule any device repairs */
78 for (i = 0; i < MAXEVENTS; i++)
79 {
80 e = &Event[i];
81 if (e->evcode != E_FIXDV)
82 continue;
83 reschedule(e, (e->date - Now.date) * Param.dockfac);
84 }
85 return;
86 }
87
88
89 /*
90 ** LEAVE A STARBASE
91 **
92 ** This is the inverse of dock(). The main function it performs
93 ** is to reschedule any damages so that they will take longer.
94 */
95
undock()96 undock()
97 {
98 register struct event *e;
99 register int i;
100
101 if (Ship.cond != DOCKED)
102 {
103 printf("Sulu: Pardon me captain, but we are not docked.\n");
104 return;
105 }
106 Ship.cond = GREEN;
107 Move.free = 0;
108
109 /* reschedule device repair times (again) */
110 for (i = 0; i < MAXEVENTS; i++)
111 {
112 e = &Event[i];
113 if (e->evcode != E_FIXDV)
114 continue;
115 reschedule(e, (e->date - Now.date) / Param.dockfac);
116 }
117 return;
118 }
119