Skip to content

Commit e544d2b

Browse files
committed
Create some abstraction for sending messages.
Make a send and receive function for each possible message. Make these have useful argument signatures. Hide the list of message codes inside sync.c.
1 parent 82357f6 commit e544d2b

File tree

16 files changed

+843
-341
lines changed

16 files changed

+843
-341
lines changed

games/sail/assorted.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: assorted.c,v 1.16 2009/03/14 19:35:13 dholland Exp $ */
1+
/* $NetBSD: assorted.c,v 1.17 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)assorted.c 8.2 (Berkeley) 4/28/95";
3636
#else
37-
__RCSID("$NetBSD: assorted.c,v 1.16 2009/03/14 19:35:13 dholland Exp $");
37+
__RCSID("$NetBSD: assorted.c,v 1.17 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -133,19 +133,23 @@ table(struct ship *from, struct ship *on,
133133
ghits = 0;
134134
}
135135
hull -= ghits;
136-
if (Ghit)
137-
Write(portside(from, on, 0) ? W_GUNR : W_GUNL,
138-
on, guns, car, 0, 0);
136+
if (Ghit) {
137+
if (portside(from, on, 0)) {
138+
send_gunr(on, guns, car);
139+
} else {
140+
send_gunl(on, guns, car);
141+
}
142+
}
139143
hull -= hhits;
140144
hull = hull < 0 ? 0 : hull;
141145
if (on->file->captured != 0 && Chit)
142-
Write(W_PCREW, on, pc, 0, 0, 0);
146+
send_pcrew(on, pc);
143147
if (Hhit)
144-
Write(W_HULL, on, hull, 0, 0, 0);
148+
send_hull(on, hull);
145149
if (Chit)
146-
Write(W_CREW, on, crew[0], crew[1], crew[2], 0);
150+
send_crew(on, crew[0], crew[1], crew[2]);
147151
if (Rhit)
148-
Write(W_RIGG, on, rigg[0], rigg[1], rigg[2], rigg[3]);
152+
send_rigg(on, rigg[0], rigg[1], rigg[2], rigg[3]);
149153
switch (shot) {
150154
case L_ROUND:
151155
message = "firing round shot on $$";
@@ -213,7 +217,7 @@ table(struct ship *from, struct ship *on,
213217
break;
214218
case 5:
215219
message = "rudder cables shot through";
216-
Write(W_TA, on, 0, 0, 0, 0);
220+
send_ta(on, 0);
217221
break;
218222
case 6:
219223
message = "shot holes below the water line";
@@ -245,12 +249,12 @@ void
245249
Cleansnag(struct ship *from, struct ship *to, int all, int flag)
246250
{
247251
if (flag & 1) {
248-
Write(W_UNGRAP, from, to->file->index, all, 0, 0);
249-
Write(W_UNGRAP, to, from->file->index, all, 0, 0);
252+
send_ungrap(from, to->file->index, all);
253+
send_ungrap(to, from->file->index, all);
250254
}
251255
if (flag & 2) {
252-
Write(W_UNFOUL, from, to->file->index, all, 0, 0);
253-
Write(W_UNFOUL, to, from->file->index, all, 0, 0);
256+
send_unfoul(from, to->file->index, all);
257+
send_unfoul(to, from->file->index, all);
254258
}
255259
if (!snagged2(from, to)) {
256260
if (!snagged(from)) {
@@ -273,20 +277,20 @@ strike(struct ship *ship, struct ship *from)
273277

274278
if (ship->file->struck)
275279
return;
276-
Write(W_STRUCK, ship, 1, 0, 0, 0);
280+
send_struck(ship, 1);
277281
points = ship->specs->pts + from->file->points;
278-
Write(W_POINTS, from, points, 0, 0, 0);
282+
send_points(from, points);
279283
unboard(ship, ship, 0); /* all offense */
280284
unboard(ship, ship, 1); /* all defense */
281285
switch (dieroll()) {
282286
case 3:
283287
case 4: /* ship may sink */
284-
Write(W_SINK, ship, 1, 0, 0, 0);
288+
send_sink(ship, 1);
285289
break;
286290
case 5:
287291
case 6: /* ship may explode */
288-
Write(W_EXPLODE, ship, 1, 0, 0, 0);
292+
send_explode(ship, 1);
289293
break;
290294
}
291-
Writestr(W_SIGNAL, ship, "striking her colours!");
295+
send_signal(ship, "striking her colours!");
292296
}

