pl_3.c revision 1.12 1 1.12 jwise /* $NetBSD: pl_3.c,v 1.12 2001/01/04 03:21:17 jwise Exp $ */
2 1.3 cgd
3 1.1 cgd /*
4 1.3 cgd * Copyright (c) 1983, 1993
5 1.3 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.4 christos #include <sys/cdefs.h>
37 1.1 cgd #ifndef lint
38 1.3 cgd #if 0
39 1.3 cgd static char sccsid[] = "@(#)pl_3.c 8.1 (Berkeley) 5/31/93";
40 1.3 cgd #else
41 1.12 jwise __RCSID("$NetBSD: pl_3.c,v 1.12 2001/01/04 03:21:17 jwise Exp $");
42 1.3 cgd #endif
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.12 jwise #include <stdlib.h>
46 1.1 cgd #include "player.h"
47 1.11 jwise
48 1.11 jwise void acceptcombat(void);
49 1.11 jwise void grapungrap(void);
50 1.11 jwise void unfoulplayer(void);
51 1.1 cgd
52 1.4 christos void
53 1.10 jwise acceptcombat(void)
54 1.1 cgd {
55 1.1 cgd int men = 0;
56 1.1 cgd int target, temp;
57 1.1 cgd int n, r;
58 1.1 cgd int index, rakehim, sternrake;
59 1.1 cgd int hhits = 0, ghits = 0, rhits = 0, chits = 0;
60 1.1 cgd int crew[3];
61 1.1 cgd int load;
62 1.1 cgd int guns, car, ready, shootat, hit;
63 1.1 cgd int roll;
64 1.1 cgd struct ship *closest;
65 1.1 cgd
66 1.1 cgd crew[0] = mc->crew1;
67 1.1 cgd crew[1] = mc->crew2;
68 1.1 cgd crew[2] = mc->crew3;
69 1.1 cgd for (n = 0; n < 3; n++) {
70 1.1 cgd if (mf->OBP[n].turnsent)
71 1.1 cgd men += mf->OBP[n].mensent;
72 1.1 cgd }
73 1.1 cgd for (n = 0; n < 3; n++) {
74 1.1 cgd if (mf->DBP[n].turnsent)
75 1.1 cgd men += mf->DBP[n].mensent;
76 1.1 cgd }
77 1.1 cgd if (men) {
78 1.1 cgd crew[0] = men/100 ? 0 : crew[0] != 0;
79 1.1 cgd crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
80 1.1 cgd crew[2] = men%10 ? 0 : crew[2] != 0;
81 1.1 cgd }
82 1.1 cgd for (r = 0; r < 2; r++) {
83 1.1 cgd if (r) {
84 1.1 cgd ready = mf->readyR;
85 1.1 cgd load = mf->loadR;
86 1.1 cgd guns = mc->gunR;
87 1.1 cgd car = mc->carR;
88 1.1 cgd } else {
89 1.1 cgd ready = mf->readyL;
90 1.1 cgd load = mf->loadL;
91 1.1 cgd guns = mc->gunL;
92 1.1 cgd car = mc->carL;
93 1.1 cgd }
94 1.4 christos if ((!guns && !car) || load == L_EMPTY || (ready & R_LOADED) == 0)
95 1.1 cgd goto cant;
96 1.1 cgd if (mf->struck || !crew[2])
97 1.1 cgd goto cant;
98 1.1 cgd closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
99 1.1 cgd if (closest == 0)
100 1.1 cgd goto cant;
101 1.1 cgd if (closest->file->struck)
102 1.1 cgd goto cant;
103 1.1 cgd target = range(ms, closest);
104 1.4 christos if (target > rangeofshot[load] || (!guns && target >= 3))
105 1.1 cgd goto cant;
106 1.5 christos Signal("$$ within range of %s broadside.",
107 1.1 cgd closest, r ? "right" : "left");
108 1.1 cgd if (load > L_CHAIN && target < 6) {
109 1.1 cgd switch (sgetch("Aim for hull or rigging? ",
110 1.1 cgd (struct ship *)0, 1)) {
111 1.1 cgd case 'r':
112 1.1 cgd shootat = RIGGING;
113 1.1 cgd break;
114 1.1 cgd case 'h':
115 1.1 cgd shootat = HULL;
116 1.1 cgd break;
117 1.1 cgd default:
118 1.1 cgd shootat = -1;
119 1.4 christos Msg("'Avast there! Hold your fire.'");
120 1.1 cgd }
121 1.1 cgd } else {
122 1.1 cgd if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
123 1.1 cgd shootat = -1;
124 1.4 christos Msg("Belay that! Hold your fire.");
125 1.1 cgd } else
126 1.1 cgd shootat = RIGGING;
127 1.1 cgd }
128 1.1 cgd if (shootat == -1)
129 1.1 cgd continue;
130 1.1 cgd fired = 1;
131 1.1 cgd rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
132 1.1 cgd temp = portside(closest, ms, 1) - closest->file->dir + 1;
133 1.1 cgd if (temp < 1)
134 1.1 cgd temp += 8;
135 1.1 cgd else if (temp > 8)
136 1.1 cgd temp -= 8;
137 1.1 cgd sternrake = temp > 4 && temp < 6;
138 1.6 veego if (rakehim) {
139 1.1 cgd if (!sternrake)
140 1.5 christos Msg("Raking the %s!", closest->shipname);
141 1.1 cgd else
142 1.5 christos Msg("Stern Rake! %s splintering!",
143 1.5 christos closest->shipname);
144 1.6 veego }
145 1.1 cgd index = guns;
146 1.1 cgd if (target < 3)
147 1.1 cgd index += car;
148 1.1 cgd index = (index - 1)/3;
149 1.1 cgd index = index > 8 ? 8 : index;
150 1.1 cgd if (!rakehim)
151 1.1 cgd hit = HDT[index][target-1];
152 1.1 cgd else
153 1.1 cgd hit = HDTrake[index][target-1];
154 1.1 cgd if (rakehim && sternrake)
155 1.1 cgd hit++;
156 1.1 cgd hit += QUAL[index][mc->qual-1];
157 1.1 cgd for (n = 0; n < 3 && mf->captured == 0; n++)
158 1.6 veego if (!crew[n]) {
159 1.1 cgd if (index <= 5)
160 1.1 cgd hit--;
161 1.1 cgd else
162 1.1 cgd hit -= 2;
163 1.6 veego }
164 1.6 veego if (ready & R_INITIAL) {
165 1.1 cgd if (index <= 3)
166 1.1 cgd hit++;
167 1.1 cgd else
168 1.1 cgd hit += 2;
169 1.6 veego }
170 1.6 veego if (mf->captured != 0) {
171 1.1 cgd if (index <= 1)
172 1.1 cgd hit--;
173 1.1 cgd else
174 1.1 cgd hit -= 2;
175 1.6 veego }
176 1.1 cgd hit += AMMO[index][load - 1];
177 1.1 cgd if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
178 1.1 cgd hit--;
179 1.1 cgd if (windspeed == 6 && temp == 4)
180 1.1 cgd hit -= 2;
181 1.1 cgd if (windspeed == 6 && temp <= 3)
182 1.1 cgd hit--;
183 1.1 cgd if (hit >= 0) {
184 1.9 jwise roll = dieroll();
185 1.1 cgd if (load == L_GRAPE)
186 1.1 cgd chits = hit;
187 1.1 cgd else {
188 1.8 jsm const struct Tables *t;
189 1.1 cgd if (hit > 10)
190 1.1 cgd hit = 10;
191 1.1 cgd t = &(shootat == RIGGING ? RigTable : HullTable)
192 1.1 cgd [hit][roll-1];
193 1.1 cgd chits = t->C;
194 1.1 cgd rhits = t->R;
195 1.1 cgd hhits = t->H;
196 1.1 cgd ghits = t->G;
197 1.1 cgd if (closest->file->FS)
198 1.1 cgd rhits *= 2;
199 1.1 cgd if (load == L_CHAIN) {
200 1.1 cgd ghits = 0;
201 1.1 cgd hhits = 0;
202 1.1 cgd }
203 1.1 cgd }
204 1.1 cgd table(shootat, load, hit, closest, ms, roll);
205 1.1 cgd }
206 1.4 christos Msg("Damage inflicted on the %s:", closest->shipname);
207 1.4 christos Msg("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
208 1.4 christos hhits, ghits, chits, rhits);
209 1.1 cgd if (!r) {
210 1.1 cgd mf->loadL = L_EMPTY;
211 1.1 cgd mf->readyL = R_EMPTY;
212 1.1 cgd } else {
213 1.1 cgd mf->loadR = L_EMPTY;
214 1.1 cgd mf->readyR = R_EMPTY;
215 1.1 cgd }
216 1.1 cgd continue;
217 1.1 cgd cant:
218 1.4 christos Msg("Unable to fire %s broadside", r ? "right" : "left");
219 1.1 cgd }
220 1.1 cgd blockalarm();
221 1.1 cgd draw_stat();
222 1.1 cgd unblockalarm();
223 1.1 cgd }
224 1.1 cgd
225 1.4 christos void
226 1.10 jwise grapungrap(void)
227 1.1 cgd {
228 1.4 christos struct ship *sp;
229 1.4 christos int i;
230 1.1 cgd
231 1.1 cgd foreachship(sp) {
232 1.1 cgd if (sp == ms || sp->file->dir == 0)
233 1.1 cgd continue;
234 1.1 cgd if (range(ms, sp) > 1 && !grappled2(ms, sp))
235 1.1 cgd continue;
236 1.5 christos switch (sgetch("Attempt to grapple or ungrapple $$: ",
237 1.1 cgd sp, 1)) {
238 1.1 cgd case 'g':
239 1.9 jwise if (dieroll() < 3
240 1.1 cgd || ms->nationality == capship(sp)->nationality) {
241 1.7 hubertf Write(W_GRAP, ms, sp->file->index, 0, 0, 0);
242 1.7 hubertf Write(W_GRAP, sp, player, 0, 0, 0);
243 1.4 christos Msg("Attempt succeeds!");
244 1.5 christos makesignal(ms, "grappled with $$", sp);
245 1.1 cgd } else
246 1.4 christos Msg("Attempt fails.");
247 1.1 cgd break;
248 1.1 cgd case 'u':
249 1.1 cgd for (i = grappled2(ms, sp); --i >= 0;) {
250 1.1 cgd if (ms->nationality
251 1.1 cgd == capship(sp)->nationality
252 1.9 jwise || dieroll() < 3) {
253 1.1 cgd cleangrapple(ms, sp, 0);
254 1.4 christos Msg("Attempt succeeds!");
255 1.5 christos makesignal(ms, "ungrappling with $$",
256 1.1 cgd sp);
257 1.1 cgd } else
258 1.4 christos Msg("Attempt fails.");
259 1.1 cgd }
260 1.1 cgd break;
261 1.1 cgd }
262 1.1 cgd }
263 1.1 cgd }
264 1.1 cgd
265 1.4 christos void
266 1.10 jwise unfoulplayer(void)
267 1.1 cgd {
268 1.4 christos struct ship *to;
269 1.4 christos int i;
270 1.1 cgd
271 1.1 cgd foreachship(to) {
272 1.1 cgd if (fouled2(ms, to) == 0)
273 1.1 cgd continue;
274 1.5 christos if (sgetch("Attempt to unfoul with the $$? ", to, 1) != 'y')
275 1.1 cgd continue;
276 1.1 cgd for (i = fouled2(ms, to); --i >= 0;) {
277 1.9 jwise if (dieroll() <= 2) {
278 1.1 cgd cleanfoul(ms, to, 0);
279 1.4 christos Msg("Attempt succeeds!");
280 1.5 christos makesignal(ms, "Unfouling $$", to);
281 1.1 cgd } else
282 1.4 christos Msg("Attempt fails.");
283 1.1 cgd }
284 1.1 cgd }
285 1.1 cgd }
286