]> git.pond.sub.org Git - empserver/blob - src/lib/common/nsc.c
License upgrade to GPL version 3 or later
[empserver] / src / lib / common / nsc.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  nsc.c: Empire selection global structures
28  *
29  *  Known contributors to this file:
30  *     Markus Armbruster, 2004-2009
31  */
32
33 /*
34  * Convention: uid selector comes first.  Table TYPE has an uid
35  * selector if empfile[TYPE].cadef[0].ca_table == TYPE.
36  */
37
38 #include <config.h>
39
40 #include <stdlib.h>
41 #include "empobj.h"
42 #include "file.h"
43 #include "optlist.h"
44 #include "nsc.h"
45 #include "product.h"
46 #include "unit.h"
47
48 static void *nsc_ver(struct valstr *, struct natstr *, void *);
49 static void *nsc_ver_maxnoc(struct valstr *, struct natstr *, void *);
50 static void *nsc_sct_terr(struct valstr *, struct natstr *, void *);
51 static void *nsc_sct_track(struct valstr *, struct natstr *, void *);
52 static void *nsc_cargo_nplane(struct valstr *, struct natstr *, void *);
53 static void *nsc_cargo_nchopper(struct valstr *, struct natstr *, void *);
54 static void *nsc_cargo_nxlight(struct valstr *, struct natstr *, void *);
55 static void *nsc_cargo_nland(struct valstr *, struct natstr *, void *);
56 static void *nsc_pln_att(struct valstr *, struct natstr *, void *);
57 static void *nsc_pln_def(struct valstr *, struct natstr *, void *);
58 static void *nsc_pln_nuketype(struct valstr *, struct natstr *, void *);
59 static void *nsc_lnd_att(struct valstr *, struct natstr *, void *);
60 static void *nsc_lnd_def(struct valstr *, struct natstr *, void *);
61 static void *nsc_lnd_vul(struct valstr *, struct natstr *, void *);
62 static void *nsc_lnd_spd(struct valstr *, struct natstr *, void *);
63 static void *nsc_lnd_vis(struct valstr *, struct natstr *, void *);
64 static void *nsc_lnd_frg(struct valstr *, struct natstr *, void *);
65 static void *nsc_lnd_acc(struct valstr *, struct natstr *, void *);
66 static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *);
67 static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
68 static void *nsc_lchr(struct valstr *, struct natstr *, void *);
69 static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *);
70
71 /* Ugly hack to improve legibility by avoid long lines */
72 #define fldoff(fld) offsetof(CURSTR, fld)
73 #define empobjoff(fld) offsetof(struct empobj, fld)
74
75 #define NSC_IELT(name, pfx, sfx, base, itype)   \
76     {sizeof(sfx) == 1 ? name : pfx sfx,         \
77      ((base) + (itype)*sizeof(unsigned short)), \
78      NSC_SHORT, 0, NULL, EF_BAD, 0}
79
80 #define NSC_IVEC(base, sfx)                     \
81 NSC_IELT("civil", "c", sfx, base, I_CIVIL),     \
82 NSC_IELT("milit", "m", sfx, base, I_MILIT),     \
83 NSC_IELT("shell", "s", sfx, base, I_SHELL),     \
84 NSC_IELT("gun", "g", sfx, base, I_GUN),         \
85 NSC_IELT("petrol", "p", sfx, base, I_PETROL),   \
86 NSC_IELT("iron", "i", sfx, base, I_IRON),       \
87 NSC_IELT("dust", "d", sfx, base, I_DUST),       \
88 NSC_IELT("bar", "b", sfx, base, I_BAR),         \
89 NSC_IELT("food", "f", sfx, base, I_FOOD),       \
90 NSC_IELT("oil", "o", sfx, base, I_OIL),         \
91 NSC_IELT("lcm", "l", sfx, base, I_LCM),         \
92 NSC_IELT("hcm", "h", sfx, base, I_HCM),         \
93 NSC_IELT("uw", "u", sfx, base, I_UW),           \
94 NSC_IELT("rad", "r", sfx, base, I_RAD)
95
96 struct castr ichr_ca[] = {
97 #define CURSTR struct ichrstr
98     {"uid", fldoff(i_uid), NSC_SITYPE(i_type), 0, NULL, EF_ITEM, 0},
99     {"name", fldoff(i_name), NSC_STRING, 0, NULL, EF_BAD, 0},
100     {"mnem", fldoff(i_mnem), NSC_STRINGY, 1, NULL, EF_BAD, NSC_CONST},
101     {"value", fldoff(i_value), NSC_INT, 0, NULL, EF_BAD, 0},
102     {"sell", fldoff(i_sell), NSC_INT, 0, NULL, EF_BAD, 0},
103     {"lbs", fldoff(i_lbs), NSC_INT, 0, NULL, EF_BAD, 0},
104     {"pkg", fldoff(i_pkg), NSC_INT, NUMPKG, NULL, EF_BAD, 0},
105     {"melt_denom", fldoff(i_melt_denom), NSC_INT, 0, NULL, EF_BAD, 0},
106     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
107 #undef CURSTR
108 };
109
110 struct castr pchr_ca[] = {
111 #define CURSTR struct pchrstr
112     {"uid", fldoff(p_uid), NSC_INT, 0, NULL, EF_PRODUCT, 0},
113     {"name", fldoff(p_name), NSC_STRING, 0, NULL, EF_BAD, 0},
114     {"sname", fldoff(p_sname), NSC_STRING, 0, NULL, EF_BAD, NSC_CONST},
115     {"ctype", fldoff(p_ctype), NSC_SITYPE(i_type), MAXPRCON, NULL,
116      EF_ITEM, 0},
117     {"camt", fldoff(p_camt), NSC_USHORT, MAXPRCON, NULL, EF_BAD, 0},
118     {"type", fldoff(p_type), NSC_SITYPE(i_type), 0, NULL, EF_ITEM, 0},
119     {"level", fldoff(p_level), NSC_INT, 0, NULL, EF_LEVEL, 0},
120     {"cost", fldoff(p_cost), NSC_INT, 0, NULL, EF_BAD, 0},
121     {"nrndx", fldoff(p_nrndx), NSC_INT, 0, NULL, EF_RESOURCES, 0},
122     {"nrdep", fldoff(p_nrdep), NSC_INT, 0, NULL, EF_BAD, 0},
123     {"nlndx", fldoff(p_nlndx), NSC_INT, 0, NULL, EF_LEVEL, 0},
124     {"nlmin", fldoff(p_nlmin), NSC_INT, 0, NULL, EF_BAD, 0},
125     {"nllag", fldoff(p_nllag), NSC_INT, 0, NULL, EF_BAD, 0},
126     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
127 #undef CURSTR
128 };
129
130 struct castr sect_ca[] = {
131 #define CURSTR struct sctstr
132     /* uid needs to be NSC_DEITY because it discloses true origin */
133     {"uid", fldoff(sct_uid), NSC_INT, 0, NULL,
134      EF_SECTOR, NSC_DEITY | NSC_EXTRA},
135     {"timestamp", fldoff(sct_timestamp), NSC_TIME, 0, NULL,
136      EF_BAD, NSC_EXTRA},
137     {"owner", fldoff(sct_own), NSC_NATID, 0, NULL, EF_NATION, 0},
138     {"xloc", fldoff(sct_x), NSC_XCOORD, 0, NULL, EF_BAD, NSC_CONST},
139     {"yloc", fldoff(sct_y), NSC_YCOORD, 0, NULL, EF_BAD, NSC_CONST},
140     {"des", fldoff(sct_type), NSC_CHAR, 0, NULL, EF_SECTOR_CHR, 0},
141     {"effic", fldoff(sct_effic), NSC_CHAR, 0, NULL, EF_BAD, 0},
142     {"mobil", fldoff(sct_mobil), NSC_CHAR, 0, NULL, EF_BAD, 0},
143     {"off", fldoff(sct_off), NSC_UCHAR, 0, NULL, EF_BAD, 0},
144     {"loyal", fldoff(sct_loyal), NSC_UCHAR, 0, NULL, EF_BAD, NSC_DEITY},
145     {"terr", 0, NSC_UCHAR, 0, nsc_sct_terr, EF_BAD, NSC_EXTRA},
146     {"terr0", fldoff(sct_terr), NSC_UCHAR, 0, NULL, EF_BAD, 0},
147     {"terr1", fldoff(sct_terr1), NSC_UCHAR, 0, NULL, EF_BAD, 0},
148     {"terr2", fldoff(sct_terr2), NSC_UCHAR, 0, NULL, EF_BAD, 0},
149     {"terr3", fldoff(sct_terr3), NSC_UCHAR, 0, NULL, EF_BAD, 0},
150     {"dterr", fldoff(sct_dterr), NSC_UCHAR, 0, NULL, EF_BAD, NSC_DEITY},
151     {"xdist", fldoff(sct_dist_x), NSC_XCOORD, 0, NULL, EF_BAD, 0},
152     {"ydist", fldoff(sct_dist_y), NSC_YCOORD, 0, NULL, EF_BAD, 0},
153     {"avail", fldoff(sct_avail), NSC_SHORT, 0, NULL, EF_BAD, 0},
154     {"elev", fldoff(sct_elev), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
155     {"work", fldoff(sct_work), NSC_UCHAR, 0, NULL, EF_BAD, 0},
156     {"coastal", fldoff(sct_coastal), NSC_UCHAR, 0, NULL, EF_BAD, 0},
157     {"newdes", fldoff(sct_newtype), NSC_CHAR, 0, NULL, EF_SECTOR_CHR, 0},
158     {"min", fldoff(sct_min), NSC_UCHAR, 0, NULL, EF_BAD, 0},
159     {"gold", fldoff(sct_gmin), NSC_UCHAR, 0, NULL, EF_BAD, 0},
160     {"fert", fldoff(sct_fertil), NSC_UCHAR, 0, NULL, EF_BAD, 0},
161     {"ocontent", fldoff(sct_oil), NSC_UCHAR, 0, NULL, EF_BAD, 0},
162     {"uran", fldoff(sct_uran), NSC_UCHAR, 0, NULL, EF_BAD, 0},
163     {"oldown", fldoff(sct_oldown), NSC_NATID, 0, NULL, EF_NATION, 0},
164     {"track", 0, NSC_LONG, 0, nsc_sct_track, EF_BAD, NSC_EXTRA},
165     NSC_IVEC(fldoff(sct_item), ""),
166     NSC_IVEC(fldoff(sct_dist), "_dist"),
167     NSC_IVEC(fldoff(sct_del), "_del"),
168     /* should let old owner access mines, but can't express that: */
169     {"mines", fldoff(sct_mines), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
170     {"pstage", fldoff(sct_pstage), NSC_SHORT, 0, NULL,
171      EF_PLAGUE_STAGES, NSC_DEITY},
172     {"ptime", fldoff(sct_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
173     {"che", fldoff(sct_che), NSC_UCHAR, 0, NULL, EF_BAD, NSC_DEITY},
174     {"che_target", fldoff(sct_che_target), NSC_NATID, 0, NULL,
175      EF_NATION, NSC_DEITY},
176     {"fallout", fldoff(sct_fallout), NSC_USHORT, 0, NULL, EF_BAD, 0},
177     {"access", fldoff(sct_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
178     {"road", fldoff(sct_road), NSC_UCHAR, 0, NULL, EF_BAD, 0},
179     {"rail", fldoff(sct_rail), NSC_UCHAR, 0, NULL, EF_BAD, 0},
180     {"dfense", fldoff(sct_defense), NSC_UCHAR, 0, NULL, EF_BAD, 0},
181     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
182 #undef CURSTR
183 };
184
185 struct castr dchr_ca[] = {
186 #define CURSTR struct dchrstr
187     {"uid", fldoff(d_uid), NSC_UCHAR, 0, NULL, EF_SECTOR_CHR, 0},
188     {"name", fldoff(d_name), NSC_STRING, 0, NULL, EF_BAD, 0},
189     {"mnem", fldoff(d_mnem), NSC_STRINGY, 1, NULL, EF_BAD, NSC_CONST},
190     {"terrain", fldoff(d_terrain), NSC_UCHAR, 0, NULL, EF_SECTOR_CHR, 0},
191     {"prd", fldoff(d_prd), NSC_INT, 0, NULL, EF_PRODUCT, 0},
192     {"peffic", fldoff(d_peffic), NSC_INT, 0, NULL, EF_BAD, 0},
193     {"mob0", fldoff(d_mob0), NSC_FLOAT, 0, NULL, EF_BAD, 0},
194     {"mob1", fldoff(d_mob1), NSC_FLOAT, 0, NULL, EF_BAD, 0},
195     {"nav", fldoff(d_nav), NSC_SITYPE(enum d_navigation), 0, NULL,
196      EF_SECTOR_NAVIGATION, 0},
197     {"pkg", fldoff(d_pkg), NSC_SITYPE(enum i_packing), 0, NULL,
198      EF_PACKING, 0},
199     {"ostr", fldoff(d_ostr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
200     {"dstr", fldoff(d_dstr), NSC_FLOAT, 0, NULL, EF_BAD, 0},
201     {"value", fldoff(d_value), NSC_INT, 0, NULL, EF_BAD, 0},
202     {"cost", fldoff(d_cost), NSC_INT, 0, NULL, EF_BAD, 0},
203     {"build", fldoff(d_build), NSC_INT, 0, NULL, EF_BAD, 0},
204     {"lcms", fldoff(d_lcms), NSC_INT, 0, NULL, EF_BAD, 0},
205     {"hcms", fldoff(d_hcms), NSC_INT, 0, NULL, EF_BAD, 0},
206     {"maint", fldoff(d_maint), NSC_INT, 0, NULL, EF_BAD, 0},
207     {"maxpop", fldoff(d_maxpop), NSC_INT, 0, NULL, EF_BAD, 0},
208     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
209 #undef CURSTR
210 };
211
212 #define NSC_GENITEM(ef_type, ef_chr)                                    \
213     {"uid", empobjoff(uid), NSC_INT, 0, NULL, ef_type, 0},              \
214     {"timestamp", empobjoff(timestamp), NSC_TIME, 0, NULL, EF_BAD, NSC_EXTRA}, \
215     {"owner", empobjoff(own), NSC_NATID, 0, NULL, EF_NATION, 0},        \
216     {"xloc", empobjoff(x), NSC_XCOORD, 0, NULL, EF_BAD, 0},             \
217     {"yloc", empobjoff(y), NSC_YCOORD, 0, NULL, EF_BAD, 0},             \
218     {"type", empobjoff(type), NSC_CHAR, 0, NULL, ef_chr, 0},            \
219     {"effic", empobjoff(effic), NSC_CHAR, 0, NULL, EF_BAD, 0},          \
220     {"mobil", empobjoff(mobil), NSC_CHAR , 0, NULL, EF_BAD, 0},         \
221     {"off", empobjoff(off), NSC_UCHAR , 0, NULL, EF_BAD, 0},            \
222     {"tech", empobjoff(tech), NSC_SHORT, 0, NULL, EF_BAD, 0},           \
223     {"group", empobjoff(group), NSC_STRINGY, 1, NULL, EF_BAD, NSC_EXTRA}, \
224     {"opx", empobjoff(opx), NSC_XCOORD, 0, NULL, EF_BAD, 0},            \
225     {"opy", empobjoff(opy), NSC_YCOORD, 0, NULL, EF_BAD, 0},            \
226     {"mission", empobjoff(mission), NSC_SHORT, 0, NULL, EF_MISSIONS, 0}, \
227     {"radius", empobjoff(radius), NSC_SHORT, 0, NULL, EF_BAD, 0}
228
229 struct castr ship_ca[] = {
230 #define CURSTR struct shpstr
231     NSC_GENITEM(EF_SHIP, EF_SHIP_CHR),
232     {"fleet", fldoff(shp_fleet), NSC_STRINGY, 1, NULL, EF_BAD, 0},
233     {"xstart", fldoff(shp_destx[0]), NSC_XCOORD, 0, NULL, EF_BAD, 0},
234     {"xend", fldoff(shp_destx[1]), NSC_XCOORD, 0, NULL, EF_BAD, 0},
235     {"ystart", fldoff(shp_desty[0]), NSC_YCOORD, 0, NULL, EF_BAD, 0},
236     {"yend", fldoff(shp_desty[1]), NSC_YCOORD, 0, NULL, EF_BAD, 0},
237     {"cargostart", fldoff(shp_tstart), NSC_SITYPE(i_type), TMAX, NULL,
238      EF_ITEM, 0},
239     {"cargoend", fldoff(shp_tend), NSC_SITYPE(i_type), TMAX, NULL,
240      EF_ITEM, 0},
241     {"amtstart", fldoff(shp_lstart), NSC_SHORT, TMAX, NULL, EF_BAD, 0},
242     {"amtend", fldoff(shp_lend), NSC_SHORT, TMAX, NULL, EF_BAD, 0},
243     {"autonav", fldoff(shp_autonav), NSC_UCHAR, 0, NULL, EF_BAD, 0},
244     NSC_IVEC(fldoff(shp_item), ""),
245     {"pstage", fldoff(shp_pstage), NSC_SHORT, 0, NULL,
246      EF_PLAGUE_STAGES, NSC_DEITY},
247     {"ptime", fldoff(shp_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
248     {"access", fldoff(shp_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
249     {"mquota", fldoff(shp_mobquota), NSC_UCHAR, 0, NULL, EF_BAD, 0},
250     {"path", fldoff(shp_path), NSC_STRINGY, MAXSHPPATH, NULL, EF_BAD, 0},
251     {"follow", fldoff(shp_follow), NSC_INT, 0, NULL, EF_BAD, 0},
252     {"name", fldoff(shp_name), NSC_STRINGY, MAXSHPNAMLEN, NULL,
253      EF_BAD, 0},
254     /* should let builder access xbuilt, ybuilt, but can't express that: */
255     {"xbuilt", fldoff(shp_orig_x), NSC_XCOORD, 0, NULL,
256      EF_BAD, NSC_DEITY},
257     {"ybuilt", fldoff(shp_orig_y), NSC_YCOORD, 0, NULL,
258      EF_BAD, NSC_DEITY},
259     {"builder", fldoff(shp_orig_own), NSC_NATID, 0, NULL,
260      EF_NATION, NSC_DEITY},
261     {"rflags", fldoff(shp_rflags), NSC_INT, 0, NULL,
262      EF_RETREAT_FLAGS, NSC_BITS},
263     {"rpath", fldoff(shp_rpath), NSC_STRINGY, RET_LEN, NULL, EF_BAD, 0},
264     {"nplane", 0, NSC_LONG, 0, nsc_cargo_nplane, EF_BAD, NSC_EXTRA},
265     {"nchoppers", 0, NSC_LONG, 0, nsc_cargo_nchopper, EF_BAD, NSC_EXTRA},
266     {"nxlight", 0, NSC_LONG, 0, nsc_cargo_nxlight, EF_BAD, NSC_EXTRA},
267     {"nland", 0, NSC_LONG, 0, nsc_cargo_nland, EF_BAD, NSC_EXTRA},
268     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
269 #undef CURSTR
270 };
271
272 struct castr mchr_ca[] = {
273 #define CURSTR struct mchrstr
274     {"type", fldoff(m_type), NSC_CHAR, 0, NULL, EF_SHIP_CHR, 0},
275     {"name", fldoff(m_name), NSC_STRING, 0, NULL, EF_BAD, 0},
276     NSC_IVEC(fldoff(m_item), ""),
277     {"l_build", fldoff(m_lcm), NSC_INT, 0, NULL, EF_BAD, 0},
278     {"h_build", fldoff(m_hcm), NSC_INT, 0, NULL, EF_BAD, 0},
279     {"armor", fldoff(m_armor), NSC_INT, 0, NULL, EF_BAD, 0},
280     {"speed", fldoff(m_speed), NSC_INT, 0, NULL, EF_BAD, 0},
281     {"visib", fldoff(m_visib), NSC_INT, 0, NULL, EF_BAD, 0},
282     {"vrnge", fldoff(m_vrnge), NSC_INT, 0, NULL, EF_BAD, 0},
283     {"frnge", fldoff(m_frnge), NSC_INT, 0, NULL, EF_BAD, 0},
284     {"glim", fldoff(m_glim), NSC_INT, 0, NULL, EF_BAD, 0},
285     {"nxlight", fldoff(m_nxlight), NSC_UCHAR, 0, NULL, EF_BAD, 0},
286     {"nchoppers", fldoff(m_nchoppers), NSC_UCHAR, 0, NULL, EF_BAD, 0},
287     {"tech", fldoff(m_tech), NSC_INT, 0, NULL, EF_BAD, 0},
288     {"cost", fldoff(m_cost), NSC_INT, 0, NULL, EF_BAD, 0},
289     {"flags", fldoff(m_flags), NSC_LONG, 0, NULL,
290      EF_SHIP_CHR_FLAGS, NSC_BITS},
291     {"nplanes", fldoff(m_nplanes), NSC_UCHAR, 0, NULL, EF_BAD, 0},
292     {"nland", fldoff(m_nland), NSC_UCHAR, 0, NULL, EF_BAD, 0},
293     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
294 #undef CURSTR
295 };
296
297 struct castr plane_ca[] = {
298 #define CURSTR struct plnstr
299     NSC_GENITEM(EF_PLANE, EF_PLANE_CHR),
300     {"wing", fldoff(pln_wing), NSC_STRINGY, 1, NULL, EF_BAD, 0},
301     {"range", fldoff(pln_range), NSC_UCHAR, 0, NULL, EF_BAD, 0},
302     {"ship", fldoff(pln_ship), NSC_INT, 0, NULL, EF_BAD, 0},
303     {"land", fldoff(pln_land), NSC_INT, 0, NULL, EF_BAD, 0},
304     {"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0},
305     {"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL,
306      EF_PLANE_FLAGS, NSC_BITS},
307     {"access", fldoff(pln_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
308     {"theta", fldoff(pln_theta), NSC_FLOAT, 0, NULL, EF_BAD, 0},
309     {"att", 0, NSC_LONG, 0, nsc_pln_att, EF_BAD, NSC_EXTRA},
310     {"def", 0, NSC_LONG, 0, nsc_pln_def, EF_BAD, NSC_EXTRA},
311     {"nuketype", 0, NSC_LONG, 0, nsc_pln_nuketype, EF_BAD, NSC_EXTRA},
312     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
313 #undef CURSTR
314 };
315
316 struct castr plchr_ca[] = {
317 #define CURSTR struct plchrstr
318     {"type", fldoff(pl_type), NSC_CHAR, 0, NULL, EF_PLANE_CHR, 0},
319     {"name", fldoff(pl_name), NSC_STRING, 0, NULL, EF_BAD, 0},
320     {"l_build", fldoff(pl_lcm), NSC_INT, 0, NULL, EF_BAD, 0},
321     {"h_build", fldoff(pl_hcm), NSC_INT, 0, NULL, EF_BAD, 0},
322     {"cost", fldoff(pl_cost), NSC_INT, 0, NULL, EF_BAD, 0},
323     {"tech", fldoff(pl_tech), NSC_INT, 0, NULL, EF_BAD, 0},
324     {"acc", fldoff(pl_acc), NSC_INT, 0, NULL, EF_BAD, 0},
325     {"load", fldoff(pl_load), NSC_INT, 0, NULL, EF_BAD, 0},
326     {"att", fldoff(pl_att), NSC_INT, 0, NULL, EF_BAD, 0},
327     {"def", fldoff(pl_def), NSC_INT, 0, NULL, EF_BAD, 0},
328     {"range", fldoff(pl_range), NSC_INT, 0, NULL, EF_BAD, 0},
329     {"crew", fldoff(pl_crew), NSC_INT, 0, NULL, EF_BAD, 0},
330     {"fuel", fldoff(pl_fuel), NSC_INT, 0, NULL, EF_BAD, 0},
331     {"stealth", fldoff(pl_stealth), NSC_INT, 0, NULL, EF_BAD, 0},
332     {"flags", fldoff(pl_flags), NSC_INT, 0, NULL,
333      EF_PLANE_CHR_FLAGS, NSC_BITS},
334     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
335 #undef CURSTR
336 };
337
338 struct castr land_ca[] = {
339 #define CURSTR struct lndstr
340     NSC_GENITEM(EF_LAND, EF_LAND_CHR),
341     {"army", fldoff(lnd_army), NSC_STRINGY, 1, NULL, EF_BAD, 0},
342     {"ship", fldoff(lnd_ship), NSC_INT, 0, NULL, EF_BAD, 0},
343     {"harden", fldoff(lnd_harden), NSC_CHAR, 0, NULL, EF_BAD, 0},
344     {"retreat", fldoff(lnd_retreat), NSC_SHORT, 0, NULL, EF_BAD, 0},
345     {"rflags", fldoff(lnd_rflags), NSC_INT, 0, NULL,
346      EF_RETREAT_FLAGS, NSC_BITS},
347     {"rpath", fldoff(lnd_rpath), NSC_STRINGY, RET_LEN, NULL, EF_BAD, 0},
348     NSC_IVEC(fldoff(lnd_item), ""),
349     {"pstage", fldoff(lnd_pstage), NSC_SHORT, 0, NULL,
350      EF_PLAGUE_STAGES, NSC_DEITY},
351     {"ptime", fldoff(lnd_ptime), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
352     {"land", fldoff(lnd_land), NSC_INT, 0, NULL, EF_BAD, 0},
353     {"access", fldoff(lnd_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
354     {"att", 0, NSC_DOUBLE, 0, nsc_lnd_att, EF_BAD, NSC_EXTRA},
355     {"def", 0, NSC_DOUBLE, 0, nsc_lnd_def, EF_BAD, NSC_EXTRA},
356     {"vul", 0, NSC_LONG, 0, nsc_lnd_vul, EF_BAD, NSC_EXTRA},
357     {"spd", 0, NSC_LONG, 0, nsc_lnd_spd, EF_BAD, NSC_EXTRA},
358     {"vis", 0, NSC_LONG, 0, nsc_lnd_vis, EF_BAD, NSC_EXTRA},
359     {"frg", 0, NSC_LONG, 0, nsc_lnd_frg, EF_BAD, NSC_EXTRA},
360     {"acc", 0, NSC_LONG, 0, nsc_lnd_acc, EF_BAD, NSC_EXTRA},
361     {"dam", 0, NSC_LONG, 0, nsc_lnd_dam, EF_BAD, NSC_EXTRA},
362     {"aaf", 0, NSC_LONG, 0, nsc_lnd_aaf, EF_BAD, NSC_EXTRA},
363     {"nland", 0, NSC_LONG, 0, nsc_cargo_nland, EF_BAD, NSC_EXTRA},
364     {"nxlight", 0, NSC_LONG, 0, nsc_cargo_nxlight, EF_BAD, NSC_EXTRA},
365 #undef CURSTR
366 #define CURSTR struct lchrstr
367     {"spy", fldoff(l_spy), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
368     {"rmax", fldoff(l_rad), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
369     {"ammo", fldoff(l_ammo), NSC_INT, 0, nsc_lchr, EF_BAD, NSC_EXTRA},
370     {"maxlight", fldoff(l_nxlight), NSC_UCHAR, 0, nsc_lchr,
371      EF_BAD, NSC_EXTRA},
372     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
373 #undef CURSTR
374 };
375
376 struct castr lchr_ca[] = {
377 #define CURSTR struct lchrstr
378     {"type", fldoff(l_type), NSC_CHAR, 0, NULL, EF_LAND_CHR, 0},
379     {"name", fldoff(l_name), NSC_STRING, 0, NULL, EF_BAD, 0},
380     NSC_IVEC(fldoff(l_item), ""),
381     {"l_build", fldoff(l_lcm), NSC_INT, 0, NULL, EF_BAD, 0},
382     {"h_build", fldoff(l_hcm), NSC_INT, 0, NULL, EF_BAD, 0},
383     {"tech", fldoff(l_tech), NSC_INT, 0, NULL, EF_BAD, 0},
384     {"cost", fldoff(l_cost), NSC_INT, 0, NULL, EF_BAD, 0},
385     {"att", fldoff(l_att), NSC_FLOAT, 0, NULL, EF_BAD, 0},
386     {"def", fldoff(l_def), NSC_FLOAT, 0, NULL, EF_BAD, 0},
387     {"vul", fldoff(l_vul), NSC_INT, 0, NULL, EF_BAD, 0},
388     {"spd", fldoff(l_spd), NSC_INT, 0, NULL, EF_BAD, 0},
389     {"vis", fldoff(l_vis), NSC_INT, 0, NULL, EF_BAD, 0},
390     {"spy", fldoff(l_spy), NSC_INT, 0, NULL, EF_BAD, 0},
391     {"rmax", fldoff(l_rad), NSC_INT, 0, NULL, EF_BAD, 0},
392     {"frg", fldoff(l_frg), NSC_INT, 0, NULL, EF_BAD, 0},
393     {"acc", fldoff(l_acc), NSC_INT, 0, NULL, EF_BAD, 0},
394     {"dam", fldoff(l_dam), NSC_INT, 0, NULL, EF_BAD, 0},
395     {"ammo", fldoff(l_ammo), NSC_INT, 0, NULL, EF_BAD, 0},
396     {"aaf", fldoff(l_aaf), NSC_INT, 0, NULL, EF_BAD, 0},
397     {"nxlight", fldoff(l_nxlight), NSC_UCHAR, 0, NULL, EF_BAD, 0},
398     {"nland", fldoff(l_nland), NSC_UCHAR, 0, NULL, EF_BAD, 0},
399     {"flags", fldoff(l_flags), NSC_LONG, 0, NULL,
400      EF_LAND_CHR_FLAGS, NSC_BITS},
401     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
402 #undef CURSTR
403 };
404
405 struct castr nuke_ca[] = {
406 #define CURSTR struct nukstr
407     NSC_GENITEM(EF_NUKE, EF_NUKE_CHR),
408     {"plane", fldoff(nuk_plane), NSC_INT, 0, NULL, EF_BAD, 0},
409     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
410 #undef CURSTR
411 };
412
413 struct castr nchr_ca[] = {
414 #define CURSTR struct nchrstr
415     {"type", fldoff(n_type), NSC_CHAR, 0, NULL, EF_NUKE_CHR, 0},
416     {"name", fldoff(n_name), NSC_STRING, 0, NULL, EF_BAD, 0},
417     {"l_build", fldoff(n_lcm), NSC_INT, 0, NULL, EF_BAD, 0},
418     {"h_build", fldoff(n_hcm), NSC_INT, 0, NULL, EF_BAD, 0},
419     {"o_build", fldoff(n_oil), NSC_INT, 0, NULL, EF_BAD, 0},
420     {"r_build", fldoff(n_rad), NSC_INT, 0, NULL, EF_BAD, 0},
421     {"blast", fldoff(n_blast), NSC_INT, 0, NULL, EF_BAD, 0},
422     {"dam", fldoff(n_dam), NSC_INT, 0, NULL, EF_BAD, 0},
423     {"cost", fldoff(n_cost), NSC_INT, 0, NULL, EF_BAD, 0},
424     {"tech", fldoff(n_tech), NSC_INT, 0, NULL, EF_BAD, 0},
425     {"weight", fldoff(n_weight), NSC_INT, 0, NULL, EF_BAD, 0},
426     {"flags", fldoff(n_flags), NSC_INT, 0, NULL,
427      EF_NUKE_CHR_FLAGS, NSC_BITS},
428     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
429 #undef CURSTR
430 };
431
432 struct castr treaty_ca[] = {
433 #define CURSTR struct trtstr
434     {"uid", fldoff(trt_uid), NSC_INT, 0, NULL, EF_TREATY, 0},
435     {"timestamp", fldoff(trt_timestamp), NSC_TIME, 0, NULL,
436      EF_BAD, NSC_EXTRA},
437     {"cna", fldoff(trt_cna), NSC_NATID, 0, NULL, EF_NATION, 0},
438     {"cnb", fldoff(trt_cnb), NSC_NATID, 0, NULL, EF_NATION, 0},
439     {"status", fldoff(trt_status), NSC_CHAR, 0, NULL,
440      EF_AGREEMENT_STATUS, 0},
441     {"acond", fldoff(trt_acond), NSC_SHORT, 0, NULL,
442      EF_TREATY_FLAGS, NSC_BITS},
443     {"bcond", fldoff(trt_bcond), NSC_SHORT, 0, NULL,
444      EF_TREATY_FLAGS, NSC_BITS},
445     {"exp", fldoff(trt_exp), NSC_TIME, 0, NULL, EF_BAD, 0},
446     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
447 #undef CURSTR
448 };
449
450 struct castr loan_ca[] = {
451 #define CURSTR struct lonstr
452     {"uid", fldoff(l_uid), NSC_INT, 0, NULL, EF_LOAN, 0},
453     {"timestamp", fldoff(l_timestamp), NSC_TIME, 0, NULL,
454      EF_BAD, NSC_EXTRA},
455     {"loaner", fldoff(l_loner), NSC_NATID, 0, NULL, EF_NATION, 0},
456     {"loanee", fldoff(l_lonee), NSC_NATID, 0, NULL, EF_NATION, 0},
457     {"status", fldoff(l_status), NSC_CHAR, 0, NULL,
458      EF_AGREEMENT_STATUS, 0},
459     {"irate", fldoff(l_irate), NSC_INT, 0, NULL, EF_BAD, 0},
460     {"ldur", fldoff(l_ldur), NSC_INT, 0, NULL, EF_BAD, 0},
461     {"amtpaid", fldoff(l_amtpaid), NSC_LONG, 0, NULL, EF_BAD, 0},
462     {"amtdue", fldoff(l_amtdue), NSC_LONG, 0, NULL, EF_BAD, 0},
463     {"lastpay", fldoff(l_lastpay), NSC_TIME, 0, NULL, EF_BAD, 0},
464     {"duedate", fldoff(l_duedate), NSC_TIME, 0, NULL, EF_BAD, 0},
465     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
466 #undef CURSTR
467 };
468
469 struct castr news_ca[] = {
470 #define CURSTR struct nwsstr
471     {"timestamp", 0, NSC_LONG, 0, nsc_nws_timestamp, EF_BAD, NSC_EXTRA},
472     {"actor", fldoff(nws_ano), NSC_NATID, 0, NULL, EF_NATION, 0},
473     {"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0},
474     {"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0},
475     {"times", fldoff(nws_ntm), NSC_CHAR, 0, NULL, EF_BAD, 0},
476     {"duration", fldoff(nws_duration), NSC_SHORT, 0, NULL, EF_BAD, 0},
477     {"time", fldoff(nws_when), NSC_TIME, 0, NULL, EF_BAD, 0},
478     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
479 #undef CURSTR
480 };
481
482 struct castr lost_ca[] = {
483 #define CURSTR struct loststr
484     /* no need for uid as long as it's not referenced from other tables */
485     {"timestamp", fldoff(lost_timestamp), NSC_TIME, 0, NULL,
486      EF_BAD, 0},
487     {"owner", fldoff(lost_owner), NSC_NATID, 0, NULL, EF_NATION, 0},
488     {"type", fldoff(lost_type), NSC_CHAR, 0, NULL, EF_TABLE, 0},
489     {"id", fldoff(lost_id), NSC_INT, 0, NULL, EF_BAD, 0},
490     {"x", fldoff(lost_x), NSC_XCOORD, 0, NULL, EF_BAD, 0},
491     {"y", fldoff(lost_y), NSC_YCOORD, 0, NULL, EF_BAD, 0},
492     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
493 #undef CURSTR
494 };
495
496 struct castr commodity_ca[] = {
497 #define CURSTR struct comstr
498     {"uid", fldoff(com_uid), NSC_INT, 0, NULL, EF_COMM, 0},
499     {"timestamp", fldoff(com_timestamp), NSC_TIME, 0, NULL,
500      EF_BAD, NSC_EXTRA},
501     {"owner", fldoff(com_owner), NSC_NATID, 0, NULL, EF_NATION, 0},
502     {"type", fldoff(com_type), NSC_SITYPE(i_type), 0, NULL, EF_ITEM, 0},
503     {"amount", fldoff(com_amount), NSC_INT, 0, NULL, EF_BAD, 0},
504     {"price", fldoff(com_price), NSC_FLOAT, 0, NULL, EF_BAD, 0},
505     {"maxbidder", fldoff(com_maxbidder), NSC_INT, 0, NULL, EF_NATION, 0},
506     {"markettime", fldoff(com_markettime), NSC_TIME, 0, NULL, EF_BAD, 0},
507     /* should let maxbidder access xbuy, ybuy, but can't express that: */
508     {"xbuy", fldoff(com_x), NSC_XCOORD, 0, NULL, EF_BAD, NSC_DEITY},
509     {"ybuy", fldoff(com_y), NSC_XCOORD, 0, NULL, EF_BAD, NSC_DEITY},
510     /* should let owner access xsell, ysell, but can't express that: */
511     {"xsell", fldoff(sell_x), NSC_XCOORD, 0, NULL, EF_BAD, NSC_DEITY},
512     {"ysell", fldoff(sell_y), NSC_YCOORD, 0, NULL, EF_BAD, NSC_DEITY},
513     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
514 #undef CURSTR
515 };
516
517 struct castr trade_ca[] = {
518 #define CURSTR struct trdstr
519     {"uid", fldoff(trd_uid), NSC_INT, 0, NULL, EF_TRADE, 0},
520     {"timestamp", fldoff(trd_timestamp), NSC_TIME, 0, NULL,
521      EF_BAD, NSC_EXTRA},
522     {"owner", fldoff(trd_owner), NSC_NATID, 0, NULL, EF_NATION, 0},
523     {"type", fldoff(trd_type), NSC_CHAR, 0, NULL, EF_TABLE, 0},
524     {"unitid", fldoff(trd_unitid), NSC_INT, 0, NULL, EF_BAD, 0},
525     {"price", fldoff(trd_price), NSC_LONG, 0, NULL, EF_BAD, 0},
526     {"maxbidder", fldoff(trd_maxbidder), NSC_INT, 0, NULL, EF_NATION, 0},
527     {"markettime", fldoff(trd_markettime), NSC_TIME, 0, NULL, EF_BAD, 0},
528     /* should let maxbidder access xloc, yloc, but can't express that: */
529     {"xloc", fldoff(trd_x), NSC_XCOORD, 0, NULL, EF_BAD, NSC_DEITY},
530     {"yloc", fldoff(trd_y), NSC_YCOORD, 0, NULL, EF_BAD, NSC_DEITY},
531     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
532 #undef CURSTR
533 };
534
535 struct castr cou_ca[] = {
536 #define CURSTR struct natstr
537     /*
538      * This is the owner's view, i.e. it applies only to the own
539      * nation.  The public view nat_ca[], which applies to all
540      * nations, has the same selectors with different flags: NSC_DEITY
541      * is set except for cnum (which must come first) and all
542      * NSC_EXTRA selectors; NSC_EXTRA is cleared except for timestamp
543      * (which must come second).
544      * nat_ca[] should also make tech, research, education and
545      * happiness available, but we can't express the obfuscation
546      * necessary for foreign levels.
547      */
548     {"cnum", fldoff(nat_cnum), NSC_NATID, 0, NULL, EF_NATION, 0},
549     {"timestamp", fldoff(nat_timestamp), NSC_TIME, 0, NULL,
550      EF_BAD, NSC_EXTRA},
551     {"stat", fldoff(nat_stat), NSC_SITYPE(enum nat_status), 0, NULL,
552      EF_NATION_STATUS, NSC_EXTRA},
553     {"cname", fldoff(nat_cnam), NSC_STRINGY, 20, NULL, EF_BAD, NSC_EXTRA},
554     {"passwd", fldoff(nat_pnam), NSC_STRINGY, 20, NULL,
555      EF_BAD, NSC_DEITY | NSC_EXTRA},
556     {"ip", fldoff(nat_hostaddr), NSC_STRINGY, 32, NULL, EF_BAD, 0},
557     {"hostname", fldoff(nat_hostname), NSC_STRINGY, 512, NULL, EF_BAD, 0},
558     {"userid", fldoff(nat_userid), NSC_STRINGY, 32, NULL, EF_BAD, 0},
559     {"xcap", fldoff(nat_xcap), NSC_XCOORD, 0, NULL, EF_BAD, 0},
560     {"ycap", fldoff(nat_ycap), NSC_YCOORD, 0, NULL, EF_BAD, 0},
561     {"xorg", fldoff(nat_xorg), NSC_XCOORD, 0, NULL,
562      EF_BAD, NSC_DEITY | NSC_EXTRA},
563     {"yorg", fldoff(nat_yorg), NSC_YCOORD, 0, NULL,
564      EF_BAD, NSC_DEITY | NSC_EXTRA},
565     {"update", fldoff(nat_update), NSC_CHAR, 0, NULL, EF_BAD, 0},
566     {"tgms", fldoff(nat_tgms), NSC_USHORT, 0, NULL, EF_BAD, 0},
567     {"ann", fldoff(nat_ann), NSC_USHORT, 0, NULL, EF_BAD, 0},
568     {"timeused", fldoff(nat_timeused), NSC_INT, 0, NULL, EF_BAD, 0},
569     {"btu", fldoff(nat_btu), NSC_SHORT, 0, NULL, EF_BAD, 0},
570     {"access", fldoff(nat_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
571     {"milreserve", fldoff(nat_reserve), NSC_LONG, 0, NULL, EF_BAD, 0},
572     {"money", fldoff(nat_money), NSC_LONG, 0, NULL, EF_BAD, 0},
573     {"login", fldoff(nat_last_login), NSC_TIME, 0, NULL, EF_BAD, 0},
574     {"logout", fldoff(nat_last_logout), NSC_TIME, 0, NULL, EF_BAD, 0},
575     {"newstim", fldoff(nat_newstim), NSC_TIME, 0, NULL, EF_BAD, 0},
576     {"annotim", fldoff(nat_annotim), NSC_TIME, 0, NULL, EF_BAD, 0},
577     {"tech", fldoff(nat_level[NAT_TLEV]), NSC_FLOAT, 0, NULL, EF_BAD, 0},
578     {"research", fldoff(nat_level[NAT_RLEV]), NSC_FLOAT, 0, NULL,
579      EF_BAD, 0},
580     {"education", fldoff(nat_level[NAT_ELEV]), NSC_FLOAT, 0, NULL,
581      EF_BAD, 0},
582     {"happiness", fldoff(nat_level[NAT_HLEV]), NSC_FLOAT, 0, NULL,
583      EF_BAD, 0},
584     {"relations", fldoff(nat_relate), NSC_HIDDEN, MAXNOC, NULL,
585      EF_NATION_RELATIONS, NSC_EXTRA},
586     /* mortals know there's contact (relations show), but not how strong */
587     {"contacts", fldoff(nat_contact), NSC_UCHAR, MAXNOC, NULL,
588      EF_BAD, NSC_DEITY | NSC_EXTRA},
589     {"rejects", fldoff(nat_rejects), NSC_UCHAR, MAXNOC, NULL,
590      EF_NATION_REJECTS, NSC_EXTRA | NSC_BITS},
591     {"flags", fldoff(nat_flags), NSC_LONG, 0, NULL,
592      EF_NATION_FLAGS, NSC_BITS},
593     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
594 #undef CURSTR
595 };
596
597 struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
598 /* initialized by nsc_init() */
599
600 struct castr realm_ca[] = {
601 #define CURSTR struct realmstr
602     /* uid is encoded in cnum, realm */
603     {"timestamp", fldoff(r_timestamp), NSC_TIME, 0, NULL,
604      EF_BAD, NSC_EXTRA},
605     {"cnum", fldoff(r_cnum), NSC_NATID, 0, NULL, EF_NATION, NSC_CONST},
606     {"realm", fldoff(r_realm), NSC_USHORT, 0, NULL, EF_BAD, NSC_CONST},
607     {"xl", fldoff(r_xl), NSC_XCOORD, 0, NULL, EF_BAD, 0},
608     {"xh", fldoff(r_xh), NSC_XCOORD, 0, NULL, EF_BAD, 0},
609     {"yl", fldoff(r_yl), NSC_YCOORD, 0, NULL, EF_BAD, 0},
610     {"yh", fldoff(r_yh), NSC_YCOORD, 0, NULL, EF_BAD, 0},
611     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
612 #undef CURSTR
613 };
614
615 struct castr game_ca[] = {
616 #define CURSTR struct gamestr
617     /* no need for uid */
618     {"timestamp", fldoff(game_timestamp), NSC_TIME, 0, NULL,
619      EF_BAD, NSC_EXTRA},
620     {"upd_disable", fldoff(game_upd_disable), NSC_CHAR, 0, NULL,
621      EF_BAD, 0},
622     {"down", fldoff(game_down), NSC_CHAR, 0, NULL, EF_BAD, 0},
623     {"turn", fldoff(game_turn), NSC_SHORT, 0, NULL, EF_BAD, 0},
624     {"tick", fldoff(game_tick), NSC_SHORT, 0, NULL, EF_BAD, NSC_DEITY},
625     {"rt", fldoff(game_rt), NSC_TIME, 0, NULL, EF_BAD, NSC_DEITY},
626     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
627 #undef CURSTR
628 };
629
630 struct castr intrchr_ca[] = {
631 #define CURSTR struct sctintrins
632     /* no need for uid as long as it's not referenced from other tables */
633     {"name", fldoff(in_name), NSC_STRING, 0, NULL, EF_BAD, NSC_CONST},
634     {"lcms", fldoff(in_lcms), NSC_UCHAR, 0, NULL, EF_BAD, 0},
635     {"hcms", fldoff(in_hcms), NSC_UCHAR, 0, NULL, EF_BAD, 0},
636     {"dcost", fldoff(in_dcost), NSC_UCHAR, 0, NULL, EF_BAD, 0},
637     {"mcost", fldoff(in_mcost), NSC_UCHAR, 0, NULL, EF_BAD, 0},
638     {"enable", fldoff(in_enable), NSC_UCHAR, 0, NULL, EF_BAD, 0},
639     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
640 #undef CURSTR
641 };
642
643 struct castr rpt_ca[] = {
644 #define CURSTR struct rptstr
645     {"uid", fldoff(r_uid), NSC_CHAR, 0, NULL, EF_NEWS_CHR, 0},
646     {"newstory", fldoff(r_newstory), NSC_STRING, NUM_RPTS, NULL,
647      EF_BAD, 0},
648     {"good_will", fldoff(r_good_will), NSC_INT, 0, NULL, EF_BAD, 0},
649     {"newspage", fldoff(r_newspage), NSC_INT, 0, NULL,
650      EF_PAGE_HEADINGS, 0},
651     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
652 #undef CURSTR
653 };
654
655 struct castr update_ca[] = {
656     {"time", 0, NSC_TIME, 0, NULL, EF_BAD, 0},
657     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
658 };
659
660 struct castr empfile_ca[] = {
661 #define CURSTR struct empfile
662     {"uid", fldoff(uid), NSC_INT, 0, NULL, EF_TABLE, 0},
663     {"name", fldoff(name), NSC_STRING, 0, NULL, EF_BAD, NSC_CONST},
664     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
665 #undef CURSTR
666 };
667
668 struct castr symbol_ca[] = {
669 #define CURSTR struct symbol
670     /*
671      * value is is const because it has to match what is compiled into
672      * the server.  name is const because clients key on it.
673      */
674     {"value", fldoff(value), NSC_INT, 0, NULL, EF_BAD, NSC_CONST},
675     {"name", fldoff(name), NSC_STRING, 0, NULL, EF_BAD, NSC_CONST},
676     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
677 #undef CURSTR
678 };
679
680 struct castr mdchr_ca[] = {
681 #define CURSTR struct castr
682     /* no need for uid */
683     /* name must come first, clients may rely on it */
684     {"name", fldoff(ca_name), NSC_STRING, 0, NULL, EF_BAD, NSC_CONST},
685     {"type", fldoff(ca_type), NSC_CHAR, 0, NULL, EF_META_TYPE, NSC_CONST},
686     {"flags", fldoff(ca_flags), NSC_UCHAR, 0, NULL,
687      EF_META_FLAGS, NSC_CONST | NSC_BITS},
688     {"len", fldoff(ca_len), NSC_USHORT, 0, NULL, EF_BAD, NSC_CONST},
689     {"table", fldoff(ca_table), NSC_INT, 0, NULL, EF_BAD, NSC_CONST},
690     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
691 #undef CURSTR
692 };
693
694 void
695 nsc_init(void)
696 {
697     static struct castr version_ca0 = {
698         "version", 0, NSC_STRINGY, sizeof(PACKAGE_STRING), NULL, EF_BAD, 0
699     };
700     static struct castr version_ca1 = {
701         "maxnoc", 0, NSC_LONG, 0, nsc_ver_maxnoc, EF_BAD, 0
702     };
703     static struct castr *ca;
704     struct keymatch *kp;
705     int n, i;
706     unsigned flags;
707
708     /* derive empfile[EF_VERSION].cadef from configkeys[] */
709     n = 0;
710     for (kp = configkeys; kp->km_key; ++kp) {
711         if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL))
712             n++;
713     }
714     ca = calloc(2 + n + 1, sizeof(*ca));
715     ca[0] = version_ca0;
716     ca[1] = version_ca1;
717     i = 2;
718     for (kp = configkeys; kp->km_key; ++kp) {
719         if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) {
720             ca[i].ca_type = kp->km_type;
721             ca[i].ca_off = kp - configkeys;
722             ca[i].ca_name = kp->km_key;
723             ca[i].ca_table = EF_BAD;
724             ca[i].ca_get = nsc_ver;
725             i++;
726         }
727     }
728     empfile[EF_VERSION].cadef = ca;
729
730     /* derive nat_ca[] from cou_ca[] */
731     nat_ca[0] = cou_ca[0];      /* cnum */
732     nat_ca[1] = cou_ca[1];      /* timestamp */
733     for (i = 2; cou_ca[i].ca_name; i++) {
734         nat_ca[i] = cou_ca[i];
735         flags = nat_ca[i].ca_flags;
736         if (flags & NSC_EXTRA)
737             flags &= ~NSC_EXTRA;
738         else
739             flags |= NSC_DEITY;
740         nat_ca[i].ca_flags = flags;
741     }
742     nat_ca[i] = cou_ca[i];      /* sentinel */
743 }
744
745 /*
746  * Virtual selectors
747  */
748
749 static void *
750 nsc_ver(struct valstr *val, struct natstr *np, void *ptr)
751 {
752     struct keymatch *kp = &configkeys[val->val_as.sym.off];
753     val->val_as.sym.off = 0;
754     val->val_as.sym.get = NULL;
755     return kp->km_data;
756 }
757
758 static void *
759 nsc_ver_maxnoc(struct valstr *val, struct natstr *np, void *ptr)
760 {
761     val->val_as.lng = MAXNOC;
762     return NULL;
763 }
764
765 static void *
766 nsc_sct_terr(struct valstr *val, struct natstr *np, void *ptr)
767 {
768     if (!np || np->nat_stat == STAT_GOD)
769         val->val_as.sym.off = offsetof(struct sctstr, sct_dterr);
770     else
771         val->val_as.sym.off = offsetof(struct sctstr, sct_terr);
772     val->val_as.sym.get = NULL;
773     return ptr;
774 }
775
776 static void *
777 nsc_sct_track(struct valstr *val, struct natstr *np, void *ptr)
778 {
779     val->val_as.lng = sct_rail_track(ptr);
780     return NULL;
781 }
782
783 static void *
784 nsc_cargo_nplane(struct valstr *val, struct natstr *np, void *ptr)
785 {
786     struct empobj *obj = ptr;
787     int n, nch, nxl;
788
789     n = unit_nplane(obj->ef_type, obj->uid, &nch, &nxl, NULL);
790     val->val_as.lng = n - nch - nxl;
791     return NULL;
792 }
793
794 static void *
795 nsc_cargo_nchopper(struct valstr *val, struct natstr *np, void *ptr)
796 {
797     struct empobj *obj = ptr;
798     int n;
799
800     unit_nplane(obj->ef_type, obj->uid, &n, NULL, NULL);
801     val->val_as.lng = n;
802     return NULL;
803 }
804
805 static void *
806 nsc_cargo_nxlight(struct valstr *val, struct natstr *np, void *ptr)
807 {
808     struct empobj *obj = ptr;
809     int n;
810
811     unit_nplane(obj->ef_type, obj->uid, NULL, &n, NULL);
812     val->val_as.lng = n;
813     return NULL;
814 }
815
816 static void *
817 nsc_cargo_nland(struct valstr *val, struct natstr *np, void *ptr)
818 {
819     struct empobj *obj = ptr;
820
821     val->val_as.lng = unit_cargo_count(obj->ef_type, obj->uid, EF_LAND);
822     return NULL;
823 }
824
825 static void *
826 nsc_pln_def(struct valstr *val, struct natstr *np, void *ptr)
827 {
828     val->val_as.lng = pln_def(ptr);;
829     return NULL;
830 }
831
832 static void *
833 nsc_pln_att(struct valstr *val, struct natstr *np, void *ptr)
834 {
835     val->val_as.lng = pln_att(ptr);
836     return NULL;
837 }
838
839 static void *
840 nsc_pln_nuketype(struct valstr *val, struct natstr *np, void *ptr)
841 {
842     struct nukstr *nukp = getnukep(nuk_on_plane(ptr));
843     val->val_as.lng = nukp ? nukp->nuk_type : -1;
844     return NULL;
845 }
846
847 static void *
848 nsc_lnd_att(struct valstr *val, struct natstr *np, void *ptr)
849 {
850     val->val_as.dbl = lnd_att(ptr);
851     return NULL;
852 }
853
854 static void *
855 nsc_lnd_def(struct valstr *val, struct natstr *np, void *ptr)
856 {
857     val->val_as.dbl = lnd_def(ptr);
858     return NULL;
859 }
860
861 static void *
862 nsc_lnd_vul(struct valstr *val, struct natstr *np, void *ptr)
863 {
864     val->val_as.lng = lnd_vul(ptr);
865     return NULL;
866 }
867
868 static void *
869 nsc_lnd_spd(struct valstr *val, struct natstr *np, void *ptr)
870 {
871     val->val_as.lng = lnd_spd(ptr);
872     return NULL;
873 }
874
875 static void *
876 nsc_lnd_vis(struct valstr *val, struct natstr *np, void *ptr)
877 {
878     val->val_as.lng = lnd_vis(ptr);
879     return NULL;
880 }
881
882 static void *
883 nsc_lnd_frg(struct valstr *val, struct natstr *np, void *ptr)
884 {
885     val->val_as.lng = lnd_frg(ptr);
886     return NULL;
887 }
888
889 static void *
890 nsc_lnd_acc(struct valstr *val, struct natstr *np, void *ptr)
891 {
892     val->val_as.lng = lnd_acc(ptr);
893     return NULL;
894 }
895
896 static void *
897 nsc_lnd_dam(struct valstr *val, struct natstr *np, void *ptr)
898 {
899     val->val_as.lng = lnd_dam(ptr);
900     return NULL;
901 }
902
903 static void *
904 nsc_lnd_aaf(struct valstr *val, struct natstr *np, void *ptr)
905 {
906     val->val_as.lng = lnd_aaf(ptr);
907     return NULL;
908 }
909
910 static void *
911 nsc_lchr(struct valstr *val, struct natstr *np, void *ptr)
912 {
913     val->val_as.sym.get = NULL;
914     return lchr + ((struct lndstr *)ptr)->lnd_type;
915 }
916
917 static void *
918 nsc_nws_timestamp(struct valstr *val, struct natstr *natp, void *ptr)
919 {
920     struct nwsstr *np = ptr;
921
922     val->val_as.lng = np->nws_when + np->nws_duration;
923     return NULL;
924 }