extern char *empobj_chr_name(struct empobj *gp);
extern int get_empobj_mob_max(int type);
+extern int empobj_in_use(int, void *);
#endif
#include <ctype.h>
#include "commands.h"
#include "empobj.h"
-#include "news.h"
#include "optlist.h"
-#include "product.h"
-#include "version.h"
#include "xdump.h"
/*
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])
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:
*
* Known contributors to this file:
* Ron Koenderink, 2005
- * Markus Armbruster, 2006-2010
+ * Markus Armbruster, 2006-2011
*/
#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#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 *, ...)
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;
}
}
+ 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 */
}
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",
#include "empobj.h"
#include "file.h"
+#include "news.h"
#include "optlist.h"
+#include "product.h"
char *
empobj_chr_name(struct empobj *gp)
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;
+ }
+}