Factors out the common makelost()/makenotlost() pattern.
#define putlost(n, p) ef_write(EF_LOST, (n), (p))
/* src/lib/subs/lostsub.c */
+extern void lost_and_found(int, natid, natid, int, coord, coord);
extern void makelost(short, natid, short, coord, coord);
extern void makenotlost(short, natid, short, coord, coord);
}
/* We've avoided assigning to llp->lnd_own, in case oldsp == sp */
- if (oldlp->lnd_own != own) {
- if (oldlp->lnd_own)
- makelost(EF_LAND, oldlp->lnd_own,
- llp->lnd_uid, llp->lnd_x, llp->lnd_y);
- if (own)
- makenotlost(EF_LAND, own,
- llp->lnd_uid, llp->lnd_x, llp->lnd_y);
- }
+ if (oldlp->lnd_own != own)
+ lost_and_found(EF_LAND, oldlp->lnd_own, own,
+ llp->lnd_uid, llp->lnd_x, llp->lnd_y);
llp->lnd_own = own;
}
static int findlost(short, natid, short, coord, coord, int);
+/*
+ * Record item ID of type TYPE changed owner from EXOWN to OWN at X, Y.
+ */
+void
+lost_and_found(int type, natid exown, natid own, int id, coord x, coord y)
+{
+ if (exown == own)
+ return;
+ if (exown)
+ makelost(type, exown, id, x, y);
+ if (own)
+ makenotlost(type, own, id, x, y);
+}
+
void
makelost(short type, natid owner, short id, coord x, coord y)
{
own = 0;
/* We've avoided assigning to np->nuk_own, in case oldsp == sp */
- if (oldnp->nuk_own != own) {
- if (oldnp->nuk_own)
- makelost(EF_NUKE, oldnp->nuk_own,
- np->nuk_uid, np->nuk_x, np->nuk_y);
- if (own)
- makenotlost(EF_NUKE, own,
- np->nuk_uid, np->nuk_x, np->nuk_y);
- }
+ if (oldnp->nuk_own != own)
+ lost_and_found(EF_NUKE, oldnp->nuk_own, own,
+ np->nuk_uid, np->nuk_x, np->nuk_y);
np->nuk_own = own;
}
}
/* We've avoided assigning to pp->pln_own, in case oldsp == sp */
- if (oldpp->pln_own != own) {
- if (oldpp->pln_own)
- makelost(EF_PLANE, oldpp->pln_own,
- pp->pln_uid, pp->pln_x, pp->pln_y);
- if (own)
- makenotlost(EF_PLANE, own,
- pp->pln_uid, pp->pln_x, pp->pln_y);
- }
+ if (oldpp->pln_own != own)
+ lost_and_found(EF_PLANE, oldpp->pln_own, own,
+ pp->pln_uid, pp->pln_x, pp->pln_y);
pp->pln_own = own;
}
}
/* We've avoided assigning to sp->sct_own, in case oldsp == sp */
- if (oldsp->sct_own != own) {
- if (oldsp->sct_own)
- makelost(EF_SECTOR, oldsp->sct_own,
- 0, sp->sct_x, sp->sct_y);
- if (own)
- makenotlost(EF_SECTOR, own,
- 0, sp->sct_x, sp->sct_y);
- }
+ if (oldsp->sct_own != own)
+ lost_and_found(EF_SECTOR, oldsp->sct_own, own,
+ 0, sp->sct_x, sp->sct_y);
sp->sct_own = own;
}
}
/* We've avoided assigning to sp->shp_own, in case oldsp == sp */
- if (oldsp->shp_own != own) {
- if (oldsp->shp_own)
- makelost(EF_SHIP, oldsp->shp_own,
- sp->shp_uid, sp->shp_x, sp->shp_y);
- if (own)
- makenotlost(EF_SHIP, own,
- sp->shp_uid, sp->shp_x, sp->shp_y);
- }
+ if (oldsp->shp_own != own)
+ lost_and_found(EF_SHIP, oldsp->shp_own, own,
+ sp->shp_uid, sp->shp_x, sp->shp_y);
sp->shp_own = own;
}
if (sp->sct_own == sp->sct_oldown)
sp->sct_oldown = 0;
else {
- makelost(EF_SECTOR, sp->sct_own,
- 0, sp->sct_x, sp->sct_y);
- makenotlost(EF_SECTOR, sp->sct_oldown,
- 0, sp->sct_x, sp->sct_y);
+ lost_and_found(EF_SECTOR, sp->sct_own, sp->sct_oldown,
+ 0, sp->sct_x, sp->sct_y);
takeover(sp, sp->sct_oldown);
}
sp->sct_mobil = oldmob;