Annotation of 43BSDReno/games/sail/pl_3.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.