1 /* $OpenBSD: shield.c,v 1.9 2016/01/07 14:37:51 mestre Exp $ */
2 /* $NetBSD: shield.c,v 1.4 1995/04/24 12:26:09 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 "getpar.h"
36 #include "trek.h"
37
38 /*
39 ** SHIELD AND CLOAKING DEVICE CONTROL
40 **
41 ** 'f' is one for auto shield up (in case of Condition RED),
42 ** zero for shield control, and negative one for cloaking
43 ** device control.
44 **
45 ** Called with an 'up' or 'down' on the same line, it puts
46 ** the shields/cloak into the specified mode. Otherwise it
47 ** reports to the user the current mode, and asks if she wishes
48 ** to change.
49 **
50 ** This is not a free move. Hits that occur as a result of
51 ** this move appear as though the shields are half up/down,
52 ** so you get partial hits.
53 */
54
55 const struct cvntab Udtab[] =
56 {
57 { "u", "p", (cmdfun)1, 0 },
58 { "d", "own", (cmdfun)0, 0 },
59 { NULL, NULL, NULL, 0 }
60 };
61
62 void
shield(int f)63 shield(int f)
64 {
65 int i;
66 const struct cvntab *r;
67 char s[100];
68 const char *device, *dev2, *dev3;
69 int ind;
70 char *stat;
71
72 if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
73 return;
74 if (f < 0)
75 {
76 /* cloaking device */
77 if (Ship.ship == QUEENE)
78 {
79 printf("Ye Faire Queene does not have the cloaking device.\n");
80 return;
81 }
82 device = "Cloaking device";
83 dev2 = "is";
84 ind = CLOAK;
85 dev3 = "it";
86 stat = &Ship.cloaked;
87 }
88 else
89 {
90 /* shields */
91 device = "Shields";
92 dev2 = "are";
93 dev3 = "them";
94 ind = SHIELD;
95 stat = &Ship.shldup;
96 }
97 if (damaged(ind))
98 {
99 if (f <= 0)
100 out(ind);
101 return;
102 }
103 if (Ship.cond == DOCKED)
104 {
105 printf("%s %s down while docked\n", device, dev2);
106 return;
107 }
108 if (f <= 0 && !testnl())
109 {
110 r = getcodpar("Up or down", Udtab);
111 i = (long) r->value;
112 }
113 else
114 {
115 if (*stat)
116 (void)snprintf(s, sizeof s,
117 "%s %s up. Do you want %s down", device, dev2, dev3);
118 else
119 (void)snprintf(s, sizeof s,
120 "%s %s down. Do you want %s up", device, dev2, dev3);
121 if (!getynpar(s))
122 return;
123 i = !*stat;
124 }
125 if (*stat == i)
126 {
127 printf("%s already ", device);
128 if (i)
129 printf("up\n");
130 else
131 printf("down\n");
132 return;
133 }
134 if (i)
135 {
136 if (f >= 0)
137 Ship.energy -= Param.shupengy;
138 else
139 Ship.cloakgood = 0;
140 }
141 Move.free = 0;
142 if (f >= 0)
143 Move.shldchg = 1;
144 *stat = i;
145 }
146