]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_3.c
1 /* $NetBSD: dr_3.c,v 1.6 1999/02/10 00:45:45 hubertf 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_3.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: dr_3.c,v 1.6 1999/02/10 00:45:45 hubertf Exp $");
49 moveall() /* move all comp ships */
54 int row
[NSHIP
], col
[NSHIP
], dir
[NSHIP
], drift
[NSHIP
];
58 * first try to create moves for OUR ships
65 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
67 if (!sp
->file
->struck
&& windspeed
&& !snagged(sp
)
68 && sp
->specs
->crew3
) {
69 ta
= maxturns(sp
, &af
);
70 ma
= maxmove(sp
, sp
->file
->dir
, 0);
71 closest
= closestenemy(sp
, 0, 0);
73 *sp
->file
->movebuf
= '\0';
75 closeon(sp
, closest
, sp
->file
->movebuf
,
78 *sp
->file
->movebuf
= '\0';
81 * Then execute the moves for ALL ships (dead ones too),
82 * checking for collisions and snags at each step.
83 * The old positions are saved in row[], col[], dir[].
84 * At the end, we compare and write out the changes.
89 (void) strcpy(sp
->file
->movebuf
, "d");
91 if (*sp
->file
->movebuf
!= 'd')
92 (void) strcat(sp
->file
->movebuf
, "d");
93 row
[n
] = sp
->file
->row
;
94 col
[n
] = sp
->file
->col
;
95 dir
[n
] = sp
->file
->dir
;
96 drift
[n
] = sp
->file
->drift
;
101 * Now resolve collisions.
102 * This is the tough part.
104 for (k
= 0; stillmoving(k
); k
++) {
107 * And propagate the nulls at the end of sp->file->movebuf.
111 if (!sp
->file
->movebuf
[k
])
112 sp
->file
->movebuf
[k
+1] = '\0';
113 else if (sp
->file
->dir
)
114 step(sp
->file
->movebuf
[k
], sp
, &moved
[n
]);
122 if (sp
->file
->dir
== 0 || isolated(sp
))
130 if (sq
->file
->dir
== 0)
134 if (snagged2(sp
, sq
) && range(sp
, sq
) > 1)
136 if (!range(sp
, sq
) && !fouled2(sp
, sq
)) {
137 makesignal(sp
, "collision with $$", sq
);
139 makesignal(sp
, "fouled with $$",
141 Write(W_FOUL
, sp
, l
, 0, 0, 0);
142 Write(W_FOUL
, sq
, n
, 0, 0, 0);
147 sp
->file
->movebuf
[k
+ 1] = 0;
148 sq
->file
->movebuf
[k
+ 1] = 0;
149 sq
->file
->row
= sp
->file
->row
- 1;
150 if (sp
->file
->dir
== 1
151 || sp
->file
->dir
== 5)
155 sq
->file
->col
= sp
->file
->col
;
156 sq
->file
->dir
= sp
->file
->dir
;
166 * Clear old moves. And write out new pos.
170 if (sp
->file
->dir
!= 0) {
171 *sp
->file
->movebuf
= 0;
172 if (row
[n
] != sp
->file
->row
)
173 Write(W_ROW
, sp
, sp
->file
->row
, 0, 0, 0);
174 if (col
[n
] != sp
->file
->col
)
175 Write(W_COL
, sp
, sp
->file
->col
, 0, 0, 0);
176 if (dir
[n
] != sp
->file
->dir
)
177 Write(W_DIR
, sp
, sp
->file
->dir
, 0, 0, 0);
178 if (drift
[n
] != sp
->file
->drift
)
179 Write(W_DRIFT
, sp
, sp
->file
->drift
, 0, 0, 0);
192 if (sp
->file
->movebuf
[k
])
204 if (ship
!= sp
&& range(ship
, sp
) <= 10)
212 struct ship
*from
, *to
;
216 sb
= to
->specs
->guns
;
217 bs
= from
->specs
->guns
;
235 if (++sp
->file
->dir
== 9)
239 if (--sp
->file
->dir
== 0)
242 case '0': case '1': case '2': case '3':
243 case '4': case '5': case '6': case '7':
244 if (sp
->file
->dir
% 2 == 0)
245 dist
= dtab
[com
- '0'];
248 sp
->file
->row
-= dr
[sp
->file
->dir
] * dist
;
249 sp
->file
->col
-= dc
[sp
->file
->dir
] * dist
;
256 if (windspeed
!= 0 && ++sp
->file
->drift
> 2 &&
257 ((sp
->specs
->class >= 3 && !snagged(sp
))
258 || (turn
& 1) == 0)) {
259 sp
->file
->row
-= dr
[winddir
];
260 sp
->file
->col
-= dc
[winddir
];
269 sendbp(from
, to
, sections
, isdefense
)
270 struct ship
*from
, *to
;
277 bp
= isdefense
? from
->file
->DBP
: from
->file
->OBP
;
278 for (n
= 0; n
< NBP
&& bp
[n
].turnsent
; n
++)
280 if (n
< NBP
&& sections
) {
281 Write(isdefense
? W_DBP
: W_OBP
, from
,
282 n
, turn
, to
->file
->index
, sections
);
284 makemsg(from
, "repelling boarders");
286 makesignal(from
, "boarding the $$", to
);
291 toughmelee(ship
, to
, isdefense
, count
)
292 struct ship
*ship
, *to
;
293 int isdefense
, count
;
297 int n
, OBP
= 0, DBP
= 0, dbp
= 0;
300 qual
= ship
->specs
->qual
;
301 bp
= isdefense
? ship
->file
->DBP
: ship
->file
->OBP
;
302 for (n
= 0; n
< NBP
; n
++, bp
++) {
303 if (bp
->turnsent
&& (to
== bp
->toship
|| isdefense
)) {
304 obp
+= bp
->mensent
/ 100
305 ? ship
->specs
->crew1
* qual
: 0;
306 obp
+= (bp
->mensent
% 100)/10
307 ? ship
->specs
->crew2
* qual
: 0;
308 obp
+= bp
->mensent
% 10
309 ? ship
->specs
->crew3
* qual
: 0;
312 if (count
|| isdefense
)
314 OBP
= toughmelee(to
, ship
, 0, count
+ 1);
315 dbp
= toughmelee(ship
, to
, 1, count
+ 1);
316 DBP
= toughmelee(to
, ship
, 1, count
+ 1);
317 if (OBP
> obp
+ 10 || OBP
+ DBP
>= obp
+ dbp
+ 10)
329 sp
->file
->loadwith
= 0;
341 if (sp
->file
->captain
[0] != 0)
343 rig
= sp
->specs
->rig1
;
344 if (windspeed
== 6 || (windspeed
== 5 && sp
->specs
->class > 4))
346 if (rig
&& sp
->specs
->crew3
) {
347 close
= closestenemy(sp
, 0, 0);
349 if (range(sp
, close
) > 9)
357 if ((sp
->file
->FS
!= 0) != full
)
358 Write(W_FS
, sp
, full
, 0, 0, 0);