home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / sail / part01 / pl_5.c < prev    next >
C/C++ Source or Header  |  1988-04-13  |  5KB  |  234 lines

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