/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* ef_verify.c: Verify game configuration
- *
+ *
* Known contributors to this file:
* Ron Koenderink, 2005
+ * Markus Armbruster, 2006-2008
*/
#include <config.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 *, ...)
putc('\n', stderr);
}
+static int
+verify_ca(int type)
+{
+ struct castr *ca = ef_cadef(type);
+ int i;
+
+ for (i = 0; ca[i].ca_name; i++) {
+ /*
+ * Virtual selectors must be NSC_EXTRA, because xundump can't
+ * cope with them without setter methods. Exception: if
+ * EFF_MEM is not set, xundump doesn't touch the table.
+ */
+ if (CANT_HAPPEN((ef_flags(type) & EFF_MEM)
+ && ca[i].ca_get && !(ca[i].ca_flags & NSC_EXTRA)))
+ ca[i].ca_flags |= NSC_EXTRA;
+ }
+ return 0;
+}
+
static int
verify_row(int type, int row)
{
struct valstr val;
int ret_val = 0;
int flags = ef_flags(type);
-
+
if (flags & EFF_MEM)
- row_ref = ef_ptr(type, row);
+ row_ref = ef_ptr(type, row);
else {
- row_ref = malloc(empfile[type].size);
+ row_ref = malloc(empfile[type].size);
ef_read(type, row, row_ref);
}
do {
if (ca[i].ca_table == EF_BAD)
continue;
- /* FIXME use xdeval() */
- val.val_type = ca[i].ca_type;
- val.val_cat = NSC_OFF;
- val.val_as.sym.off = ca[i].ca_off;
- val.val_as.sym.len = ca[i].ca_len;
- val.val_as.sym.idx = j;
+ nstr_mksymval(&val, &ca[i], j);
nstr_exec_val(&val, 0, row_ref, NSC_NOTYPE);
if (val.val_type != NSC_LONG)
continue;
}
}
} while (++j < n);
- }
+ }
if (!(flags & EFF_MEM))
free(row_ref);
return ret_val;
}
+static void
+pln_zap_transient_flags(void)
+{
+ int i;
+ struct plnstr *pp;
+ int dirty = 0;
+
+ /* laziness: assumes plane file is EFF_MEM */
+ for (i = 0; (pp = getplanep(i)) != NULL; i++) {
+ if (!pp->pln_own)
+ continue;
+ if (pp->pln_flags & PLN_LAUNCHED
+ && (plchr[pp->pln_type].pl_flags & (P_M | P_O)) != P_O) {
+ pp->pln_flags &= ~PLN_LAUNCHED;
+ /* FIXME missile should be destroyed instead */
+ dirty = 1;
+ verify_fail(EF_PLANE, i, NULL, 0, "stuck in the air (fixed)");
+ /*
+ * Can't putplane() here, because pln_prewrite() crashes
+ * without a valid player.
+ */
+ }
+ }
+ if (dirty)
+ ef_flush(EF_PLANE); /* pretty wasteful */
+}
+
int
ef_verify()
{
for (ep = empfile; ep->name; ep++) {
if (!ef_cadef(ep->uid))
continue;
+ verify_ca(ep->uid);
for (i = 0; i < ef_nelem(ep->uid); i++) {
retval += verify_row(ep->uid, i);
}
}
}
+ pln_zap_transient_flags();
return retval;
}