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