2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * nsc.h: Definitions for Empire conditionals
30 * Known contributors to this file:
32 * Markus Armbruster, 2004
50 NSC_DOUBLE, /* double */
51 NSC_STRING, /* char *, zero-terminated string */
52 /* unpromoted types */
53 NSC_CHAR, /* signed char */
54 NSC_UCHAR, /* unsigned char */
55 NSC_SHORT, /* short */
56 NSC_USHORT, /* unsigned short */
58 NSC_XCOORD, /* coord that needs x conversion */
59 NSC_YCOORD, /* coord that needs y conversion */
60 NSC_HIDDEN, /* unsigned char in struct natstr that
62 NSC_TIME, /* time_t */
63 NSC_FLOAT, /* float */
64 NSC_STRINGY, /* char[], zero-terminated string */
65 /* FIXME zero may be missing */
66 /* aliases, must match typedefs */
67 NSC_NATID = NSC_UCHAR /* nation id */
69 typedef char packed_nsc_type;
71 /* Return nsc_type for a signed integer with the same size as TYPE. */
72 #define NSC_SITYPE(type) \
73 (sizeof(type) == 1 ? NSC_CHAR \
74 : sizeof(type) == sizeof(short) ? NSC_SHORT \
75 : sizeof(type) == sizeof(int) ? NSC_INT \
76 : sizeof(type) == sizeof(long) ? NSC_LONG \
82 NSC_VAL, /* evaluated value */
83 NSC_OFF, /* symbolic value: at offset in object */
84 NSC_ID /* unresolved identifier (internal use) */
86 typedef char packed_nsc_cat;
89 NSC_DEITY = bit(0), /* access restricted to deity */
90 NSC_EXTRA = bit(1), /* computable from other selectors */
91 NSC_CONST = bit(2), /* field cannot be changed */
92 NSC_BITS = bit(3) /* value consists of flag bits */
94 typedef unsigned char nsc_flags;
97 * Value, possibly symbolic.
98 * If type is NSC_NOTYPE, it's an error value.
99 * If category is NSC_OFF, the value is in a context object at offset
100 * val_as.sym.off + val_as.sym.idx * S, where S is the size of the
102 * If category is NSC_VAL, the value is in val_as, and the type is a
106 packed_nsc_type val_type; /* type of value */
107 packed_nsc_cat val_cat; /* category of value */
109 struct { /* cat NSC_OFF */
114 double dbl; /* cat NSC_VAL, type NSC_DOUBLE */
115 struct { /* cat NSC_VAL, type NSC_STRING, cat NSC_ID */
119 long lng; /* cat NSC_VAL, type NSC_LONG */
123 /* Compiled condition */
125 char operator; /* '<', '=', '>', '#' */
126 packed_nsc_type optype; /* operator type */
127 struct valstr lft; /* left operand */
128 struct valstr rgt; /* right operand */
133 NS_UNDEF, /* error value */
134 NS_LIST, /* list of IDs */
135 NS_DIST, /* circular area */
136 NS_AREA, /* rectangular area */
137 NS_ALL, /* everything */
138 NS_XY, /* one sector area */
139 NS_GROUP /* group, i.e. fleet, wing, army */
142 /* Sector iterator */
144 coord x, y; /* current x-y */
145 coord dx, dy; /* accumlated x,y travel */
146 int id; /* return value of sctoff */
147 ns_seltype type; /* type of query */
148 int curdist; /* dist query: current range */
149 struct range range; /* area of coverage */
150 int dist; /* dist query: range */
151 coord cx, cy; /* dist query: center x-y */
152 int (*read)(int type, int id, void *ptr); /* read function */
153 int ncond; /* # of selection conditions */
154 struct nscstr cond[NS_NCOND]; /* selection conditions */
159 int cur; /* current item */
160 ns_seltype sel; /* selection type */
161 int type; /* item type being selected */
162 int curdist; /* if NS_DIST, current item's dist */
163 struct range range; /* NS_AREA/NS_DIST: range selector */
164 int dist; /* NS_DIST: distance selector */
165 coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */
166 int group; /* NS_GROUP: fleet/wing match */
167 int size; /* NS_LIST: size of list */
168 int index; /* NS_LIST: index */
169 int list[NS_LSIZE]; /* NS_LIST: item list */
170 int (*read)(int type, int id, void *ptr); /* read function */
171 int flags; /* ef_flags(TYPE) */
172 int ncond; /* # of selection conditions */
173 struct nscstr cond[NS_NCOND]; /* selection conditions */
177 * Symbol binding: associate NAME with VALUE.
185 * Selector descriptor.
188 packed_nsc_type ca_type; /* type of value */
190 unsigned short ca_len; /* non-zero: is an array; #array elements */
191 ptrdiff_t ca_off; /* offset of value in the context object */
193 int ca_table; /* referred table ID, or EF_BAD */
196 /* variables using the above */
198 extern struct castr ichr_ca[];
199 extern struct castr pchr_ca[];
200 extern struct castr sect_ca[];
201 extern struct castr dchr_ca[];
202 extern struct castr ship_ca[];
203 extern struct castr mchr_ca[];
204 extern struct castr plane_ca[];
205 extern struct castr plchr_ca[];
206 extern struct castr land_ca[];
207 extern struct castr lchr_ca[];
208 extern struct castr nuke_ca[];
209 extern struct castr nchr_ca[];
210 extern struct castr treaty_ca[];
211 extern struct castr loan_ca[];
212 extern struct castr news_ca[];
213 extern struct castr lost_ca[];
214 extern struct castr commodity_ca[];
215 extern struct castr trade_ca[];
216 extern struct castr nat_ca[];
217 extern struct castr cou_ca[];
218 extern struct castr realm_ca[];
219 extern struct castr game_ca[];
220 extern struct castr intrchr_ca[];
221 extern struct castr rpt_ca[];
222 extern struct castr update_ca[];
223 extern struct castr empfile_ca[];
224 extern struct castr symbol_ca[];
225 extern struct symbol ship_chr_flags[];
226 extern struct symbol plane_chr_flags[];
227 extern struct symbol land_chr_flags[];
228 extern struct symbol nuke_chr_flags[];
229 extern struct symbol treaty_flags[];
230 extern struct castr mdchr_ca[];
231 extern struct symbol meta_type[];
232 extern struct symbol meta_flags[];
233 extern struct symbol missions[];
234 extern struct symbol plane_flags[];
235 extern struct symbol retreat_flags[];
236 extern struct symbol nation_status[];
237 extern struct symbol nation_flags[];
238 extern struct symbol nation_rejects[];
239 extern struct symbol nation_relations[];
240 extern struct symbol level[];
241 extern struct symbol agreement_statuses[];
242 extern struct symbol plague_stages[];
243 extern struct symbol packing[];
244 extern struct symbol resources[];
245 extern struct symbol sector_navigation[];
247 /* src/lib/subs/nstr.c */
248 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
249 extern char *nstr_comp_val(char *, struct valstr*, int);
250 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
251 extern int nstr_exec(struct nscstr *, int, void *);
252 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);
253 extern char *symbol_by_value(int, struct symbol *);