something else wrong
[unix-history] / usr / src / games / sail / pl_3.c
CommitLineData
b1823ffa 1#ifndef lint
ce837792 2static char *sccsid = "@(#)pl_3.c 2.1 83/10/31";
b1823ffa
EW
3#endif
4
5#include "player.h"
6
7acceptcombat()
8{
9 int men = 0;
10 int target, temp;
11 int n, r;
12 int index, rakehim, sternrake;
13 int hhits = 0, ghits = 0, rhits = 0, chits = 0;
14 int crew[3];
15 int load;
16 int guns, car, ready, shootat, hit;
17 int roll;
18 struct ship *closest;
19
20 crew[0] = mc->crew1;
21 crew[1] = mc->crew2;
22 crew[2] = mc->crew3;
23 for (n = 0; n < 3; n++) {
24 if (mf->OBP[n].turnsent)
25 men += mf->OBP[n].mensent;
26 }
27 for (n = 0; n < 3; n++) {
28 if (mf->DBP[n].turnsent)
29 men += mf->DBP[n].mensent;
30 }
31 if (men) {
32 crew[0] = men/100 ? 0 : crew[0] != 0;
33 crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
34 crew[2] = men%10 ? 0 : crew[2] != 0;
35 }
36 for (r = 0; r < 2; r++) {
37 if (r) {
38 ready = mf->readyR;
39 load = mf->loadR;
40 guns = mc->gunR;
41 car = mc->carR;
42 } else {
43 ready = mf->readyL;
44 load = mf->loadL;
45 guns = mc->gunL;
46 car = mc->carL;
47 }
48 if (!guns && !car || load == L_EMPTY || (ready & R_LOADED) == 0)
49 goto cant;
50 if (mf->struck || !crew[2])
51 goto cant;
52 closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
53 if (closest == 0)
54 goto cant;
55 if (closest->file->struck)
56 goto cant;
57 target = range(ms, closest);
58 if (target > rangeofshot[load] || !guns && target >= 3)
59 goto cant;
60 Signal("%s (%c%c) within range of %s broadside.",
61 closest, r ? "right" : "left");
62 if (load > L_CHAIN && target < 6) {
789d5e82
EW
63 switch (sgetch("Aim for hull or rigging? ",
64 (struct ship *)0, 1)) {
b1823ffa
EW
65 case 'r':
66 shootat = RIGGING;
67 break;
68 case 'h':
69 shootat = HULL;
70 break;
71 default:
72 shootat = -1;
73 Signal("'Avast there! Hold your fire.'",
74 (struct ship *)0);
75 }
76 } else {
789d5e82 77 if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
b1823ffa
EW
78 shootat = -1;
79 Signal("Belay that! Hold your fire.",
80 (struct ship *)0);
81 } else
82 shootat = RIGGING;
83 }
84 if (shootat == -1)
85 continue;
86 fired = 1;
87 rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
88 temp = portside(closest, ms, 1) - closest->file->dir + 1;
89 if (temp < 1)
90 temp += 8;
91 else if (temp > 8)
92 temp -= 8;
93 sternrake = temp > 4 && temp < 6;
94 if (rakehim)
95 if (!sternrake)
96 Signal("Raking the %s!", closest);
97 else
98 Signal("Stern Rake! %s splintering!", closest);
99 index = guns;
100 if (target < 3)
101 index += car;
102 index = (index - 1)/3;
103 index = index > 8 ? 8 : index;
104 if (!rakehim)
105 hit = HDT[index][target-1];
106 else
107 hit = HDTrake[index][target-1];
108 if (rakehim && sternrake)
109 hit++;
110 hit += QUAL[index][mc->qual-1];
111 for (n = 0; n < 3 && mf->captured == 0; n++)
112 if (!crew[n])
113 if (index <= 5)
114 hit--;
115 else
116 hit -= 2;
117 if (ready & R_INITIAL)
118 if (index <= 3)
119 hit++;
120 else
121 hit += 2;
122 if (mf->captured != 0)
123 if (index <= 1)
124 hit--;
125 else
126 hit -= 2;
127 hit += AMMO[index][load - 1];
128 if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
129 hit--;
130 if (windspeed == 6 && temp == 4)
131 hit -= 2;
132 if (windspeed == 6 && temp <= 3)
133 hit--;
134 if (hit >= 0) {
135 roll = die();
136 if (load == L_GRAPE)
137 chits = hit;
138 else {
139 struct Tables *t;
140 if (hit > 10)
141 hit = 10;
142 t = &(shootat == RIGGING ? RigTable : HullTable)
143 [hit][roll-1];
144 chits = t->C;
145 rhits = t->R;
146 hhits = t->H;
147 ghits = t->G;
148 if (closest->file->FS)
149 rhits *= 2;
150 if (load == L_CHAIN) {
151 ghits = 0;
152 hhits = 0;
153 }
154 }
155 table(shootat, load, hit, closest, ms, roll);
156 }
789d5e82
EW
157 Signal("Damage inflicted on the %s:",
158 (struct ship *)0, closest->shipname);
159 Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
160 (struct ship *)0, hhits, ghits, chits, rhits);
b1823ffa
EW
161 if (!r) {
162 mf->loadL = L_EMPTY;
163 mf->readyL = R_EMPTY;
164 } else {
165 mf->loadR = L_EMPTY;
166 mf->readyR = R_EMPTY;
167 }
168 continue;
169 cant:
170 Signal("Unable to fire %s broadside",
171 (struct ship *)0, r ? "right" : "left");
172 }
fcc6b1db 173 draw_stat();
b1823ffa
EW
174}
175
176grapungrap()
177{
178 register struct ship *sp;
179 register int n, k;
180 register struct snag *p;
70461436 181 int r;
b1823ffa
EW
182
183 n = -1;
184 foreachship(sp) {
185 n++;
186 if (sp == ms)
187 continue;
70461436 188 r = range(ms, sp);
789d5e82 189 if ((r < 0 || r > 1) && !grappled2(ms, sp))
b1823ffa 190 continue;
789d5e82
EW
191 switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
192 sp, 1)) {
b1823ffa
EW
193 case 'g':
194 if (die() < 3
195 || ms->nationality == capship(sp)->nationality) {
196 for (k = 0, p = mf->grapples;
197 k < NSHIP && p->turnfoul; k++, p++)
198 ; /* XXX */
199 if (k < NSHIP)
200 Write(W_GRAP, ms, 0, k, turn, n, 0);
201 for (k = 0, p = sp->file->grapples;
202 k < NSHIP && p->turnfoul; k++, p++)
203 ; /* XXX */
204 if (k < NSHIP)
205 Write(W_GRAP, sp, 0,
206 k, turn, player, 0);
207 Signal("Attempt succeeds!", (struct ship *)0);
208 makesignal(ms, "grappled with %s (%c%c)", sp);
209 } else
210 Signal("Attempt fails.", (struct ship *)0);
211 break;
212 case 'u':
213 for (k = 0; k < NSHIP; k++) {
214 if (!mf->grapples[k].turnfoul)
215 continue;
216 if (sp != mf->grapples[k].toship)
217 continue;
218 if (die() < 3 || ms->nationality
219 == capship(sp)->nationality) {
220 cleangrapple(ms, sp, k);
221 Signal("Attempt succeeds!",
222 (struct ship *)0);
223 makesignal(ms,
224 "ungrappling with %s (%c%c)",
225 sp);
226 } else
227 Signal("Attempt fails.",
228 (struct ship *)0);
229 }
230 }
231 }
232}
233
234unfoulplayer()
235{
236 register struct snag *s = mf->fouls;
237 register struct ship *to;
238 int n;
239
240 for (n = 0; n < NSHIP; n++, s++) {
241 if (s->turnfoul == 0)
242 continue;
243 to = s->toship;
789d5e82
EW
244 if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1)
245 == 'y') {
b1823ffa
EW
246 if (die() < 3) {
247 cleanfoul(ms, to, n);
789d5e82 248 Signal("Attempt succeeds!", (struct ship *)0);
b1823ffa
EW
249 makesignal(ms, "Unfouling %s (%c%c)", to);
250 } else
251 Signal("Attempt fails.", (struct ship *)0);
252 }
253 }
254}