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