static char *sccsid
= "@(#)driver2.c 1.1 83/03/17";
#define couldwin(from, to) (specs[scene[game].ship[from].shipnum].crew2 > specs[scene[game].ship[to].shipnum].crew2 * 1.5)
register int n
, l
, friendly
;
for (n
=0; n
< scene
[game
].vessels
; n
++){
if (!scene
[game
].ship
[n
].file
-> captain
[0] && pos
[n
].dir
){
for (l
=0; l
< scene
[game
].vessels
; l
++){
if ((friendly
= scene
[game
].ship
[l
].file
-> captured
) < 0)
friendly
= scene
[game
].ship
[n
].nationality
== scene
[game
].ship
[l
].nationality
;
friendly
= scene
[game
].ship
[n
].nationality
== scene
[game
].ship
[friendly
].nationality
;
if (range(n
,l
) == 1 && !scene
[game
].ship
[n
].file
-> struck
&& scene
[game
].ship
[n
].file
-> captured
< 0){
register int k
, n
, explode
, sink
;
for (n
=0; n
< scene
[game
].vessels
; n
++){
explode
= scene
[game
].ship
[n
].file
-> explode
;
sink
= scene
[game
].ship
[n
].file
-> sink
;
if (die() >= 5 && (explode
== 1 || sink
== 1)){
Write(FILES
+ n
, 0, 232, explode
);
Write(FILES
+ n
, 0, 234, explode
);
pos
[n
].dir
= 0; /* hopefully enough to kill ship */
if (fouled(n
) || grappled(n
)){
if (scene
[game
].ship
[n
].file
-> fouls
[k
].turnfoul
)
cleanfoul(n
,scene
[game
].ship
[n
].file
-> fouls
[k
].toship
,k
);
if (scene
[game
].ship
[n
].file
-> grapples
[k
].turnfoul
)
cleangrapple(n
,scene
[game
].ship
[n
].file
-> grapples
[k
].toship
,k
);
makesignal("exploding!", 0, n
);
for (k
=0; k
< scene
[game
].vessels
; k
++)
if (k
!= n
&& pos
[k
].dir
&& range(n
,k
) < 4)
table(RIGGING
, EXPLODE
, specs
[scene
[game
].ship
[n
].shipnum
].guns
/13, k
, n
, 6);
makesignal("sinking!", 0, n
);
register int n
, captured
, pc
, prisoners
, points
;
for (n
=0; n
< scene
[game
].vessels
; n
++){
ptr1
= scene
[game
].ship
[n
].file
;
if ((captured
= ptr1
-> captured
) > -1 && !scene
[game
].ship
[n
].file
-> struck
&& pos
[n
].dir
){
ptr
= &specs
[scene
[game
].ship
[n
].shipnum
];
points
= scene
[game
].ship
[captured
].file
-> points
;
prisoners
= ptr
-> crew1
+ ptr
-> crew2
+ ptr
-> crew3
;
if (prisoners
> ptr1
-> pcrew
* 6){
Write(FILES
+ n
, 0, 68,-1);
points
-= 2 * ptr
-> pts
;
Write(FILES
+ n
, 1, 164, "prize crew overthrown");
Write(FILES
+ captured
, 0, 20, points
);
for (n
=0; *(str
+n
); n
++);
return( n
? *(str
+ n
-1) : 0);
closeon(fromship
, toship
, command
, ta
, ma
, af
)
int fromship
, toship
, ma
, ta
, af
;
temp
[0] = command
[0] = '\0';
try(command
, temp
, ma
, ta
, af
, ma
, pos
[fromship
].dir
, fromship
, toship
, &high
, 0);
int dtab
[8] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */
score(movement
,shipnum
, toship
, permanent
, onlytemp
)
int shipnum
, toship
, permanent
, onlytemp
;
int drift
, row
, col
, dir
, n
, dist
, total
, ran
;
if (dir
= pos
[shipnum
].dir
){
for (n
=0; movement
[n
]; n
++)
if ((++pos
[shipnum
].dir
) == 9)
if (!(--pos
[shipnum
].dir
))
drdc(&dr
, &dc
, pos
[shipnum
].dir
);
if (!(pos
[shipnum
].dir
% 2))
dist
= dtab
[movement
[n
] - '0'];
dist
= movement
[n
] - '0';
pos
[shipnum
].row
-= dr
* dist
;
pos
[shipnum
].col
-= dc
* dist
;
drift
= scene
[game
].ship
[shipnum
].file
-> drift
;
if (!windspeed
) drift
= 1;
if (row
== pos
[shipnum
].row
&& col
== pos
[shipnum
].col
){
dist
= 1 - ((specs
[scene
[game
].ship
[shipnum
].shipnum
].class < 3 || fouled(shipnum
) || grappled(shipnum
)) && turn
% 2);
pos
[shipnum
].row
-= dr
* dist
;
pos
[shipnum
].col
-= dc
* dist
;
ran
= range(shipnum
, toship
);
if (ran
< 4 && gunsbear(shipnum
, toship
))
if ((ran
= portside(shipnum
, toship
, 1) - pos
[shipnum
].dir
) == 4 || ran
== -4)
if (!*movement
) strcpy(movement
, "d");
if (drift
!= scene
[game
].ship
[shipnum
].file
-> drift
)
Write(FILES
+ shipnum
, 0, 82, drift
);
if (pos
[shipnum
].row
!= scene
[game
].ship
[shipnum
].shiprow
)
Write(shipnum
, 0, 6, pos
[shipnum
].row
);
if (pos
[shipnum
].col
!= scene
[game
].ship
[shipnum
].shipcol
)
Write(shipnum
, 0, 8, pos
[shipnum
].col
);
if (pos
[shipnum
].dir
!= scene
[game
].ship
[shipnum
].shipdir
)
Write(shipnum
, 0, 10, pos
[shipnum
].dir
);
try(command
, temp
,ma
, ta
, af
, vma
, dir
, shipnum
, toship
, high
, rakeme
)
int ma
, ta
, af
, shipnum
, toship
, *high
, rakeme
;
char command
[10], temp
[10];
if ((n
= strend(temp
)) < '1' || n
> '9')
for(n
= 1; vma
- n
>= 0; n
++){
new = score(temp
, shipnum
, toship
, 0, rakeme
);
if (new > *high
&& (!rakeme
|| (gunsbear(shipnum
, toship
) && !gunsbear(toship
, shipnum
)))){
try(command
, temp
, ma
-n
, ta
, af
, vma
-n
, dir
, shipnum
, toship
, high
, rakeme
);
if ((ma
> 0 && ta
> 0 && (n
= strend(temp
)) != 'l' && n
!= 'r') || !lengthof(temp
)){
new = score(temp
, shipnum
, toship
, 0, rakeme
);
if (new > *high
&& (!rakeme
|| (gunsbear(shipnum
, toship
) && !gunsbear(toship
, shipnum
)))){
try(command
, temp
, ma
-1, ta
-1, af
, (min(ma
-1,maxmove(shipnum
, (dir
== 8 ? 1 : dir
+1), 0))), (dir
== 8 ? 1 : dir
+1),shipnum
,toship
,high
,rakeme
);
if ((ma
> 0 && ta
> 0 && (n
= strend(temp
)) != 'l' && n
!= 'r') || !lengthof(temp
)){
new = score(temp
, shipnum
, toship
, 0, rakeme
);
if (new > *high
&& (!rakeme
|| (gunsbear(shipnum
, toship
) && !gunsbear(toship
, shipnum
)))){
try(command
, temp
, ma
-1, ta
-1, af
, (min(ma
-1,maxmove(shipnum
, (dir
-1 ? dir
-1 : 8), 0))), (dir
-1 ? dir
-1 : 8), shipnum
, toship
, high
, rakeme
);
closestenemy(fromship
, side
, anyship
) /*returns the NUMBER of the closest ship*/
register int n
, olddist
= 30000, ident
, captured
;
register int dist
, eclosest
= 30000;
if ((ident
= scene
[game
].ship
[fromship
].file
-> captured
) < 0)
for (n
=0; n
< scene
[game
].vessels
; n
++){
if ((captured
= scene
[game
].ship
[n
].file
-> captured
) < 0)
if (n
!= fromship
&& pos
[n
].dir
&& (scene
[game
].ship
[ident
].nationality
!= scene
[game
].ship
[captured
].nationality
|| anyship
)){
if (!side
|| gunsbear(fromship
, n
) == side
){
dist
= range(fromship
, n
);