]> git.pond.sub.org Git - empserver/blob - src/lib/global/nsc.c
Selector rewrite: values other than long, interpret identifiers
[empserver] / src / lib / global / nsc.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  nsc.c: Empire selection global structures
29  * 
30  *  Known contributors to this file:
31  *     Markus Armbruster, 2004
32  *  
33  */
34
35 #include <struct.h>
36 #include "misc.h"
37 #include "var.h"
38 #include "xy.h"
39 #include "loan.h"
40 #include "nsc.h"
41 #include "news.h"
42 #include "nuke.h"
43 #include "plane.h"
44 #include "ship.h"
45 #include "land.h"
46 #include "sect.h"
47 #include "trade.h"
48 #include "treaty.h"
49 #include "genitem.h"
50 #include "nat.h"
51 #include "map.h"
52 #include "commodity.h"
53 #include "lost.h"
54
55 #define NSC_IELT(name, pfx, sfx, base, itype)           \
56 {NSC_USHORT, 0, 0, ((base) + (itype)*sizeof(u_short)),  \
57 sizeof(sfx) == 1 ? name : pfx sfx}
58
59 #define NSC_IVEC(base, sfx)             \
60 NSC_IELT("civil", "c", sfx, base, I_CIVIL),     \
61 NSC_IELT("milit", "m", sfx, base, I_MILIT),     \
62 NSC_IELT("shell", "s", sfx, base, I_SHELL),     \
63 NSC_IELT("gun", "g", sfx, base, I_GUN),         \
64 NSC_IELT("petrol", "p", sfx, base, I_PETROL),   \
65 NSC_IELT("iron", "i", sfx, base, I_IRON),       \
66 NSC_IELT("dust", "d", sfx, base, I_DUST),       \
67 NSC_IELT("bar", "b", sfx, base, I_BAR),         \
68 NSC_IELT("food", "f", sfx, base, I_FOOD),       \
69 NSC_IELT("oil", "o", sfx, base, I_OIL),         \
70 NSC_IELT("lcm", "l", sfx, base, I_LCM),         \
71 NSC_IELT("hcm", "h", sfx, base, I_HCM),         \
72 NSC_IELT("uw", "u", sfx, base, I_UW),           \
73 NSC_IELT("rad", "r", sfx, base, I_RAD)
74
75 struct castr sect_ca[] = {
76     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_own), "owner"},
77     {NSC_XCOORD, 0, 0, fldoff(sctstr, sct_x), "xloc"},
78     {NSC_YCOORD, 0, 0, fldoff(sctstr, sct_y), "yloc"},
79     {NSC_TYPEID, 0, 0, fldoff(sctstr, sct_type), "des"},
80     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_effic), "effic"},
81     {NSC_SHORT, 0, 0, fldoff(sctstr, sct_mobil), "mobil"},
82     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr), "terr"},
83     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr), "terr0"},
84     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr1), "terr1"},
85     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr2), "terr2"},
86     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_terr3), "terr3"},
87     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_work), "work"},
88     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_coastal), "coastal"},
89     {NSC_TYPEID, 0, 0, fldoff(sctstr, sct_newtype), "newdes"},
90     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_min), "min"},
91     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_gmin), "gold"},
92     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_fertil), "fert"},
93     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_oil), "ocontent"},
94     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_uran), "uran"},
95     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_oldown), "oldown"},
96     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_off), "off"},
97     {NSC_XCOORD, 0, 0, fldoff(sctstr, sct_dist_x), "xdist"},
98     {NSC_YCOORD, 0, 0, fldoff(sctstr, sct_dist_y), "ydist"},
99     {NSC_SHORT, 0, 0, fldoff(sctstr, sct_avail), "avail"},
100     NSC_IVEC(fldoff(sctstr, sct_item), ""),
101     NSC_IVEC(fldoff(sctstr, sct_dist), "_dist"),
102     NSC_IVEC(fldoff(sctstr, sct_del), "_del"),
103     {NSC_USHORT, NSC_DEITY, 0, fldoff(sctstr, sct_mines), "mines"},
104     {NSC_USHORT, NSC_DEITY, 0, fldoff(sctstr, sct_pstage), "pstage"},
105     {NSC_USHORT, NSC_DEITY, 0, fldoff(sctstr, sct_ptime), "ptime"},
106     {NSC_USHORT, NSC_DEITY, 0, fldoff(sctstr, sct_che), "che"},
107     {NSC_USHORT, NSC_DEITY, 0, fldoff(sctstr, sct_che_target), "che_target"},
108     {NSC_USHORT, 0, 0, fldoff(sctstr, sct_fallout), "fallout"},
109     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_road), "road"},
110     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_rail), "rail"},
111     {NSC_UCHAR, 0, 0, fldoff(sctstr, sct_defense), "dfense"},
112     {NSC_TIME, 0, 0, fldoff(sctstr, sct_timestamp), "timestamp"},
113     {NSC_NOTYPE, 0, 0, 0, NULL}
114 };
115
116 #define NSC_GENITEM \
117 { NSC_UCHAR, 0, 0, fldoff(genitem, own), "owner"},      \
118 { NSC_SHORT, 0, 0, fldoff(genitem, uid), "uid"},        \
119 { NSC_XCOORD, 0, 0, fldoff(genitem, x), "xloc"},        \
120 { NSC_YCOORD, 0, 0, fldoff(genitem, y), "yloc"},        \
121 { NSC_TYPEID, 0, 0, fldoff(genitem, type), "type"},     \
122 { NSC_UCHAR, 0, 0, fldoff(genitem, effic), "effic"},    \
123 { NSC_CHAR , 0, 0, fldoff(genitem, mobil), "mobil"},    \
124 { NSC_SHORT, 0, 0, fldoff(genitem, tech), "tech"},      \
125 { NSC_CHAR, 0, 0, fldoff(genitem, group), "group"},     \
126 { NSC_XCOORD, 0, 0, fldoff(genitem, opx), "opx"},       \
127 { NSC_YCOORD, 0, 0, fldoff(genitem, opy), "opy"},       \
128 { NSC_SHORT, 0, 0, fldoff(genitem, mission), "mission"}
129
130 struct castr ship_ca[] = {
131     NSC_GENITEM,
132     {NSC_CHAR, 0, 0, fldoff(shpstr, shp_fleet), "fleet"},
133     {NSC_CHAR, 0, 0, fldoff(shpstr, shp_nplane), "nplane"},
134     {NSC_TIME, 0, 0, fldoff(shpstr, shp_timestamp), "timestamp"},
135     {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_fuel), "fuel"},
136     {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nxlight), "nxlight"},
137     {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_nchoppers), "nchoppers"},
138     {NSC_UCHAR, 0, 0, fldoff(shpstr, shp_autonav), "autonav"},
139     {NSC_USHORT, NSC_DEITY, 0, fldoff(shpstr, shp_pstage), "pstage"},
140     {NSC_USHORT, NSC_DEITY, 0, fldoff(shpstr, shp_ptime), "ptime"},
141     NSC_IVEC(fldoff(shpstr, shp_item), ""),
142     {NSC_NOTYPE, 0, 0, 0, NULL}
143 };
144
145 struct castr plane_ca[] = {
146     NSC_GENITEM,
147     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_wing), "wing"},
148     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_range), "range"},
149     {NSC_SHORT, 0, 0, fldoff(plnstr, pln_ship), "ship"},
150     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_att), "att"},
151     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_def), "def"},
152     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_harden), "harden"},
153     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_nuketype), "nuketype"},
154     {NSC_UCHAR, 0, 0, fldoff(plnstr, pln_flags), "flags"},
155     {NSC_SHORT, 0, 0, fldoff(plnstr, pln_land), "land"},
156     {NSC_TIME, 0, 0, fldoff(plnstr, pln_timestamp), "timestamp"},
157     {NSC_NOTYPE, 0, 0, 0, NULL}
158 };
159
160 struct castr land_ca[] = {
161     NSC_GENITEM,
162     {NSC_CHAR, 0, 0, fldoff(lndstr, lnd_army), "army"},
163     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_ship), "ship"},
164     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_land), "land"},
165     {NSC_CHAR, 0, 0, fldoff(lndstr, lnd_harden), "harden"},
166     {NSC_SHORT, 0, 0, fldoff(lndstr, lnd_retreat), "retreat"},
167     {NSC_UCHAR, 0, 0, fldoff(lndstr, lnd_fuel), "fuel"},
168     {NSC_UCHAR, 0, 0, fldoff(lndstr, lnd_nxlight), "nxlight"},
169     NSC_IVEC(fldoff(lndstr, lnd_item), ""),
170     {NSC_USHORT, NSC_DEITY, 0, fldoff(lndstr, lnd_pstage), "pstage"},
171     {NSC_USHORT, NSC_DEITY, 0, fldoff(lndstr, lnd_ptime), "ptime"},
172     {NSC_FLOAT, 0, 0, fldoff(lndstr, lnd_att), "att"},
173     {NSC_FLOAT, 0, 0, fldoff(lndstr, lnd_def), "def"},
174     {NSC_INT, 0, 0, fldoff(lndstr, lnd_vul), "vul"},
175     {NSC_INT, 0, 0, fldoff(lndstr, lnd_spd), "spd"},
176     {NSC_INT, 0, 0, fldoff(lndstr, lnd_vis), "vis"},
177     {NSC_INT, 0, 0, fldoff(lndstr, lnd_spy), "spy"},
178     {NSC_INT, 0, 0, fldoff(lndstr, lnd_rad), "rad"},
179     {NSC_INT, 0, 0, fldoff(lndstr, lnd_frg), "frg"},
180     {NSC_INT, 0, 0, fldoff(lndstr, lnd_acc), "acc"},
181     {NSC_INT, 0, 0, fldoff(lndstr, lnd_dam), "dam"},
182     {NSC_INT, 0, 0, fldoff(lndstr, lnd_ammo), "ammo"},
183     {NSC_INT, 0, 0, fldoff(lndstr, lnd_aaf), "aaf"},
184     {NSC_UCHAR, 0, 0, fldoff(lndstr, lnd_fuelc), "fuelc"},
185     {NSC_UCHAR, 0, 0, fldoff(lndstr, lnd_fuelu), "fuelu"},
186     {NSC_UCHAR, 0, 0, fldoff(lndstr, lnd_maxlight), "maxlight"},
187     {NSC_TIME, 0, 0, fldoff(lndstr, lnd_timestamp), "timestamp"},
188     {NSC_NOTYPE, 0, 0, 0, NULL}
189 };
190
191 struct castr nuke_ca[] = {
192     {NSC_UCHAR, 0, 0, fldoff(nukstr, nuk_own), "owner"},
193     {NSC_SHORT, 0, 0, fldoff(nukstr, nuk_uid), "uid"},
194     {NSC_XCOORD, 0, 0, fldoff(nukstr, nuk_x), "xloc"},
195     {NSC_YCOORD, 0, 0, fldoff(nukstr, nuk_y), "yloc"},
196     {NSC_CHAR, 0, 0, fldoff(nukstr, nuk_n), "number"},
197 #if !defined(_WIN32)
198     {NSC_CHAR, 0, N_MAXNUKE, fldoff(nukstr, nuk_types[0]), "types"},
199 #else
200     {NSC_CHAR, 0, N_MAXNUKE, fldoff(nukstr, nuk_types), "types"},
201 #endif
202     {NSC_TIME, 0, 0, fldoff(nukstr, nuk_timestamp), "timestamp"},
203     {NSC_NOTYPE, 0, 0, 0, NULL}
204 };
205
206 struct castr treaty_ca[] = {
207     {NSC_UCHAR, 0, 0, fldoff(trtstr, trt_cna), "cna"},
208     {NSC_UCHAR, 0, 0, fldoff(trtstr, trt_cnb), "cnb"},
209     {NSC_UCHAR, 0, 0, fldoff(trtstr, trt_status), "status"},
210     {NSC_SHORT, 0, 0, fldoff(trtstr, trt_acond), "acond"},
211     {NSC_SHORT, 0, 0, fldoff(trtstr, trt_bcond), "bcond"},
212     {NSC_LONG, 0, 0, fldoff(trtstr, trt_exp), "exp"},
213     {NSC_NOTYPE, 0, 0, 0, NULL}
214 };
215
216 struct castr loan_ca[] = {
217     {NSC_UCHAR, 0, 0, fldoff(lonstr, l_loner), "loaner"},
218     {NSC_SHORT, 0, 0, fldoff(lonstr, l_uid), "uid"},
219     {NSC_UCHAR, 0, 0, fldoff(lonstr, l_lonee), "loanee"},
220     {NSC_CHAR, 0, 0, fldoff(lonstr, l_status), "status"},
221     {NSC_INT, 0, 0, fldoff(lonstr, l_irate), "irate"},
222     {NSC_INT, 0, 0, fldoff(lonstr, l_ldur), "ldur"},
223     {NSC_LONG, 0, 0, fldoff(lonstr, l_amtpaid), "amtpaid"},
224     {NSC_LONG, 0, 0, fldoff(lonstr, l_amtdue), "amtdue"},
225     {NSC_TIME, 0, 0, fldoff(lonstr, l_lastpay), "lastpay"},
226     {NSC_TIME, 0, 0, fldoff(lonstr, l_duedate), "duedate"},
227     {NSC_NOTYPE, 0, 0, 0, NULL}
228 };
229
230 struct castr news_ca[] = {
231     {NSC_CHAR, 0, 0, fldoff(nwsstr, nws_ano), "actor"},
232     {NSC_CHAR, 0, 0, fldoff(nwsstr, nws_vrb), "action"},
233     {NSC_CHAR, 0, 0, fldoff(nwsstr, nws_vno), "victim"},
234     {NSC_CHAR, 0, 0, fldoff(nwsstr, nws_ntm), "times"},
235     {NSC_LONG, 0, 0, fldoff(nwsstr, nws_when), "time"},
236     {NSC_NOTYPE, 0, 0, 0, NULL}
237 };
238
239 struct castr lost_ca[] = {
240     {NSC_UCHAR, 0, 0, fldoff(loststr, lost_owner), "owner"},
241     {NSC_INT, 0, 0, fldoff(loststr, lost_uid), "uid"},
242     {NSC_UCHAR, 0, 0, fldoff(loststr, lost_type), "type"},
243     {NSC_XCOORD, 0, 0, fldoff(loststr, lost_x), "x"},
244     {NSC_YCOORD, 0, 0, fldoff(loststr, lost_y), "y"},
245     {NSC_TIME, 0, 0, fldoff(loststr, lost_timestamp), "timestamp"},
246     {NSC_NOTYPE, 0, 0, 0, NULL}
247 };
248
249 struct castr commodity_ca[] = {
250     {NSC_UCHAR, 0, 0, fldoff(comstr, com_owner), "owner"},
251     {NSC_SHORT, 0, 0, fldoff(comstr, com_uid), "uid"},
252     {NSC_UCHAR, 0, 0, fldoff(comstr, com_type), "type"},
253     {NSC_INT, 0, 0, fldoff(comstr, com_amount), "amount"},
254     {NSC_INT, 0, 0, fldoff(comstr, com_maxbidder), "maxbidder"},
255     {NSC_TIME, 0, 0, fldoff(comstr, com_markettime), "markettime"},
256     /* could let maxbidder access these, but we can't express that yet: */
257     {NSC_INT, NSC_DEITY, 0, fldoff(comstr, com_x), "xbuy"},
258     {NSC_INT, NSC_DEITY, 0, fldoff(comstr, com_y), "ybuy"},
259     /* could let the owner access these, but we can't express that yet: */
260     {NSC_XCOORD, NSC_DEITY, 0, fldoff(comstr, sell_x), "xsell"},
261     {NSC_YCOORD, NSC_DEITY, 0, fldoff(comstr, sell_y), "ysell"},
262     {NSC_FLOAT, NSC_DEITY, 0, fldoff(comstr, com_price), "price"},
263     {NSC_NOTYPE, 0, 0, 0, NULL}
264 };
265
266 struct castr trade_ca[] = {
267     {NSC_UCHAR, 0, 0, fldoff(trdstr, trd_owner), "owner"},
268     {NSC_SHORT, 0, 0, fldoff(trdstr, trd_uid), "uid"},
269     {NSC_UCHAR, 0, 0, fldoff(trdstr, trd_type), "type"},
270     {NSC_SHORT, 0, 0, fldoff(trdstr, trd_unitid), "unitid"},
271     {NSC_LONG, 0, 0, fldoff(trdstr, trd_price), "price"},
272     {NSC_INT, 0, 0, fldoff(trdstr, trd_maxbidder), "maxbidder"},
273     {NSC_TIME, 0, 0, fldoff(trdstr, trd_markettime), "markettime"},
274     /* could let the owner access these, but we can't express that yet: */
275     {NSC_XCOORD, NSC_DEITY, 0, fldoff(trdstr, trd_x), "xloc"},
276     {NSC_YCOORD, NSC_DEITY, 0, fldoff(trdstr, trd_y), "yloc"},
277     {NSC_NOTYPE, 0, 0, 0, NULL}
278 };
279
280 struct castr nat_ca[] = {
281     {NSC_UCHAR, 0, 0, fldoff(natstr, nat_cnum), "cnum"},
282 #if !defined(_WIN32)
283     {NSC_CHAR, 0, 20, fldoff(natstr, nat_cnam[0]), "cnam"},
284     {NSC_CHAR, NSC_DEITY, 20, fldoff(natstr, nat_pnam[0]), "pnam"},
285 #else
286     {NSC_CHAR, 0, 20, fldoff(natstr, nat_cnam), "cnam"},
287     {NSC_CHAR, NSC_DEITY, 20, fldoff(natstr, nat_pnam), "pnam"},
288 #endif
289     {NSC_XCOORD, 0, 0, fldoff(natstr, nat_xstart), "xstart"},
290     {NSC_YCOORD, 0, 0, fldoff(natstr, nat_ystart), "ystart"},
291     {NSC_XCOORD, 0, 0, fldoff(natstr, nat_xcap), "xcap"},
292     {NSC_YCOORD, 0, 0, fldoff(natstr, nat_ycap), "ycap"},
293     {NSC_XCOORD, NSC_DEITY, 0, fldoff(natstr, nat_xorg), "xorg"},
294     {NSC_YCOORD, NSC_DEITY, 0, fldoff(natstr, nat_yorg), "yorg"},
295 #ifdef MAYBE_LATER
296     {NSC_CHAR, 0, 0, fldoff(natstr, nat_stat), "stat"},
297     {NSC_CHAR, 0, 0, fldoff(natstr, nat_dayno), "dayno"},
298     {NSC_CHAR, 0, 0, fldoff(natstr, nat_update), "update"},
299     {NSC_UCHAR, 0, 0, fldoff(natstr, nat_missed), "missed"},
300 #endif /* MAYBE_LATER */
301     {NSC_USHORT, 0, 0, fldoff(natstr, nat_tgms), "tgms"},
302     {NSC_USHORT, 0, 0, fldoff(natstr, nat_ann), "ann"},
303     {NSC_USHORT, 0, 0, fldoff(natstr, nat_minused), "minused"},
304     {NSC_SHORT, 0, 0, fldoff(natstr, nat_btu), "btu"},
305     {NSC_LONG, 0, 0, fldoff(natstr, nat_reserve), "reserve"},
306     {NSC_LONG, 0, 0, fldoff(natstr, nat_money), "money"},
307 #ifdef MAYBE_LATER
308     {NSC_LONG, 0, 0, fldoff(natstr, nat_last_login), "last_login"},
309     {NSC_LONG, 0, 0, fldoff(natstr, nat_last_logout), "last_logout"},
310     {NSC_LONG, 0, 0, fldoff(natstr, nat_newstim), "newstim"},
311 #endif /* MAYBE_LATER */
312 #if !defined(_WIN32)
313     {NSC_FLOAT, 0, 4, fldoff(natstr, nat_level[0]), "level"},
314 #else
315     {NSC_FLOAT, 0, 4, fldoff(natstr, nat_level), "level"},
316 #endif
317 /* {NSC_SHORT, 0, 0, fldoff(natstr, nat_relate[0]),"relate",MAXNOC}, */
318 /* {NSC_CHAR, 0, 0, fldoff(natstr, nat_priorities[0]),"priorities",39}, */
319 /* {NSC_LONG, 0, 0, fldoff(natstr, nat_flags),"flags",0}, */
320     {NSC_NOTYPE, 0, 0, 0, NULL}
321 };