static char *sccsid
= "@(#)pl_1.c 1.6 83/05/20";
int crew
[3], men
= 0, rangeofshot
, target
, temp
;
int n
, r
, guns
[2], load
[2], car
[2], roll
[2];
int ready
[2], index
, rakehim
, sternrake
;
int shootat
[2], hit
[2], closest
[2], ship
;
int hhits
= 0, ghits
= 0, rhits
= 0, chits
= 0;
ptr
= &specs
[scene
[game
].ship
[player
].shipnum
];
ptr1
= scene
[game
].ship
[player
].file
;
ready
[0] = ptr1
-> readyL
;
ready
[1] = ptr1
-> readyR
;
for (n
= 0; n
< 3; n
++) {
if (ptr1
-> OBP
[n
].turnsent
)
men
+= ptr1
-> OBP
[n
].mensent
;
for (n
= 0; n
< 3; n
++) {
if (ptr1
-> DBP
[n
].turnsent
)
men
+= ptr1
-> DBP
[n
].mensent
;
crew
[0] = men
/100 ? 0 : crew
[0] != 0;
crew
[1] = (men
%100)/10 ? 0 : crew
[1] != 0;
crew
[2] = men
%10 ? 0 : crew
[2] != 0;
for (r
= 0; r
< 2; r
++) {
if ((guns
[r
] || car
[r
]) && crew
[2] && load
[r
] && ready
[r
] <= 0 && !ptr1
-> struck
&& ((closest
[r
] = closestenemy(player
, (r
? 'r' : 'l'), 1)) != 30000)) {
if ((target
= range(player
, closest
[r
])) <= rangeofshot
&& !scene
[game
].ship
[closest
[r
]].file
-> struck
&& (guns
[r
] || (car
[r
] && target
< 3))) {
Signal("%s (%c%c) within range of %s broadside.", closest
[r
], (r
?"right":"left"));
if (load
[r
] > CHAIN
&& target
< 6) {
Signal("Aim for hull or rigging? ", -1, 0);
while ((buf
= getch()) == EOF
);
Signal("'Avast there! Hold your fire.'", -1, 0);
while ((buf
= getch()) == EOF
);
Signal("Belay that! Hold your fire.", -1, 0);
rakehim
= gunsbear(player
, closest
[r
]) && !gunsbear(closest
[r
], player
);
temp
= portside(closest
[r
], player
, 1) - pos
[closest
[r
]].dir
+ 1;
sternrake
= temp
> 4 && temp
< 6;
if (rakehim
&& !sternrake
)
Signal("Raking the %s!", closest
[r
], 0);
else if (rakehim
&& sternrake
)
Signal("Stern Rake! %s splintering!", closest
[r
], 0);
index
= index
> 8 ? 8 : index
;
hit
[r
] = HDT
[index
][target
-1];
hit
[r
] = HDTrake
[index
][target
-1];
if (rakehim
&& sternrake
)
hit
[r
] += QUAL
[index
][ptr
-> qual
-1];
for (n
=0; n
< 3 && ptr1
-> captured
< 0; n
++)
if (ptr1
-> captured
> -1)
hit
[r
] += AMMO
[index
][load
[r
] - 1];
if (((temp
= ptr
-> class) >= 5 || temp
== 1) && windspeed
== 5)
if (windspeed
== 6 && temp
== 4)
if (windspeed
== 6 && temp
<= 3)
hit
[r
] = hit
[r
] > 10 ? 10 : hit
[r
];
t
= &(shootat
[r
] ? RigTable
: HullTable
)[hit
[r
]][roll
[r
]-1];
if (scene
[game
].ship
[closest
[r
]].file
-> FS
)
table(shootat
[r
], load
[r
], hit
[r
], closest
[r
], player
, roll
[r
]);
printw("Damage inflicted on the %s:", scene
[game
].ship
[closest
[r
]].shipname
);
printw("\t%d HULL, %d GUNS, %d CREW, %d RIGGING", hhits
, ghits
, chits
, rhits
);
Signal("Unable to fire %s broadside", -1, (r
?"right":"left"));
Signal("Unable to fire %s broadside", -1, (r
?"right":"left"));
struct logs log
[10], temp
;
signal(SIGQUIT
, SIG_IGN
);
signal(SIGALRM
, SIG_IGN
);
capn
= scene
[game
].ship
[player
].file
-> captain
;
sprintf(message
,"Captain %s relinquishing.",capn
);
Write(FILES
+ player
, 1, 164, message
);
if (fp
= fopen(LOGFILE
, "r+")) {
net
= (float) (scene
[game
].ship
[player
].file
-> points
) / specs
[scene
[game
].ship
[player
].shipnum
].pts
;
n
= fread(log
, sizeof(struct logs
), 10, fp
);
log
[n
].fname
[0] = log
[n
].uid
= log
[n
].fshipnum
= log
[n
].fgamenum
= log
[n
].netpoints
= 0;
if (net
> (float) log
[n
].netpoints
/ specs
[scene
[log
[n
].fgamenum
].ship
[log
[n
].fshipnum
].shipnum
].pts
) {
fwrite(log
, sizeof(struct logs
), n
, fp
);
strcpy(temp
.fname
, capn
);
temp
.netpoints
= scene
[game
].ship
[player
].file
-> points
;
fwrite(&temp
, sizeof(struct logs
), 1, fp
);
fwrite(log
+ n
, sizeof(struct logs
), 9 - n
, fp
);
Write(FILES
+ player
, 1, 0, " ");
Write(SCENARIO
, 0, 8, scene
[game
].people
- 1);
Signal("It looks like you've had it!", -1, 0);
Signal("Your ship was captured.", -1, 0);
Signal("No more enemies.", -1, 0);
Signal("Hurricane! All ships destroyed.",
register int n
, k
, l
, number
, captured
;
for (n
=0; n
< scene
[game
].vessels
; n
++) {
if (n
!= player
&& (range(player
, n
) <= 1 || grapple(player
, n
))) {
if ((captured
= scene
[game
].ship
[n
].file
-> captured
) < 0)
Signal("Attempt to grapple or ungrapple %s (%c%c): ", n
, 0);
while ((buf
= getch()) == EOF
);
if (!number
&& scene
[game
].ship
[player
].nationality
== scene
[game
].ship
[captured
].nationality
)
for (l
=0; l
< 10 && scene
[game
].ship
[player
].file
-> grapples
[l
].turnfoul
; l
++);
if (!scene
[game
].ship
[player
].file
-> grapples
[l
].turnfoul
) {
Write(FILES
+ player
, 0, 124 + l
*4, turn
);
Write(FILES
+ player
, 0, 124 + l
*4 + 2, n
);
for (l
=0; l
< 10 && scene
[game
].ship
[n
].file
-> grapples
[l
].turnfoul
; l
++);
if (!scene
[game
].ship
[n
].file
-> grapples
[l
].turnfoul
) {
Write(FILES
+ n
, 0, 124 + l
*4, turn
);
Write(FILES
+ n
, 0, 124 + l
*4 + 2, player
);
Signal("Attempt succeeds!", 0, 0);
makesignal("grappled with %s (%c%c)", n
, player
);
Signal("Attempt fails.", 0, 0);
if (scene
[game
].ship
[player
].file
-> grapples
[k
].turnfoul
&& n
== scene
[game
].ship
[player
].file
-> grapples
[k
].toship
) {
if (die() < 3 || scene
[game
].ship
[player
].nationality
== scene
[game
].ship
[captured
].nationality
) {
cleangrapple(player
, n
, k
);
Signal("Attempt succeeds!", 0, 0);
makesignal("ungrappling with %s (%c%c)", n
, player
);
Signal("Attempt fails.", 0, 0);
if (scene
[game
].ship
[player
].file
-> fouls
[n
].turnfoul
) {
Signal("Attempt to unfoul with the %s (%c%c)? ", (toship
= scene
[game
].ship
[player
].file
-> fouls
[n
].toship
), 0);
while ((buf
= getch()) == EOF
);
if (buf
== 'y' && die() < 3) {
cleanfoul(player
, toship
, n
);
Signal("Attempt succeeds!", 0, 0);
makesignal("unfouling %s (%c%c)", toship
, player
);
Signal("Attempt fails.", 0, 0);
initialize(nodriver
, randomize
, debug
)
char randomize
, nodriver
, debug
;
char comm
[80], file
[25], capn
;
int load
= ROUND
, ready
= -30000;
puts("Choose a scenario:\n");
puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
for (n
=0; n
< NUMOFSCENES
; n
++) {
sprintf(file
, "/tmp/.%d", n
);
printf("\t%d):\t%d", n
, scene
[n
].vessels
);
if (access(file
, 0) >= 0)
printf("\t%s\n", scene
[n
].name
);
printf("\nScenario number? ");
while (getchar() != '\n');
if (game
< 0 || game
>= NUMOFSCENES
) {
sprintf(file
, "/tmp/.%d", game
);
if (access(file
, 0) < 0) {
syncfile
= fopen(file
, "w+");
syncfile
= fopen(file
, "r+");
for (n
=0; n
< scene
[game
].vessels
; n
++) {
nation
[scene
[game
].ship
[n
].nationality
+ 1] = n
+ 1;
if ((scene
[game
].ship
[n
].file
= (struct File
*) calloc(1, sizeof(struct File
))) == NULL
) {
scene
[game
].ship
[n
].file
-> captured
= -1;
puts("Synchronizing with the other players...");
for (n
=0; n
< scene
[game
].vessels
&& capn
; n
++) {
capn
= scene
[game
].ship
[n
].file
-> captain
[0];
if (scene
[game
].ship
[n
].file
-> struck
|| scene
[game
].ship
[n
].file
-> captured
> -1)
puts("All ships taken in that scenario.");
for (n
=0; n
< scene
[game
].vessels
; n
++)
free(scene
[game
].ship
[n
].file
);
{ "(American)", "(British)", "(Spanish)", "(French)" };
for (n
=0; n
< scene
[game
].vessels
; n
++) {
printf(" %2d: %-10s %-15s (%-2d pts) ",
color
[scene
[game
].ship
[n
].nationality
],
scene
[game
].ship
[n
].shipname
,
specs
[scene
[game
].ship
[n
].shipnum
].pts
);
if(scene
[game
].ship
[n
].file
-> captain
[0])
puts(scene
[game
].ship
[n
].file
-> captain
);
else if (scene
[game
].ship
[n
].file
-> struck
)
else if(scene
[game
].ship
[n
].file
-> captured
> -1)
printf("Which ship do you want (0-%d)? ",scene
[game
].vessels
-1);
if (scanf("%d",&player
) != 1 || player
< 0 || player
>= scene
[game
].vessels
) {
while (getchar() != '\n');
while (getchar() != '\n');
if (scene
[game
].ship
[player
].file
-> captain
[0] || scene
[game
].ship
[player
].file
-> struck
|| scene
[game
].ship
[player
].file
-> captured
> -1)
puts("Sorry, that ship is taken.");
Write(FILES
+ player
, 1, 0, "begin"); /* he now exists */
Write(SCENARIO
, 0, 8, scene
[game
].people
+ 1);
printf("Your ship is the %s, a %s (%s crew).\n", scene
[game
].ship
[player
].shipname
, info(player
, message
), quality(player
));
if ((nameptr
= (char *) getenv("NAME")) && *nameptr
)
fputs("Your name, Captain? ", stdout
);
if (!*comm
) strcpy(comm
, "no name");
printf("\nInitial broadside %s (grape, chain, round, double): ", (k
? "right" : "left"));
scene
[game
].ship
[player
].file
-> loadR
= load
;
scene
[game
].ship
[player
].file
-> readyR
= ready
;
scene
[game
].ship
[player
].file
-> loadL
= load
;
scene
[game
].ship
[player
].file
-> readyL
= ready
;
Write(FILES
+ player
, 1, 0, comm
);
if (!people
&& !nodriver
) {
sprintf(num
, "%d", game
);
execl(DEBUGDRIVER
, DRIVERNAME
, num
, 0);
execl(DRIVER
, DRIVERNAME
, num
, 0);
view
= newwin(ROWSINVIEW
, COLSINVIEW
, 2, 1);
slot
= newwin(ROWSINVIEW
, 3, 2, 1+COLSINVIEW
);
sprintf(message
, "Captain %s assuming command",comm
);
Write(FILES
+ player
, 1, 164, message
);
windspeed
= scene
[game
].windspeed
;
winddir
= scene
[game
].winddir
;
iplotships(); /* new turn */
* Returns the NUMBER of the closest ship
closestenemy(fromship
, side
, anyship
)
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
);
if (!side
&& olddist
== 30000)
register int crew
, aheadfirst
, ma
, n
;
char nodrive
= 0, randomize
= 0, debug
= 0;
if (timetoplay() != 0 && gooduid(uid
) != 0) {
printf("Sorry Captain, but since you are not an Admiral and this is\n");
printf("a weekday between %s, you are not permitted to\n",badstring());
printf("sail. Come back again some time when the harbor is open.\n");
while (*++argv
&& **argv
== '-')
printf("Unknown flag '%s'\n",*argv
);
initialize(nodrive
, randomize
, debug
);
Signal("Aye aye, Sir", 0, 0);
crew
= specs
[scene
[game
].ship
[player
].shipnum
].crew3
;
if (crew
&& !grappled(player
) && !fouled(player
) && windspeed
) {
aheadfirst
= ta
& 0100000;
ma
= maxmove(player
, pos
[player
].dir
, 0);
acceptmove(ma
, ta
, aheadfirst
);
Signal("Unable to move", 0, 0);
Signal("'Hands to stations!'", 0, 0);
unboard(player
, player
, 1); /* cancel DBP's */
unboard(player
, player
, 0); /* cancel offense */
signal(SIGALRM
, SIG_IGN
);
viewrow
= pos
[player
].row
- ROWSINVIEW
/ 2;
viewcol
= pos
[player
].col
- COLSINVIEW
/ 2;
plotships(); /* don't create new turn */
scene
[game
].ship
[player
].file
-> loadL
= 0;
scene
[game
].ship
[player
].file
-> loadR
= 0;
scene
[game
].ship
[player
].file
-> readyL
= 0;
scene
[game
].ship
[player
].file
-> readyR
= 0;
Signal("Broadsides unloaded", 0, 0);
Signal("Type 'Q' to quit", 0, 0);
for (n
= 0; n
< scene
[game
].vessels
; n
++)
n
= closestenemy(player
, 0, 1);
if(scene
[game
].ship
[n
].file
-> captain
[0])
return(scene
[game
].ship
[n
].file
-> captain
);
else if (scene
[game
].ship
[n
].file
-> struck
)
else if(scene
[game
].ship
[n
].file
-> captured
> -1)
if (scene
[game
].ship
[n
].shipdir
) {
sprintf(message
, "%d, %s", range(player
, n
), saywhat(n
));
Signal("Sail ho! (range %s)", -1, message
);
switch(scene
[game
].ship
[n
].nationality
) {
strcpy(message
, "American ");
strcpy(message
, "British ");
strcpy(message
, "Spanish ");
strcpy(message
, "French ");
strcpy(message
, "Gremlin ");
switch(specs
[scene
[game
].ship
[n
].shipnum
].class) {
strcat(message
, "Ship of the Line ");
strcat(message
, "Frigate ");
strcat(message
, "Sloop ");
switch(portside(player
, n
, 1) - pos
[player
].dir
) {
strcat(message
, "off the starboard bow.");
strcat(message
, "off the starboard beam.");
strcat(message
, "off the starboard quarter.");
strcat(message
, "dead astern.");
strcat(message
, "off the port quarter.");
strcat(message
, "off the port beam.");
strcat(message
, "off the port bow.");
strcat(message
, "dead ahead.");