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