hull -= ghits;
if (Ghit)
Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
- on, 0, guns, car, 0, 0);
+ on, guns, car, 0, 0);
hull -= hhits;
hull = hull < 0 ? 0 : hull;
if (on->file->captured != 0 && Chit)
- Write(W_PCREW, on, 0, pc, 0, 0, 0);
+ Write(W_PCREW, on, pc, 0, 0, 0);
if (Hhit)
- Write(W_HULL, on, 0, hull, 0, 0, 0);
+ Write(W_HULL, on, hull, 0, 0, 0);
if (Chit)
- Write(W_CREW, on, 0, crew[0], crew[1], crew[2], 0);
+ Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
if (Rhit)
- Write(W_RIGG, on, 0, rigg[0], rigg[1], rigg[2], rigg[3]);
+ Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
switch (shot) {
case L_ROUND:
message = "firing round shot on %s (%c%c)";
break;
case 5:
message = "rudder cables shot through";
- Write(W_TA, on, 0, 0, 0, 0, 0);
+ Write(W_TA, on, 0, 0, 0, 0);
break;
case 6:
message = "shot holes below the water line";
Cleansnag(struct ship *from, struct ship *to, char all, char flag)
{
if (flag & 1) {
- Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
- Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
+ Write(W_UNGRAP, from, to->file->index, all, 0, 0);
+ Write(W_UNGRAP, to, from->file->index, all, 0, 0);
}
if (flag & 2) {
- Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
- Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
+ Write(W_UNFOUL, from, to->file->index, all, 0, 0);
+ Write(W_UNFOUL, to, from->file->index, all, 0, 0);
}
if (!snagged2(from, to)) {
if (!snagged(from)) {
if (ship->file->struck)
return;
- Write(W_STRUCK, ship, 0, 1, 0, 0, 0);
+ Write(W_STRUCK, ship, 1, 0, 0, 0);
points = ship->specs->pts + from->file->points;
- Write(W_POINTS, from, 0, points, 0, 0, 0);
+ Write(W_POINTS, from, points, 0, 0, 0);
unboard(ship, ship, 0); /* all offense */
unboard(ship, ship, 1); /* all defense */
switch (die()) {
case 3:
case 4: /* ship may sink */
- Write(W_SINK, ship, 0, 1, 0, 0, 0);
+ Write(W_SINK, ship, 1, 0, 0, 0);
break;
case 5:
case 6: /* ship may explode */
- Write(W_EXPLODE, ship, 0, 1, 0, 0, 0);
+ Write(W_EXPLODE, ship, 1, 0, 0, 0);
break;
}
- Write(W_SIGNAL, ship, 1, (int) "striking her colours!", 0, 0, 0);
+ Writestr(W_SIGNAL, ship, "striking her colours!");
}
makesignal(from, "boarders from %s repelled", to);
sprintf(message, "killed in melee: %d. %s: %d",
totalto, from->shipname, totalfrom);
- Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
+ Writestr(W_SIGNAL, to, message);
if (key)
return 1;
} else if (strengthto >= fromstrength * 3) {
subtract(to, totalto, crewto, tocap, pcto);
if (key) {
if (fromcap != from)
- Write(W_POINTS, fromcap, 0,
+ Write(W_POINTS, fromcap,
fromcap->file->points -
from->file->struck
? from->specs->pts
I guess that what is going on here is that the pointer is multiplied
or something. */
- Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
+ Write(W_CAPTURED, from, to->file->index, 0, 0, 0);
topoints = 2 * from->specs->pts + to->file->points;
if (from->file->struck)
topoints -= from->specs->pts;
- Write(W_POINTS, to, 0, topoints, 0, 0, 0);
+ Write(W_POINTS, to, topoints, 0, 0, 0);
mento = crewto[0] ? crewto[0] : crewto[1];
if (mento) {
subtract(to, mento, crewto, tocap, pcto);
}
sprintf(message, "captured by the %s!",
to->shipname);
- Write(W_SIGNAL, from, 1, (long) message, 0, 0, 0);
+ Writestr(W_SIGNAL, from, message);
sprintf(message, "killed in melee: %d. %s: %d",
totalto, from->shipname, totalfrom);
- Write(W_SIGNAL, to, 1, (long) message, 0, 0, 0);
+ Writestr(W_SIGNAL, to, message);
mento = 0;
return 0;
}
}
return -1;
}
- Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
+ Write(W_TURN, SHIP(0), turn, 0, 0, 0);
if (turn % 7 == 0 && (die() >= cc->windchange || !windspeed)) {
switch (die()) {
case 1:
}
else
windspeed++;
- Write(W_WIND, SHIP(0), 0, winddir, windspeed, 0, 0);
+ Write(W_WIND, SHIP(0), winddir, windspeed, 0, 0);
}
return 0;
}
continue;
if (die() < 5)
continue;
- Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0);
- Write(W_DIR, sp, 0, 0, 0, 0, 0);
+ Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 2, 0, 0, 0);
+ Write(W_DIR, sp, 0, 0, 0, 0);
if (snagged(sp))
foreachship(sq)
cleansnag(sp, sq, 1);
if (sp->file->struck || sp->file->dir == 0)
continue;
if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) {
- Write(W_SIGNAL, sp, 1,
- (int)"prize crew overthrown", 0, 0, 0);
- Write(W_POINTS, sp->file->captured, 0, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
- Write(W_CAPTURED, sp, 0, -1, 0, 0, 0);
+ Writestr(W_SIGNAL, sp, "prize crew overthrown");
+ Write(W_POINTS, sp->file->captured, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
+ Write(W_CAPTURED, sp, -1, 0, 0, 0);
}
}
}
makesignal(sp,
"fouled with %s (%c%c)",
sq);
- Write(W_FOUL, sp, 0, l, 0, 0, 0);
- Write(W_FOUL, sq, 0, n, 0, 0, 0);
+ Write(W_FOUL, sp, l, 0, 0, 0);
+ Write(W_FOUL, sq, n, 0, 0, 0);
}
snap++;
}
if (sp->file->dir != 0) {
*sp->file->movebuf = 0;
if (row[n] != sp->file->row)
- Write(W_ROW, sp, 0, sp->file->row, 0, 0, 0);
+ Write(W_ROW, sp, sp->file->row, 0, 0, 0);
if (col[n] != sp->file->col)
- Write(W_COL, sp, 0, sp->file->col, 0, 0, 0);
+ Write(W_COL, sp, sp->file->col, 0, 0, 0);
if (dir[n] != sp->file->dir)
- Write(W_DIR, sp, 0, sp->file->dir, 0, 0, 0);
+ Write(W_DIR, sp, sp->file->dir, 0, 0, 0);
if (drift[n] != sp->file->drift)
- Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
+ Write(W_DRIFT, sp, sp->file->drift, 0, 0, 0);
}
n++;
}
for (n = 0; n < NBP && bp[n].turnsent; n++)
;
if (n < NBP && sections) {
- Write(isdefense ? W_DBP : W_OBP, from, 0,
+ Write(isdefense ? W_DBP : W_OBP, from,
n, turn, to->file->index, sections);
if (isdefense)
makesignal(from, "repelling boarders",
} else
full = 0;
if ((sp->file->FS != 0) != full)
- Write(W_FS, sp, 0, full, 0, 0, 0);
+ Write(W_FS, sp, full, 0, 0, 0);
}
}
{
if (capship(from)->nationality != capship(to)->nationality && die() > 2)
return;
- Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
- Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
+ Write(W_GRAP, from, to->file->index, 0, 0, 0);
+ Write(W_GRAP, to, from->file->index, 0, 0, 0);
makesignal(from, "grappled with %s (%c%c)", to);
}
totalfrom = 0;
}
}
- Write(W_CREW, from, 0, crewfrom[0], crewfrom[1], crewfrom[2], 0);
+ Write(W_CREW, from, crewfrom[0], crewfrom[1], crewfrom[2], 0);
} else if (totalfrom) {
pcfrom -= totalfrom;
pcfrom = pcfrom < 0 ? 0 : pcfrom;
- Write(W_PCREW, from, 0, pcfrom, 0, 0, 0);
+ Write(W_PCREW, from, pcfrom, 0, 0, 0);
}
}
bool sync_exists(int);
int sync_open(void);
void sync_close(char);
-void Write(int, struct ship *, char, int, int, int, int);
+void Write(int, struct ship *, int, int, int, int);
+void Writestr(int, struct ship *, const char *);
int Sync(void);
for (n = 0; n < NBP; p++, n++)
if (p->turnsent && (p->toship == to || isdefense || ship == to))
- Write(isdefense ? W_DBP : W_OBP, ship, 0, n, 0, 0, 0);
+ Write(isdefense ? W_DBP : W_OBP, ship, n, 0, 0, 0);
}
if (conditions != LEAVE_SYNC) {
makesignal(ms, "Captain %s relinquishing.",
(struct ship *)0, mf->captain);
- Write(W_END, ms, 0, 0, 0, 0, 0);
+ Write(W_END, ms, 0, 0, 0, 0);
Sync();
}
}
case 'g':
if (die() < 3
|| ms->nationality == capship(sp)->nationality) {
- Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
- Write(W_GRAP, sp, 0, player, 0, 0, 0);
+ Write(W_GRAP, ms, sp->file->index, 0, 0, 0);
+ Write(W_GRAP, sp, player, 0, 0, 0);
Signal("Attempt succeeds!", (struct ship *)0);
makesignal(ms, "grappled with %s (%c%c)", sp);
} else
if (sgetch("Increase to Full sails? ",
(struct ship *)0, 1) == 'y') {
changed = 1;
- Write(W_FS, ms, 0, 1, 0, 0, 0);
+ Write(W_FS, ms, 1, 0, 0, 0);
}
} else {
if (sgetch("Reduce to Battle sails? ",
(struct ship *)0, 1) == 'y') {
- Write(W_FS, ms, 0, 0, 0, 0, 0);
+ Write(W_FS, ms, 0, 0, 0, 0);
changed = 1;
}
}
;
p[-1] = '"';
*p = 0;
- Write(W_SIGNAL, ms, 1, (long)buf, 0, 0, 0);
+ Writestr(W_SIGNAL, ms, buf);
}
void
Signal("Movement error.", (struct ship *)0);
if (ta < 0 && moved) {
if (mf->FS == 1) {
- Write(W_FS, ms, 0, 0, 0, 0, 0);
+ Write(W_FS, ms, 0, 0, 0, 0);
Signal("No hands to set full sails.",
(struct ship *)0);
}
}
if (af && !moved) {
if (mf->FS == 1) {
- Write(W_FS, ms, 0, 0, 0, 0, 0);
+ Write(W_FS, ms, 0, 0, 0, 0);
Signal("No hands to set full sails.",
(struct ship *)0);
}
strcpy(movebuf, buf);
else
strcpy(movebuf, "d");
- Write(W_MOVE, ms, 1, (int)movebuf, 0, 0, 0);
+ Writestr(W_MOVE, ms, movebuf);
Signal("Helm: %s.", (struct ship *)0, movebuf);
}
if (buf > '0')
Signal("Sending all crew sections.",
(struct ship *)0);
- Write(isdefense ? W_DBP : W_OBP, ms, 0,
+ Write(isdefense ? W_DBP : W_OBP, ms,
j, turn, to->file->index, men);
if (isdefense) {
wmove(slot_w, 2, 0);
int max = ptr->guns/4;
if (ptr->hull < max) {
FIX(hull, max);
- Write(W_HULL, ms, 0, ptr->hull, 0, 0, 0);
+ Write(W_HULL, ms, ptr->hull, 0, 0, 0);
}
break;
}
int max = ptr->guns/5 - ptr->carL;
if (ptr->gunL < max) {
FIX(gunL, max);
- Write(W_GUNL, ms, 0, ptr->gunL,
+ Write(W_GUNL, ms, ptr->gunL,
ptr->carL, 0, 0);
}
} else {
int max = ptr->guns/5 - ptr->carR;
if (ptr->gunR < max) {
FIX(gunR, max);
- Write(W_GUNR, ms, 0, ptr->gunR,
+ Write(W_GUNR, ms, ptr->gunR,
ptr->carR, 0, 0);
}
}
#define X 2
if (ptr->rig4 >= 0 && ptr->rig4 < X) {
FIX(rig4, X);
- Write(W_RIG4, ms, 0, ptr->rig4, 0, 0, 0);
+ Write(W_RIG4, ms, ptr->rig4, 0, 0, 0);
}
if (count && ptr->rig3 < X) {
FIX(rig3, X);
- Write(W_RIG3, ms, 0, ptr->rig3, 0, 0, 0);
+ Write(W_RIG3, ms, ptr->rig3, 0, 0, 0);
}
if (count && ptr->rig2 < X) {
FIX(rig2, X);
- Write(W_RIG2, ms, 0, ptr->rig2, 0, 0, 0);
+ Write(W_RIG2, ms, ptr->rig2, 0, 0, 0);
}
if (count && ptr->rig1 < X) {
FIX(rig1, X);
- Write(W_RIG1, ms, 0, ptr->rig1, 0, 0, 0);
+ Write(W_RIG1, ms, ptr->rig1, 0, 0, 0);
}
break;
}
mf->readyR = R_LOADED;
}
if (!hasdriver)
- Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0);
+ Write(W_DDEAD, SHIP(0), 0, 0, 0, 0);
if (sc_hasprompt) {
wmove(scroll_w, sc_line, 0);
wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
if (turn % 50 == 0)
- Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0);
+ Write(W_ALIVE, SHIP(0), 0, 0, 0, 0);
if (mf->FS && (!mc->rig1 || windspeed == 6))
- Write(W_FS, ms, 0, 0, 0, 0, 0);
+ Write(W_FS, ms, 0, 0, 0, 0);
if (mf->FS == 1)
- Write(W_FS, ms, 0, 2, 0, 0, 0);
+ Write(W_FS, ms, 2, 0, 0, 0);
if (mf->struck)
leave(LEAVE_QUIT);
mf = ms->file;
mc = ms->specs;
- Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
+ Write(W_BEGIN, ms, 0, 0, 0, 0);
if (Sync() < 0)
leave(LEAVE_SYNC);
else
captain[sizeof(captain) - 1] = '\0';
}
- Write(W_CAPTAIN, ms, 1, (long)captain, 0, 0, 0);
+ Writestr(W_CAPTAIN, ms, captain);
for (n = 0; n < 2; n++) {
char buf[10];
initscreen();
draw_board();
- sprintf(message, "Captain %s assuming command", captain);
- Write(W_SIGNAL, ms, 1, (long)message, 0, 0, 0);
+ snprintf(message, sizeof message, "Captain %s assuming command",
+ captain);
+ Writestr(W_SIGNAL, ms, message);
newturn();
}
#include "externs.h"
#include <sys/file.h>
#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#define BUFSIZE 4096
#define SF "/tmp/#sailsink.%d"
#define LF "/tmp/#saillock.%d"
-static int sync_update(int, struct ship *, long, long, long, long);
+static int sync_update(int, struct ship *, const char *, long, long, long,
+ long);
void
fmtship(char *buf, size_t len, const char *fmt, struct ship *ship)
vsprintf(message, format, ap);
}
va_end(ap);
- Write(W_SIGNAL, from, 1, (long)message, 0, 0, 0);
+ Writestr(W_SIGNAL, from, message);
}
-#include <sys/types.h>
-#include <sys/stat.h>
bool
sync_exists(int lgame)
{
}
void
-Write(int type, struct ship *ship, char isstr, int a, int b, int c, int d)
+Write(int type, struct ship *ship, int a, int b, int c, int d)
+{
+ sprintf(sync_bp, "%d %d 0 %d %d %d %d\n",
+ type, ship->file->index, a, b, c, d);
+ while (*sync_bp++)
+ ;
+ sync_bp--;
+ if (sync_bp >= &sync_buf[sizeof sync_buf])
+ abort();
+ sync_update(type, ship, NULL, a, b, c, d);
+}
+
+void
+Writestr(int type, struct ship *ship, const char *a)
{
- if (isstr)
- sprintf(sync_bp, "%d %d %d %s\n",
- type, ship->file->index, isstr, (char *)a);
- else
- sprintf(sync_bp, "%d %d %d %d %d %d %d\n",
- type, ship->file->index, isstr, a, b, c, d);
+ sprintf(sync_bp, "%d %d 1 %s\n", type, ship->file->index, a);
while (*sync_bp++)
;
sync_bp--;
if (sync_bp >= &sync_buf[sizeof sync_buf])
abort();
- sync_update(type, ship, a, b, c, d);
+ sync_update(type, ship, a, 0, 0, 0, 0);
}
int
sig_t sighup, sigint;
int n;
int type, shipnum, isstr, a, b, c, d;
+ char *astr;
char buf[80];
char erred = 0;
sighup = signal(SIGHUP, SIG_IGN);
*p = 0;
for (p = buf; *p == ' '; p++)
;
- a = (long)p;
- b = c = d = 0;
- } else
+ astr = p;
+ a = b = c = d = 0;
+ } else {
if (fscanf(sync_fp, "%d%d%d%d", &a, &b, &c, &d) != 4)
goto bad;
- if (sync_update(type, SHIP(shipnum), a, b, c, d) < 0)
+ astr = NULL;
+ }
+ if (sync_update(type, SHIP(shipnum), astr, a, b, c, d) < 0)
goto bad;
}
bad:
erred++;
out:
if (!erred && sync_bp != sync_buf) {
- fseek(sync_fp, 0L, 2);
+ fseek(sync_fp, 0L, SEEK_END);
fwrite(sync_buf, sizeof *sync_buf, sync_bp - sync_buf,
sync_fp);
fflush(sync_fp);
}
static int
-sync_update(int type, struct ship *ship, long a, long b, long c, long d)
+sync_update(int type, struct ship *ship, const char *astr, long a, long b,
+ long c, long d)
{
switch (type) {
case W_DBP: {
case W_SIGNAL:
if (mode == MODE_PLAYER) {
if (nobells)
- Signal("%s (%c%c): %s", ship, a);
+ Signal("%s (%c%c): %s", ship, astr);
else
- Signal("\7%s (%c%c): %s", ship, a);
+ Signal("\7%s (%c%c): %s", ship, astr);
}
break;
case W_CREW: {
break;
}
case W_CAPTAIN:
- strncpy(ship->file->captain, (char *)a,
+ strncpy(ship->file->captain, astr,
sizeof ship->file->captain - 1);
ship->file->captain[sizeof ship->file->captain - 1] = 0;
break;
ship->specs->hull = a;
break;
case W_MOVE:
- strncpy(ship->file->movebuf, (char *)a,
+ strncpy(ship->file->movebuf, astr,
sizeof ship->file->movebuf - 1);
ship->file->movebuf[sizeof ship->file->movebuf - 1] = 0;
break;