Also get rid of some mildly silly manual packing of enum types.
#include "misc.h"
-typedef enum {
+enum i_packing {
IPKG, /* "inefficient" packaging (eff<60) */
NPKG, /* no special packaging */
WPKG, /* "warehouse" packaging */
UPKG, /* "urban" packaging */
BPKG /* "bank" packaging */
-} i_packing;
+};
enum {
NUMPKG = BPKG + 1
#define MAXNOR 50 /* max # realms */
/* Nation status */
-typedef enum {
+enum nat_status {
/*
* Don't change order without checking inequality comparisons and
* array initializers!
STAT_SANCT, /* still in sanctuary */
STAT_ACTIVE, /* active (sanctuary broken) */
STAT_GOD /* deity powers */
-} nat_status;
+};
/*
short nat_uid; /* equals nat_cnum */
natid nat_cnum; /* our country number */
/* end of part matching struct empobj */
- nat_status nat_stat;
+ enum nat_status nat_stat;
char nat_cnam[20]; /* country name */
char nat_pnam[20]; /* representative */
char nat_hostaddr[32]; /* host addr of last user */
#define NS_NCOND 16
/* Value type */
-typedef enum {
+enum nsc_type {
NSC_NOTYPE,
/* promoted types */
NSC_LONG, /* long */
NSC_STRINGY, /* char[], may be zero-terminated */
/* aliases, must match typedefs */
NSC_NATID = NSC_UCHAR /* nation id */
-} nsc_type;
-typedef char packed_nsc_type;
+};
/* Is TYPE a promoted value type? */
#define NSC_IS_PROMOTED(type) (NSC_LONG <= (type) && (type) <= NSC_STRING)
: 1/0)
/* Value category */
-typedef enum {
+enum nsc_cat {
NSC_NOCAT,
NSC_VAL, /* evaluated value */
NSC_OFF, /* symbolic value: at offset in object */
NSC_ID /* unresolved identifier (internal use) */
-} nsc_cat;
-typedef char packed_nsc_cat;
+};
/*
* Value, possibly symbolic
* context object and sets VAL->val_as.sym for it.
*/
struct valstr {
- packed_nsc_type val_type; /* type of value */
- packed_nsc_cat val_cat; /* category of value */
+ enum nsc_type val_type; /* type of value */
+ enum nsc_cat val_cat; /* category of value */
union {
struct { /* cat NSC_OFF */
ptrdiff_t off;
/* Compiled condition */
struct nscstr {
char operator; /* '<', '=', '>', '#' */
- packed_nsc_type optype; /* operator type */
+ enum nsc_type optype; /* operator type */
struct valstr lft; /* left operand */
struct valstr rgt; /* right operand */
};
/* Selection type */
-typedef enum {
+enum ns_seltype {
NS_UNDEF, /* error value */
NS_LIST, /* list of IDs */
NS_DIST, /* circular area */
NS_ALL, /* everything */
NS_XY, /* one sector area */
NS_GROUP /* group, i.e. fleet, wing, army */
-} ns_seltype;
+};
/* Sector iterator */
struct nstr_sect {
coord x, y; /* current x-y */
coord dx, dy; /* accumlated x,y travel */
int id; /* return value of sctoff */
- ns_seltype type; /* type of query */
+ enum ns_seltype type; /* type of query */
int curdist; /* dist query: current range */
struct range range; /* area of coverage */
int dist; /* dist query: range */
/* Item iterator */
struct nstr_item {
int cur; /* current item */
- ns_seltype sel; /* selection type */
+ enum ns_seltype sel; /* selection type */
int type; /* item type being selected */
int curdist; /* if NS_DIST, current item's dist */
struct range range; /* NS_AREA/NS_DIST: range selector */
NSC_CONST = bit(2), /* field cannot be changed */
NSC_BITS = bit(3) /* value consists of flag bits */
};
-typedef unsigned char nsc_flags;
/*
* Selector descriptor
struct castr {
char *ca_name;
ptrdiff_t ca_off;
- packed_nsc_type ca_type;
+ enum nsc_type ca_type;
unsigned short ca_len;
void *(*ca_get)(struct valstr *, natid, void *);
int ca_table;
- nsc_flags ca_flags;
+ int ca_flags;
};
/* variables using the above */
/* src/lib/subs/nstr.c */
extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
extern char *nstr_comp_val(char *, struct valstr*, int);
-extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
+extern int nstr_coerce_val(struct valstr *, enum nsc_type, char *);
extern int nstr_exec(struct nscstr *, int, void *);
/* src/lib/common/nstreval.c */
extern struct valstr *nstr_mksymval(struct valstr *, struct castr *, int);
-extern struct valstr *nstr_exec_val(struct valstr *, natid, void *, nsc_type);
+extern struct valstr *nstr_exec_val(struct valstr *, natid, void *, enum nsc_type);
extern int nstr_promote(int);
extern char *symbol_by_value(int, struct symbol *);
/* src/lib/global/nsc.c */
struct keymatch {
char *km_key; /* the key */
- nsc_type km_type; /* type of associated data */
+ enum nsc_type km_type; /* type of associated data */
void *km_data; /* pointer to associated data */
int km_flags; /* useful flags */
char *km_comment; /* Comment (hopefully useful) */
extern int check_retreat_and_do_shipdamage(struct shpstr *, int);
extern int check_retreat_and_do_landdamage(struct lndstr *, int);
/* sarg.c */
-extern ns_seltype sarg_type(char *);
+extern enum ns_seltype sarg_type(char *);
extern int sarg_xy(char *, coord *, coord *);
extern int sarg_area(char *, struct range *);
extern int sarg_range(char *, coord *, coord *, int *);
time_t sct_timestamp; /* Last time this sector was written to */
};
-typedef enum {
+enum d_navigation {
NAV_NONE, /* ships can't navigate */
NAVOK, /* ships can always navigate */
NAV_02, /* requires 2% effic to navigate */
NAV_CANAL, /* requires 2% effic to navigate and M_CANAL capability */
NAV_60 /* requires 60% effic to navigate */
-} d_navigation;
+};
struct dchrstr {
unsigned char d_uid;
int d_prd; /* product type */
int d_peffic; /* process efficiency, in percent */
float d_mob0, d_mob1; /* movement cost at 0 and 100% eff */
- d_navigation d_nav; /* navigation capability */
- i_packing d_pkg; /* type of packaging in these sects */
+ enum d_navigation d_nav; /* navigation capability */
+ enum i_packing d_pkg; /* type of packaging in these sects */
float d_ostr; /* offensive strength */
float d_dstr; /* defensive strength */
int d_value; /* resale ("collect") value */
np->nat_yorg = newy;
break;
case 's':
- np->nat_stat = (nat_status)errcheck(arg, STAT_UNUSED, STAT_GOD);
+ np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD);
break;
case 'u':
arg = errcheck(arg, 0, m_m_p_d);
* nstr_coerce_val(VAL, WANT, STR) succeeded.
*/
struct valstr *
-nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
+nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
{
char *memb_ptr;
- nsc_type valtype;
+ enum nsc_type valtype;
int idx;
struct natstr *natp;
{"peffic", fldoff(d_peffic), NSC_INT, 0, NULL, EF_BAD, 0},
{"mob0", fldoff(d_mob0), NSC_FLOAT, 0, NULL, EF_BAD, 0},
{"mob1", fldoff(d_mob1), NSC_FLOAT, 0, NULL, EF_BAD, 0},
- {"nav", fldoff(d_nav), NSC_SITYPE(d_navigation), 0, NULL,
+ {"nav", fldoff(d_nav), NSC_SITYPE(enum d_navigation), 0, NULL,
EF_SECTOR_NAVIGATION, 0},
- {"pkg", fldoff(d_pkg), NSC_SITYPE(i_packing), 0, NULL, EF_PACKING, 0},
+ {"pkg", fldoff(d_pkg), NSC_SITYPE(enum i_packing), 0, NULL,
+ EF_PACKING, 0},
{"ostr", fldoff(d_ostr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
{"dstr", fldoff(d_dstr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
{"value", fldoff(d_value), NSC_INT, 0, NULL, EF_BAD, 0},
* necessary for foreign levels.
*/
{"cnum", fldoff(nat_cnum), NSC_NATID, 0, NULL, EF_NATION, 0},
- {"stat", fldoff(nat_stat), NSC_SITYPE(nat_status), 0, NULL,
+ {"stat", fldoff(nat_stat), NSC_SITYPE(enum nat_status), 0, NULL,
EF_NATION_STATUS, NSC_EXTRA},
{"cname", fldoff(nat_cnam), NSC_STRINGY, 20, NULL, EF_BAD, NSC_EXTRA},
{"passwd", fldoff(nat_pnam), NSC_STRINGY, 20, NULL,
* messages if it is a null pointer.
*/
int
-nstr_coerce_val(struct valstr *val, nsc_type to, char *str)
+nstr_coerce_val(struct valstr *val, enum nsc_type to, char *str)
{
/* FIXME get rid of promotion? */
- nsc_type from = nstr_promote(val->val_type);
+ enum nsc_type from = nstr_promote(val->val_type);
if (from == NSC_NOTYPE)
return 0;
*
* or 0 for none of the above.
*/
-ns_seltype
+enum ns_seltype
sarg_type(char *str)
{
int c;
static int
deliver(struct sctstr *from, struct ichrstr *ip, int dir,
- int thresh, int amt_src, int plague, i_packing packing)
+ int thresh, int amt_src, int plague, enum i_packing packing)
{
struct sctstr *to;
i_type vtype; /* item vartype */
int thresh;
int dir;
int plague;
- i_packing packing;
+ enum i_packing packing;
int n;
if (sp->sct_mobil <= 0)
int thresh;
int amt_dist;
int amt_sect;
- i_packing sect_packing, dist_packing;
+ enum i_packing sect_packing, dist_packing;
int pack;
double mcost;
int diff;