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