]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/nstreval.c
Update copyright notice
[empserver] / src / lib / common / nstreval.c
index 3e49b4789f5b3dd24e4c6120bf44d325b1caba78..1a9c78233c07d726195b345712249ea04ee03c88 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Dave Pare, 1989
  *     Steve McClure, 1997
- *     Markus Armbruster, 2004-2015
+ *     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)
@@ -60,17 +59,17 @@ 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)
@@ -80,6 +79,7 @@ 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);
@@ -179,13 +179,13 @@ nstr_eval(struct valstr *val, natid cnum, void *ptr, enum nsc_type 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;
@@ -212,10 +212,10 @@ nstr_eval(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
 }
 
 /*
- * 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)
@@ -262,9 +262,9 @@ symbol_by_value(int key, struct symbol *table)
 
 int
 symbol_set_fmt(char *buf, size_t sz, int flags, struct symbol symtab[],
-              int all)
+              char *sep, int all)
 {
-    char *sep = "";
+    char *pfx = "";
     int n, i;
     char *p;
 
@@ -276,12 +276,12 @@ symbol_set_fmt(char *buf, size_t sz, int flags, struct symbol symtab[],
            continue;
        p = symbol_by_value(bit(i), symtab);
        if (p)
-           n += snprintf(buf + n, sz - n, "%s%s", sep, p);
+           n += snprintf(buf + n, sz - n, "%s%s", pfx, p);
        else if (all)
-           n += snprintf(buf + n, sz - n, "%s#%d", sep, i);
+           n += snprintf(buf + n, sz - n, "%s#%d", pfx, i);
        if ((size_t)n >= sz)
            sz = n;
-       sep = ", ";
+       pfx = sep;
     }
 
     CANT_HAPPEN((size_t)n >= sz && buf);