Changed ERR to CURSES_ERR.
[unix-history] / usr / src / games / sail / assorted.c
CommitLineData
b5f0675e 1/*
1e008c14 2 * Copyright (c) 1983 Regents of the University of California.
c0ca48ec
KB
3 * All rights reserved.
4 *
b2e7427f 5 * %sccs.include.redist.c%
b5f0675e
EW
6 */
7
931d7dfa 8#ifndef lint
b2e7427f 9static char sccsid[] = "@(#)assorted.c 5.4 (Berkeley) %G%";
c0ca48ec 10#endif /* not lint */
b3a57661 11
931d7dfa
CL
12#include "externs.h"
13
b3a57661
EW
14table(rig, shot, hittable, on, from, roll)
15struct ship *on, *from;
16int rig, shot, hittable, roll;
931d7dfa
CL
17{
18 register int hhits = 0, chits = 0, ghits = 0, rhits = 0;
19 int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0;
20 int guns, car, pc, hull;
21 int crew[3];
22 register int n;
23 int rigg[4];
b3a57661
EW
24 char *message;
25 struct Tables *tp;
931d7dfa 26
b3a57661
EW
27 pc = on->file->pcrew;
28 hull = on->specs->hull;
29 crew[0] = on->specs->crew1;
30 crew[1] = on->specs->crew2;
31 crew[2] = on->specs->crew3;
32 rigg[0] = on->specs->rig1;
33 rigg[1] = on->specs->rig2;
34 rigg[2] = on->specs->rig3;
35 rigg[3] = on->specs->rig4;
36 if (shot == L_GRAPE)
931d7dfa
CL
37 Chit = chits = hittable;
38 else {
b3a57661
EW
39 tp = &(rig ? RigTable : HullTable)[hittable][roll-1];
40 Chit = chits = tp->C;
41 Rhit = rhits = tp->R;
42 Hhit = hhits = tp->H;
43 Ghit = ghits = tp->G;
44 if (on->file->FS)
931d7dfa 45 rhits *= 2;
b3a57661 46 if (shot == L_CHAIN) {
931d7dfa
CL
47 Ghit = ghits = 0;
48 Hhit = hhits = 0;
49 }
50 }
b3a57661
EW
51 if (on->file->captured != 0) {
52 pc -= (chits + 1) / 2;
931d7dfa
CL
53 chits /= 2;
54 }
b3a57661
EW
55 for (n = 0; n < 3; n++)
56 if (chits > crew[n]) {
931d7dfa
CL
57 chits -= crew[n];
58 crew[n] = 0;
b3a57661 59 } else {
931d7dfa
CL
60 crew[n] -= chits;
61 chits = 0;
62 }
b3a57661 63 for (n = 0; n < 3; n++)
931d7dfa
CL
64 if (rhits > rigg[n]){
65 rhits -= rigg[n];
66 rigg[n] = 0;
b3a57661 67 } else {
931d7dfa
CL
68 rigg[n] -= rhits;
69 rhits = 0;
70 }
b3a57661 71 if (rigg[3] != -1 && rhits > rigg[3]) {
931d7dfa
CL
72 rhits -= rigg[3];
73 rigg[3] = 0;
b3a57661 74 } else if (rigg[3] != -1) {
931d7dfa
CL
75 rigg[3] -= rhits;
76 }
77 if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1))
b3a57661
EW
78 makesignal(on, "dismasted!", (struct ship *)0);
79 if (portside(from, on, 0)) {
b3a57661
EW
80 guns = on->specs->gunR;
81 car = on->specs->carR;
0fc2c279
EW
82 } else {
83 guns = on->specs->gunL;
84 car = on->specs->carL;
931d7dfa 85 }
b3a57661 86 if (ghits > car) {
931d7dfa
CL
87 ghits -= car;
88 car = 0;
b3a57661 89 } else {
931d7dfa
CL
90 car -= ghits;
91 ghits = 0;
92 }
93 if (ghits > guns){
94 ghits -= guns;
95 guns = 0;
b3a57661 96 } else {
931d7dfa
CL
97 guns -= ghits;
98 ghits = 0;
99 }
100 hull -= ghits;
b3a57661 101 if (Ghit)
0fc2c279 102 Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
b3a57661 103 on, 0, guns, car, 0, 0);
931d7dfa
CL
104 hull -= hhits;
105 hull = hull < 0 ? 0 : hull;
b3a57661
EW
106 if (on->file->captured != 0 && Chit)
107 Write(W_PCREW, on, 0, pc, 0, 0, 0);
931d7dfa 108 if (Hhit)
b3a57661 109 Write(W_HULL, on, 0, hull, 0, 0, 0);
931d7dfa 110 if (Chit)
b3a57661 111 Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
931d7dfa 112 if (Rhit)
b3a57661
EW
113 Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
114 switch (shot) {
115 case L_ROUND:
116 message = "firing round shot on %s (%c%c)";
117 break;
118 case L_GRAPE:
119 message = "firing grape shot on %s (%c%c)";
120 break;
121 case L_CHAIN:
122 message = "firing chain shot on %s (%c%c)";
123 break;
124 case L_DOUBLE:
125 message = "firing double shot on %s (%c%c)";
126 break;
127 case L_EXPLODE:
128 message = "exploding shot on %s (%c%c)";
129 }
130 makesignal(from, message, on);
131 if (roll == 6 && rig) {
132 switch(Rhit) {
133 case 0:
134 message = "fore topsail sheets parted";
931d7dfa 135 break;
b3a57661
EW
136 case 1:
137 message = "mizzen shrouds parted";
931d7dfa 138 break;
b3a57661
EW
139 case 2:
140 message = "main topsail yard shot away";
931d7dfa 141 break;
b3a57661
EW
142 case 4:
143 message = "fore topmast and foremast shrouds shot away";
144 break;
145 case 5:
146 message = "mizzen mast and yard shot through";
147 break;
148 case 6:
149 message = "foremast and spritsail yard shattered";
150 break;
151 case 7:
152 message = "main topmast and mizzen mast shattered";
931d7dfa 153 break;
931d7dfa 154 }
b3a57661
EW
155 makesignal(on, message, (struct ship *)0);
156 } else if (roll == 6) {
157 switch (Hhit) {
158 case 0:
159 message = "anchor cables severed";
160 break;
161 case 1:
162 message = "two anchor stocks shot away";
163 break;
164 case 2:
165 message = "quarterdeck bulwarks damaged";
166 break;
167 case 3:
168 message = "three gun ports shot away";
169 break;
170 case 4:
171 message = "four guns dismounted";
172 break;
173 case 5:
174 message = "rudder cables shot through";
175 Write(W_TA, on, 0, 0, 0, 0, 0);
176 break;
177 case 6:
178 message = "shot holes below the water line";
179 break;
931d7dfa 180 }
b3a57661 181 makesignal(on, message, (struct ship *)0);
931d7dfa 182 }
46c1696b
EW
183 /*
184 if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
b3a57661
EW
185 on->specs->qual--;
186 if (on->specs->qual <= 0) {
187 makesignal(on, "crew mutinying!", (struct ship *)0);
188 on->specs->qual = 5;
6ca45914 189 Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
931d7dfa 190 } else
b3a57661
EW
191 makesignal(on, "crew demoralized", (struct ship *)0);
192 Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
931d7dfa 193 }
46c1696b 194 */
931d7dfa 195 if (!hull)
b3a57661 196 strike(on, from);
931d7dfa
CL
197}
198
6ca45914 199Cleansnag(from, to, all, flag)
b3a57661 200register struct ship *from, *to;
6ca45914 201char all, flag;
931d7dfa 202{
6ca45914
EW
203 if (flag & 1) {
204 Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
205 Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
206 }
207 if (flag & 2) {
208 Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
209 Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
931d7dfa 210 }
b3a57661 211 if (!snagged2(from, to)) {
6ca45914 212 if (!snagged(from)) {
b3a57661
EW
213 unboard(from, from, 1); /* defense */
214 unboard(from, from, 0); /* defense */
931d7dfa 215 } else
6ca45914
EW
216 unboard(from, to, 0); /* offense */
217 if (!snagged(to)) {
218 unboard(to, to, 1); /* defense */
219 unboard(to, to, 0); /* defense */
931d7dfa 220 } else
b3a57661 221 unboard(to, from, 0); /* offense */
931d7dfa
CL
222 }
223}
224
b3a57661
EW
225strike(ship, from)
226register struct ship *ship, *from;
931d7dfa
CL
227{
228 int points;
229
b3a57661
EW
230 if (ship->file->struck)
231 return;
232 Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
233 points = ship->specs->pts + from->file->points;
234 Write(W_POINTS, from, 0, points, 0, 0, 0);
235 unboard(ship, ship, 0); /* all offense */
236 unboard(ship, ship, 1); /* all defense */
237 switch (die()) {
238 case 3:
239 case 4: /* ship may sink */
240 Write(W_SINK, ship, 0, 1, 0, 0, 0);
241 break;
242 case 5:
243 case 6: /* ship may explode */
244 Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
245 break;
931d7dfa 246 }
b3a57661 247 Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
931d7dfa 248}