]> git.pond.sub.org Git - empserver/blob - src/lib/global/file.c
(empfile): Rename member ef_uid to uid for consistency with other
[empserver] / src / lib / global / file.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2005, 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  *  file.c: Empire game data file descriptions.
29  * 
30  *  Known contributors to this file:
31  *     
32  */
33
34 #include <stddef.h>
35 #include "misc.h"
36 #include "xy.h"
37 #include "loan.h"
38 #include "nsc.h"
39 #include "nuke.h"
40 #include "plane.h"
41 #include "ship.h"
42 #include "land.h"
43 #include "sect.h"
44 #include "trade.h"
45 #include "treaty.h"
46 #include "file.h"
47 #include "power.h"
48 #include "news.h"
49 #include "nat.h"
50 #include "lost.h"
51 #include "product.h"
52
53 #include "gamesdef.h"
54 #include "commodity.h"
55 #include "nsc.h"
56
57 /* Some abbreviations: */
58 #define SZ(array) (sizeof(array) / sizeof((array)[0]))
59 /* Unmapped cache initializers for members flags... */
60 #define UNMAPPED_INIT(type, flags) \
61     sizeof(type), flags, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
62 /* Same for cache mapped to array with known size */
63 #define ARRAY_INIT(array, flags) \
64     sizeof(*(array)), flags, (char *)(array), \
65     SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL, NULL
66 /* Same for unknown size, size to be filled in by ef_init() */
67 #define PTR_INIT(ptr, flags) sizeof(*(ptr)), flags, (char *)(ptr), \
68     0, 0, 0, 0, -1, NULL, NULL, NULL
69 /* Common configuration table flags */
70 #define EFF_CFG (EFF_RDONLY | EFF_MEM | EFF_STATIC)
71
72 struct empfile empfile[] = {
73     /*
74      * How empfile[] is initialized:
75      *
76      * Members uid, name, file, size, cadef, and the EFF_IMMUTABLE
77      * bits of flags get their final value.
78      * If flags & EFF_STATIC, the cache is mapped here, and members
79      * cache, csize get their final value.
80      * Members baseid, cids, fids and the EFF_MEM|EFF_RDONLY bits of
81      * flags are initialized according the initial cache contents.
82      * Member fd is initialized to -1.
83      * Members init, postread, prewrite get initialized to NULL, but
84      * that can be changed by users.
85      *
86      * Whatever of the above can't be done here must be done in
87      * ef_init().
88      */
89
90     /* Dynamic game data */
91     {EF_SECTOR, "sect", "sector", sect_ca,
92      UNMAPPED_INIT(struct sctstr, EFF_XY | EFF_OWNER)},
93     {EF_SHIP, "ship", "ship", ship_ca,
94      UNMAPPED_INIT(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
95     {EF_PLANE, "plane", "plane", plane_ca,
96      UNMAPPED_INIT(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
97     {EF_LAND, "land", "land", land_ca,
98      UNMAPPED_INIT(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
99     {EF_NUKE, "nuke", "nuke", nuke_ca,
100      UNMAPPED_INIT(struct nukstr, EFF_XY | EFF_OWNER)},
101     {EF_NEWS, "news", "news", news_ca,
102      UNMAPPED_INIT(struct nwsstr, 0)},
103     {EF_TREATY, "treaty", "treaty", treaty_ca,
104      UNMAPPED_INIT(struct trtstr, 0)},
105     {EF_TRADE, "trade", "trade", trade_ca,
106      UNMAPPED_INIT(struct trdstr, 0)},
107     {EF_POWER, "pow", "power", NULL,
108      UNMAPPED_INIT(struct powstr, 0)},
109     {EF_NATION, "nat", "nation", nat_ca,
110      UNMAPPED_INIT(struct natstr, EFF_OWNER)},
111     {EF_LOAN, "loan", "loan", loan_ca,
112      UNMAPPED_INIT(struct lonstr, 0)},
113     {EF_MAP, "map", "map", NULL,
114      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
115     {EF_BMAP, "bmap", "bmap", NULL,
116      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
117     {EF_COMM, "commodity", "commodity", commodity_ca,
118      UNMAPPED_INIT(struct comstr, 0)},
119     {EF_LOST, "lost", "lostitems", lost_ca,
120      UNMAPPED_INIT(struct loststr, EFF_OWNER)},
121
122     /* Static game data (configuration) */
123     {EF_SECTOR_CHR, "sect chr", NULL, dchr_ca, ARRAY_INIT(dchr, EFF_CFG)},
124     {EF_SHIP_CHR, "ship chr", NULL, mchr_ca, PTR_INIT(mchr, EFF_CFG)},
125     {EF_PLANE_CHR, "plane chr", NULL, plchr_ca, PTR_INIT(plchr, EFF_CFG)},
126     {EF_LAND_CHR, "land chr", NULL, lchr_ca, PTR_INIT(lchr, EFF_CFG)},
127     {EF_NUKE_CHR, "nuke chr", NULL, nchr_ca, PTR_INIT(nchr, EFF_CFG)},
128     {EF_NEWS_CHR, "news chr", NULL, rpt_ca, ARRAY_INIT(rpt, EFF_CFG)},
129     {EF_TREATY_FLAGS, "treaty flags", NULL, symbol_ca,
130      PTR_INIT(treaty_flags, EFF_CFG)},
131     {EF_ITEM, "item", NULL, ichr_ca, ARRAY_INIT(ichr, EFF_CFG)},
132     {EF_INFRASTRUCTURE, "infrastructure", NULL, intrchr_ca,
133      ARRAY_INIT(intrchr, EFF_CFG)},
134     {EF_PRODUCT, "product", NULL, pchr_ca, ARRAY_INIT(pchr, EFF_CFG)},
135     {EF_TABLE, "table", NULL, empfile_ca, ARRAY_INIT(empfile, EFF_CFG)},
136     {EF_SHIP_CHR_FLAGS, "ship chr flags", NULL, symbol_ca,
137      PTR_INIT(ship_chr_flags, EFF_CFG)},
138     {EF_PLANE_CHR_FLAGS, "plane chr flags", NULL, symbol_ca,
139      PTR_INIT(plane_chr_flags, EFF_CFG)},
140     {EF_LAND_CHR_FLAGS, "land chr flags", NULL, symbol_ca,
141      PTR_INIT(land_chr_flags, EFF_CFG)},
142     {EF_NUKE_CHR_FLAGS, "nuke chr flags", NULL, symbol_ca,
143      PTR_INIT(nuke_chr_flags, EFF_CFG)},
144     {EF_META, "meta", NULL, mdchr_ca, PTR_INIT(mdchr_ca, EFF_CFG)},
145     {EF_META_TYPE, "meta type", NULL, symbol_ca,
146      PTR_INIT(meta_type, EFF_CFG)},
147     {EF_META_FLAGS, "meta flags", NULL, symbol_ca,
148      PTR_INIT(meta_flags, EFF_CFG)},
149
150     /* Sentinel */
151     {EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
152 };