}
if (!empobj_in_use(type, row_ref))
- return ret_val;
+ goto out;
for (i = 0; ca[i].ca_name; ++i) {
if (ca[i].ca_get)
}
} while (++j < n);
}
+
+out:
if (!(flags & EFF_MEM))
free(row_ref);
return ret_val;
}
-static void
-pln_zap_transient_flags(int may_put)
+static int
+verify_table(int type)
{
+ int retval = 0;
+ int i;
+
+ if (!ef_cadef(type))
+ return 0;
+ verify_ca(type);
+ for (i = 0; i < ef_nelem(type); i++)
+ retval |= verify_row(type, i);
+ return retval;
+}
+
+static int
+verify_planes(int may_put)
+{
+ int retval = 0;
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.
- */
+ for (i = 0; (pp = getplanep(i)); i++) {
+ if (pp->pln_own) {
+ 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 */
+ if (may_put)
+ putplane(i, pp);
+ verify_fail(EF_PLANE, i, NULL, 0, "stuck in the air (fixed)");
+ }
+ if (pp->pln_ship >= 0 && pp->pln_land >= 0) {
+ verify_fail(EF_PLANE, i, NULL, 0, "on two carriers");
+ retval = -1;
+ }
+ } else {
+ if (pp->pln_ship >= 0 || pp->pln_land >= 0) {
+ pp->pln_ship = pp->pln_land = -1;
+ if (may_put)
+ putplane(i, pp);
+ verify_fail(EF_PLANE, i, NULL, 0,
+ "ghost stuck on carrier (fixed)");
+ }
}
}
- if (dirty && may_put)
- ef_flush(EF_PLANE); /* pretty wasteful */
+ return retval;
}
-/*
- * Verify game state and configuration are sane.
- * Correct minor problems, but write corrections to backing files only
- * if MAY_PUT is non-zero.
- * Return -1 if uncorrected problems remain, else 0.
- */
-int
-ef_verify(int may_put)
+static int
+verify_lands(int may_put)
{
- struct empfile *ep;
int retval = 0;
int i;
+ struct lndstr *lp;
- 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);
+ /* laziness: assumes land file is EFF_MEM */
+ for (i = 0; (lp = getlandp(i)); i++) {
+ if (lp->lnd_own) {
+ if (lp->lnd_ship >= 0 && lp->lnd_land >= 0) {
+ verify_fail(EF_LAND, i, NULL, 0, "on two carriers");
+ retval = -1;
+ }
+ } else {
+ if (lp->lnd_ship >= 0 || lp->lnd_land >= 0) {
+ lp->lnd_ship = lp->lnd_land = -1;
+ if (may_put)
+ putland(i, lp);
+ verify_fail(EF_LAND, i, NULL, 0,
+ "ghost stuck on carrier (fixed)");
+ }
}
}
+ return retval;
+}
- /* Special checks */
+static int
+verify_nukes(int may_put)
+{
+ int retval = 0;
+ int i;
+ struct nukstr *np;
+
+ /* laziness: assumes nuke file is EFF_MEM */
+ for (i = 0; (np = getnukep(i)); i++) {
+ if (!np->nuk_own) {
+ if (np->nuk_plane >= 0) {
+ np->nuk_plane = -1;
+ if (may_put)
+ putnuke(i, np);
+ verify_fail(EF_NUKE, i, NULL, 0,
+ "ghost stuck on carrier (fixed)");
+ }
+ }
+ }
+ return retval;
+}
+
+static int
+verify_products(void)
+{
+ int retval = 0;
+ int i;
+
+ /* product makes either level or item, not both */
for (i = 0; pchr[i].p_sname; i++) {
if (!pchr[i].p_sname[0])
continue;
retval = -1;
}
}
+ return retval;
+}
- pln_zap_transient_flags(may_put);
+/*
+ * Verify game configuration is sane.
+ * Return 0 on success, -1 on failure.
+ */
+int
+ef_verify_config(void)
+{
+ int retval = 0;
+ int i;
+
+ for (i = 0; i < EF_MAX; i++) {
+ if (!EF_IS_GAME_STATE(i) && !EF_IS_VIEW(i))
+ retval |= verify_table(i);
+ }
+
+ /* Special checks */
+ retval |= verify_products();
+ return retval;
+}
+
+/*
+ * Verify game state is sane.
+ * Correct minor problems, but write corrections to backing files only
+ * if MAY_PUT is non-zero.
+ * Return -1 if uncorrected problems remain, else 0.
+ */
+int
+ef_verify_state(int may_put)
+{
+ int retval = 0;
+ int i;
+
+ for (i = 0; i < EF_MAX; i++) {
+ if (EF_IS_GAME_STATE(i) || EF_IS_VIEW(i))
+ retval |= verify_table(i);
+ }
+
+ /* Special checks */
+ retval |= verify_planes(may_put);
+ retval |= verify_lands(may_put);
+ retval |= verify_nukes(may_put);
return retval;
}