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