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