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