]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_2.c
1 /* $NetBSD: dr_2.c,v 1.13 2001/01/01 21:57:37 jwise Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: dr_2.c,v 1.13 2001/01/01 21:57:37 jwise Exp $");
48 #define couldwin(f,t) (f->specs->crew2 > t->specs->crew2 * 1.5)
57 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
60 friendly
= sp
->nationality
== capship(sq
)->nationality
;
62 if (sp
->file
->struck
|| sp
->file
->captured
!= 0)
64 if (range(sp
, sq
) != 1)
66 if (grappled2(sp
, sq
))
67 if (is_toughmelee(sp
, sq
, 0, 0))
71 else if (couldwin(sp
, sq
)) {
73 sp
->file
->loadwith
= L_GRAPE
;
88 if (sp
->file
->dir
== 0)
90 explode
= sp
->file
->explode
;
91 sink
= sp
->file
->sink
;
92 if (explode
!= 1 && sink
!= 1)
96 Write(sink
== 1 ? W_SINK
: W_EXPLODE
, sp
, 2, 0, 0, 0);
97 Write(W_DIR
, sp
, 0, 0, 0, 0);
100 cleansnag(sp
, sq
, 1);
102 makemsg(sp
, "exploding!");
104 if (sp
!= sq
&& sq
->file
->dir
&& range(sp
, sq
) < 4)
105 table(RIGGING
, L_EXPLODE
, sp
->specs
->guns
/13, sq
, sp
, 6);
108 makemsg(sp
, "sinking!");
118 if (sp
->file
->captured
== 0)
120 if (sp
->file
->struck
|| sp
->file
->dir
== 0)
122 if (sp
->specs
->crew1
+ sp
->specs
->crew2
+ sp
->specs
->crew3
> sp
->file
->pcrew
* 6) {
123 Writestr(W_SIGNAL
, sp
, "prize crew overthrown");
124 Write(W_POINTS
, sp
->file
->captured
, sp
->file
->captured
->file
->points
- 2 * sp
->specs
->pts
, 0, 0, 0);
125 Write(W_CAPTURED
, sp
, -1, 0, 0, 0);
131 str_end(const char *str
)
135 for (p
= str
; *p
; p
++)
137 return p
== str
? 0 : p
[-1];
141 closeon(struct ship
*from
, struct ship
*to
, char *command
, int ta
, int ma
, int af
)
146 temp
[0] = command
[0] = '\0';
148 try(command
, temp
, ma
, ta
, af
, ma
, from
->file
->dir
, from
, to
, &high
, 0);
151 const int dtab
[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */
154 score(char *movement
, struct ship
*ship
, struct ship
*to
, int onlytemp
)
157 int row
, col
, dir
, total
, ran
;
158 struct File
*fp
= ship
->file
;
160 if ((dir
= fp
->dir
) == 0)
165 move_ship(movement
, ship
, &fp
->dir
, &fp
->row
, &fp
->col
, &drift
);
167 strcpy(movement
, "d");
169 ran
= range(ship
, to
);
171 if (ran
< 4 && gunsbear(ship
, to
))
173 if ((ran
= portside(ship
, to
, 1) - fp
->dir
) == 4 || ran
== -4)
185 move_ship(const char *p
, struct ship
*ship
, unsigned char *dir
, short *row
, short *col
, char *drift
)
200 case '1': case '2': case '3': case '4':
201 case '5': case '6': case '7':
204 dist
= dtab
[*p
- '0'];
207 *row
-= dr
[*dir
] * dist
;
208 *col
-= dc
[*dir
] * dist
;
213 if (windspeed
!= 0 && ++*drift
> 2) {
214 if ((ship
->specs
->class >= 3 && !snagged(ship
))
215 || (turn
& 1) == 0) {
225 try(char *command
, char *temp
, int ma
, int ta
, int af
, int vma
, int dir
, struct ship
*f
, struct ship
*t
, int *high
, int rakeme
)
229 #define rakeyou (gunsbear(f, t) && !gunsbear(t, f))
231 if ((n
= str_end(temp
)) < '1' || n
> '9')
232 for (n
= 1; vma
- n
>= 0; n
++) {
233 sprintf(st
, "%d", n
);
235 new = score(temp
, f
, t
, rakeme
);
236 if (new > *high
&& (!rakeme
|| rakeyou
)) {
238 strcpy(command
, temp
);
240 try(command
, temp
, ma
-n
, ta
, af
, vma
-n
,
241 dir
, f
, t
, high
, rakeme
);
244 if ((ma
> 0 && ta
> 0 && (n
= str_end(temp
)) != 'l' && n
!= 'r') || !strlen(temp
)) {
246 new = score(temp
, f
, t
, rakeme
);
247 if (new > *high
&& (!rakeme
|| (gunsbear(f
, t
) && !gunsbear(t
, f
)))) {
249 strcpy(command
, temp
);
251 try(command
, temp
, ma
-1, ta
-1, af
, min(ma
-1, maxmove(f
, (dir
== 8 ? 1 : dir
+1), 0)), (dir
== 8 ? 1 : dir
+1),f
,t
,high
,rakeme
);
254 if ((ma
> 0 && ta
> 0 && (n
= str_end(temp
)) != 'l' && n
!= 'r') || !strlen(temp
)){
256 new = score(temp
, f
, t
, rakeme
);
257 if (new > *high
&& (!rakeme
|| (gunsbear(f
, t
) && !gunsbear(t
, f
)))){
259 strcpy(command
, temp
);
261 try(command
, temp
, ma
-1, ta
-1, af
, (min(ma
-1,maxmove(f
, (dir
-1 ? dir
-1 : 8), 0))), (dir
-1 ? dir
-1 : 8), f
, t
, high
, rakeme
);
271 for (p
= str
; *p
; p
++)