1 /* $OpenBSD: dock.c,v 1.7 2016/01/07 14:37:51 mestre Exp $ */
2 /* $NetBSD: dock.c,v 1.3 1995/04/22 10:58:45 cgd Exp $ */
3
4 /*
5 * Copyright (c) 1980, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #include <stdio.h>
34
35 #include "trek.h"
36
37 /*
38 ** DOCK TO STARBASE
39 **
40 ** The starship is docked to a starbase. For this to work you
41 ** must be adjacent to a starbase.
42 **
43 ** You get your supplies replenished and your captives are
44 ** disembarked. Note that your score is updated now, not when
45 ** you actually take the captives.
46 **
47 ** Any repairs that need to be done are rescheduled to take
48 ** place sooner. This provides for the faster repairs when you
49 ** are docked.
50 */
51
52 void
dock(int v)53 dock(int v)
54 {
55 int i, j;
56 int ok;
57 struct event *e;
58
59 if (Ship.cond == DOCKED)
60 {
61 printf("Chekov: But captain, we are already docked\n");
62 return;
63 }
64 /* check for ok to dock, i.e., adjacent to a starbase */
65 ok = 0;
66 for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++)
67 {
68 if (i < 0 || i >= NSECTS)
69 continue;
70 for (j = Ship.secty - 1; j <= Ship.secty + 1; j++)
71 {
72 if (j < 0 || j >= NSECTS)
73 continue;
74 if (Sect[i][j] == BASE)
75 {
76 ok++;
77 break;
78 }
79 }
80 }
81 if (!ok)
82 {
83 printf("Chekov: But captain, we are not adjacent to a starbase.\n");
84 return;
85 }
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
95 /* reset ship's defenses */
96 Ship.shldup = 0;
97 Ship.cloaked = 0;
98 Ship.cond = DOCKED;
99 Ship.reserves = Param.reserves;
100
101 /* recalibrate space inertial navigation system */
102 Ship.sinsbad = 0;
103
104 /* output any saved radio messages */
105 dumpssradio();
106
107 /* reschedule any device repairs */
108 for (i = 0; i < MAXEVENTS; i++)
109 {
110 e = &Event[i];
111 if (e->evcode != E_FIXDV)
112 continue;
113 reschedule(e, (e->date - Now.date) * Param.dockfac);
114 }
115 }
116
117
118 /*
119 ** LEAVE A STARBASE
120 **
121 ** This is the inverse of dock(). The main function it performs
122 ** is to reschedule any damages so that they will take longer.
123 */
124
125 void
undock(int v)126 undock(int v)
127 {
128 struct event *e;
129 int i;
130
131 if (Ship.cond != DOCKED)
132 {
133 printf("Sulu: Pardon me captain, but we are not docked.\n");
134 return;
135 }
136 Ship.cond = GREEN;
137 Move.free = 0;
138
139 /* reschedule device repair times (again) */
140 for (i = 0; i < MAXEVENTS; i++)
141 {
142 e = &Event[i];
143 if (e->evcode != E_FIXDV)
144 continue;
145 reschedule(e, (e->date - Now.date) / Param.dockfac);
146 }
147 }
148