static char *sccsid
= "@(#)driver1.c 1.3 83/05/20";
#define couldwin(from, to) (specs[scene[game].ship[from].shipnum].crew2 > specs[scene[game].ship[to].shipnum].crew2 * 1.5)
for (n
=0; n
< scene
[game
].vessels
; n
++){
ptr
= scene
[game
].ship
[n
].file
;
if (ptr
-> fouls
[k
].turnfoul
){
if ((ident
= ptr
-> captured
) < 0)
ship
= ptr
-> fouls
[k
].toship
;
if ((captured
= scene
[game
].ship
[ship
].file
-> captured
) < 0)
if (scene
[game
].ship
[ident
].nationality
== scene
[game
].ship
[ship
].nationality
|| toughmelee(n
, ship
, 0, 0))
register int n
, k
, l
, men
= 0, captured
;
for (n
= 0; n
< scene
[game
].vessels
; n
++){
ptr
= &specs
[scene
[game
].ship
[n
].shipnum
];
ptr1
= scene
[game
].ship
[n
].file
;
if (!ptr1
-> captain
[0] && (fouled(n
) || grappled(n
)) && pos
[n
].dir
&& !ptr1
-> struck
&& ptr1
-> captured
< 0){
crew
[0] = ptr
-> crew1
!= 0;
crew
[1] = ptr
-> crew2
!= 0;
crew
[2] = ptr
-> crew3
!= 0;
for (l
=0; l
< scene
[game
].vessels
; l
++)
if (foul(n
+100,l
) || grapple(n
+100,l
)){
if ((captured
= scene
[game
].ship
[l
].file
-> captured
) < 0)
if (pos
[l
].dir
&& scene
[game
].ship
[n
].nationality
!= scene
[game
].ship
[captured
].nationality
){
switch(specs
[scene
[game
].ship
[n
].shipnum
].class - specs
[scene
[game
].ship
[l
].shipnum
].class){
send(n
, l
, crew
[0]*100, 200); /* OBP */
send(n
, l
, crew
[1]*10, 200); /* OBP */
send(n
, l
, crew
[0]*100+crew
[1]*10, 200); /* OBP */
send(n
, l
, crew
[0]*100+crew
[1]*10, 200); /* OBP */
send(n
, l
, crew
[0]*100+crew
[1]*10+crew
[2], 200); /* OBP */
crew
[0] = crew
[1] = crew
[2] = 0;
fightitout(from
, to
, key
)
int crewfrom
[3], crewto
[3], menfrom
, mento
, fromcap
, tocap
;
int pcto
, pcfrom
, fromstrength
, strengthto
, frominjured
, toinjured
;
int index
, totalfrom
= 0, totalto
= 0, topoints
, frompoints
, struck
;
ptr
= scene
[game
].ship
[from
].file
;
ptr1
= &specs
[scene
[game
].ship
[from
].shipnum
];
menfrom
= mensent(from
, to
, crewfrom
, &fromcap
, &pcfrom
, &frompoints
, key
);
mento
= mensent(to
, from
, crewto
, &tocap
, &pcto
, &topoints
, 0);
fromstrength
= menfrom
* specs
[scene
[game
].ship
[fromcap
].shipnum
].qual
;
strengthto
= mento
* specs
[scene
[game
].ship
[tocap
].shipnum
].qual
;
menfrom
= ptr1
-> crew1
+ ptr1
-> crew2
+ ptr1
-> crew3
;
for (count
= 0; (!(fromstrength
>= strengthto
* 3 || strengthto
>= fromstrength
* 3) || fromstrength
== -1) && count
< 4;count
++){
toinjured
= MT
[index
][2 - die() / 3];
frominjured
= MT
[index
][2 - die() / 3];
totalfrom
+= frominjured
;
fromstrength
= menfrom
* specs
[scene
[game
].ship
[fromcap
].shipnum
].qual
;
strengthto
= mento
* specs
[scene
[game
].ship
[tocap
].shipnum
].qual
;
if (fromstrength
>= strengthto
* 3 || count
== 4){
subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
subtract(to
, totalto
, crewto
, tocap
, pcto
);
makesignal("boarders from %s repelled", to
, from
);
sprintf(message
, "killed in melee: %d. %s: %d", totalto
, scene
[game
].ship
[from
].shipname
, totalfrom
);
Write(FILES
+ to
, 1, 164, message
);
else if (strengthto
>= fromstrength
* 3){
subtract(from
, totalfrom
, crewfrom
, fromcap
, pcfrom
);
subtract(to
, totalto
, crewto
, tocap
, pcto
);
/* Write(FILES + fromcap, 0, 20, scene[game].ship[fromcap].file -> points - (2 - ptr -> struck)*ptr1 -> points); */ /* original line... */
Write(FILES
+ fromcap
, 0, 20,
(scene
[game
].ship
[fromcap
].file
-> points
) -
(2 - (ptr
-> struck
))*(ptr1
-> pts
)
/* (2 - (ptr -> struck))*(ptr1 -> points) */
/* ptr1 points to the shipspec for the ship that was just unboarded.
I guess that what is going on here is that the pointer is multiplied
Write(FILES
+ from
, 0, 68, to
);
topoints
= 2*ptr1
-> pts
+ scene
[game
].ship
[to
].file
-> points
;
Write(FILES
+ to
, 0, 20, topoints
);
mento
= crewto
[0] ? crewto
[0] : crewto
[1];
subtract(to
, mento
, crewto
, tocap
, pcto
);
subtract(from
, -mento
, crewfrom
, to
, 0);
sprintf(message
, "captured by the %s!",scene
[game
].ship
[to
].shipname
);
Write(FILES
+ from
, 1, 164, message
);
sprintf(message
, "killed in melee: %d. %s: %d", totalto
, scene
[game
].ship
[from
].shipname
, totalfrom
);
Write(FILES
+ to
, 1, 164, message
);
} /* end of fightitout */
register int n
, l
, k
, thwart
;
for (n
=0; n
< scene
[game
].vessels
; n
++){
for (l
=n
+1; l
< scene
[game
].vessels
; l
++){
if (pos
[l
].dir
&& meleeing(n
,l
) && meleeing(l
,n
)){ /* offense */
for (l
=0; l
< scene
[game
].vessels
; l
++){ /* defense */
if (pos
[l
].dir
&& meleeing(l
,n
)){
thwart
= fightitout(n
,l
,1);
for (k
=0; k
< scene
[game
].vessels
; k
++){
if (pos
[k
].dir
&& meleeing(k
,n
)){
int crew
[3], men
= 0, 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
;
for (ship
= 0; ship
< scene
[game
].vessels
; ship
++){
ptr
= &specs
[scene
[game
].ship
[ship
].shipnum
];
ptr1
= scene
[game
].ship
[ship
].file
;
if (!ptr1
-> captain
[0] && pos
[ship
].dir
){
ready
[0] = ptr1
-> readyL
;
ready
[1] = ptr1
-> readyR
;
if (ptr1
-> OBP
[n
].turnsent
)
men
+= ptr1
-> OBP
[n
].mensent
;
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;
if ((guns
[r
] || car
[r
]) && crew
[2] && ready
[r
] <= 0 && !ptr1
-> struck
&& ((closest
[r
] = closestenemy(ship
, (r
? 'r' : 'l'), 0)) != 30000) && range(closest
[r
], ship
) <= range(ship
, closestenemy(ship
, (r
? 'r' : 'l'), 1))){
if ((target
= range(ship
, closest
[r
])) <= 10 && !scene
[game
].ship
[closest
[r
]].file
-> struck
&& (guns
[r
] || (car
[r
] && target
< 3))){
if (target
== 1 && loadwith
[ship
] == GRAPE
)
if (target
<= 3 && scene
[game
].ship
[closest
[r
]].file
-> FS
)
if (target
== 1 && load
[r
] != GRAPE
)
if (load
[r
] > CHAIN
&& target
< 6){
rakehim
= gunsbear(ship
, closest
[r
]) && !gunsbear(closest
[r
], ship
);
temp
= portside(closest
[r
], ship
, 1) - pos
[closest
[r
]].dir
+ 1;
sternrake
= temp
> 4 && temp
< 6;
index
= index
> 8 ? 8 : index
;
hit
[r
] = HDT
[index
][target
-1];
hit
[r
] = HDTrake
[index
][target
-1];
if (rakehim
&& sternrake
){
hit
[r
] += QUAL
[index
][ptr1
-> captured
< 0 ? ptr
-> qual
-1 : specs
[scene
[game
].ship
[ptr1
-> captured
].shipnum
].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
];
table(shootat
[r
], load
[r
], hit
[r
], closest
[r
], ship
, roll
[r
]);
scene
[game
].people
= 0; /* die if no one */
if (scene
[game
].people
<= 0 || windspeed
== 7){
sprintf(string
, "/tmp/.%d", game
);
if (unlink(string
) == -1)
Write(SCENARIO
, 0, 6, turn
);
if (die() >= scene
[game
].windchange
|| !windspeed
){
Write(SCENARIO
, 0, 0, winddir
);
Write(SCENARIO
, 0, 2, windspeed
);
makesignal("*Load getting high, brace yourselves.", 0, 0);
makesignal("*Load average is blowing a gale!", 0, 0);
Write(SCENARIO, 0, 2, 7);
/* ;;; add code here to check the game number. */
sprintf(file
, "/tmp/.%s",argv
[1]);
for (n
= 0; access(file
, 0) < 0 && n
< 20; n
++)
syncfile
= fopen(file
, "r+");
sscanf(argv
[1], "%d", &game
);
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
){
printf("OUT OF MEMORY\n");
scene
[game
].ship
[n
].file
-> captured
= -1;
for (n
= 0; n
< scene
[game
].vessels
; n
++){ /* initial loads */
scene
[game
].ship
[n
].file
-> loadL
= ROUND
;
scene
[game
].ship
[n
].file
-> loadR
= ROUND
;
scene
[game
].ship
[n
].file
-> readyR
= -30000;
scene
[game
].ship
[n
].file
-> readyL
= -30000;
windspeed
= scene
[game
].windspeed
;
winddir
= scene
[game
].winddir
;