1 /* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. 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 * @(#)pl_3.c 8.1 (Berkeley) 5/31/93 34 * $FreeBSD: src/games/sail/pl_3.c,v 1.6 1999/11/30 03:49:37 billf Exp $ 35 * $DragonFly: src/games/sail/pl_3.c,v 1.2 2003/06/17 04:25:25 dillon Exp $ 36 */ 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 } 133 index = guns; 134 if (target < 3) 135 index += car; 136 index = (index - 1)/3; 137 index = index > 8 ? 8 : index; 138 if (!rakehim) 139 hit = HDT[index][target-1]; 140 else 141 hit = HDTrake[index][target-1]; 142 if (rakehim && sternrake) 143 hit++; 144 hit += QUAL[index][mc->qual-1]; 145 for (n = 0; n < 3 && mf->captured == 0; n++) 146 if (!crew[n]) { 147 if (index <= 5) 148 hit--; 149 else 150 hit -= 2; 151 } 152 if (ready & R_INITIAL) { 153 if (index <= 3) 154 hit++; 155 else 156 hit += 2; 157 } 158 if (mf->captured != 0) { 159 if (index <= 1) 160 hit--; 161 else 162 hit -= 2; 163 } 164 hit += AMMO[index][load - 1]; 165 if (((temp = mc->class) >= 5 || temp == 1) && windspeed == 5) 166 hit--; 167 if (windspeed == 6 && temp == 4) 168 hit -= 2; 169 if (windspeed == 6 && temp <= 3) 170 hit--; 171 if (hit >= 0) { 172 roll = die(); 173 if (load == L_GRAPE) 174 chits = hit; 175 else { 176 struct Tables *t; 177 if (hit > 10) 178 hit = 10; 179 t = &(shootat == RIGGING ? RigTable : HullTable) 180 [hit][roll-1]; 181 chits = t->C; 182 rhits = t->R; 183 hhits = t->H; 184 ghits = t->G; 185 if (closest->file->FS) 186 rhits *= 2; 187 if (load == L_CHAIN) { 188 ghits = 0; 189 hhits = 0; 190 } 191 } 192 table(shootat, load, hit, closest, ms, roll); 193 } 194 Signal("Damage inflicted on the %s:", 195 (struct ship *)0, closest->shipname); 196 Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING", 197 (struct ship *)0, hhits, ghits, chits, rhits); 198 if (!r) { 199 mf->loadL = L_EMPTY; 200 mf->readyL = R_EMPTY; 201 } else { 202 mf->loadR = L_EMPTY; 203 mf->readyR = R_EMPTY; 204 } 205 continue; 206 cant: 207 Signal("Unable to fire %s broadside", 208 (struct ship *)0, r ? "right" : "left"); 209 } 210 blockalarm(); 211 draw_stat(); 212 unblockalarm(); 213 } 214 215 grapungrap() 216 { 217 struct ship *sp; 218 int i; 219 220 foreachship(sp) { 221 if (sp == ms || sp->file->dir == 0) 222 continue; 223 if (range(ms, sp) > 1 && !grappled2(ms, sp)) 224 continue; 225 switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ", 226 sp, 1)) { 227 case 'g': 228 if (die() < 3 229 || ms->nationality == capship(sp)->nationality) { 230 Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0); 231 Write(W_GRAP, sp, 0, player, 0, 0, 0); 232 Signal("Attempt succeeds!", (struct ship *)0); 233 makesignal(ms, "grappled with %s (%c%c)", sp); 234 } else 235 Signal("Attempt fails.", (struct ship *)0); 236 break; 237 case 'u': 238 for (i = grappled2(ms, sp); --i >= 0;) { 239 if (ms->nationality 240 == capship(sp)->nationality 241 || die() < 3) { 242 cleangrapple(ms, sp, 0); 243 Signal("Attempt succeeds!", 244 (struct ship *)0); 245 makesignal(ms, 246 "ungrappling with %s (%c%c)", 247 sp); 248 } else 249 Signal("Attempt fails.", 250 (struct ship *)0); 251 } 252 break; 253 } 254 } 255 } 256 257 unfoulplayer() 258 { 259 struct ship *to; 260 int i; 261 262 foreachship(to) { 263 if (fouled2(ms, to) == 0) 264 continue; 265 if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y') 266 continue; 267 for (i = fouled2(ms, to); --i >= 0;) { 268 if (die() <= 2) { 269 cleanfoul(ms, to, 0); 270 Signal("Attempt succeeds!", (struct ship *)0); 271 makesignal(ms, "Unfouling %s (%c%c)", to); 272 } else 273 Signal("Attempt fails.", (struct ship *)0); 274 } 275 } 276 } 277