(nsc_type): New member NSC_HIDDEN.
(meta_type): Add its entry. (setnum, nstr_promote, nstr_exec_val): Deal with it. nstr_exec_val() implements opt_HIDDEN by mapping unknown values to -1. (natstr, nat_ca): Use it for member nat_relate. This also halves its size. Fixes very minor leak: before, player could see relations to all countries, regardless of contact. (nation_relations): Add entry for -1.
This commit is contained in:
parent
6844c94b4a
commit
75604d817c
6 changed files with 23 additions and 4 deletions
|
@ -114,7 +114,7 @@ struct natstr {
|
||||||
time_t nat_newstim; /* date news last read */
|
time_t nat_newstim; /* date news last read */
|
||||||
time_t nat_annotim; /* date annos last read */
|
time_t nat_annotim; /* date annos last read */
|
||||||
float nat_level[4]; /* technology, etc */
|
float nat_level[4]; /* technology, etc */
|
||||||
short nat_relate[MAXNOC];
|
unsigned char nat_relate[MAXNOC];
|
||||||
unsigned char nat_contact[MAXNOC];
|
unsigned char nat_contact[MAXNOC];
|
||||||
unsigned char nat_rejects[MAXNOC];
|
unsigned char nat_rejects[MAXNOC];
|
||||||
signed char nat_priorities[PRI_MAX+1]; /* budget priority */
|
signed char nat_priorities[PRI_MAX+1]; /* budget priority */
|
||||||
|
|
|
@ -57,6 +57,8 @@ typedef enum {
|
||||||
NSC_INT, /* int */
|
NSC_INT, /* int */
|
||||||
NSC_XCOORD, /* coord that needs x conversion */
|
NSC_XCOORD, /* coord that needs x conversion */
|
||||||
NSC_YCOORD, /* coord that needs y conversion */
|
NSC_YCOORD, /* coord that needs y conversion */
|
||||||
|
NSC_HIDDEN, /* unsigned char in struct natstr that
|
||||||
|
may need hiding */
|
||||||
NSC_TIME, /* time_t */
|
NSC_TIME, /* time_t */
|
||||||
NSC_FLOAT, /* float */
|
NSC_FLOAT, /* float */
|
||||||
NSC_STRINGY, /* char[], zero-terminated string */
|
NSC_STRINGY, /* char[], zero-terminated string */
|
||||||
|
|
|
@ -447,6 +447,7 @@ setnum(int fldno, double dbl)
|
||||||
((signed char *)memb_ptr)[idx] = (signed char)dbl;
|
((signed char *)memb_ptr)[idx] = (signed char)dbl;
|
||||||
break;
|
break;
|
||||||
case NSC_UCHAR:
|
case NSC_UCHAR:
|
||||||
|
case NSC_HIDDEN:
|
||||||
old = ((unsigned char *)memb_ptr)[idx];
|
old = ((unsigned char *)memb_ptr)[idx];
|
||||||
((unsigned char *)memb_ptr)[idx] = (unsigned char)dbl;
|
((unsigned char *)memb_ptr)[idx] = (unsigned char)dbl;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -527,7 +527,7 @@ struct castr nat_ca[] = {
|
||||||
EF_BAD},
|
EF_BAD},
|
||||||
{NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_HLEV]), "happiness",
|
{NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_HLEV]), "happiness",
|
||||||
EF_BAD},
|
EF_BAD},
|
||||||
{NSC_SHORT, 0, MAXNOC, fldoff(natstr, nat_relate), "relations",
|
{NSC_HIDDEN, 0, MAXNOC, fldoff(natstr, nat_relate), "relations",
|
||||||
EF_NATION_RELATIONS},
|
EF_NATION_RELATIONS},
|
||||||
/* should show mortals whether there's contact (obvious from relations?) */
|
/* should show mortals whether there's contact (obvious from relations?) */
|
||||||
{NSC_UCHAR, NSC_DEITY, MAXNOC, fldoff(natstr, nat_contact), "contacts",
|
{NSC_UCHAR, NSC_DEITY, MAXNOC, fldoff(natstr, nat_contact), "contacts",
|
||||||
|
|
|
@ -94,6 +94,7 @@ struct symbol meta_type[] = {
|
||||||
{NSC_INT, "d"},
|
{NSC_INT, "d"},
|
||||||
{NSC_XCOORD, "d"},
|
{NSC_XCOORD, "d"},
|
||||||
{NSC_YCOORD, "d"},
|
{NSC_YCOORD, "d"},
|
||||||
|
{NSC_HIDDEN, "d"},
|
||||||
{NSC_TIME, "d"},
|
{NSC_TIME, "d"},
|
||||||
{NSC_FLOAT, "g"},
|
{NSC_FLOAT, "g"},
|
||||||
{NSC_STRINGY,"c"},
|
{NSC_STRINGY,"c"},
|
||||||
|
@ -124,6 +125,7 @@ struct symbol nation_flags[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct symbol nation_relations[] = {
|
struct symbol nation_relations[] = {
|
||||||
|
{-1, "unknown"},
|
||||||
{AT_WAR, "at-war"},
|
{AT_WAR, "at-war"},
|
||||||
{SITZKRIEG, "sitzkrieg"},
|
{SITZKRIEG, "sitzkrieg"},
|
||||||
{MOBILIZATION, "mobilization"},
|
{MOBILIZATION, "mobilization"},
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
#include "nsc.h"
|
#include "nsc.h"
|
||||||
|
#include "optlist.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
static char *nstr_parse_val(char *, struct valstr *);
|
static char *nstr_parse_val(char *, struct valstr *);
|
||||||
|
@ -500,6 +501,7 @@ nstr_promote(int valtype)
|
||||||
case NSC_INT:
|
case NSC_INT:
|
||||||
case NSC_XCOORD:
|
case NSC_XCOORD:
|
||||||
case NSC_YCOORD:
|
case NSC_YCOORD:
|
||||||
|
case NSC_HIDDEN:
|
||||||
case NSC_TIME:
|
case NSC_TIME:
|
||||||
valtype = NSC_LONG;
|
valtype = NSC_LONG;
|
||||||
break;
|
break;
|
||||||
|
@ -562,9 +564,10 @@ nstr_coerce_val(struct valstr *val, nsc_type to, char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val->val_cat == NSC_VAL) {
|
if (val->val_cat == NSC_VAL) {
|
||||||
/* coord literals don't occur, conversion not implemented */
|
/* unimplemented conversions; don't currently occur here */
|
||||||
CANT_HAPPEN(val->val_type == NSC_XCOORD
|
CANT_HAPPEN(val->val_type == NSC_XCOORD
|
||||||
|| val->val_type == NSC_YCOORD);
|
|| val->val_type == NSC_YCOORD
|
||||||
|
|| val->val_type == NSC_HIDDEN);
|
||||||
val->val_type = to;
|
val->val_type = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,6 +590,7 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
|
||||||
char *memb_ptr;
|
char *memb_ptr;
|
||||||
nsc_type valtype;
|
nsc_type valtype;
|
||||||
int idx;
|
int idx;
|
||||||
|
struct natstr *natp;
|
||||||
|
|
||||||
switch (val->val_cat) {
|
switch (val->val_cat) {
|
||||||
default:
|
default:
|
||||||
|
@ -625,6 +629,16 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
|
||||||
case NSC_YCOORD:
|
case NSC_YCOORD:
|
||||||
val->val_as.lng = yrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
val->val_as.lng = yrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
||||||
break;
|
break;
|
||||||
|
case NSC_HIDDEN:
|
||||||
|
val->val_as.lng = -1;
|
||||||
|
if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
|
||||||
|
break;
|
||||||
|
natp = getnatp(cnum);
|
||||||
|
if (!opt_HIDDEN
|
||||||
|
|| natp->nat_stat == STAT_GOD
|
||||||
|
|| (getcontact(natp, idx) && getcontact(ptr, idx)))
|
||||||
|
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
case NSC_FLOAT:
|
case NSC_FLOAT:
|
||||||
val->val_as.dbl = ((float *)memb_ptr)[idx];
|
val->val_as.dbl = ((float *)memb_ptr)[idx];
|
||||||
valtype = NSC_DOUBLE;
|
valtype = NSC_DOUBLE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue