2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
49 NSC_DOUBLE, /* double */
50 NSC_STRING, /* char *, zero-terminated string */
51 NSC_TYPEID, /* signed char, index into chr table */
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_TIME, /* time_t */
61 NSC_FLOAT, /* float */
62 NSC_STRINGY, /* char[], zero-terminated string */
63 /* aliases, must match typedefs */
64 NSC_NATID = NSC_UCHAR /* nation id */
66 typedef char packed_nsc_type;
68 /* Return nsc_type for a signed integer with the same size as TYPE. */
69 #define NSC_SITYPE(type) \
70 (sizeof(type) == 1 ? NSC_CHAR \
71 : sizeof(type) == sizeof(short) ? NSC_SHORT \
72 : sizeof(type) == sizeof(int) ? NSC_INT \
73 : sizeof(type) == sizeof(long) ? NSC_LONG \
79 NSC_VAL, /* evaluated value */
80 NSC_OFF, /* symbolic value: at offset in object */
81 NSC_ID /* unresolved identifier (internal use) */
83 typedef char packed_nsc_cat;
86 NSC_DEITY = bit(0), /* access restricted to deity */
87 NSC_EXTRA = bit(1), /* computable from other selectors */
88 NSC_CONST = bit(2) /* field cannot be changed */
90 typedef unsigned char nsc_flags;
93 * Value, possibly symbolic.
94 * If type is NSC_NOTYPE, it's an error value.
95 * If category is NSC_OFF, the value is in a context object at offset
96 * val_as.sym.off + val_as.sym.idx * S, where S is the size of the
98 * If category is NSC_VAL, the value is in val_as, and the type is a
102 packed_nsc_type val_type; /* type of value */
103 packed_nsc_cat val_cat; /* category of value */
105 struct { /* cat NSC_OFF */
110 double dbl; /* cat NSC_VAL, type NSC_DOUBLE */
111 struct { /* cat NSC_VAL, type NSC_STRING, cat NSC_ID */
115 long lng; /* cat NSC_VAL, type NSC_LONG, NSC_TYPEID */
119 /* Compiled condition */
121 char operator; /* '<', '=', '>', '#' */
122 packed_nsc_type optype; /* operator type */
123 struct valstr lft; /* left operand */
124 struct valstr rgt; /* right operand */
129 NS_UNDEF, /* error value */
130 NS_LIST, /* list of IDs */
131 NS_DIST, /* circular area */
132 NS_AREA, /* rectangular area */
133 NS_ALL, /* everything */
134 NS_XY, /* one sector area */
135 NS_GROUP /* group, i.e. fleet, wing, army */
138 /* Sector iterator */
140 coord x, y; /* current x-y */
141 coord dx, dy; /* accumlated x,y travel */
142 int id; /* return value of sctoff */
143 ns_seltype type; /* type of query */
144 int curdist; /* dist query: current range */
145 struct range range; /* area of coverage */
146 int dist; /* dist query: range */
147 coord cx, cy; /* dist query: center x-y */
148 int (*read)(int type, int id, void *ptr); /* read function */
149 int ncond; /* # of selection conditions */
150 struct nscstr cond[NS_NCOND]; /* selection conditions */
155 int cur; /* current item */
156 ns_seltype sel; /* selection type */
157 int type; /* item type being selected */
158 int curdist; /* if NS_DIST, current item's dist */
159 struct range range; /* NS_AREA/NS_DIST: range selector */
160 int dist; /* NS_DIST: distance selector */
161 coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */
162 int group; /* NS_GROUP: fleet/wing match */
163 int size; /* NS_LIST: size of list */
164 int index; /* NS_LIST: index */
165 int list[NS_LSIZE]; /* NS_LIST: item list */
166 int (*read)(int type, int id, void *ptr); /* read function */
167 int flags; /* ef_flags(TYPE) */
168 int ncond; /* # of selection conditions */
169 struct nscstr cond[NS_NCOND]; /* selection conditions */
173 * Symbol binding: associate NAME with VALUE.
181 * Selector descriptor.
182 * Value is at offset CA_OFF in the context object.
185 packed_nsc_type ca_type; /* type of value */
187 unsigned short ca_len; /* non-zero: is an array; #array elements */
190 int ca_table; /* table index -- symbols, symbol sets */
193 /* variables using the above */
195 extern struct castr ichr_ca[];
196 extern struct castr pchr_ca[];
197 extern struct castr sect_ca[];
198 extern struct castr dchr_ca[];
199 extern struct castr ship_ca[];
200 extern struct castr mchr_ca[];
201 extern struct castr plane_ca[];
202 extern struct castr plchr_ca[];
203 extern struct castr land_ca[];
204 extern struct castr lchr_ca[];
205 extern struct castr nuke_ca[];
206 extern struct castr nchr_ca[];
207 extern struct castr treaty_ca[];
208 extern struct castr tchr_ca[];
209 extern struct castr loan_ca[];
210 extern struct castr news_ca[];
211 extern struct castr lost_ca[];
212 extern struct castr commodity_ca[];
213 extern struct castr trade_ca[];
214 extern struct castr nat_ca[];
215 extern struct castr intrchr_ca[];
216 extern struct castr rpt_ca[];
217 extern struct castr empfile_ca[];
218 extern struct castr symbol_ca[];
219 extern struct symbol ship_chr_flags[];
220 extern struct symbol plane_chr_flags[];
221 extern struct symbol land_chr_flags[];
222 extern struct symbol nuke_chr_flags[];
223 extern struct castr mdchr_ca[];
224 extern struct symbol meta_type[];
225 extern struct symbol meta_flags[];
227 /* src/lib/subs/nstr.c */
228 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
229 extern char *nstr_comp_val(char *, struct valstr*, int);
230 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
231 extern int nstr_exec(struct nscstr *, int, void *);
232 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);