]> git.pond.sub.org Git - empserver/blobdiff - include/nsc.h
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / include / nsc.h
index d2f022af733dc8f7e7dbc65a463ee9fc1613bb5c..7cf466a7c872e65c9740127310f811b06e55b32c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
@@ -32,8 +32,8 @@
  *     Markus Armbruster, 2004
  */
 
-#ifndef _NSC_H_
-#define _NSC_H_
+#ifndef NSC_H
+#define NSC_H
 
 #include <stddef.h>
 #include "xy.h"
@@ -60,22 +60,34 @@ typedef enum {
     NSC_TIME,                  /* time_t */
     NSC_FLOAT,                 /* float */
     NSC_STRINGY,               /* char[], zero-terminated string */
+                               /* FIXME zero may be missing */
     /* aliases, must match typedefs */
     NSC_NATID = NSC_UCHAR      /* nation id */
 } nsc_type;
 typedef char packed_nsc_type;
 
+/* Return nsc_type for a signed integer with the same size as TYPE.  */
+#define NSC_SITYPE(type)                               \
+    (sizeof(type) == 1 ? NSC_CHAR                      \
+     : sizeof(type) == sizeof(short) ? NSC_SHORT       \
+     : sizeof(type) == sizeof(int) ? NSC_INT           \
+     : sizeof(type) == sizeof(long) ? NSC_LONG         \
+     : 1/0)
+
 /* Value category */
 typedef enum {
     NSC_NOCAT,
     NSC_VAL,                   /* evaluated value */
-    NSC_OFF                    /* symbolic value: at offset in object */
+    NSC_OFF,                   /* symbolic value: at offset in object */
+    NSC_ID                     /* unresolved identifier (internal use) */
 } nsc_cat;
 typedef char packed_nsc_cat;
 
 enum {
     NSC_DEITY = bit(0),                /* access restricted to deity */
-    NSC_EXTRA = bit(1)         /* computable from other selectors */
+    NSC_EXTRA = bit(1),                /* computable from other selectors */
+    NSC_CONST = bit(2),                /* field cannot be changed */
+    NSC_BITS = bit(3)          /* value consists of flag bits */
 };
 typedef unsigned char nsc_flags;
 
@@ -87,21 +99,22 @@ typedef unsigned char nsc_flags;
  * value.
  * If category is NSC_VAL, the value is in val_as, and the type is a
  * promoted type.
- * Some values can also be interpreted as an object type.  The value's
- * consumer chooses how to interpret it, depending on context.
  */
 struct valstr {
     packed_nsc_type val_type;  /* type of value */
     packed_nsc_cat val_cat;    /* category of value */
-    signed char val_as_type;   /* value interpreted as object type */
     union {
        struct {                /* cat NSC_OFF */
            ptrdiff_t off;
+           int len;
            int idx;
        } sym;
        double dbl;             /* cat NSC_VAL, type NSC_DOUBLE */
-       char *str;              /* cat NSC_VAL, type NSC_STRING */
-       long lng;               /* cat NSC_VAL, type NSC_LONG */
+       struct {                /* cat NSC_VAL, type NSC_STRING, cat NSC_ID */
+           char *base;
+           size_t maxsz;
+       } str;
+       long lng;               /* cat NSC_VAL, type NSC_LONG, NSC_TYPEID */
     } val_as;
 };
 
@@ -158,33 +171,73 @@ struct nstr_item {
     struct nscstr cond[NS_NCOND]; /* selection conditions */
 };
 
+/*
+ * Symbol binding: associate NAME with VALUE.
+ */
+struct symbol {
+    int value;
+    char *name;
+};
+
 /*
  * Selector descriptor.
- * Value is at offset CA_OFF in the context object.
  */
 struct castr {
     packed_nsc_type ca_type;   /* type of value */
     nsc_flags ca_flags;
     unsigned short ca_len;     /* non-zero: is an array; #array elements */
-    ptrdiff_t ca_off;
+    ptrdiff_t ca_off;          /* offset of value in the context object */
     char *ca_name;
+    int ca_table;              /* referred table ID, or EF_BAD */
 };
 
 /* variables using the above */
 
+extern struct castr ichr_ca[];
+extern struct castr pchr_ca[];
 extern struct castr sect_ca[];
+extern struct castr dchr_ca[];
 extern struct castr ship_ca[];
+extern struct castr mchr_ca[];
 extern struct castr plane_ca[];
+extern struct castr plchr_ca[];
 extern struct castr land_ca[];
+extern struct castr lchr_ca[];
 extern struct castr nuke_ca[];
-extern struct castr news_ca[];
-extern struct castr nat_ca[];
+extern struct castr nchr_ca[];
 extern struct castr treaty_ca[];
-extern struct castr trade_ca[];
 extern struct castr loan_ca[];
-extern struct castr genitem_ca[];
+extern struct castr news_ca[];
 extern struct castr lost_ca[];
 extern struct castr commodity_ca[];
+extern struct castr trade_ca[];
+extern struct castr nat_ca[];
+extern struct castr cou_ca[];
+extern struct castr realm_ca[];
+extern struct castr intrchr_ca[];
+extern struct castr rpt_ca[];
+extern struct castr empfile_ca[];
+extern struct castr symbol_ca[];
+extern struct symbol ship_chr_flags[];
+extern struct symbol plane_chr_flags[];
+extern struct symbol land_chr_flags[];
+extern struct symbol nuke_chr_flags[];
+extern struct symbol treaty_flags[];
+extern struct castr mdchr_ca[];
+extern struct symbol meta_type[];
+extern struct symbol meta_flags[];
+extern struct symbol missions[];
+extern struct symbol plane_flags[];
+extern struct symbol retreat_flags[];
+extern struct symbol nation_status[];
+extern struct symbol nation_flags[];
+extern struct symbol nation_relations[];
+extern struct symbol level[];
+extern struct symbol agreement_statuses[];
+extern struct symbol plague_stages[];
+extern struct symbol packing[];
+extern struct symbol resources[];
+extern struct symbol sector_navigation[];
 
 /* src/lib/subs/nstr.c */
 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
@@ -192,5 +245,6 @@ extern char *nstr_comp_val(char *, struct valstr*, int);
 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
 extern int nstr_exec(struct nscstr *, int, void *);
 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);
+extern char *symbol_by_value(int, struct symbol *);
 
-#endif /* _NSC_H_ */
+#endif