Update lost file from prewrite callbacks
Losses of sectors, ships, planes, land units and nukes are tracked in the lost file. To keep it current, makelost() and makenotlost() were called whenever one of these changed owners. Cumbersome and error-prone. In fact, the lost file was never perfectly accurate. Detect the ownership change in the prewrite callback and call makelost() / makenotlost() from there. Remove lost file updates from where they're no longer needed: right before a put. takeover() is a bit more involved: it doesn't put the sectors, but all callers do, except for guerrilla(). So remove the lost file update from takeover(), but add it to guerrilla(). This takes care of lost file update for all ownership changes that go through ef_write(). It can't take care of any missing updates for changes that don't go through it.
This commit is contained in:
parent
c5482e4bfb
commit
0d139ee1d1
19 changed files with 85 additions and 133 deletions
|
@ -361,8 +361,6 @@ put_combat(struct combat *com)
|
|||
sect.sct_mobil = (short)(com->mob - com->mobcost);
|
||||
}
|
||||
}
|
||||
makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
|
||||
makenotlost(EF_SECTOR, com->own, 0, sect.sct_x, sect.sct_y);
|
||||
sect.sct_own = com->own;
|
||||
if (com->plague) {
|
||||
if (sect.sct_pstage == PLG_HEALTHY)
|
||||
|
@ -381,11 +379,7 @@ put_combat(struct combat *com)
|
|||
else
|
||||
land.lnd_mobil = (signed char)(com->mob - com->mobcost);
|
||||
}
|
||||
makelost(EF_LAND, land.lnd_own, land.lnd_uid,
|
||||
land.lnd_x, land.lnd_y);
|
||||
land.lnd_own = com->own;
|
||||
makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
|
||||
land.lnd_x, land.lnd_y);
|
||||
if (com->plague) {
|
||||
if (land.lnd_pstage == PLG_HEALTHY)
|
||||
land.lnd_pstage = PLG_EXPOSED;
|
||||
|
@ -409,11 +403,7 @@ put_combat(struct combat *com)
|
|||
else
|
||||
ship.shp_mobil = (signed char)(com->mob - com->mobcost);
|
||||
}
|
||||
makelost(EF_SHIP, ship.shp_own, ship.shp_uid,
|
||||
ship.shp_x, ship.shp_y);
|
||||
ship.shp_own = com->own;
|
||||
makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid,
|
||||
ship.shp_x, ship.shp_y);
|
||||
if (com->plague) {
|
||||
if (ship.shp_pstage == PLG_HEALTHY)
|
||||
ship.shp_pstage = PLG_EXPOSED;
|
||||
|
|
|
@ -134,7 +134,6 @@ knockdown(struct sctstr *sp)
|
|||
xyas(sp->sct_x, sp->sct_y, sp->sct_own));
|
||||
sp->sct_type = SCT_WATER;
|
||||
sp->sct_newtype = SCT_WATER;
|
||||
makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
|
||||
sp->sct_own = 0;
|
||||
sp->sct_oldown = 0;
|
||||
sp->sct_mobil = 0;
|
||||
|
|
|
@ -116,7 +116,6 @@ detonate(struct nukstr *np, coord x, coord y, int airburst)
|
|||
sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
|
||||
}
|
||||
if (damage > 100) {
|
||||
makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
|
||||
sect.sct_oldown = 0;
|
||||
sect.sct_own = 0;
|
||||
if (type == SCT_WATER || type == SCT_BSPAN ||
|
||||
|
|
|
@ -111,15 +111,15 @@ lnd_postread(int n, void *ptr)
|
|||
void
|
||||
lnd_prewrite(int n, void *old, void *new)
|
||||
{
|
||||
struct lndstr *oldlp = old;
|
||||
struct lndstr *llp = new;
|
||||
natid own = llp->lnd_own;
|
||||
struct lndstr *lp;
|
||||
struct plnstr *pp;
|
||||
int i;
|
||||
|
||||
if (llp->lnd_own && llp->lnd_effic < LAND_MINEFF) {
|
||||
makelost(EF_LAND, llp->lnd_own, llp->lnd_uid,
|
||||
llp->lnd_x, llp->lnd_y);
|
||||
llp->lnd_own = 0;
|
||||
own = 0;
|
||||
|
||||
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
||||
if (lp->lnd_own && lp->lnd_land == n) {
|
||||
|
@ -149,6 +149,17 @@ lnd_prewrite(int n, void *old, void *new)
|
|||
item_prewrite(llp->lnd_item);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
llp->lnd_own = own;
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
|
@ -76,15 +76,24 @@ nuk_postread(int n, void *ptr)
|
|||
void
|
||||
nuk_prewrite(int n, void *old, void *new)
|
||||
{
|
||||
struct nukstr *oldnp = old;
|
||||
struct nukstr *np = new;
|
||||
natid own = np->nuk_own;
|
||||
|
||||
if (np->nuk_effic == 0) {
|
||||
if (np->nuk_own)
|
||||
makelost(EF_NUKE, np->nuk_own, np->nuk_uid,
|
||||
np->nuk_x, np->nuk_y);
|
||||
np->nuk_own = 0;
|
||||
np->nuk_effic = 0;
|
||||
if (np->nuk_effic == 0)
|
||||
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);
|
||||
}
|
||||
|
||||
np->nuk_own = own;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -110,15 +110,14 @@ pln_postread(int n, void *ptr)
|
|||
void
|
||||
pln_prewrite(int n, void *old, void *new)
|
||||
{
|
||||
struct plnstr *oldpp = old;
|
||||
struct plnstr *pp = new;
|
||||
natid own = pp->pln_own;
|
||||
struct nukstr *np;
|
||||
int i;
|
||||
|
||||
if (pp->pln_effic < PLANE_MINEFF) {
|
||||
if (pp->pln_own)
|
||||
makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
|
||||
pp->pln_x, pp->pln_y);
|
||||
pp->pln_own = 0;
|
||||
own = 0;
|
||||
pp->pln_effic = 0;
|
||||
for (i = 0; NULL != (np = getnukep(i)); i++) {
|
||||
if (np->nuk_own && np->nuk_plane == n) {
|
||||
|
@ -129,6 +128,18 @@ pln_prewrite(int n, void *old, void *new)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
pp->pln_own = own;
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
|
@ -61,6 +61,7 @@ sct_postread(int id, void *ptr)
|
|||
void
|
||||
sct_prewrite(int id, void *old, void *new)
|
||||
{
|
||||
struct sctstr *oldsp = old;
|
||||
struct sctstr *sp = new;
|
||||
int mil, civs;
|
||||
natid own;
|
||||
|
@ -70,23 +71,33 @@ sct_prewrite(int id, void *old, void *new)
|
|||
|
||||
mil = sp->sct_item[I_MILIT];
|
||||
civs = sp->sct_item[I_CIVIL];
|
||||
own = sp->sct_own;
|
||||
|
||||
if (sp->sct_own != 0 && !civs) {
|
||||
if (own && !civs) {
|
||||
sp->sct_work = 100;
|
||||
sp->sct_oldown = sp->sct_own;
|
||||
sp->sct_oldown = own;
|
||||
}
|
||||
|
||||
if (sp->sct_own && !civs && !mil
|
||||
&& !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)
|
||||
if (own && !civs && !mil && !has_units(sp->sct_x, sp->sct_y, own, NULL)
|
||||
&& !(sp->sct_flags & MOVE_IN_PROGRESS)) {
|
||||
/* more cruft! */
|
||||
own = sp->sct_own;
|
||||
makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
|
||||
sp->sct_own = 0;
|
||||
own = 0;
|
||||
sp->sct_mobil = 0;
|
||||
if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
|
||||
caploss(sp, 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);
|
||||
}
|
||||
|
||||
sp->sct_own = own;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -64,15 +64,16 @@ shp_postread(int n, void *ptr)
|
|||
void
|
||||
shp_prewrite(int n, void *old, void *new)
|
||||
{
|
||||
struct shpstr *oldsp = old;
|
||||
struct shpstr *sp = new;
|
||||
natid own = sp->shp_own;
|
||||
struct lndstr *lp;
|
||||
struct plnstr *pp;
|
||||
int i;
|
||||
|
||||
if (sp->shp_own != 0 && sp->shp_effic < SHIP_MINEFF) {
|
||||
mpr(sp->shp_own, "\t%s sunk!\n", prship(sp));
|
||||
makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
|
||||
sp->shp_own = 0;
|
||||
if (own && sp->shp_effic < SHIP_MINEFF) {
|
||||
mpr(own, "\t%s sunk!\n", prship(sp));
|
||||
own = 0;
|
||||
|
||||
for (i = 0; NULL != (lp = getlandp(i)); i++) {
|
||||
if (lp->lnd_own && lp->lnd_ship == n) {
|
||||
|
@ -95,6 +96,18 @@ shp_prewrite(int n, void *old, void *new)
|
|||
} else {
|
||||
item_prewrite(sp->shp_item);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
sp->shp_own = own;
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
|
@ -158,8 +158,6 @@ takeover(struct sctstr *sp, natid newown)
|
|||
*/
|
||||
sp->sct_loyal = 50;
|
||||
}
|
||||
makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y);
|
||||
makenotlost(EF_SECTOR, newown, 0, sp->sct_x, sp->sct_y);
|
||||
sp->sct_own = newown;
|
||||
if (opt_MOB_ACCESS) {
|
||||
game_tick_to_now(&sp->sct_access);
|
||||
|
@ -206,9 +204,7 @@ takeover_plane(struct plnstr *pp, natid newown)
|
|||
trdswitchown(EF_PLANE, pp, newown);
|
||||
if (pp->pln_mobil > 0)
|
||||
pp->pln_mobil = 0;
|
||||
makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
|
||||
pp->pln_own = newown;
|
||||
makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
|
||||
pp->pln_mission = 0;
|
||||
pp->pln_wing = 0;
|
||||
putplane(pp->pln_uid, pp);
|
||||
|
@ -225,9 +221,7 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
|||
|
||||
if (opt_MARKET)
|
||||
trdswitchown(EF_SHIP, sp, newown);
|
||||
makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
|
||||
sp->shp_own = newown;
|
||||
makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
|
||||
sp->shp_mission = 0;
|
||||
sp->shp_fleet = 0;
|
||||
sp->shp_rflags = 0;
|
||||
|
@ -251,10 +245,7 @@ takeover_ship(struct shpstr *sp, natid newown, int hostile)
|
|||
if (opt_MARKET)
|
||||
trdswitchown(EF_PLANE, pp, newown);
|
||||
pp->pln_mission = 0;
|
||||
makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
|
||||
pp->pln_own = newown;
|
||||
makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
|
||||
pp->pln_x, pp->pln_y);
|
||||
putplane(pp->pln_uid, pp);
|
||||
}
|
||||
/* Take over land units */
|
||||
|
@ -290,11 +281,7 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
|||
if (opt_MARKET)
|
||||
trdswitchown(EF_LAND, landp, newown);
|
||||
landp->lnd_mission = 0;
|
||||
makelost(EF_LAND, landp->lnd_own, landp->lnd_uid,
|
||||
landp->lnd_x, landp->lnd_y);
|
||||
landp->lnd_own = newown;
|
||||
makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid,
|
||||
landp->lnd_x, landp->lnd_y);
|
||||
pp = &p;
|
||||
lp = &llp;
|
||||
/* Take over planes */
|
||||
|
@ -314,10 +301,7 @@ takeover_land(struct lndstr *landp, natid newown, int hostile)
|
|||
if (opt_MARKET)
|
||||
trdswitchown(EF_PLANE, pp, newown);
|
||||
pp->pln_mission = 0;
|
||||
makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
|
||||
pp->pln_own = newown;
|
||||
makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid,
|
||||
pp->pln_x, pp->pln_y);
|
||||
putplane(pp->pln_uid, pp);
|
||||
}
|
||||
/* Take over land units */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue