Commit | Line | Data |
---|---|---|
e984bffe | 1 | #ifndef lint |
e0fafce6 | 2 | static char *sccsid = "@(#)pl_5.c 2.5 83/12/21"; |
e984bffe EW |
3 | #endif |
4 | ||
5 | #include "player.h" | |
6 | ||
7 | #define turnfirst(x) (*x == 'r' || *x == 'l') | |
8 | ||
9 | acceptmove() | |
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"); | |
944c0fac | 109 | Write(W_MOVE, ms, 1, (int)movebuf, 0, 0, 0); |
e984bffe EW |
110 | Signal("Helm: %s.", (struct ship *)0, movebuf); |
111 | } | |
112 | ||
113 | acceptboard() | |
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) | |
e0fafce6 | 126 | men += mf->OBP[n].mensent; |
e984bffe EW |
127 | } |
128 | for (n = 0; n < NBP; n++) { | |
129 | if (mf->DBP[n].turnsent) | |
e0fafce6 | 130 | men += mf->DBP[n].mensent; |
e984bffe EW |
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 | } | |
490c485f | 160 | blockalarm(); |
fcc6b1db | 161 | draw_slot(); |
490c485f | 162 | unblockalarm(); |
e984bffe EW |
163 | } |
164 | ||
165 | parties(crew, to, isdefense, buf) | |
166 | register struct ship *to; | |
167 | int crew[3]; | |
168 | char isdefense; | |
169 | char buf; | |
170 | { | |
171 | register int k, j, men; | |
172 | struct BP *ptr; | |
173 | int temp[3]; | |
174 | ||
175 | for (k = 0; k < 3; k++) | |
176 | temp[k] = crew[k]; | |
177 | if (isdigit(buf)) { | |
178 | ptr = isdefense ? to->file->DBP : to->file->OBP; | |
179 | for (j = 0; j < NBP && ptr[j].turnsent; j++) | |
180 | ; | |
181 | if (!ptr[j].turnsent && buf > '0') { | |
182 | men = 0; | |
183 | for (k = 0; k < 3 && buf > '0'; k++) { | |
184 | men += crew[k] | |
185 | * (k == 0 ? 100 : (k == 1 ? 10 : 1)); | |
186 | crew[k] = 0; | |
187 | if (men) | |
188 | buf--; | |
189 | } | |
190 | if (buf > '0') | |
191 | Signal("Sending all crew sections.", | |
192 | (struct ship *)0); | |
193 | Write(isdefense ? W_DBP : W_OBP, ms, 0, | |
944c0fac | 194 | j, turn, to->file->index, men); |
e984bffe EW |
195 | if (isdefense) { |
196 | (void) wmove(slot_w, 2, 0); | |
197 | for (k=0; k < NBP; k++) | |
198 | if (temp[k] && !crew[k]) | |
199 | (void) waddch(slot_w, k + '1'); | |
200 | else | |
201 | (void) wmove(slot_w, 2, 1 + k); | |
202 | (void) mvwaddstr(slot_w, 3, 0, "DBP"); | |
203 | makesignal(ms, "repelling boarders", | |
204 | (struct ship *)0); | |
205 | } else { | |
206 | (void) wmove(slot_w, 0, 0); | |
207 | for (k=0; k < NBP; k++) | |
208 | if (temp[k] && !crew[k]) | |
209 | (void) waddch(slot_w, k + '1'); | |
210 | else | |
211 | (void) wmove(slot_w, 0, 1 + k); | |
212 | (void) mvwaddstr(slot_w, 1, 0, "OBP"); | |
213 | makesignal(ms, "boarding the %s (%c%c)", to); | |
214 | } | |
14e6adf2 | 215 | blockalarm(); |
e984bffe | 216 | (void) wrefresh(slot_w); |
14e6adf2 | 217 | unblockalarm(); |
e984bffe EW |
218 | } else |
219 | Signal("Sending no crew sections.", (struct ship *)0); | |
220 | } | |
221 | } |