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