]> git.pond.sub.org Git - empserver/blob - src/lib/global/file.c
(dchr_ca, packing, empfile): Add packing symbol table.
[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 /* Number of elements in ARRAY.  */
58 #define SZ(array) (sizeof(array) / sizeof((array)[0]))
59
60 /* Initializers for members flags... */
61 /* Unmapped cache */
62 #define UNMAPPED_CACHE(type, flags) \
63     sizeof(type), flags, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
64 /*
65  * Mapped cache, array with known size.
66  * Members cids, fids are not set.
67  */
68 #define ARRAY_CACHE(array, flags) \
69     sizeof(*(array)), (flags), (char *)(array), \
70     SZ((array)), 0, 0, 0, -1, NULL, NULL, NULL
71 /*
72  * Mapped cache, array with unknown size.
73  * Members csize, cids, fids are not set.
74  */
75 #define PTR_CACHE(ptr, flags) \
76     sizeof(*(ptr)), (flags), (char *)(ptr), \
77     0, 0, 0, 0, -1, NULL, NULL, NULL
78 /*
79  * Array-backed table.
80  * The array's last element is the sentinel.
81  */
82 #define ARRAY_TABLE(array, flags) \
83     sizeof(*(array)), (flags), (char *)(array), \
84     SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL, NULL
85
86 /* Common configuration table flags */
87 #define EFF_CFG (EFF_RDONLY | EFF_MEM | EFF_STATIC)
88
89 struct empfile empfile[] = {
90     /*
91      * How empfile[] is initialized:
92      *
93      * Members uid, name, file, size, cadef, and the EFF_IMMUTABLE
94      * bits of flags get their final value.
95      * If flags & EFF_STATIC, the cache is mapped here, and members
96      * cache, csize get their final value.
97      * Members baseid, cids, fids and the EFF_MEM|EFF_RDONLY bits of
98      * flags are initialized according the initial cache contents.
99      * Member fd is initialized to -1.
100      * Members init, postread, prewrite get initialized to NULL, but
101      * that can be changed by users.
102      *
103      * Whatever of the above can't be done here must be done in
104      * ef_init().
105      */
106
107     /* Dynamic game data */
108     {EF_SECTOR, "sect", "sector", sect_ca,
109      UNMAPPED_CACHE(struct sctstr, EFF_XY | EFF_OWNER)},
110     {EF_SHIP, "ship", "ship", ship_ca,
111      UNMAPPED_CACHE(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
112     {EF_PLANE, "plane", "plane", plane_ca,
113      UNMAPPED_CACHE(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
114     {EF_LAND, "land", "land", land_ca,
115      UNMAPPED_CACHE(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
116     {EF_NUKE, "nuke", "nuke", nuke_ca,
117      UNMAPPED_CACHE(struct nukstr, EFF_XY | EFF_OWNER)},
118     {EF_NEWS, "news", "news", news_ca,
119      UNMAPPED_CACHE(struct nwsstr, 0)},
120     {EF_TREATY, "treaty", "treaty", treaty_ca,
121      UNMAPPED_CACHE(struct trtstr, 0)},
122     {EF_TRADE, "trade", "trade", trade_ca,
123      UNMAPPED_CACHE(struct trdstr, 0)},
124     {EF_POWER, "pow", "power", NULL,
125      UNMAPPED_CACHE(struct powstr, 0)},
126     {EF_NATION, "nat", "nation", nat_ca,
127      UNMAPPED_CACHE(struct natstr, EFF_OWNER)},
128     {EF_LOAN, "loan", "loan", loan_ca,
129      UNMAPPED_CACHE(struct lonstr, 0)},
130     {EF_MAP, "map", "map", NULL,
131      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
132     {EF_BMAP, "bmap", "bmap", NULL,
133      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
134     {EF_COMM, "commodity", "commodity", commodity_ca,
135      UNMAPPED_CACHE(struct comstr, 0)},
136     {EF_LOST, "lost", "lostitems", lost_ca,
137      UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
138
139     /* Static game data (configuration) */
140     {EF_SECTOR_CHR, "sect chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},
141     {EF_SHIP_CHR, "ship chr", "ship_def", mchr_ca, ARRAY_CACHE(mchr, EFF_CFG)},
142     {EF_PLANE_CHR, "plane chr", "plane_def", plchr_ca, ARRAY_CACHE(plchr, EFF_CFG)},
143     {EF_LAND_CHR, "land chr", "land_def", lchr_ca, ARRAY_CACHE(lchr, EFF_CFG)},
144     {EF_NUKE_CHR, "nuke chr", "nuke_def", nchr_ca, ARRAY_CACHE(nchr, EFF_CFG)},
145     {EF_NEWS_CHR, "news chr", NULL, rpt_ca, ARRAY_TABLE(rpt, EFF_CFG)},
146     {EF_TREATY_FLAGS, "treaty flags", NULL, symbol_ca,
147      PTR_CACHE(treaty_flags, EFF_CFG)},
148     {EF_ITEM, "item", "item_def", ichr_ca, ARRAY_TABLE(ichr, EFF_CFG)},
149     {EF_INFRASTRUCTURE, "infrastructure", "infrastructure_def", intrchr_ca,
150      ARRAY_TABLE(intrchr, EFF_CFG)},
151     {EF_PRODUCT, "product", "product_def", pchr_ca, ARRAY_TABLE(pchr, EFF_CFG)},
152     {EF_TABLE, "table", NULL, empfile_ca, ARRAY_TABLE(empfile, EFF_CFG)},
153     {EF_SHIP_CHR_FLAGS, "ship chr flags", NULL, symbol_ca,
154      PTR_CACHE(ship_chr_flags, EFF_CFG)},
155     {EF_PLANE_CHR_FLAGS, "plane chr flags", NULL, symbol_ca,
156      PTR_CACHE(plane_chr_flags, EFF_CFG)},
157     {EF_LAND_CHR_FLAGS, "land chr flags", NULL, symbol_ca,
158      PTR_CACHE(land_chr_flags, EFF_CFG)},
159     {EF_NUKE_CHR_FLAGS, "nuke chr flags", NULL, symbol_ca,
160      PTR_CACHE(nuke_chr_flags, EFF_CFG)},
161     {EF_META, "meta", NULL, mdchr_ca, PTR_CACHE(mdchr_ca, EFF_CFG)},
162     {EF_META_TYPE, "meta type", NULL, symbol_ca,
163      PTR_CACHE(meta_type, EFF_CFG)},
164     {EF_META_FLAGS, "meta flags", NULL, symbol_ca,
165      PTR_CACHE(meta_flags, EFF_CFG)},
166     {EF_MISSIONS, "missions", NULL, symbol_ca,
167      PTR_CACHE(missions, EFF_CFG)},
168     {EF_PLANE_FLAGS, "plane flags", NULL, symbol_ca,
169      PTR_CACHE(plane_flags, EFF_CFG)},
170     {EF_RETREAT_FLAGS, "retreat flags", NULL, symbol_ca,
171      PTR_CACHE(retreat_flags, EFF_CFG)},
172     {EF_NATION_FLAGS, "nation flags", NULL, symbol_ca,
173      PTR_CACHE(nation_flags, EFF_CFG)},
174     {EF_NATION_RELATIONS, "nation relationships", NULL, symbol_ca,
175      PTR_CACHE(nation_relations, EFF_CFG)},
176     {EF_LEVEL, "level", NULL, symbol_ca, PTR_CACHE(level, EFF_CFG)},
177     {EF_AGREEMENT_STATUS, "agreement status", NULL, symbol_ca,
178      PTR_CACHE(agreement_statuses, EFF_CFG)},
179     {EF_PLAGUE_STAGES, "plague stages", NULL, symbol_ca,
180      PTR_CACHE(plague_stages, EFF_CFG)},
181     {EF_PACKING, "packing", NULL, symbol_ca,
182      PTR_CACHE(packing, EFF_CFG)},
183
184     /* Sentinel */
185     {EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
186 };