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