Commit | Line | Data |
---|---|---|
9758240b KM |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
e9fb6bea KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
d99e6414 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
9758240b KM |
16 | */ |
17 | ||
cc9c0a85 | 18 | #ifndef lint |
d99e6414 | 19 | static char sccsid[] = "@(#)shield.c 5.4 (Berkeley) %G%"; |
e9fb6bea | 20 | #endif /* not lint */ |
cc9c0a85 KM |
21 | |
22 | # include "trek.h" | |
23 | # include "getpar.h" | |
24 | ||
25 | /* | |
26 | ** SHIELD AND CLOAKING DEVICE CONTROL | |
27 | ** | |
28 | ** 'f' is one for auto shield up (in case of Condition RED), | |
29 | ** zero for shield control, and negative one for cloaking | |
30 | ** device control. | |
31 | ** | |
32 | ** Called with an 'up' or 'down' on the same line, it puts | |
33 | ** the shields/cloak into the specified mode. Otherwise it | |
34 | ** reports to the user the current mode, and asks if she wishes | |
35 | ** to change. | |
36 | ** | |
37 | ** This is not a free move. Hits that occur as a result of | |
38 | ** this move appear as though the shields are half up/down, | |
39 | ** so you get partial hits. | |
40 | */ | |
41 | ||
401a08c7 | 42 | struct cvntab Udtab[] = |
cc9c0a85 | 43 | { |
401a08c7 | 44 | "u", "p", (int (*)())1, 0, |
cc9c0a85 KM |
45 | "d", "own", 0, 0, |
46 | 0 | |
47 | }; | |
48 | ||
49 | shield(f) | |
50 | int f; | |
51 | { | |
52 | register int i; | |
53 | char c; | |
54 | struct cvntab *r; | |
55 | char s[100]; | |
56 | char *device, *dev2, *dev3; | |
57 | int ind; | |
58 | char *stat; | |
59 | ||
60 | if (f > 0 && (Ship.shldup || damaged(SRSCAN))) | |
61 | return; | |
62 | if (f < 0) | |
63 | { | |
64 | /* cloaking device */ | |
65 | if (Ship.ship == QUEENE) | |
66 | return (printf("Ye Faire Queene does not have the cloaking device.\n")); | |
67 | device = "Cloaking device"; | |
68 | dev2 = "is"; | |
69 | ind = CLOAK; | |
70 | dev3 = "it"; | |
71 | stat = &Ship.cloaked; | |
72 | } | |
73 | else | |
74 | { | |
75 | /* shields */ | |
76 | device = "Shields"; | |
77 | dev2 = "are"; | |
78 | dev3 = "them"; | |
79 | ind = SHIELD; | |
80 | stat = &Ship.shldup; | |
81 | } | |
82 | if (damaged(ind)) | |
83 | { | |
84 | if (f <= 0) | |
85 | out(ind); | |
86 | return; | |
87 | } | |
88 | if (Ship.cond == DOCKED) | |
89 | { | |
90 | printf("%s %s down while docked\n", device, dev2); | |
91 | return; | |
92 | } | |
93 | if (f <= 0 && !testnl()) | |
94 | { | |
95 | r = getcodpar("Up or down", Udtab); | |
401a08c7 | 96 | i = (int) r->value; |
cc9c0a85 KM |
97 | } |
98 | else | |
99 | { | |
100 | if (*stat) | |
e578d1f3 | 101 | (void)sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3); |
cc9c0a85 | 102 | else |
e578d1f3 | 103 | (void)sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3); |
cc9c0a85 KM |
104 | if (!getynpar(s)) |
105 | return; | |
106 | i = !*stat; | |
107 | } | |
108 | if (*stat == i) | |
109 | { | |
110 | printf("%s already ", device); | |
111 | if (i) | |
112 | printf("up\n"); | |
113 | else | |
114 | printf("down\n"); | |
115 | return; | |
116 | } | |
117 | if (i) | |
118 | if (f >= 0) | |
401a08c7 | 119 | Ship.energy -= Param.shupengy; |
cc9c0a85 KM |
120 | else |
121 | Ship.cloakgood = 0; | |
122 | Move.free = 0; | |
123 | if (f >= 0) | |
124 | Move.shldchg = 1; | |
125 | *stat = i; | |
126 | return; | |
127 | } |