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