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