games/sail/dr_1.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_1.c,v 1.26 2009/03/14 19:55:16 dholland Exp $ */
1+
/* $NetBSD: dr_1.c,v 1.27 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)dr_1.c 8.1 (Berkeley) 5/31/93";
3636
#else
37-
__RCSID("$NetBSD: dr_1.c,v 1.26 2009/03/14 19:55:16 dholland Exp $");
37+
__RCSID("$NetBSD: dr_1.c,v 1.27 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -193,7 +193,7 @@ fightitout(struct ship *from, struct ship *to, int key)
193193
snprintf(message, sizeof(message),
194194
"killed in melee: %d. %s: %d",
195195
totalto, from->shipname, totalfrom);
196-
Writestr(W_SIGNAL, to, message);
196+
send_signal(to, message);
197197
if (key)
198198
return 1;
199199
} else if (strengthto >= fromstrength * 3) {
@@ -202,30 +202,29 @@ fightitout(struct ship *from, struct ship *to, int key)
202202
subtract(to, tocap, totalto, crewto, pcto);
203203
if (key) {
204204
if (fromcap != from)
205-
Write(W_POINTS, fromcap,
205+
send_points(fromcap,
206206
fromcap->file->points -
207207
from->file->struck
208208
? from->specs->pts
209-
: 2 * from->specs->pts,
210-
0, 0, 0);
209+
: 2 * from->specs->pts);
211210

212-
Write(W_CAPTURED, from, to->file->index, 0, 0, 0);
211+
send_captured(from, to->file->index);
213212
topoints = 2 * from->specs->pts + to->file->points;
214213
if (from->file->struck)
215214
topoints -= from->specs->pts;
216-
Write(W_POINTS, to, topoints, 0, 0, 0);
215+
send_points(to, topoints);
217216
mento = crewto[0] ? crewto[0] : crewto[1];
218217
if (mento) {
219218
subtract(to, tocap, mento, crewto, pcto);
220219
subtract(from, to, - mento, crewfrom, 0);
221220
}
222221
snprintf(message, sizeof(message),
223222
"captured by the %s!", to->shipname);
224-
Writestr(W_SIGNAL, from, message);
223+
send_signal(from, message);
225224
snprintf(message, sizeof(message),
226225
"killed in melee: %d. %s: %d",
227226
totalto, from->shipname, totalfrom);
228-
Writestr(W_SIGNAL, to, message);
227+
send_signal(to, message);
229228
mento = 0;
230229
return 0;
231230
}
@@ -437,7 +436,7 @@ next(void)
437436
}
438437
return -1;
439438
}
440-
Write(W_TURN, SHIP(0), turn, 0, 0, 0);
439+
send_turn(turn);
441440
if (turn % 7 == 0 && (dieroll() >= cc->windchange || !windspeed)) {
442441
switch (dieroll()) {
443442
case 1:
@@ -475,7 +474,7 @@ next(void)
475474
}
476475
else
477476
windspeed++;
478-
Write(W_WIND, SHIP(0), winddir, windspeed, 0, 0);
477+
send_wind( winddir, windspeed);
479478
}
480479
return 0;
481480
}

games/sail/dr_2.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_2.c,v 1.24 2009/03/14 20:04:43 dholland Exp $ */
1+
/* $NetBSD: dr_2.c,v 1.25 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
3636
#else
37-
__RCSID("$NetBSD: dr_2.c,v 1.24 2009/03/14 20:04:43 dholland Exp $");
37+
__RCSID("$NetBSD: dr_2.c,v 1.25 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -105,8 +105,12 @@ checkup(void)
105105
continue;
106106
if (dieroll() < 5)
107107
continue;
108-
Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 2, 0, 0, 0);
109-
Write(W_DIR, sp, 0, 0, 0, 0);
108+
if (sink == 1) {
109+
send_sink(sp, 2);
110+
} else {
111+
send_explode(sp, 2);
112+
}
113+
send_dir(sp, 0);
110114
if (snagged(sp))
111115
foreachship(sq)
112116
cleansnag(sp, sq, 1);
@@ -136,12 +140,11 @@ prizecheck(void)
136140
continue;
137141
if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 >
138142
sp->file->pcrew * 6) {
139-
Writestr(W_SIGNAL, sp, "prize crew overthrown");
140-
Write(W_POINTS, sp->file->captured,
143+
send_signal(sp, "prize crew overthrown");
144+
send_points(sp->file->captured,
141145
sp->file->captured->file->points
142-
- 2 * sp->specs->pts,
143-
0, 0, 0);
144-
Write(W_CAPTURED, sp, -1, 0, 0, 0);
146+
- 2 * sp->specs->pts);
147+
send_captured(sp, -1);
145148
}
146149
}
147150
}

games/sail/dr_3.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_3.c,v 1.18 2009/03/14 20:04:43 dholland Exp $ */
1+
/* $NetBSD: dr_3.c,v 1.19 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)dr_3.c 8.1 (Berkeley) 5/31/93";
3636
#else
37-
__RCSID("$NetBSD: dr_3.c,v 1.18 2009/03/14 20:04:43 dholland Exp $");
37+
__RCSID("$NetBSD: dr_3.c,v 1.19 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -143,8 +143,8 @@ moveall(void)
143143
if (dieroll() < 4) {
144144
makesignal(sp, "fouled with $$",
145145
sq);
146-
Write(W_FOUL, sp, l, 0, 0, 0);
147-
Write(W_FOUL, sq, n, 0, 0, 0);
146+
send_foul(sp, l);
147+
send_foul(sq, n);
148148
}
149149
snap++;
150150
}
@@ -175,13 +175,13 @@ moveall(void)
175175
if (sp->file->dir != 0) {
176176
*sp->file->movebuf = 0;
177177
if (row[n] != sp->file->row)
178-
Write(W_ROW, sp, sp->file->row, 0, 0, 0);
178+
send_row(sp, sp->file->row);
179179
if (col[n] != sp->file->col)
180-
Write(W_COL, sp, sp->file->col, 0, 0, 0);
180+
send_col(sp, sp->file->col);
181181
if (dir[n] != sp->file->dir)
182-
Write(W_DIR, sp, sp->file->dir, 0, 0, 0);
182+
send_dir(sp, sp->file->dir);
183183
if (drift[n] != sp->file->drift)
184-
Write(W_DRIFT, sp, sp->file->drift, 0, 0, 0);
184+
send_drift(sp, sp->file->drift);
185185
}
186186
n++;
187187
}
@@ -275,8 +275,11 @@ sendbp(struct ship *from, struct ship *to, int sections, int isdefense)
275275
for (n = 0; n < NBP && bp[n].turnsent; n++)
276276
;
277277
if (n < NBP && sections) {
278-
Write(isdefense ? W_DBP : W_OBP, from,
279-
n, turn, to->file->index, sections);
278+
if (isdefense) {
279+
send_dbp(from, n, turn, to->file->index, sections);
280+
} else {
281+
send_obp(from, n, turn, to->file->index, sections);
282+
}
280283
if (isdefense)
281284
makemsg(from, "repelling boarders");
282285
else
@@ -352,6 +355,6 @@ checksails(void)
352355
full = 0;
353356
}
354357
if ((sp->file->FS != 0) != full)
355-
Write(W_FS, sp, full, 0, 0, 0);
358+
send_fs(sp, full);
356359
}
357360
}

games/sail/dr_4.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_4.c,v 1.14 2009/03/14 19:35:13 dholland Exp $ */
1+
/* $NetBSD: dr_4.c,v 1.15 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)dr_4.c 8.2 (Berkeley) 4/28/95";
3636
#else
37-
__RCSID("$NetBSD: dr_4.c,v 1.14 2009/03/14 19:35:13 dholland Exp $");
37+
__RCSID("$NetBSD: dr_4.c,v 1.15 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -64,7 +64,7 @@ grap(struct ship *from, struct ship *to)
6464
if (capship(from)->nationality != capship(to)->nationality &&
6565
dieroll() > 2)
6666
return;
67-
Write(W_GRAP, from, to->file->index, 0, 0, 0);
68-
Write(W_GRAP, to, from->file->index, 0, 0, 0);
67+
send_grap(from, to->file->index);
68+
send_grap(to, from->file->index);
6969
makesignal(from, "grappled with $$", to);
7070
}

games/sail/dr_5.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: dr_5.c,v 1.13 2009/03/14 19:35:13 dholland Exp $ */
1+
/* $NetBSD: dr_5.c,v 1.14 2009/03/14 22:52:52 dholland Exp $ */
22

33
/*
44
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
3434
#if 0
3535
static char sccsid[] = "@(#)dr_5.c 8.2 (Berkeley) 4/28/95";
3636
#else
37-
__RCSID("$NetBSD: dr_5.c,v 1.13 2009/03/14 19:35:13 dholland Exp $");
37+
__RCSID("$NetBSD: dr_5.c,v 1.14 2009/03/14 22:52:52 dholland Exp $");
3838
#endif
3939
#endif /* not lint */
4040

@@ -57,11 +57,11 @@ subtract(struct ship *from, struct ship *fromcap, int totalfrom, int *crewfrom,
5757
totalfrom = 0;
5858
}
5959
}
60-
Write(W_CREW, from, crewfrom[0], crewfrom[1], crewfrom[2], 0);
60+
send_crew(from, crewfrom[0], crewfrom[1], crewfrom[2]);
6161
} else if (totalfrom) {
6262
pcfrom -= totalfrom;
6363
pcfrom = pcfrom < 0 ? 0 : pcfrom;
64-
Write(W_PCREW, from, pcfrom, 0, 0, 0);
64+
send_pcrew(from, pcfrom);
6565
}
6666
}
6767

0 commit comments

Comments
 (0)