Annotation of 42BSD/games/sail/driver2.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)driver2.c   1.1 83/03/17";
                      3: #endif
                      4: #define EXPLODE 5
                      5: #include "externs.h"
                      6: 
                      7: #define couldwin(from, to)     (specs[scene[game].ship[from].shipnum].crew2 > specs[scene[game].ship[to].shipnum].crew2 * 1.5)
                      8: 
                      9: thinkofgrapples()
                     10: {
                     11:        register int n, l, friendly;
                     12: 
                     13:        for (n=0; n < scene[game].vessels; n++){
                     14:                if (!scene[game].ship[n].file -> captain[0] && pos[n].dir){
                     15:                        for (l=0; l < scene[game].vessels; l++){
                     16:                                if ((friendly = scene[game].ship[l].file -> captured) < 0)
                     17:                                        friendly = scene[game].ship[n].nationality == scene[game].ship[l].nationality;
                     18:                                else
                     19:                                        friendly = scene[game].ship[n].nationality == scene[game].ship[friendly].nationality;
                     20:                                if (!friendly){
                     21:                                        if (range(n,l) == 1 && !scene[game].ship[n].file -> struck && scene[game].ship[n].file -> captured < 0){
                     22:                                                if (grapple(n,l))
                     23:                                                        if (toughmelee(n,l,0,0))
                     24:                                                                ungrap(n, l);
                     25:                                                        else
                     26:                                                                grap(n, l);
                     27:                                                else if (couldwin(n,l)){
                     28:                                                        grap(n, l);
                     29:                                                        loadwith[n] = GRAPE;
                     30:                                                }
                     31:                                        }
                     32:                                }
                     33:                                else
                     34:                                        ungrap(n,l);
                     35:                        }
                     36:                }
                     37:        }
                     38: }
                     39: 
                     40: 
                     41: checkup()
                     42: {
                     43:        register int k, n, explode, sink;
                     44: 
                     45:        readpos();
                     46:        for (n=0; n < scene[game].vessels; n++){
                     47:                explode = scene[game].ship[n].file -> explode;
                     48:                sink = scene[game].ship[n].file -> sink;
                     49:                if (die() >= 5 && (explode == 1 || sink == 1)){
                     50:                        explode = 2;
                     51:                        if (sink != 1)
                     52:                                Write(FILES + n, 0, 232, explode);
                     53:                        else
                     54:                                Write(FILES + n, 0, 234, explode);
                     55:                        pos[n].dir = 0; /* hopefully enough to kill ship */
                     56:                        Write(n, 0, 10, 0);
                     57:                        if (fouled(n) || grappled(n)){
                     58:                                for (k=0; k < 10; k++){
                     59:                                        if (scene[game].ship[n].file -> fouls[k].turnfoul)
                     60:                                                cleanfoul(n,scene[game].ship[n].file -> fouls[k].toship,k);
                     61:                                }
                     62:                                for (k=0; k < 10; k++){
                     63:                                        if (scene[game].ship[n].file -> grapples[k].turnfoul)
                     64:                                                cleangrapple(n,scene[game].ship[n].file -> grapples[k].toship,k);
                     65:                                }
                     66:                        }
                     67:                        if (sink != 1){
                     68:                                makesignal("exploding!", 0, n);
                     69:                                for (k=0; k < scene[game].vessels; k++)
                     70:                                        if (k != n && pos[k].dir && range(n,k) < 4)
                     71:                                                table(RIGGING, EXPLODE, specs[scene[game].ship[n].shipnum].guns/13, k, n, 6);
                     72:                        }
                     73:                        else {
                     74:                                makesignal("sinking!", 0, n);
                     75:                        }
                     76:                }
                     77:        }
                     78: }
                     79: 
                     80: prizecheck()
                     81: {
                     82:        register int n, captured, pc, prisoners, points;
                     83:        struct shipspecs *ptr;
                     84:        struct File *ptr1;
                     85: 
                     86:        for (n=0; n < scene[game].vessels; n++){
                     87:                ptr1 = scene[game].ship[n].file;
                     88:                if ((captured = ptr1 -> captured) > -1 && !scene[game].ship[n].file -> struck && pos[n].dir){
                     89:                        ptr = &specs[scene[game].ship[n].shipnum];
                     90:                        points = scene[game].ship[captured].file -> points;
                     91:                        prisoners = ptr -> crew1 + ptr -> crew2 + ptr -> crew3;
                     92:                        if (prisoners > ptr1 -> pcrew * 6){
                     93:                                Write(FILES + n, 0, 68,-1);
                     94:                                points -= 2 * ptr -> pts;
                     95:                                Write(FILES + n, 1, 164, "prize crew overthrown");
                     96:                                Write(FILES + captured, 0, 20, points);
                     97:                        }
                     98:                }
                     99:        }
                    100: }
                    101: 
                    102: char strend(str)
                    103: char *str;
                    104: {
                    105:        register int n;
                    106: 
                    107:        for (n=0; *(str+n); n++);
                    108:        return( n ? *(str + n -1) : 0);
                    109: }
                    110: 
                    111: 
                    112: closeon(fromship, toship, command, ta, ma, af)
                    113: int fromship, toship, ma, ta, af;
                    114: char command[10];
                    115: {
                    116:        int high;
                    117:        char temp[10];
                    118: 
                    119:        temp[0] = command[0] = '\0';
                    120:        high = -30000;
                    121:        try(command, temp, ma, ta, af, ma, pos[fromship].dir, fromship, toship, &high, 0);
                    122: }
                    123: 
                    124: int dtab[8] = {0,1,1,2,3,4,4,5};       /* diagonal distances in x==y */
                    125: 
                    126: score(movement,shipnum, toship, permanent, onlytemp)
                    127: int shipnum, toship, permanent, onlytemp;
                    128: char movement[10];
                    129: {
                    130:        int drift, row, col, dir, n, dist, total, ran;
                    131:        int dr = 0, dc = 0;
                    132: 
                    133:        if (dir = pos[shipnum].dir){
                    134:                row = pos[shipnum].row;
                    135:                col = pos[shipnum].col;
                    136:                for (n=0; movement[n]; n++)
                    137:                        switch(movement[n]){
                    138:                                case 'r':
                    139:                                        if ((++pos[shipnum].dir) == 9)
                    140:                                                pos[shipnum].dir = 1;
                    141:                                        break;
                    142:                                case 'l':
                    143:                                        if (!(--pos[shipnum].dir))
                    144:                                                pos[shipnum].dir = 8;
                    145:                                        break;
                    146:                                case '1':
                    147:                                case '2':
                    148:                                case '3':
                    149:                                case '4':
                    150:                                case '5':
                    151:                                case '6':
                    152:                                case '7':
                    153:                                        drdc(&dr, &dc, pos[shipnum].dir);
                    154:                                        if (!(pos[shipnum].dir % 2))
                    155:                                                dist = dtab[movement[n] - '0'];
                    156:                                        else
                    157:                                                dist = movement[n] - '0';
                    158:                                        pos[shipnum].row -= dr * dist;
                    159:                                        pos[shipnum].col -= dc * dist;
                    160:                                        dr = dc = 0;
                    161:                                        break;
                    162:                        }
                    163:                drift = scene[game].ship[shipnum].file -> drift;
                    164:                if (!windspeed) drift = 1;
                    165:                if (row == pos[shipnum].row && col == pos[shipnum].col){
                    166:                        drift++;
                    167:                        if (drift > 2){
                    168:                                drdc(&dr, &dc, winddir);
                    169:                                dist = 1 - ((specs[scene[game].ship[shipnum].shipnum].class < 3 || fouled(shipnum) || grappled(shipnum)) && turn % 2);
                    170:                                pos[shipnum].row -= dr * dist;
                    171:                                pos[shipnum].col -= dc * dist;
                    172:                                if (permanent)
                    173:                                        strcat(movement, "d");
                    174:                        }
                    175:                }
                    176:                else
                    177:                        drift = 0;
                    178:                ran = range(shipnum, toship);
                    179:                total = -50*ran;
                    180:                if (ran < 4 && gunsbear(shipnum, toship))
                    181:                        total += 60;
                    182:                if ((ran = portside(shipnum, toship, 1) - pos[shipnum].dir) == 4 || ran == -4)
                    183:                        total = -30000;
                    184:                if (!*movement) strcpy(movement, "d");
                    185:                if (permanent){
                    186:                        if (drift != scene[game].ship[shipnum].file -> drift)
                    187:                                Write(FILES + shipnum, 0, 82, drift);
                    188:                        if (pos[shipnum].row != scene[game].ship[shipnum].shiprow)
                    189:                                Write(shipnum, 0, 6, pos[shipnum].row);
                    190:                        if (pos[shipnum].col != scene[game].ship[shipnum].shipcol)
                    191:                                Write(shipnum, 0, 8, pos[shipnum].col);
                    192:                        if (pos[shipnum].dir != scene[game].ship[shipnum].shipdir)
                    193:                                Write(shipnum, 0, 10, pos[shipnum].dir);
                    194:                }
                    195:                if (!onlytemp){
                    196:                        pos[shipnum].row = row;
                    197:                        pos[shipnum].col = col;
                    198:                        pos[shipnum].dir = dir;
                    199:                }
                    200:                return(total);
                    201:        }
                    202:        return(0);
                    203: }
                    204: 
                    205: try(command, temp,ma, ta, af, vma, dir, shipnum, toship, high, rakeme)
                    206: int ma, ta, af, shipnum, toship, *high, rakeme;
                    207: char command[10], temp[10];
                    208: {
                    209:        register int new, n;
                    210:        char st[4];
                    211: 
                    212:        if ((n = strend(temp)) < '1' || n > '9')
                    213:                for(n = 1; vma - n >= 0; n++){
                    214:                        sprintf(st, "%d", n);
                    215:                        strcat(temp, st);
                    216:                        new = score(temp, shipnum, toship, 0, rakeme);
                    217:                        if (new > *high && (!rakeme || (gunsbear(shipnum, toship) && !gunsbear(toship, shipnum)))){
                    218:                                *high = new;
                    219:                                strcpy(command, temp);
                    220:                        }
                    221:                        try(command, temp, ma-n, ta, af, vma-n, dir, shipnum, toship, high, rakeme);
                    222:                        rmend(temp);
                    223:                }
                    224:        if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !lengthof(temp)){
                    225:                strcat(temp, "r");
                    226:                new = score(temp, shipnum, toship, 0, rakeme);
                    227:                if (new > *high && (!rakeme || (gunsbear(shipnum, toship) && !gunsbear(toship, shipnum)))){
                    228:                        *high = new;
                    229:                        strcpy(command, temp);
                    230:                }
                    231:                try(command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(shipnum, (dir == 8 ? 1 : dir+1), 0))), (dir == 8 ? 1 : dir+1),shipnum,toship,high,rakeme);
                    232:                rmend(temp);
                    233:        }
                    234:        if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !lengthof(temp)){
                    235:                strcat(temp, "l");
                    236:                new = score(temp, shipnum, toship, 0, rakeme);
                    237:                if (new > *high && (!rakeme || (gunsbear(shipnum, toship) && !gunsbear(toship, shipnum)))){
                    238:                        *high = new;
                    239:                        strcpy(command, temp);
                    240:                }
                    241:                try(command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(shipnum, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), shipnum, toship, high, rakeme);
                    242:                rmend(temp);
                    243:        }
                    244: }
                    245: 
                    246: 
                    247: closestenemy(fromship, side, anyship) /*returns the NUMBER of the closest ship*/
                    248: int fromship; 
                    249: char side, anyship;
                    250: {
                    251:        register int n, olddist = 30000, ident, captured;
                    252:        register int dist, eclosest = 30000;
                    253: 
                    254:        if ((ident = scene[game].ship[fromship].file -> captured) < 0)
                    255:                ident = fromship;
                    256:        for (n=0; n < scene[game].vessels; n++){
                    257:                if ((captured = scene[game].ship[n].file -> captured) < 0)
                    258:                        captured = n;
                    259:                if (n != fromship && pos[n].dir && (scene[game].ship[ident].nationality != scene[game].ship[captured].nationality || anyship)){
                    260:                        if (!side || gunsbear(fromship, n) == side){
                    261:                                dist = range(fromship, n);
                    262:                                if (dist < olddist){
                    263:                                        eclosest = n;
                    264:                                        olddist = dist;
                    265:                                }
                    266:                        }
                    267:                }
                    268:        }
                    269:        return(eclosest);
                    270: }
                    271: 
                    272: choke()
                    273: {
                    274: }
                    275: 

unix.superglobalmegacorp.com

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