2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
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.
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.
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/>.
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.
27 * filetable.c: Empire game data file descriptions.
29 * Known contributors to this file:
30 * Markus Armbruster, 2005-2008
36 #include "commodity.h"
58 static void sct_oninit(void *);
59 static void pln_oninit(void *);
60 static void lnd_oninit(void *);
61 static void nuk_oninit(void *);
62 static void nat_oninit(void *);
63 static void realm_oninit(void *);
64 static void game_oninit(void *);
66 /* Number of elements in ARRAY. */
67 #define SZ(array) (sizeof(array) / sizeof((array)[0]))
69 /* Initializers for members flags... */
71 #define UNMAPPED_CACHE(type, nent, flags) \
72 sizeof(type), (nent), (flags), NULL, \
75 * Mapped cache, array with known size.
76 * Members cids, fids are zero, i.e. cache is empty.
78 #define ARRAY_CACHE(array, flags) \
79 sizeof(*(array)), -1, (flags), (char *)(array), \
80 SZ((array)), 0, 0, 0, -1
82 * Mapped cache, array with unknown size.
83 * Member csize gets a bogus value, needs to be fixed up.
84 * Members cids, fids are zero, i.e. cache is empty.
86 #define PTR_CACHE(ptr, flags) \
87 sizeof(*(ptr)), -1, (flags), (char *)(ptr), \
90 * Array-backed table of fixed size.
92 #define ARRAY_TABLE(array, nent, flags) \
93 sizeof(*(array)), (nent), (flags), (char *)(array), \
94 SZ((array)), 0, (nent), (nent), -1
96 /* Common configuration table flags */
97 #define EFF_CFG (EFF_PRIVATE | EFF_MEM | EFF_STATIC | EFF_SENTINEL)
99 struct empfile empfile[] = {
101 * How this initializer works:
103 * Members uid, name, file, cadef, size, and the EFF_IMMUTABLE
104 * bits of flags get their final value.
105 * If flags & EFF_STATIC, the cache is mapped here, and members
106 * cache, csize get their final value.
107 * Members baseid, cids, fids and the EFF_MEM|EFF_PRIVATE bits of
108 * flags are initialized according the initial cache contents.
109 * Member fd is initialized to -1.
110 * Members init, postread, prewrite get initialized to NULL, but
111 * that can be changed by users.
113 * Whatever of the above can't be done here must be done in
114 * empfile_init() or empfile_fixup(). Except cadef may be set in
115 * nsc_init() instead.
119 * Keep in mind that player command arguments are matched against
120 * values of member name: no whitespace there, please.
126 * All caches unmapped. EF_SECTOR gets bogus nent here. EF_MAP
127 * and EF_BMAP get a bogus size here. Fixed up by
130 {EF_SECTOR, "sect", "sector", sect_ca, EF_BAD,
131 UNMAPPED_CACHE(struct sctstr, -1, EFF_TYPED | EFF_XY | EFF_OWNER),
132 sct_oninit, NULL, NULL, NULL},
133 {EF_SHIP, "ship", "ship", ship_ca, EF_BAD,
134 UNMAPPED_CACHE(struct shpstr, -1,
135 EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP),
136 NULL, NULL, NULL, NULL},
137 {EF_PLANE, "plane", "plane", plane_ca, EF_BAD,
138 UNMAPPED_CACHE(struct plnstr, -1,
139 EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP),
140 pln_oninit, NULL, NULL, NULL},
141 {EF_LAND, "land", "land", land_ca, EF_BAD,
142 UNMAPPED_CACHE(struct lndstr, -1,
143 EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP),
144 lnd_oninit, NULL, NULL, NULL},
145 {EF_NUKE, "nuke", "nuke", nuke_ca, EF_BAD,
146 UNMAPPED_CACHE(struct nukstr, -1, EFF_TYPED | EFF_XY | EFF_OWNER),
147 nuk_oninit, NULL, NULL, NULL},
148 {EF_NEWS, "news", "news", news_ca, EF_BAD,
149 UNMAPPED_CACHE(struct nwsstr, -1, 0),
150 NULL, NULL, NULL, NULL},
151 {EF_TREATY, "treaty", "treaty", treaty_ca, EF_BAD,
152 UNMAPPED_CACHE(struct trtstr, -1, EFF_TYPED),
153 NULL, NULL, NULL, NULL},
154 {EF_TRADE, "trade", "trade", trade_ca, EF_BAD,
155 UNMAPPED_CACHE(struct trdstr, -1, EFF_TYPED | EFF_OWNER),
156 NULL, NULL, NULL, NULL},
157 {EF_POWER, "pow", "power", NULL, EF_BAD,
158 UNMAPPED_CACHE(struct powstr, -1, 0),
159 NULL, NULL, NULL, NULL},
160 {EF_NATION, "nat", "nation", nat_ca, EF_BAD,
161 UNMAPPED_CACHE(struct natstr, MAXNOC, EFF_TYPED | EFF_OWNER),
162 nat_oninit, NULL, NULL, NULL},
163 {EF_LOAN, "loan", "loan", loan_ca, EF_BAD,
164 UNMAPPED_CACHE(struct lonstr, -1, EFF_TYPED),
165 NULL, NULL, NULL, NULL},
166 {EF_MAP, "map", "map", NULL, EF_BAD,
167 0, MAXNOC, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL, NULL},
168 {EF_BMAP, "bmap", "bmap", NULL, EF_BAD,
169 0, MAXNOC, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL, NULL},
170 {EF_COMM, "commodity", "commodity", commodity_ca, EF_BAD,
171 UNMAPPED_CACHE(struct comstr, -1, EFF_TYPED | EFF_OWNER),
172 NULL, NULL, NULL, NULL},
173 {EF_LOST, "lost", "lostitems", lost_ca, EF_BAD,
174 UNMAPPED_CACHE(struct loststr, -1, EFF_TYPED | EFF_OWNER),
175 NULL, NULL, NULL, NULL},
176 {EF_REALM, "realm", "realms", realm_ca, EF_BAD,
177 UNMAPPED_CACHE(struct realmstr, MAXNOC * MAXNOR,
178 EFF_TYPED | EFF_OWNER),
179 realm_oninit, NULL, NULL, NULL},
180 {EF_GAME, "game", "game", game_ca, EF_BAD,
181 UNMAPPED_CACHE(struct gamestr, 1, EFF_TYPED),
182 game_oninit, NULL, NULL, NULL},
185 * Static game data (configuration)
188 * Characteristics tables. Characteristics with a null file
189 * member are compiled in. The others are empty; use
190 * read_builtin_tables() to fill them.
192 {EF_ITEM, "item", "item.config", ichr_ca, EF_BAD,
193 ARRAY_CACHE(ichr, EFF_CFG), NULL, NULL, NULL, NULL},
194 {EF_PRODUCT, "product", "product.config", pchr_ca, EF_BAD,
195 ARRAY_CACHE(pchr, EFF_CFG), NULL, NULL, NULL, NULL},
196 {EF_SECTOR_CHR, "sect-chr", "sect.config", dchr_ca, EF_BAD,
197 ARRAY_CACHE(dchr, EFF_CFG), NULL, NULL, NULL, NULL},
198 {EF_SHIP_CHR, "ship-chr", "ship.config", mchr_ca, EF_BAD,
199 ARRAY_CACHE(mchr, EFF_CFG), NULL, NULL, NULL, NULL},
200 {EF_PLANE_CHR, "plane-chr", "plane.config", plchr_ca, EF_BAD,
201 ARRAY_CACHE(plchr, EFF_CFG), NULL, NULL, NULL, NULL},
202 {EF_LAND_CHR, "land-chr", "land.config", lchr_ca, EF_BAD,
203 ARRAY_CACHE(lchr, EFF_CFG), NULL, NULL, NULL, NULL},
204 {EF_NUKE_CHR, "nuke-chr", "nuke.config", nchr_ca, EF_BAD,
205 ARRAY_CACHE(nchr, EFF_CFG), NULL, NULL, NULL, NULL},
206 {EF_NEWS_CHR, "news-chr", NULL, rpt_ca, EF_BAD,
207 ARRAY_TABLE(rpt, N_MAX_VERB + 1, EFF_CFG), NULL, NULL, NULL, NULL},
208 {EF_INFRASTRUCTURE, "infrastructure", "infra.config", intrchr_ca, EF_BAD,
209 ARRAY_CACHE(intrchr, EFF_CFG), NULL, NULL, NULL, NULL},
211 * Update schedule table. Use read_schedule() to fill.
213 {EF_UPDATES, "updates", NULL, update_ca, EF_BAD,
214 ARRAY_CACHE(update_time, EFF_CFG),
215 NULL, NULL, NULL, NULL},
217 * Special tables. EF_META gets bogus size, cids and fids here.
218 * Fixed up by empfile_init(). EF_VERSION's cadef is set by
221 {EF_TABLE, "table", NULL, empfile_ca, EF_BAD,
222 ARRAY_TABLE(empfile, EF_MAX, EFF_CFG),
223 NULL, NULL, NULL, NULL},
224 {EF_VERSION, "version", NULL, NULL, EF_BAD,
225 sizeof(PACKAGE_STRING), -1, EFF_STATIC, version, 1, 0, 1, 1, -1,
226 NULL, NULL, NULL, NULL},
227 {EF_META, "meta", NULL, mdchr_ca, EF_BAD,
228 PTR_CACHE(mdchr_ca, EFF_CFG),
229 NULL, NULL, NULL, NULL},
234 * These get bogus csize, cids and fids here. Fixed up by
237 #define SYMTAB(type, name, tab) {(type), (name), NULL, symbol_ca, EF_BAD, \
238 PTR_CACHE((tab), EFF_CFG), \
239 NULL, NULL, NULL, NULL}
240 SYMTAB(EF_AGREEMENT_STATUS, "agreement-status", agreement_statuses),
241 SYMTAB(EF_LAND_CHR_FLAGS, "land-chr-flags", land_chr_flags),
242 SYMTAB(EF_LEVEL, "level", level),
243 SYMTAB(EF_META_FLAGS, "meta-flags", meta_flags),
244 SYMTAB(EF_META_TYPE, "meta-type", meta_type),
245 SYMTAB(EF_MISSIONS, "missions", missions),
246 SYMTAB(EF_NATION_FLAGS, "nation-flags", nation_flags),
247 SYMTAB(EF_NATION_REJECTS, "nation-rejects", nation_rejects),
248 SYMTAB(EF_NATION_RELATIONS, "nation-relationships", nation_relations),
249 SYMTAB(EF_NATION_STATUS, "nation-status", nation_status),
250 SYMTAB(EF_NUKE_CHR_FLAGS, "nuke-chr-flags", nuke_chr_flags),
251 SYMTAB(EF_PACKING, "packing", packing),
252 SYMTAB(EF_PAGE_HEADINGS, "page-headings", page_headings),
253 SYMTAB(EF_PLAGUE_STAGES, "plague-stages", plague_stages),
254 SYMTAB(EF_PLANE_CHR_FLAGS, "plane-chr-flags", plane_chr_flags),
255 SYMTAB(EF_PLANE_FLAGS, "plane-flags", plane_flags),
256 SYMTAB(EF_RESOURCES, "resources", resources),
257 SYMTAB(EF_RETREAT_FLAGS, "retreat-flags", retreat_flags),
258 SYMTAB(EF_SECTOR_NAVIGATION, "sector-navigation", sector_navigation),
259 SYMTAB(EF_SHIP_CHR_FLAGS, "ship-chr-flags", ship_chr_flags),
260 SYMTAB(EF_TREATY_FLAGS, "treaty-flags", treaty_flags),
263 {EF_COUNTRY, "country", NULL, cou_ca, EF_NATION,
264 UNMAPPED_CACHE(struct natstr, MAXNOC, EFF_TYPED | EFF_OWNER),
265 NULL, NULL, NULL, NULL},
268 {EF_BAD, NULL, NULL, NULL, EF_BAD,
269 0, -1, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL, NULL},
273 sct_oninit(void *ptr)
275 struct sctstr *sp = (struct sctstr *)ptr;
277 sp->sct_y = sp->sct_uid * 2 / WORLD_X;
278 sp->sct_x = sp->sct_uid * 2 % WORLD_X + sp->sct_y % 2;
279 sp->sct_dist_x = sp->sct_x;
280 sp->sct_dist_y = sp->sct_y;
281 sp->sct_newtype = sp->sct_type = SCT_WATER;
286 pln_oninit(void *ptr)
288 struct plnstr *pp = ptr;
290 pp->pln_ship = pp->pln_land = -1;
294 lnd_oninit(void *ptr)
296 struct lndstr *lp = ptr;
298 lp->lnd_ship = lp->lnd_land = -1;
302 nuk_oninit(void *ptr)
304 struct nukstr *np = ptr;
310 nat_oninit(void *ptr)
312 struct natstr *np = ptr;
314 np->nat_cnum = np->nat_uid;
318 realm_oninit(void *ptr)
320 struct realmstr *realm = ptr;
322 realm->r_cnum = realm->r_uid / MAXNOR;
323 realm->r_realm = realm->r_uid % MAXNOR;
327 game_oninit(void *ptr)
329 ((struct gamestr *)ptr)->game_turn = 1;
333 ef_fix_size(struct empfile *ep, int n)
335 ep->nent = ep->cids = ep->fids = n;
347 ca = (struct castr *)empfile[EF_META].cache;
348 for (i = 0; ca[i].ca_name; i++) ;
349 ef_fix_size(&empfile[EF_META], i);
351 for (ep = empfile; ep->uid >= 0; ep++) {
352 if (ep->cadef == symbol_ca) {
353 lup = (struct symbol *)ep->cache;
354 for (i = 0; lup[i].name; i++) ;
363 empfile[EF_SECTOR].nent = WORLD_SZ();
364 empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ();