Home | History | Annotate | Line # | Download | only in sail
pl_3.c revision 1.1
      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, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  */
     33 
     34 #ifndef lint
     35 static char sccsid[] = "@(#)pl_3.c	5.4 (Berkeley) 6/1/90";
     36 #endif /* not lint */
     37 
     38 #include "player.h"
     39 
     40 acceptcombat()
     41 {
     42 	int men = 0;
     43 	int target, temp;
     44 	int n, r;
     45 	int index, rakehim, sternrake;
     46 	int hhits = 0, ghits = 0, rhits = 0, chits = 0;
     47 	int crew[3];
     48 	int load;
     49 	int guns, car, ready, shootat, hit;
     50 	int roll;
     51 	struct ship *closest;
     52 
     53 	crew[0] = mc->crew1;
     54 	crew[1] = mc->crew2;
     55 	crew[2] = mc->crew3;
     56 	for (n = 0; n < 3; n++) {
     57 		if (mf->OBP[n].turnsent)
     58 			men += mf->OBP[n].mensent;
     59 	}
     60 	for (n = 0; n < 3; n++) {
     61 		if (mf->DBP[n].turnsent)
     62 			men += mf->DBP[n].mensent;
     63 	}
     64 	if (men) {
     65 		crew[0] = men/100 ? 0 : crew[0] != 0;
     66 		crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
     67 		crew[2] = men%10 ? 0 : crew[2] != 0;
     68 	}
     69 	for (r = 0; r < 2; r++) {
     70 		if (r) {
     71 			ready = mf->readyR;
     72 			load = mf->loadR;
     73 			guns = mc->gunR;
     74 			car = mc->carR;
     75 		} else {
     76 			ready = mf->readyL;
     77 			load = mf->loadL;
     78 			guns = mc->gunL;
     79 			car = mc->carL;
     80 		}
     81 		if (!guns && !car || load == L_EMPTY || (ready & R_LOADED) == 0)
     82 			goto cant;
     83 		if (mf->struck || !crew[2])
     84 			goto cant;
     85 		closest = closestenemy(ms, (r ? 'r' : 'l'), 1);
     86 		if (closest == 0)
     87 			goto cant;
     88 		if (closest->file->struck)
     89 			goto cant;
     90 		target = range(ms, closest);
     91 		if (target > rangeofshot[load] || !guns && target >= 3)
     92 			goto cant;
     93 		Signal("%s (%c%c) within range of %s broadside.",
     94 			closest, r ? "right" : "left");
     95 		if (load > L_CHAIN && target < 6) {
     96 			switch (sgetch("Aim for hull or rigging? ",
     97 				(struct ship *)0, 1)) {
     98 			case 'r':
     99 				shootat = RIGGING;
    100 				break;
    101 			case 'h':
    102 				shootat = HULL;
    103 				break;
    104 			default:
    105 				shootat = -1;
    106 				Signal("'Avast there! Hold your fire.'",
    107 					(struct ship *)0);
    108 			}
    109 		} else {
    110 			if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
    111 				shootat = -1;
    112 				Signal("Belay that! Hold your fire.",
    113 					(struct ship *)0);
    114 			} else
    115 				shootat = RIGGING;
    116 		}
    117 		if (shootat == -1)
    118 			continue;
    119 		fired = 1;
    120 		rakehim = gunsbear(ms, closest) && !gunsbear(closest, ms);
    121 		temp = portside(closest, ms, 1) - closest->file->dir + 1;
    122 		if (temp < 1)
    123 			temp += 8;
    124 		else if (temp > 8)
    125 			temp -= 8;
    126 		sternrake = temp > 4 && temp < 6;
    127 		if (rakehim)
    128 			if (!sternrake)
    129 				Signal("Raking the %s!", closest);
    130 			else
    131 				Signal("Stern Rake! %s splintering!", closest);
    132 		index = guns;
    133 		if (target < 3)
    134 			index += car;
    135 		index = (index - 1)/3;
    136 		index = index > 8 ? 8 : index;
    137 		if (!rakehim)
    138 			hit = HDT[index][target-1];
    139 		else
    140 			hit = HDTrake[index][target-1];
    141 		if (rakehim && sternrake)
    142 			hit++;
    143 		hit += QUAL[index][mc->qual-1];
    144 		for (n = 0; n < 3 && mf->captured == 0; n++)
    145 			if (!crew[n])
    146 				if (index <= 5)
    147 					hit--;
    148 				else
    149 					hit -= 2;
    150 		if (ready & R_INITIAL)
    151 			if (index <= 3)
    152 				hit++;
    153 			else
    154 				hit += 2;
    155 		if (mf->captured != 0)
    156 			if (index <= 1)
    157 				hit--;
    158 			else
    159 				hit -= 2;
    160 		hit += AMMO[index][load - 1];
    161 		if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5)
    162 			hit--;
    163 		if (windspeed == 6 && temp == 4)
    164 			hit -= 2;
    165 		if (windspeed == 6 && temp <= 3)
    166 			hit--;
    167 		if (hit >= 0) {
    168 			roll = die();
    169 			if (load == L_GRAPE)
    170 				chits = hit;
    171 			else {
    172 				struct Tables *t;
    173 				if (hit > 10)
    174 					hit = 10;
    175 				t = &(shootat == RIGGING ? RigTable : HullTable)
    176 					[hit][roll-1];
    177 				chits = t->C;
    178 				rhits = t->R;
    179 				hhits = t->H;
    180 				ghits = t->G;
    181 				if (closest->file->FS)
    182 					rhits *= 2;
    183 				if (load == L_CHAIN) {
    184 					ghits = 0;
    185 					hhits = 0;
    186 				}
    187 			}
    188 			table(shootat, load, hit, closest, ms, roll);
    189 		}
    190 		Signal("Damage inflicted on the %s:",
    191 			(struct ship *)0, closest->shipname);
    192 		Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
    193 			(struct ship *)0, hhits, ghits, chits, rhits);
    194 		if (!r) {
    195 			mf->loadL = L_EMPTY;
    196 			mf->readyL = R_EMPTY;
    197 		} else {
    198 			mf->loadR = L_EMPTY;
    199 			mf->readyR = R_EMPTY;
    200 		}
    201 		continue;
    202 	cant:
    203 		Signal("Unable to fire %s broadside",
    204 			(struct ship *)0, r ? "right" : "left");
    205 	}
    206 	blockalarm();
    207 	draw_stat();
    208 	unblockalarm();
    209 }
    210 
    211 grapungrap()
    212 {
    213 	register struct ship *sp;
    214 	register int i;
    215 
    216 	foreachship(sp) {
    217 		if (sp == ms || sp->file->dir == 0)
    218 			continue;
    219 		if (range(ms, sp) > 1 && !grappled2(ms, sp))
    220 			continue;
    221 		switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
    222 			sp, 1)) {
    223 		case 'g':
    224 			if (die() < 3
    225 			    || ms->nationality == capship(sp)->nationality) {
    226 				Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
    227 				Write(W_GRAP, sp, 0, player, 0, 0, 0);
    228 				Signal("Attempt succeeds!", (struct ship *)0);
    229 				makesignal(ms, "grappled with %s (%c%c)", sp);
    230 			} else
    231 				Signal("Attempt fails.", (struct ship *)0);
    232 			break;
    233 		case 'u':
    234 			for (i = grappled2(ms, sp); --i >= 0;) {
    235 				if (ms->nationality
    236 					== capship(sp)->nationality
    237 				    || die() < 3) {
    238 					cleangrapple(ms, sp, 0);
    239 					Signal("Attempt succeeds!",
    240 						(struct ship *)0);
    241 					makesignal(ms,
    242 						"ungrappling with %s (%c%c)",
    243 						sp);
    244 				} else
    245 					Signal("Attempt fails.",
    246 						(struct ship *)0);
    247 			}
    248 			break;
    249 		}
    250 	}
    251 }
    252 
    253 unfoulplayer()
    254 {
    255 	register struct ship *to;
    256 	register i;
    257 
    258 	foreachship(to) {
    259 		if (fouled2(ms, to) == 0)
    260 			continue;
    261 		if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y')
    262 			continue;
    263 		for (i = fouled2(ms, to); --i >= 0;) {
    264 			if (die() <= 2) {
    265 				cleanfoul(ms, to, 0);
    266 				Signal("Attempt succeeds!", (struct ship *)0);
    267 				makesignal(ms, "Unfouling %s (%c%c)", to);
    268 			} else
    269 				Signal("Attempt fails.", (struct ship *)0);
    270 		}
    271 	}
    272 }
    273