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

Defined functions

acceptcombat defined in line 13; used 1 times
grapungrap defined in line 184; used 1 times
unfoulplayer defined in line 226; used 1 times

Defined variables

sccsid defined in line 8; never used
Last modified: 1985-05-30
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3135
Valid CSS Valid XHTML 1.0 Strict