2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 */
63 typedef char packed_nsc_type;
68 NSC_VAL, /* evaluated value */
69 NSC_OFF /* symbolic value: at offset in object */
71 typedef char packed_nsc_cat;
74 NSC_DEITY = 1 /* access restricted to deity */
76 typedef unsigned char nsc_flags;
79 * Value, possibly symbolic.
80 * If type is NSC_NOTYPE, it's an error value.
81 * If category is NSC_OFF, the value is in a context object at offset
82 * val_as.sym.off + val_as.sym.idx * S, where S is the size of the
84 * If category is NSC_VAL, the value is in val_as, and the type is a
86 * Some values can also be interpreted as an object type. The value's
87 * consumer chooses how to interpret it, depending on context.
90 packed_nsc_type val_type; /* type of value */
91 packed_nsc_cat val_cat; /* category of value */
92 signed char val_as_type; /* value interpreted as object type */
94 struct { /* cat NSC_OFF */
98 double dbl; /* cat NSC_VAL, type NSC_DOUBLE */
99 char *str; /* cat NSC_VAL, type NSC_STRING */
100 long lng; /* cat NSC_VAL, type NSC_LONG */
104 /* Compiled condition */
106 char operator; /* '<', '=', '>', '#' */
107 packed_nsc_type optype; /* operator type */
108 struct valstr lft; /* left operand */
109 struct valstr rgt; /* right operand */
114 NS_UNDEF, /* error value */
115 NS_LIST, /* list of IDs */
116 NS_DIST, /* circular area */
117 NS_AREA, /* rectangular area */
118 NS_ALL, /* everything */
119 NS_XY, /* one sector area */
120 NS_GROUP /* group, i.e. fleet, wing, army */
123 /* Sector iterator */
125 coord x, y; /* current x-y */
126 coord dx, dy; /* accumlated x,y travel */
127 int id; /* return value of sctoff */
128 ns_seltype type; /* type of query */
129 int curdist; /* dist query: current range */
130 struct range range; /* area of coverage */
131 int dist; /* dist query: range */
132 coord cx, cy; /* dist query: center x-y */
133 int (*read)(int type, int id, caddr_t ptr); /* read function */
134 int ncond; /* # of selection conditions */
135 struct nscstr cond[NS_NCOND]; /* selection conditions */
140 int cur; /* current item */
141 ns_seltype sel; /* selection type */
142 int type; /* item type being selected */
143 int curdist; /* if NS_DIST, current item's dist */
144 struct range range; /* NS_AREA/NS_DIST: range selector */
145 int dist; /* NS_DIST: distance selector */
146 coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */
147 int group; /* NS_GROUP: fleet/wing match */
148 int size; /* NS_LIST: size of list */
149 int index; /* NS_LIST: index */
150 int list[NS_LSIZE]; /* NS_LIST: item list */
151 int (*read)(int type, int id, caddr_t ptr); /* read function */
152 int flags; /* ef_flags(TYPE) */
153 int ncond; /* # of selection conditions */
154 struct nscstr cond[NS_NCOND]; /* selection conditions */
158 * Selector descriptor.
159 * Value is at offset CA_OFF in the context object.
162 packed_nsc_type ca_type; /* type of value */
164 unsigned short ca_len; /* non-zero: is an array; #array elements */
169 /* variables using the above */
171 extern struct castr sect_ca[];
172 extern struct castr ship_ca[];
173 extern struct castr plane_ca[];
174 extern struct castr land_ca[];
175 extern struct castr nuke_ca[];
176 extern struct castr news_ca[];
177 extern struct castr nat_ca[];
178 extern struct castr treaty_ca[];
179 extern struct castr trade_ca[];
180 extern struct castr loan_ca[];
181 extern struct castr genitem_ca[];
182 extern struct castr lost_ca[];
183 extern struct castr commodity_ca[];
185 /* src/lib/subs/nstr.c */
186 extern int nstr_comp(struct nscstr *np, int len, int type, char *str);
187 extern char *nstr_comp_val(char *, struct valstr*, int);
188 extern int nstr_coerce_val(struct valstr *, nsc_type, char *);
189 extern int nstr_exec(struct nscstr *, int, void *);
190 extern void nstr_exec_val(struct valstr *, natid, void *, nsc_type);