diff --git a/include/empobj.h b/include/empobj.h index f0e6563b..cb8a0596 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -100,5 +100,6 @@ struct empobj_chr; extern char *empobj_chr_name(struct empobj *gp); extern int get_empobj_mob_max(int type); +extern int empobj_in_use(int, void *); #endif diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index dfa7f840..133714a6 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -35,10 +35,7 @@ #include #include "commands.h" #include "empobj.h" -#include "news.h" #include "optlist.h" -#include "product.h" -#include "version.h" #include "xdump.h" /* @@ -53,63 +50,45 @@ xdvisible(int type, void *p) struct lonstr *lp = p; struct natstr *natp; int tlev; - char *name; + + if (!empobj_in_use(type, p)) + return 0; switch (type) { case EF_SECTOR: - return gp->own == player->cnum || player->god; case EF_SHIP: case EF_PLANE: case EF_LAND: case EF_NUKE: case EF_LOST: - return gp->own != 0 && (gp->own == player->cnum || player->god); - case EF_NATION: - return ((struct natstr *)p)->nat_stat != STAT_UNUSED; + case EF_REALM: + return gp->own == player->cnum || player->god; case EF_COUNTRY: return gp->own == player->cnum; case EF_NEWS: - return ((struct nwsstr *)p)->nws_vrb != 0 - && (!opt_HIDDEN || player->god); /* FIXME */ + return !opt_HIDDEN || player->god; /* FIXME */ case EF_TREATY: - return tp->trt_status != TS_FREE - && (tp->trt_cna == player->cnum || tp->trt_cnb == player->cnum - || player->god); + return tp->trt_cna == player->cnum + || tp->trt_cnb == player->cnum + || player->god; case EF_LOAN: - if (lp->l_status == LS_FREE) - return 0; if (lp->l_status == LS_SIGNED) return 1; return lp->l_loner == player->cnum || lp->l_lonee == player->cnum || player->god; - case EF_TRADE: - case EF_COMM: - return gp->own != 0; - case EF_REALM: - natp = getnatp(((struct realmstr *)p)->r_cnum); - return (gp->own == player->cnum || player->god) - && (natp->nat_stat != STAT_UNUSED); - case EF_PRODUCT: - return ((struct pchrstr *)p)->p_sname[0] != 0; case EF_SHIP_CHR: tlev = ((struct mchrstr *)p)->m_tech; - name = ((struct mchrstr *)p)->m_name; goto tech; case EF_PLANE_CHR: tlev = ((struct plchrstr *)p)->pl_tech; - name = ((struct plchrstr *)p)->pl_name; goto tech; case EF_LAND_CHR: tlev = ((struct lchrstr *)p)->l_tech; - name = ((struct lchrstr *)p)->l_name; tech: natp = getnatp(player->cnum); - if (!name[0]) - return 0; return player->god || tlev <= (int)(1.25 * natp->nat_level[NAT_TLEV]); case EF_NUKE_CHR: tlev = ((struct nchrstr *)p)->n_tech; - name = ((struct nchrstr *)p)->n_name; if (drnuke_const > MIN_DRNUKE_CONST) { natp = getnatp(player->cnum); if (tlev > (int)((int)(1.25 * natp->nat_level[NAT_RLEV]) @@ -117,8 +96,6 @@ xdvisible(int type, void *p) return player->god; } goto tech; - case EF_NEWS_CHR: - return ((struct rptstr *)p)->r_newspage != 0; case EF_TABLE: return ((struct empfile *)p)->cadef != NULL; default: diff --git a/src/lib/common/ef_verify.c b/src/lib/common/ef_verify.c index fb18e663..1ddd89e0 100644 --- a/src/lib/common/ef_verify.c +++ b/src/lib/common/ef_verify.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Ron Koenderink, 2005 - * Markus Armbruster, 2006-2010 + * Markus Armbruster, 2006-2011 */ #include @@ -36,10 +36,10 @@ #include #include #include +#include "empobj.h" #include "file.h" #include "misc.h" #include "nsc.h" -#include "plane.h" #include "product.h" static void verify_fail(int, int, struct castr *, int, char *, ...) @@ -130,7 +130,7 @@ static int verify_row(int type, int row) { struct castr *ca = ef_cadef(type); - struct emptypedstr *row_ref; + struct empobj *row_ref; int i, j, n; struct valstr val; int ret_val = 0; @@ -150,6 +150,9 @@ verify_row(int type, int row) } } + if (!empobj_in_use(type, row_ref)) + return ret_val; + for (i = 0; ca[i].ca_name; ++i) { if (ca[i].ca_get) continue; /* virtual */ @@ -166,10 +169,6 @@ verify_row(int type, int row) } if (ca[i].ca_table == type && i == 0) { /* uid */ - /* Some files contain zeroed records, cope */ - /* TODO tighten this check */ - if (val.val_as.lng == 0) - continue; if (val.val_as.lng != row) { verify_fail(type, row, &ca[i], j, "value is %ld instead of %d", diff --git a/src/lib/common/empobj.c b/src/lib/common/empobj.c index a43c7281..5efe9458 100644 --- a/src/lib/common/empobj.c +++ b/src/lib/common/empobj.c @@ -36,7 +36,9 @@ #include "empobj.h" #include "file.h" +#include "news.h" #include "optlist.h" +#include "product.h" char * empobj_chr_name(struct empobj *gp) @@ -73,3 +75,45 @@ get_empobj_mob_max(int type) CANT_REACH(); return -1; } + +int +empobj_in_use(int type, void *p) +{ + switch (type) { + case EF_SHIP: + case EF_PLANE: + case EF_LAND: + case EF_NUKE: + case EF_TRADE: + case EF_COMM: + case EF_LOST: + return ((struct empobj *)p)->own != 0; + case EF_NATION: + case EF_COUNTRY: + return ((struct natstr *)p)->nat_stat != STAT_UNUSED; + case EF_NEWS: + return ((struct nwsstr *)p)->nws_vrb != 0; + case EF_TREATY: + return ((struct trtstr *)p)->trt_status != TS_FREE; + case EF_LOAN: + return ((struct lonstr *)p)->l_status != LS_FREE; + case EF_REALM: + return empobj_in_use(EF_NATION, + ef_ptr(EF_NATION, + ((struct realmstr *)p)->r_cnum)); + case EF_PRODUCT: + return ((struct pchrstr *)p)->p_sname[0]; + case EF_SHIP_CHR: + return ((struct mchrstr *)p)->m_name[0]; + case EF_PLANE_CHR: + return ((struct plchrstr *)p)->pl_name[0]; + case EF_LAND_CHR: + return ((struct lchrstr *)p)->l_name[0]; + case EF_NUKE_CHR: + return ((struct nchrstr *)p)->n_name[0]; + case EF_NEWS_CHR: + return ((struct rptstr *)p)->r_newspage != 0; + default: + return 1; + } +}