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