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