static char *sccsid
= "@(#)dr_3.c 2.6 84/04/28";
moveall() /* move all comp ships */
register struct ship
*sp
, *sq
; /* r11, r10 */
register int k
, l
; /* r8, r7 */
int row
[NSHIP
], col
[NSHIP
], dir
[NSHIP
], drift
[NSHIP
];
* first try to create moves for OUR ships
if (sp
->file
->captain
[0] || sp
->file
->dir
== 0)
if (!sp
->file
->struck
&& windspeed
&& !snagged(sp
)
ma
= maxmove(sp
, sp
->file
->dir
, 0);
closest
= closestenemy(sp
, 0, 0);
*sp
->file
->movebuf
= '\0';
closeon(sp
, closest
, sp
->file
->movebuf
,
*sp
->file
->movebuf
= '\0';
* Then execute the moves for ALL ships (dead ones too),
* checking for collisions and snags at each step.
* The old positions are saved in row[], col[], dir[].
* At the end, we compare and write out the changes.
(void) strcpy(sp
->file
->movebuf
, "d");
if (*sp
->file
->movebuf
!= 'd')
(void) strcat(sp
->file
->movebuf
, "d");
drift
[n
] = sp
->file
->drift
;
* Now resolve collisions.
* This is the tough part.
for (k
= 0; stillmoving(k
); k
++) {
* And propagate the nulls at the end of sp->file->movebuf.
if (!sp
->file
->movebuf
[k
])
sp
->file
->movebuf
[k
+1] = '\0';
step(sp
->file
->movebuf
[k
], sp
, &moved
[n
]);
if (sp
->file
->dir
== 0 || isolated(sp
))
if (snagged2(sp
, sq
) && range(sp
, sq
) > 1)
if (!range(sp
, sq
) && !fouled2(sp
, sq
)) {
"collision with %s (%c%c)", sq
);
Write(W_FOUL
, sp
, 0, l
, 0, 0, 0);
Write(W_FOUL
, sq
, 0, n
, 0, 0, 0);
sp
->file
->movebuf
[k
+ 1] = 0;
sq
->file
->movebuf
[k
+ 1] = 0;
sq
->file
->row
= sp
->file
->row
- 1;
sq
->file
->col
= sp
->file
->col
;
sq
->file
->dir
= sp
->file
->dir
;
* Clear old moves. And write out new pos.
if (sp
->file
->dir
!= 0) {
if (row
[n
] != sp
->file
->row
)
Write(W_ROW
, sp
, 0, sp
->file
->row
, 0, 0, 0);
if (col
[n
] != sp
->file
->col
)
Write(W_COL
, sp
, 0, sp
->file
->col
, 0, 0, 0);
if (dir
[n
] != sp
->file
->dir
)
Write(W_DIR
, sp
, 0, sp
->file
->dir
, 0, 0, 0);
if (drift
[n
] != sp
->file
->drift
)
Write(W_DRIFT
, sp
, 0, sp
->file
->drift
, 0, 0, 0);
register struct ship
*sp
;
if (sp
->file
->movebuf
[k
])
register struct ship
*ship
;
register struct ship
*sp
;
if (ship
!= sp
&& range(ship
, sp
) <= 10)
register struct ship
*from
, *to
;
register struct ship
*sp
;
if (++sp
->file
->dir
== 9)
if (--sp
->file
->dir
== 0)
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
if (sp
->file
->dir
% 2 == 0)
sp
->file
->row
-= dr
[sp
->file
->dir
] * dist
;
sp
->file
->col
-= dc
[sp
->file
->dir
] * dist
;
if (windspeed
!= 0 && ++sp
->file
->drift
> 2 &&
(sp
->specs
->class >= 3 && !snagged(sp
)
sp
->file
->row
-= dr
[winddir
];
sp
->file
->col
-= dc
[winddir
];
sendbp(from
, to
, sections
, isdefense
)
register struct ship
*from
, *to
;
bp
= isdefense
? from
->file
->DBP
: from
->file
->OBP
;
for (n
= 0; n
< NBP
&& bp
[n
].turnsent
; n
++)
if (n
< NBP
&& sections
) {
Write(isdefense
? W_DBP
: W_OBP
, from
, 0,
n
, turn
, to
->file
->index
, sections
);
makesignal(from
, "repelling boarders",
makesignal(from
, "boarding the %s (%c%c)", to
);
toughmelee(ship
, to
, isdefense
, count
)
register struct ship
*ship
, *to
;
int n
, OBP
= 0, DBP
= 0, dbp
= 0;
qual
= ship
->specs
->qual
;
bp
= isdefense
? ship
->file
->DBP
: ship
->file
->OBP
;
for (n
= 0; n
< NBP
; n
++, bp
++) {
if (bp
->turnsent
&& (to
== bp
->toship
|| isdefense
)) {
? ship
->specs
->crew1
* qual
: 0;
obp
+= (bp
->mensent
% 100)/10
? ship
->specs
->crew2
* qual
: 0;
? ship
->specs
->crew3
* qual
: 0;
OBP
= toughmelee(to
, ship
, 0, count
+ 1);
dbp
= toughmelee(ship
, to
, 1, count
+ 1);
DBP
= toughmelee(to
, ship
, 1, count
+ 1);
if (OBP
> obp
+ 10 || OBP
+ DBP
>= obp
+ dbp
+ 10)
register struct ship
*sp
;
register struct ship
*sp
;
if (sp
->file
->captain
[0] != 0)
if (windspeed
== 6 || windspeed
== 5 && sp
->specs
->class > 4)
if (rig
&& sp
->specs
->crew3
) {
close
= closestenemy(sp
, 0, 0);
if (range(sp
, close
) > 9)
if ((sp
->file
->FS
!= 0) != full
)
Write(W_FS
, sp
, 0, full
, 0, 0, 0);