# 2.11BSD#431 - /usr/src/games/sail/pl_5.c

##### Functions

    acceptboard       X
    acceptmove        X
    parties           X

##### Macros

    turnfirst         X

       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_5.c	5.1 (Berkeley) 5/29/85";
       9: #endif not lint
      10:
      11: #include "player.h"
      12:
      13: #define turnfirst(x) (*x == 'r' || *x == 'l')
      14:
      15: acceptmove()
      16: {
      17:     int ta;
      18:     int ma;
      19:     char af;
      20:     int moved = 0;
      21:     int vma, dir;
      22:     char prompt[60];
      23:     char buf[60], last = '\0';
      24:     register char *p;
      25:
      26:     if (!mc->crew3 || snagged(ms) || !windspeed) {
      27:         Signal("Unable to move", (struct ship *)0);
      28:         return;
      29:     }
      30:
      31:     ta = maxturns(ms, &af);
      32:     ma = maxmove(ms, mf->dir, 0);
      33:     (void) sprintf(prompt, "move (%d,%c%d): ", ma, af ? '\'' : ' ', ta);
      34:     sgetstr(prompt, buf, sizeof buf);
      35:     dir = mf->dir;
      36:     vma = ma;
      37:     for (p = buf; *p; p++)
      38:         switch (*p) {
      39:         case 'l':
      40:             dir -= 2;
      41:         case 'r':
      42:             if (++dir == 0)
      43:                 dir = 8;
      44:             else if (dir == 9)
      45:                 dir = 1;
      46:             if (last == 't') {
      47:                 Signal("Ship can't turn that fast.",
      48:                     (struct ship *)0);
      49:                 *p-- = '\0';
      50:             }
      51:             last = 't';
      52:             ma--;
      53:             ta--;
      54:             vma = min(ma, maxmove(ms, dir, 0));
      55:             if (ta < 0 && moved || vma < 0 && moved)
      56:                 *p-- = '\0';
      57:             break;
      58:         case 'b':
      59:             ma--;
      60:             vma--;
      61:             last = 'b';
      62:             if (ta < 0 && moved || vma < 0 && moved)
      63:                 *p-- = '\0';
      64:             break;
      65:         case '0':
      66:         case 'd':
      67:             *p-- = '\0';
      68:             break;
      69:         case '\n':
      70:             *p-- = '\0';
      71:             break;
      72:         case '1': case '2': case '3': case '4':
      73:         case '5': case '6': case '7':
      74:             if (last == '0') {
      75:                 Signal("Can't move that fast.",
      76:                     (struct ship *)0);
      77:                 *p-- = '\0';
      78:             }
      79:             last = '0';
      80:             moved = 1;
      81:             ma -= *p - '0';
      82:             vma -= *p - '0';
      83:             if (ta < 0 && moved || vma < 0 && moved)
      84:                 *p-- = '\0';
      85:             break;
      86:         default:
      87:             if (!isspace(*p)) {
      88:                 Signal("Input error.", (struct ship *)0);
      89:                 *p-- = '\0';
      90:             }
      91:         }
      92:     if (ta < 0 && moved || vma < 0 && moved
      93:         || af && turnfirst(buf) && moved) {
      94:         Signal("Movement error.", (struct ship *)0);
      95:         if (ta < 0 && moved) {
      96:             if (mf->FS == 1) {
      97:                 Write(W_FS, ms, 0, 0, 0, 0, 0);
      98:                 Signal("No hands to set full sails.",
      99:                     (struct ship *)0);
     100:             }
     101:         } else if (ma >= 0)
     102:             buf[1] = '\0';
     103:     }
     104:     if (af && !moved) {
     105:         if (mf->FS == 1) {
     106:             Write(W_FS, ms, 0, 0, 0, 0, 0);
     107:             Signal("No hands to set full sails.",
     108:                 (struct ship *)0);
     109:         }
     110:     }
     111:     if (*buf)
     112:         (void) strcpy(movebuf, buf);
     113:     else
     114:         (void) strcpy(movebuf, "d");
     115:     Write(W_MOVE, ms, 1, (int)movebuf, 0, 0, 0);
     116:     Signal("Helm: %s.", (struct ship *)0, movebuf);
     117: }
     118:
     119: acceptboard()
     120: {
     121:     register struct ship *sp;
     122:     register int n;
     123:     int crew[3];
     124:     int men = 0;
     125:     char c;
     126:
     127:     crew[0] = mc->crew1;
     128:     crew[1] = mc->crew2;
     129:     crew[2] = mc->crew3;
     130:     for (n = 0; n < NBP; n++) {
     131:         if (mf->OBP[n].turnsent)
     132:                 men += mf->OBP[n].mensent;
     133:     }
     134:     for (n = 0; n < NBP; n++) {
     135:         if (mf->DBP[n].turnsent)
     136:                 men += mf->DBP[n].mensent;
     137:     }
     138:     if (men) {
     139:         crew[0] = men/100 ? 0 : crew[0] != 0;
     140:         crew[1] = (men%100)/10 ? 0 : crew[1] != 0;
     141:         crew[2] = men%10 ? 0 : crew[2] != 0;
     142:     } else {
     143:         crew[0] = crew[0] != 0;
     144:         crew[1] = crew[1] != 0;
     145:         crew[2] = crew[2] != 0;
     146:     }
     147:     foreachship(sp) {
     148:         if (sp == ms || sp->file->dir == 0 || range(ms, sp) > 1)
     149:             continue;
     150:         if (ms->nationality == capship(sp)->nationality)
     151:             continue;
     152:         if (meleeing(ms, sp) && crew[2]) {
     153:             c = sgetch("How many more to board the %s (%c%c)? ",
     154:                 sp, 1);
     155:             parties(crew, sp, 0, c);
     156:         } else if ((fouled2(ms, sp) || grappled2(ms, sp)) && crew[2]) {
     157:             c = sgetch("Crew sections to board the %s (%c%c) (3 max) ?", sp, 1);
     158:             parties(crew, sp, 0, c);
     159:         }
     160:     }
     161:     if (crew[2]) {
     162:         c = sgetch("How many sections to repel boarders? ",
     163:             (struct ship *)0, 1);
     164:         parties(crew, ms, 1, c);
     165:     }
     166:     blockalarm();
     167:     draw_slot();
     168:     unblockalarm();
     169: }
     170:
     171: parties(crew, to, isdefense, buf)
     172: register struct ship *to;
     173: int crew[3];
     174: char isdefense;
     175: char buf;
     176: {
     177:     register int k, j, men;
     178:     struct BP *ptr;
     179:     int temp[3];
     180:
     181:     for (k = 0; k < 3; k++)
     182:         temp[k] = crew[k];
     183:     if (isdigit(buf)) {
     184:         ptr = isdefense ? to->file->DBP : to->file->OBP;
     185:         for (j = 0; j < NBP && ptr[j].turnsent; j++)
     186:             ;
     187:         if (!ptr[j].turnsent && buf > '0') {
     188:             men = 0;
     189:             for (k = 0; k < 3 && buf > '0'; k++) {
     190:                 men += crew[k]
     191:                     * (k == 0 ? 100 : (k == 1 ? 10 : 1));
     192:                 crew[k] = 0;
     193:                 if (men)
     194:                     buf--;
     195:             }
     196:             if (buf > '0')
     197:                 Signal("Sending all crew sections.",
     198:                     (struct ship *)0);
     199:             Write(isdefense ? W_DBP : W_OBP, ms, 0,
     200:                 j, turn, to->file->index, men);
     201:             if (isdefense) {
     202:                 (void) wmove(slot_w, 2, 0);
     203:                 for (k=0; k < NBP; k++)
     204:                     if (temp[k] && !crew[k])
     205:                         (void) waddch(slot_w, k + '1');
     206:                     else
     207:                         (void) wmove(slot_w, 2, 1 + k);
     208:                 (void) mvwaddstr(slot_w, 3, 0, "DBP");
     209:                 makesignal(ms, "repelling boarders",
     210:                     (struct ship *)0);
     211:             } else {
     212:                 (void) wmove(slot_w, 0, 0);
     213:                 for (k=0; k < NBP; k++)
     214:                     if (temp[k] && !crew[k])
     215:                         (void) waddch(slot_w, k + '1');
     216:                     else
     217:                         (void) wmove(slot_w, 0, 1 + k);
     218:                 (void) mvwaddstr(slot_w, 1, 0, "OBP");
     219:                 makesignal(ms, "boarding the %s (%c%c)", to);
     220:             }
     221:             blockalarm();
     222:             (void) wrefresh(slot_w);
     223:             unblockalarm();
     224:         } else
     225:             Signal("Sending no crew sections.", (struct ship *)0);
     226:     }
     227: }

#### Defined functions

acceptboard defined in line 119; used 1 times

- in /usr/src/games/sail/pl_2.c line 35

acceptmove defined in line 15; used 1 times

- in /usr/src/games/sail/pl_2.c line 20

parties defined in line 171; used 3 times

- in line 155-158(2), 164

#### Defined variables

sccsid defined in line 8; never used

#### Defined macros

turnfirst defined in line 13; used 1 times

- in line 93

Last modified: 1985-05-30 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1359 |