|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)assorted.c 5.4 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include "externs.h"
25:
26: table(rig, shot, hittable, on, from, roll)
27: struct ship *on, *from;
28: int rig, shot, hittable, roll;
29: {
30: register int hhits = 0, chits = 0, ghits = 0, rhits = 0;
31: int Ghit = 0, Hhit = 0, Rhit = 0, Chit = 0;
32: int guns, car, pc, hull;
33: int crew[3];
34: register int n;
35: int rigg[4];
36: char *message;
37: struct Tables *tp;
38:
39: pc = on->file->pcrew;
40: hull = on->specs->hull;
41: crew[0] = on->specs->crew1;
42: crew[1] = on->specs->crew2;
43: crew[2] = on->specs->crew3;
44: rigg[0] = on->specs->rig1;
45: rigg[1] = on->specs->rig2;
46: rigg[2] = on->specs->rig3;
47: rigg[3] = on->specs->rig4;
48: if (shot == L_GRAPE)
49: Chit = chits = hittable;
50: else {
51: tp = &(rig ? RigTable : HullTable)[hittable][roll-1];
52: Chit = chits = tp->C;
53: Rhit = rhits = tp->R;
54: Hhit = hhits = tp->H;
55: Ghit = ghits = tp->G;
56: if (on->file->FS)
57: rhits *= 2;
58: if (shot == L_CHAIN) {
59: Ghit = ghits = 0;
60: Hhit = hhits = 0;
61: }
62: }
63: if (on->file->captured != 0) {
64: pc -= (chits + 1) / 2;
65: chits /= 2;
66: }
67: for (n = 0; n < 3; n++)
68: if (chits > crew[n]) {
69: chits -= crew[n];
70: crew[n] = 0;
71: } else {
72: crew[n] -= chits;
73: chits = 0;
74: }
75: for (n = 0; n < 3; n++)
76: if (rhits > rigg[n]){
77: rhits -= rigg[n];
78: rigg[n] = 0;
79: } else {
80: rigg[n] -= rhits;
81: rhits = 0;
82: }
83: if (rigg[3] != -1 && rhits > rigg[3]) {
84: rhits -= rigg[3];
85: rigg[3] = 0;
86: } else if (rigg[3] != -1) {
87: rigg[3] -= rhits;
88: }
89: if (rig && !rigg[2] && (!rigg[3] || rigg[3] == -1))
90: makesignal(on, "dismasted!", (struct ship *)0);
91: if (portside(from, on, 0)) {
92: guns = on->specs->gunR;
93: car = on->specs->carR;
94: } else {
95: guns = on->specs->gunL;
96: car = on->specs->carL;
97: }
98: if (ghits > car) {
99: ghits -= car;
100: car = 0;
101: } else {
102: car -= ghits;
103: ghits = 0;
104: }
105: if (ghits > guns){
106: ghits -= guns;
107: guns = 0;
108: } else {
109: guns -= ghits;
110: ghits = 0;
111: }
112: hull -= ghits;
113: if (Ghit)
114: Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
115: on, 0, guns, car, 0, 0);
116: hull -= hhits;
117: hull = hull < 0 ? 0 : hull;
118: if (on->file->captured != 0 && Chit)
119: Write(W_PCREW, on, 0, pc, 0, 0, 0);
120: if (Hhit)
121: Write(W_HULL, on, 0, hull, 0, 0, 0);
122: if (Chit)
123: Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
124: if (Rhit)
125: Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
126: switch (shot) {
127: case L_ROUND:
128: message = "firing round shot on %s (%c%c)";
129: break;
130: case L_GRAPE:
131: message = "firing grape shot on %s (%c%c)";
132: break;
133: case L_CHAIN:
134: message = "firing chain shot on %s (%c%c)";
135: break;
136: case L_DOUBLE:
137: message = "firing double shot on %s (%c%c)";
138: break;
139: case L_EXPLODE:
140: message = "exploding shot on %s (%c%c)";
141: }
142: makesignal(from, message, on);
143: if (roll == 6 && rig) {
144: switch(Rhit) {
145: case 0:
146: message = "fore topsail sheets parted";
147: break;
148: case 1:
149: message = "mizzen shrouds parted";
150: break;
151: case 2:
152: message = "main topsail yard shot away";
153: break;
154: case 4:
155: message = "fore topmast and foremast shrouds shot away";
156: break;
157: case 5:
158: message = "mizzen mast and yard shot through";
159: break;
160: case 6:
161: message = "foremast and spritsail yard shattered";
162: break;
163: case 7:
164: message = "main topmast and mizzen mast shattered";
165: break;
166: }
167: makesignal(on, message, (struct ship *)0);
168: } else if (roll == 6) {
169: switch (Hhit) {
170: case 0:
171: message = "anchor cables severed";
172: break;
173: case 1:
174: message = "two anchor stocks shot away";
175: break;
176: case 2:
177: message = "quarterdeck bulwarks damaged";
178: break;
179: case 3:
180: message = "three gun ports shot away";
181: break;
182: case 4:
183: message = "four guns dismounted";
184: break;
185: case 5:
186: message = "rudder cables shot through";
187: Write(W_TA, on, 0, 0, 0, 0, 0);
188: break;
189: case 6:
190: message = "shot holes below the water line";
191: break;
192: }
193: makesignal(on, message, (struct ship *)0);
194: }
195: /*
196: if (Chit > 1 && on->file->readyL&R_INITIAL && on->file->readyR&R_INITIAL) {
197: on->specs->qual--;
198: if (on->specs->qual <= 0) {
199: makesignal(on, "crew mutinying!", (struct ship *)0);
200: on->specs->qual = 5;
201: Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
202: } else
203: makesignal(on, "crew demoralized", (struct ship *)0);
204: Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
205: }
206: */
207: if (!hull)
208: strike(on, from);
209: }
210:
211: Cleansnag(from, to, all, flag)
212: register struct ship *from, *to;
213: char all, flag;
214: {
215: if (flag & 1) {
216: Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
217: Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
218: }
219: if (flag & 2) {
220: Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
221: Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
222: }
223: if (!snagged2(from, to)) {
224: if (!snagged(from)) {
225: unboard(from, from, 1); /* defense */
226: unboard(from, from, 0); /* defense */
227: } else
228: unboard(from, to, 0); /* offense */
229: if (!snagged(to)) {
230: unboard(to, to, 1); /* defense */
231: unboard(to, to, 0); /* defense */
232: } else
233: unboard(to, from, 0); /* offense */
234: }
235: }
236:
237: strike(ship, from)
238: register struct ship *ship, *from;
239: {
240: int points;
241:
242: if (ship->file->struck)
243: return;
244: Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
245: points = ship->specs->pts + from->file->points;
246: Write(W_POINTS, from, 0, points, 0, 0, 0);
247: unboard(ship, ship, 0); /* all offense */
248: unboard(ship, ship, 1); /* all defense */
249: switch (die()) {
250: case 3:
251: case 4: /* ship may sink */
252: Write(W_SINK, ship, 0, 1, 0, 0, 0);
253: break;
254: case 5:
255: case 6: /* ship may explode */
256: Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
257: break;
258: }
259: Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
260: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.