(UNMAPPED_INIT, UNMAPPED_CACHE, ARRAY_INIT, ARRAY_TABLE, PTR_INIT)

(PTR_CACHE): Rename.

(ARRAY_CACHE): New.
(empfile): Use it to set csize of elements EF_SHIP_CHR, EF_PLANE_CHR,
EF_LAND_CHR, EF_NUKE_CHR.
(ef_init_chr): Now that empfile[]'s initializer sets csize, remove the
temporary csize initialization here.  The value wasn't correct, but
better than nothing.
This commit is contained in:
Markus Armbruster 2005-11-03 18:25:26 +00:00
parent d71ab5a3e5
commit 41bf5be715
2 changed files with 58 additions and 41 deletions

View file

@ -54,18 +54,35 @@
#include "commodity.h"
#include "nsc.h"
/* Some abbreviations: */
/* Number of elements in ARRAY. */
#define SZ(array) (sizeof(array) / sizeof((array)[0]))
/* Unmapped cache initializers for members flags... */
#define UNMAPPED_INIT(type, flags) \
/* Initializers for members flags... */
/* Unmapped cache */
#define UNMAPPED_CACHE(type, flags) \
sizeof(type), flags, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
/* Same for cache mapped to array with known size */
#define ARRAY_INIT(array, flags) \
sizeof(*(array)), flags, (char *)(array), \
SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL, NULL
/* Same for unknown size, size to be filled in by ef_init() */
#define PTR_INIT(ptr, flags) sizeof(*(ptr)), flags, (char *)(ptr), \
/*
* 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)
@ -89,63 +106,63 @@ struct empfile empfile[] = {
/* Dynamic game data */
{EF_SECTOR, "sect", "sector", sect_ca,
UNMAPPED_INIT(struct sctstr, EFF_XY | EFF_OWNER)},
UNMAPPED_CACHE(struct sctstr, EFF_XY | EFF_OWNER)},
{EF_SHIP, "ship", "ship", ship_ca,
UNMAPPED_INIT(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
UNMAPPED_CACHE(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
{EF_PLANE, "plane", "plane", plane_ca,
UNMAPPED_INIT(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
UNMAPPED_CACHE(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
{EF_LAND, "land", "land", land_ca,
UNMAPPED_INIT(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
UNMAPPED_CACHE(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
{EF_NUKE, "nuke", "nuke", nuke_ca,
UNMAPPED_INIT(struct nukstr, EFF_XY | EFF_OWNER)},
UNMAPPED_CACHE(struct nukstr, EFF_XY | EFF_OWNER)},
{EF_NEWS, "news", "news", news_ca,
UNMAPPED_INIT(struct nwsstr, 0)},
UNMAPPED_CACHE(struct nwsstr, 0)},
{EF_TREATY, "treaty", "treaty", treaty_ca,
UNMAPPED_INIT(struct trtstr, 0)},
UNMAPPED_CACHE(struct trtstr, 0)},
{EF_TRADE, "trade", "trade", trade_ca,
UNMAPPED_INIT(struct trdstr, 0)},
UNMAPPED_CACHE(struct trdstr, 0)},
{EF_POWER, "pow", "power", NULL,
UNMAPPED_INIT(struct powstr, 0)},
UNMAPPED_CACHE(struct powstr, 0)},
{EF_NATION, "nat", "nation", nat_ca,
UNMAPPED_INIT(struct natstr, EFF_OWNER)},
UNMAPPED_CACHE(struct natstr, EFF_OWNER)},
{EF_LOAN, "loan", "loan", loan_ca,
UNMAPPED_INIT(struct lonstr, 0)},
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_INIT(struct comstr, 0)},
UNMAPPED_CACHE(struct comstr, 0)},
{EF_LOST, "lost", "lostitems", lost_ca,
UNMAPPED_INIT(struct loststr, EFF_OWNER)},
UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
/* Static game data (configuration) */
{EF_SECTOR_CHR, "sect chr", NULL, dchr_ca, ARRAY_INIT(dchr, EFF_CFG)},
{EF_SHIP_CHR, "ship chr", NULL, mchr_ca, PTR_INIT(mchr, EFF_CFG)},
{EF_PLANE_CHR, "plane chr", NULL, plchr_ca, PTR_INIT(plchr, EFF_CFG)},
{EF_LAND_CHR, "land chr", NULL, lchr_ca, PTR_INIT(lchr, EFF_CFG)},
{EF_NUKE_CHR, "nuke chr", NULL, nchr_ca, PTR_INIT(nchr, EFF_CFG)},
{EF_NEWS_CHR, "news chr", NULL, rpt_ca, ARRAY_INIT(rpt, EFF_CFG)},
{EF_SECTOR_CHR, "sect chr", NULL, dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},
{EF_SHIP_CHR, "ship chr", NULL, mchr_ca, ARRAY_CACHE(mchr, EFF_CFG)},
{EF_PLANE_CHR, "plane chr", NULL, plchr_ca, ARRAY_CACHE(plchr, EFF_CFG)},
{EF_LAND_CHR, "land chr", NULL, lchr_ca, ARRAY_CACHE(lchr, EFF_CFG)},
{EF_NUKE_CHR, "nuke chr", NULL, 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_INIT(treaty_flags, EFF_CFG)},
{EF_ITEM, "item", NULL, ichr_ca, ARRAY_INIT(ichr, EFF_CFG)},
PTR_CACHE(treaty_flags, EFF_CFG)},
{EF_ITEM, "item", NULL, ichr_ca, ARRAY_TABLE(ichr, EFF_CFG)},
{EF_INFRASTRUCTURE, "infrastructure", NULL, intrchr_ca,
ARRAY_INIT(intrchr, EFF_CFG)},
{EF_PRODUCT, "product", NULL, pchr_ca, ARRAY_INIT(pchr, EFF_CFG)},
{EF_TABLE, "table", NULL, empfile_ca, ARRAY_INIT(empfile, EFF_CFG)},
ARRAY_TABLE(intrchr, EFF_CFG)},
{EF_PRODUCT, "product", NULL, 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_INIT(ship_chr_flags, EFF_CFG)},
PTR_CACHE(ship_chr_flags, EFF_CFG)},
{EF_PLANE_CHR_FLAGS, "plane chr flags", NULL, symbol_ca,
PTR_INIT(plane_chr_flags, EFF_CFG)},
PTR_CACHE(plane_chr_flags, EFF_CFG)},
{EF_LAND_CHR_FLAGS, "land chr flags", NULL, symbol_ca,
PTR_INIT(land_chr_flags, EFF_CFG)},
PTR_CACHE(land_chr_flags, EFF_CFG)},
{EF_NUKE_CHR_FLAGS, "nuke chr flags", NULL, symbol_ca,
PTR_INIT(nuke_chr_flags, EFF_CFG)},
{EF_META, "meta", NULL, mdchr_ca, PTR_INIT(mdchr_ca, EFF_CFG)},
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_INIT(meta_type, EFF_CFG)},
PTR_CACHE(meta_type, EFF_CFG)},
{EF_META_FLAGS, "meta flags", NULL, symbol_ca,
PTR_INIT(meta_flags, EFF_CFG)},
PTR_CACHE(meta_flags, EFF_CFG)},
/* Sentinel */
{EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},