/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * fileglb.c: Empire selection global structures.
+ * file.c: Empire game data file descriptions.
*
* Known contributors to this file:
*
#include "news.h"
#include "nat.h"
#include "lost.h"
+#include "product.h"
#include "gamesdef.h"
#include "commodity.h"
+#include "nsc.h"
+
+/* Number of elements in ARRAY. */
+#define SZ(array) (sizeof(array) / sizeof((array)[0]))
+
+/* Initializers for members flags... */
+/* Unmapped cache */
+#define UNMAPPED_CACHE(type, flags) \
+ sizeof(type), flags, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
+/*
+ * Mapped cache, array with known size.
+ * Members cids, fids are not set.
+ */
+#define ARRAY_CACHE(array, flags) \
+ sizeof(*(array)), (flags), (char *)(array), \
+ SZ((array)), 0, 0, 0, -1, NULL, NULL, NULL
+/*
+ * Mapped cache, array with unknown size.
+ * Members csize, cids, fids are not set.
+ */
+#define PTR_CACHE(ptr, flags) \
+ sizeof(*(ptr)), (flags), (char *)(ptr), \
+ 0, 0, 0, 0, -1, NULL, NULL, NULL
+/*
+ * Array-backed table.
+ * The array's last element is the sentinel.
+ */
+#define ARRAY_TABLE(array, flags) \
+ sizeof(*(array)), (flags), (char *)(array), \
+ SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL, NULL
+
+/* Common configuration table flags */
+#define EFF_CFG (EFF_RDONLY | EFF_MEM | EFF_STATIC)
struct empfile empfile[] = {
- {"sect", EMPDIR "/data/sector", EFF_COM | EFF_XY | EFF_OWNER,
- 0, sizeof(struct sctstr), 0, 0, 0, offsetof(struct sctstr, sct_item),
- -1, -1, 0, 0, 0, 0, 0},
- {"ship", EMPDIR "/data/ship", EFF_COM | EFF_XY | EFF_OWNER | EFF_GROUP,
- 0, sizeof(struct shpstr), 0, 0, 0, offsetof(struct shpstr, shp_item),
- -1, -1, 0, 0, 0, 0, 0},
- {"plane", EMPDIR "/data/plane", EFF_XY | EFF_OWNER | EFF_GROUP,
- 0, sizeof(struct plnstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"land", EMPDIR "/data/land", EFF_COM | EFF_XY | EFF_OWNER | EFF_GROUP,
- 0, sizeof(struct lndstr), 0, 0, 0, offsetof(struct lndstr, lnd_item),
- -1, -1, 0, 0, 0, 0, 0},
- {"nuke", EMPDIR "/data/nuke", EFF_XY | EFF_OWNER,
- 0, sizeof(struct nukstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"news", EMPDIR "/data/news", 0,
- 0, sizeof(struct nwsstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"treaty", EMPDIR "/data/treaty", 0,
- 0, sizeof(struct trtstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"trade", EMPDIR "/data/trade", 0,
- 0, sizeof(struct trdstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"pow", EMPDIR "/data/power", 0,
- 0, sizeof(struct powstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"nat", EMPDIR "/data/nation", 0,
- 0, sizeof(struct natstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"loan", EMPDIR "/data/loan", 0,
- 0, sizeof(struct lonstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"map", EMPDIR "/data/map", 0,
- 0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"bmap", EMPDIR "/data/bmap", 0,
- 0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"commodity", EMPDIR "/data/commodity", 0,
- 0, sizeof(struct comstr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0},
- {"lost", EMPDIR "/data/lostitems", 0, 0,
- sizeof(struct loststr), 0, 0, 0, 0,
- -1, -1, 0, 0, 0, 0, 0}
+ /*
+ * How empfile[] is initialized:
+ *
+ * Members uid, name, file, size, cadef, and the EFF_IMMUTABLE
+ * bits of flags get their final value.
+ * If flags & EFF_STATIC, the cache is mapped here, and members
+ * cache, csize get their final value.
+ * Members baseid, cids, fids and the EFF_MEM|EFF_RDONLY bits of
+ * flags are initialized according the initial cache contents.
+ * Member fd is initialized to -1.
+ * Members init, postread, prewrite get initialized to NULL, but
+ * that can be changed by users.
+ *
+ * Whatever of the above can't be done here must be done in
+ * ef_init().
+ */
+
+ /* Dynamic game data */
+ {EF_SECTOR, "sect", "sector", sect_ca,
+ UNMAPPED_CACHE(struct sctstr, EFF_XY | EFF_OWNER)},
+ {EF_SHIP, "ship", "ship", ship_ca,
+ UNMAPPED_CACHE(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
+ {EF_PLANE, "plane", "plane", plane_ca,
+ UNMAPPED_CACHE(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
+ {EF_LAND, "land", "land", land_ca,
+ UNMAPPED_CACHE(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
+ {EF_NUKE, "nuke", "nuke", nuke_ca,
+ UNMAPPED_CACHE(struct nukstr, EFF_XY | EFF_OWNER)},
+ {EF_NEWS, "news", "news", news_ca,
+ UNMAPPED_CACHE(struct nwsstr, 0)},
+ {EF_TREATY, "treaty", "treaty", treaty_ca,
+ UNMAPPED_CACHE(struct trtstr, 0)},
+ {EF_TRADE, "trade", "trade", trade_ca,
+ UNMAPPED_CACHE(struct trdstr, 0)},
+ {EF_POWER, "pow", "power", NULL,
+ UNMAPPED_CACHE(struct powstr, 0)},
+ {EF_NATION, "nat", "nation", nat_ca,
+ UNMAPPED_CACHE(struct natstr, EFF_OWNER)},
+ {EF_LOAN, "loan", "loan", loan_ca,
+ UNMAPPED_CACHE(struct lonstr, 0)},
+ {EF_MAP, "map", "map", NULL,
+ 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
+ {EF_BMAP, "bmap", "bmap", NULL,
+ 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
+ {EF_COMM, "commodity", "commodity", commodity_ca,
+ UNMAPPED_CACHE(struct comstr, 0)},
+ {EF_LOST, "lost", "lostitems", lost_ca,
+ UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
+
+ /* Static game data (configuration) */
+ {EF_SECTOR_CHR, "sect chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},
+ {EF_SHIP_CHR, "ship chr", "ship_def", mchr_ca, ARRAY_CACHE(mchr, EFF_CFG)},
+ {EF_PLANE_CHR, "plane chr", "plane_def", plchr_ca, ARRAY_CACHE(plchr, EFF_CFG)},
+ {EF_LAND_CHR, "land chr", "land_def", lchr_ca, ARRAY_CACHE(lchr, EFF_CFG)},
+ {EF_NUKE_CHR, "nuke chr", "nuke_def", nchr_ca, ARRAY_CACHE(nchr, EFF_CFG)},
+ {EF_NEWS_CHR, "news chr", NULL, rpt_ca, ARRAY_TABLE(rpt, EFF_CFG)},
+ {EF_TREATY_FLAGS, "treaty flags", NULL, symbol_ca,
+ PTR_CACHE(treaty_flags, EFF_CFG)},
+ {EF_ITEM, "item", "item_def", ichr_ca, ARRAY_TABLE(ichr, EFF_CFG)},
+ {EF_INFRASTRUCTURE, "infrastructure", "infrastructure_def", intrchr_ca,
+ ARRAY_TABLE(intrchr, EFF_CFG)},
+ {EF_PRODUCT, "product", "product_def", pchr_ca, ARRAY_TABLE(pchr, EFF_CFG)},
+ {EF_TABLE, "table", NULL, empfile_ca, ARRAY_TABLE(empfile, EFF_CFG)},
+ {EF_SHIP_CHR_FLAGS, "ship chr flags", NULL, symbol_ca,
+ PTR_CACHE(ship_chr_flags, EFF_CFG)},
+ {EF_PLANE_CHR_FLAGS, "plane chr flags", NULL, symbol_ca,
+ PTR_CACHE(plane_chr_flags, EFF_CFG)},
+ {EF_LAND_CHR_FLAGS, "land chr flags", NULL, symbol_ca,
+ PTR_CACHE(land_chr_flags, EFF_CFG)},
+ {EF_NUKE_CHR_FLAGS, "nuke chr flags", NULL, symbol_ca,
+ PTR_CACHE(nuke_chr_flags, EFF_CFG)},
+ {EF_META, "meta", NULL, mdchr_ca, PTR_CACHE(mdchr_ca, EFF_CFG)},
+ {EF_META_TYPE, "meta type", NULL, symbol_ca,
+ PTR_CACHE(meta_type, EFF_CFG)},
+ {EF_META_FLAGS, "meta flags", NULL, symbol_ca,
+ PTR_CACHE(meta_flags, EFF_CFG)},
+ {EF_MISSIONS, "missions", NULL, symbol_ca,
+ PTR_CACHE(missions, EFF_CFG)},
+ {EF_PLANE_FLAGS, "plane flags", NULL, symbol_ca,
+ PTR_CACHE(plane_flags, EFF_CFG)},
+ {EF_RETREAT_FLAGS, "retreat flags", NULL, symbol_ca,
+ PTR_CACHE(retreat_flags, EFF_CFG)},
+ {EF_NATION_FLAGS, "nation flags", NULL, symbol_ca,
+ PTR_CACHE(nation_flags, EFF_CFG)},
+ {EF_NATION_RELATIONS, "nation relationships", NULL, symbol_ca,
+ PTR_CACHE(nation_relations, EFF_CFG)},
+ {EF_LEVEL, "level", NULL, symbol_ca, PTR_CACHE(level, EFF_CFG)},
+ {EF_AGREEMENT_STATUS, "agreement status", NULL, symbol_ca,
+ PTR_CACHE(agreement_statuses, EFF_CFG)},
+ {EF_PLAGUE_STAGES, "plague stages", NULL, symbol_ca,
+ PTR_CACHE(plague_stages, EFF_CFG)},
+ {EF_PACKING, "packing", NULL, symbol_ca,
+ PTR_CACHE(packing, EFF_CFG)},
+
+ /* Sentinel */
+ {EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
};