]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/dr_3.c
2 * Copyright (c) 1983 Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 /*static char sccsid[] = "from: @(#)dr_3.c 5.4 (Berkeley) 6/1/90";*/
36 static char rcsid
[] = "$Id: dr_3.c,v 1.2 1993/08/01 18:51:50 mycroft Exp $";
41 moveall() /* move all comp ships */
43 register struct ship
*sp
, *sq
; /* r11, r10 */
44 register int n
; /* r9 */
45 register int k
, l
; /* r8, r7 */
46 int row
[NSHIP
], col
[NSHIP
], dir
[NSHIP
], drift
[NSHIP
];
50 * first try to create moves for OUR ships
57 if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
59 if (!sp
->file
->struck
&& windspeed
&& !snagged(sp
)
60 && sp
->specs
->crew3
) {
61 ta
= maxturns(sp
, &af
);
62 ma
= maxmove(sp
, sp
->file
->dir
, 0);
63 closest
= closestenemy(sp
, 0, 0);
65 *sp
->file
->movebuf
= '\0';
67 closeon(sp
, closest
, sp
->file
->movebuf
,
70 *sp
->file
->movebuf
= '\0';
73 * Then execute the moves for ALL ships (dead ones too),
74 * checking for collisions and snags at each step.
75 * The old positions are saved in row[], col[], dir[].
76 * At the end, we compare and write out the changes.
81 (void) strcpy(sp
->file
->movebuf
, "d");
83 if (*sp
->file
->movebuf
!= 'd')
84 (void) strcat(sp
->file
->movebuf
, "d");
85 row
[n
] = sp
->file
->row
;
86 col
[n
] = sp
->file
->col
;
87 dir
[n
] = sp
->file
->dir
;
88 drift
[n
] = sp
->file
->drift
;
93 * Now resolve collisions.
94 * This is the tough part.
96 for (k
= 0; stillmoving(k
); k
++) {
99 * And propagate the nulls at the end of sp->file->movebuf.
103 if (!sp
->file
->movebuf
[k
])
104 sp
->file
->movebuf
[k
+1] = '\0';
105 else if (sp
->file
->dir
)
106 step(sp
->file
->movebuf
[k
], sp
, &moved
[n
]);
114 if (sp
->file
->dir
== 0 || isolated(sp
))
122 if (sq
->file
->dir
== 0)
126 if (snagged2(sp
, sq
) && range(sp
, sq
) > 1)
128 if (!range(sp
, sq
) && !fouled2(sp
, sq
)) {
130 "collision with %s (%c%c)", sq
);
133 "fouled with %s (%c%c)",
135 Write(W_FOUL
, sp
, 0, l
, 0, 0, 0);
136 Write(W_FOUL
, sq
, 0, n
, 0, 0, 0);
141 sp
->file
->movebuf
[k
+ 1] = 0;
142 sq
->file
->movebuf
[k
+ 1] = 0;
143 sq
->file
->row
= sp
->file
->row
- 1;
144 if (sp
->file
->dir
== 1
145 || sp
->file
->dir
== 5)
149 sq
->file
->col
= sp
->file
->col
;
150 sq
->file
->dir
= sp
->file
->dir
;
160 * Clear old moves. And write out new pos.
164 if (sp
->file
->dir
!= 0) {
165 *sp
->file
->movebuf
= 0;
166 if (row
[n
] != sp
->file
->row
)
167 Write(W_ROW
, sp
, 0, sp
->file
->row
, 0, 0, 0);
168 if (col
[n
] != sp
->file
->col
)
169 Write(W_COL
, sp
, 0, sp
->file
->col
, 0, 0, 0);
170 if (dir
[n
] != sp
->file
->dir
)
171 Write(W_DIR
, sp
, 0, sp
->file
->dir
, 0, 0, 0);
172 if (drift
[n
] != sp
->file
->drift
)
173 Write(W_DRIFT
, sp
, 0, sp
->file
->drift
, 0, 0, 0);
182 register struct ship
*sp
;
185 if (sp
->file
->movebuf
[k
])
191 register struct ship
*ship
;
193 register struct ship
*sp
;
196 if (ship
!= sp
&& range(ship
, sp
) <= 10)
203 register struct ship
*from
, *to
;
207 sb
= to
->specs
->guns
;
208 bs
= from
->specs
->guns
;
218 register struct ship
*sp
;
225 if (++sp
->file
->dir
== 9)
229 if (--sp
->file
->dir
== 0)
232 case '0': case '1': case '2': case '3':
233 case '4': case '5': case '6': case '7':
234 if (sp
->file
->dir
% 2 == 0)
235 dist
= dtab
[com
- '0'];
238 sp
->file
->row
-= dr
[sp
->file
->dir
] * dist
;
239 sp
->file
->col
-= dc
[sp
->file
->dir
] * dist
;
246 if (windspeed
!= 0 && ++sp
->file
->drift
> 2 &&
247 (sp
->specs
->class >= 3 && !snagged(sp
)
248 || (turn
& 1) == 0)) {
249 sp
->file
->row
-= dr
[winddir
];
250 sp
->file
->col
-= dc
[winddir
];
258 sendbp(from
, to
, sections
, isdefense
)
259 register struct ship
*from
, *to
;
264 register struct BP
*bp
;
266 bp
= isdefense
? from
->file
->DBP
: from
->file
->OBP
;
267 for (n
= 0; n
< NBP
&& bp
[n
].turnsent
; n
++)
269 if (n
< NBP
&& sections
) {
270 Write(isdefense
? W_DBP
: W_OBP
, from
, 0,
271 n
, turn
, to
->file
->index
, sections
);
273 makesignal(from
, "repelling boarders",
276 makesignal(from
, "boarding the %s (%c%c)", to
);
280 toughmelee(ship
, to
, isdefense
, count
)
281 register struct ship
*ship
, *to
;
282 int isdefense
, count
;
284 register struct BP
*bp
;
286 int n
, OBP
= 0, DBP
= 0, dbp
= 0;
289 qual
= ship
->specs
->qual
;
290 bp
= isdefense
? ship
->file
->DBP
: ship
->file
->OBP
;
291 for (n
= 0; n
< NBP
; n
++, bp
++) {
292 if (bp
->turnsent
&& (to
== bp
->toship
|| isdefense
)) {
293 obp
+= bp
->mensent
/ 100
294 ? ship
->specs
->crew1
* qual
: 0;
295 obp
+= (bp
->mensent
% 100)/10
296 ? ship
->specs
->crew2
* qual
: 0;
297 obp
+= bp
->mensent
% 10
298 ? ship
->specs
->crew3
* qual
: 0;
301 if (count
|| isdefense
)
303 OBP
= toughmelee(to
, ship
, 0, count
+ 1);
304 dbp
= toughmelee(ship
, to
, 1, count
+ 1);
305 DBP
= toughmelee(to
, ship
, 1, count
+ 1);
306 if (OBP
> obp
+ 10 || OBP
+ DBP
>= obp
+ dbp
+ 10)
314 register struct ship
*sp
;
317 sp
->file
->loadwith
= 0;
323 register struct ship
*sp
;
324 register int rig
, full
;
328 if (sp
->file
->captain
[0] != 0)
330 rig
= sp
->specs
->rig1
;
331 if (windspeed
== 6 || windspeed
== 5 && sp
->specs
->class > 4)
333 if (rig
&& sp
->specs
->crew3
) {
334 close
= closestenemy(sp
, 0, 0);
336 if (range(sp
, close
) > 9)
344 if ((sp
->file
->FS
!= 0) != full
)
345 Write(W_FS
, sp
, 0, full
, 0, 0, 0);