Factor obj_changed() out of check_sect_ok() & friends
This commit is contained in:
parent
940092ffb9
commit
6b75c21e3c
1 changed files with 20 additions and 67 deletions
|
@ -34,36 +34,31 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "commodity.h"
|
#include "commodity.h"
|
||||||
|
#include "empobj.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "land.h"
|
|
||||||
#include "loan.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "nat.h"
|
|
||||||
#include "nsc.h"
|
|
||||||
#include "nuke.h"
|
|
||||||
#include "plane.h"
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "sect.h"
|
|
||||||
#include "ship.h"
|
|
||||||
#include "trade.h"
|
|
||||||
#include "xy.h"
|
|
||||||
|
|
||||||
/* Note that timestamps make things tricky. And, we don't
|
/* Note that timestamps make things tricky. And, we don't
|
||||||
* really care about the timestamp, we just care about the rest
|
* really care about the timestamp, we just care about the rest
|
||||||
* of the structure. So, we make a copy, and zero the timestamps
|
* of the structure. So, we make a copy, and zero the timestamps
|
||||||
* in both copies, and then compare. */
|
* in both copies, and then compare. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
obj_changed(struct empobj *obj, size_t sz)
|
||||||
|
{
|
||||||
|
union empobj_storage old, tobj;
|
||||||
|
|
||||||
|
get_empobj(obj->ef_type, obj->uid, &old);
|
||||||
|
memcpy(&tobj, obj, sz);
|
||||||
|
old.gen.timestamp = tobj.gen.timestamp = 0;
|
||||||
|
return memcmp(&tobj, &old, sz);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
check_sect_ok(struct sctstr *sectp)
|
check_sect_ok(struct sctstr *sectp)
|
||||||
{
|
{
|
||||||
struct sctstr chksect;
|
if (obj_changed((struct empobj *)sectp, sizeof(*sectp))) {
|
||||||
struct sctstr tsect;
|
|
||||||
|
|
||||||
getsect(sectp->sct_x, sectp->sct_y, &chksect);
|
|
||||||
memcpy(&tsect, sectp, sizeof(struct sctstr));
|
|
||||||
tsect.sct_timestamp = chksect.sct_timestamp = 0;
|
|
||||||
if (memcmp(&tsect, &chksect, sizeof(struct sctstr))) {
|
|
||||||
pr("Sector %s has changed!\n",
|
pr("Sector %s has changed!\n",
|
||||||
xyas(sectp->sct_x, sectp->sct_y, player->cnum));
|
xyas(sectp->sct_x, sectp->sct_y, player->cnum));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -74,13 +69,7 @@ check_sect_ok(struct sctstr *sectp)
|
||||||
int
|
int
|
||||||
check_ship_ok(struct shpstr *shipp)
|
check_ship_ok(struct shpstr *shipp)
|
||||||
{
|
{
|
||||||
struct shpstr chkship;
|
if (obj_changed((struct empobj *)shipp, sizeof(*shipp))) {
|
||||||
struct shpstr tship;
|
|
||||||
|
|
||||||
getship(shipp->shp_uid, &chkship);
|
|
||||||
memcpy(&tship, shipp, sizeof(struct shpstr));
|
|
||||||
tship.shp_timestamp = chkship.shp_timestamp = 0;
|
|
||||||
if (memcmp(&tship, &chkship, sizeof(struct shpstr))) {
|
|
||||||
pr("Ship #%d has changed!\n", shipp->shp_uid);
|
pr("Ship #%d has changed!\n", shipp->shp_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -90,13 +79,7 @@ check_ship_ok(struct shpstr *shipp)
|
||||||
int
|
int
|
||||||
check_plane_ok(struct plnstr *planep)
|
check_plane_ok(struct plnstr *planep)
|
||||||
{
|
{
|
||||||
struct plnstr chkplane;
|
if (obj_changed((struct empobj *)planep, sizeof(*planep))) {
|
||||||
struct plnstr tplane;
|
|
||||||
|
|
||||||
getplane(planep->pln_uid, &chkplane);
|
|
||||||
memcpy(&tplane, planep, sizeof(struct plnstr));
|
|
||||||
tplane.pln_timestamp = chkplane.pln_timestamp = 0;
|
|
||||||
if (memcmp(&tplane, &chkplane, sizeof(struct plnstr))) {
|
|
||||||
pr("Plane #%d has changed!\n", planep->pln_uid);
|
pr("Plane #%d has changed!\n", planep->pln_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -106,13 +89,7 @@ check_plane_ok(struct plnstr *planep)
|
||||||
int
|
int
|
||||||
check_land_ok(struct lndstr *landp)
|
check_land_ok(struct lndstr *landp)
|
||||||
{
|
{
|
||||||
struct lndstr chkland;
|
if (obj_changed((struct empobj *)landp, sizeof(*landp))) {
|
||||||
struct lndstr tland;
|
|
||||||
|
|
||||||
getland(landp->lnd_uid, &chkland);
|
|
||||||
memcpy(&tland, landp, sizeof(struct lndstr));
|
|
||||||
tland.lnd_timestamp = chkland.lnd_timestamp = 0;
|
|
||||||
if (memcmp(&tland, &chkland, sizeof(struct lndstr))) {
|
|
||||||
pr("Land unit #%d has changed!\n", landp->lnd_uid);
|
pr("Land unit #%d has changed!\n", landp->lnd_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -122,13 +99,7 @@ check_land_ok(struct lndstr *landp)
|
||||||
int
|
int
|
||||||
check_nuke_ok(struct nukstr *nukep)
|
check_nuke_ok(struct nukstr *nukep)
|
||||||
{
|
{
|
||||||
struct nukstr chknuke;
|
if (obj_changed((struct empobj *)nukep, sizeof(*nukep))) {
|
||||||
struct nukstr tnuke;
|
|
||||||
|
|
||||||
getnuke(nukep->nuk_uid, &chknuke);
|
|
||||||
memcpy(&tnuke, nukep, sizeof(struct nukstr));
|
|
||||||
tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
|
|
||||||
if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
|
|
||||||
pr("Nuke %d has changed!\n", nukep->nuk_uid);
|
pr("Nuke %d has changed!\n", nukep->nuk_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -138,13 +109,7 @@ check_nuke_ok(struct nukstr *nukep)
|
||||||
int
|
int
|
||||||
check_loan_ok(struct lonstr *loanp)
|
check_loan_ok(struct lonstr *loanp)
|
||||||
{
|
{
|
||||||
struct lonstr chkloan;
|
if (obj_changed((struct empobj *)loanp, sizeof(*loanp))) {
|
||||||
struct lonstr tloan;
|
|
||||||
|
|
||||||
getloan(loanp->l_uid, &chkloan);
|
|
||||||
memcpy(&tloan, loanp, sizeof(struct lonstr));
|
|
||||||
tloan.l_timestamp = chkloan.l_timestamp = 0;
|
|
||||||
if (memcmp(loanp, &chkloan, sizeof(struct lonstr))) {
|
|
||||||
pr("Loan %d has changed!\n", loanp->l_uid);
|
pr("Loan %d has changed!\n", loanp->l_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -154,13 +119,7 @@ check_loan_ok(struct lonstr *loanp)
|
||||||
int
|
int
|
||||||
check_comm_ok(struct comstr *commp)
|
check_comm_ok(struct comstr *commp)
|
||||||
{
|
{
|
||||||
struct comstr chkcomm;
|
if (obj_changed((struct empobj *)commp, sizeof(*commp))) {
|
||||||
struct comstr tcomm;
|
|
||||||
|
|
||||||
getcomm(commp->com_uid, &chkcomm);
|
|
||||||
memcpy(&tcomm, commp, sizeof(struct comstr));
|
|
||||||
tcomm.com_timestamp = chkcomm.com_timestamp = 0;
|
|
||||||
if (memcmp(commp, &chkcomm, sizeof(struct comstr))) {
|
|
||||||
pr("Commodity %d has changed!\n", commp->com_uid);
|
pr("Commodity %d has changed!\n", commp->com_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -170,13 +129,7 @@ check_comm_ok(struct comstr *commp)
|
||||||
int
|
int
|
||||||
check_trade_ok(struct trdstr *tp)
|
check_trade_ok(struct trdstr *tp)
|
||||||
{
|
{
|
||||||
struct trdstr chktrade;
|
if (obj_changed((struct empobj *)tp, sizeof(*tp))) {
|
||||||
struct trdstr ttrade;
|
|
||||||
|
|
||||||
gettrade(tp->trd_uid, &chktrade);
|
|
||||||
memcpy(&ttrade, tp, sizeof(struct trdstr));
|
|
||||||
ttrade.trd_timestamp = chktrade.trd_timestamp = 0;
|
|
||||||
if (memcmp(tp, &chktrade, sizeof(struct trdstr))) {
|
|
||||||
pr("Trade lot #%d has changed!\n", tp->trd_uid);
|
pr("Trade lot #%d has changed!\n", tp->trd_uid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue