/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
* Known contributors to this file:
* Dave Pare, 1989
* Steve McClure, 1997
- * Markus Armbruster, 2004-2014
+ * Markus Armbruster, 2004-2016
*/
#include <config.h>
#include <limits.h>
+#include <stdio.h>
#include <string.h>
-#include "file.h"
#include "nat.h"
#include "nsc.h"
#include "optlist.h"
/*
- * Initialize VAL to symbolic value for selector CA with index IDX.
- * Return VAL.
+ * Initialize @val to symbolic value for selector @ca with index @idx.
+ * Return @val.
*/
struct valstr *
nstr_mksymval(struct valstr *val, struct castr *ca, int idx)
}
/*
- * Evaluate VAL.
- * If VAL has category NSC_OFF, read the value from the context object
- * PTR, and translate it for country CNUM (coordinate system and
- * contact status). No translation when CNUM is NATID_BAD.
- * PTR points to a context object of the type that was used to compile
+ * Evaluate @val.
+ * If @val has category NSC_OFF, read the value from the context object
+ * @ptr, and translate it for country @cnum (coordinate system and
+ * contact status). No translation when @cnum is NATID_BAD.
+ * @ptr points to a context object of the type that was used to compile
* the value.
- * Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
- * WANT. VAL must be coercible.
+ * Unless @want is NSC_NOTYPE, coerce the value to promoted value type
+ * @want. @val must be coercible.
* The result's type is promoted on success, NSC_NOTYPE on error.
* In either case, the category is NSC_VAL.
- * Return VAL.
+ * Return @val.
*/
struct valstr *
nstr_eval(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
int idx, hidden;
coord c;
struct natstr *natp;
+ struct relatstr *relp;
if (CANT_HAPPEN(want != NSC_NOTYPE && !NSC_IS_PROMOTED(want)))
want = nstr_promote(want);
if (hidden) {
if (CANT_HAPPEN(hidden && valtype != NSC_LONG))
break; /* not implemented */
- if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
+ relp = ptr;
+ if (CANT_HAPPEN(relp->ef_type != EF_RELAT))
break; /* only defined for nation selectors */
- if (!opt_HIDDEN || cnum == NATID_BAD)
+ if (!opt_HIDDEN || cnum == NATID_BAD
+ || getnatp(cnum)->nat_stat == STAT_GOD)
break;
- natp = getnatp(cnum);
- if (natp->nat_stat != STAT_GOD
- && !(getcontact(natp, idx) && getcontact(ptr, idx)))
+ if (!in_contact(cnum, idx) || !in_contact(relp->rel_uid, idx))
val->val_as.lng = -1;
}
break;
}
/*
- * Promote VALTYPE.
- * If VALTYPE is an integer type, return NSC_LONG.
- * If VALTYPE is a floating-point type, return NSC_DOUBLE.
- * If VALTYPE is a string type, return NSC_STRING.
+ * Promote @valtype.
+ * If @valtype is an integer type, return NSC_LONG.
+ * If @valtype is a floating-point type, return NSC_DOUBLE.
+ * If @valtype is a string type, return NSC_STRING.
*/
int
nstr_promote(int valtype)
return NULL;
}
+
+int
+symbol_set_fmt(char *buf, size_t sz, int flags, struct symbol symtab[],
+ char *sep, int all)
+{
+ char *pfx = "";
+ int n, i;
+ char *p;
+
+ if (buf && sz)
+ buf[0] = 0;
+ n = 0;
+ for (i = 0; i < 32; i++) {
+ if (!(flags & bit(i)))
+ continue;
+ p = symbol_by_value(bit(i), symtab);
+ if (p)
+ n += snprintf(buf + n, sz - n, "%s%s", pfx, p);
+ else if (all)
+ n += snprintf(buf + n, sz - n, "%s#%d", pfx, i);
+ if ((size_t)n >= sz)
+ sz = n;
+ pfx = sep;
+ }
+
+ CANT_HAPPEN((size_t)n >= sz && buf);
+ return n;
+}