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