]> git.pond.sub.org Git - empserver/blob - src/lib/global/file.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / global / file.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 <config.h>
35
36 #include <stddef.h>
37 #include "misc.h"
38 #include "xy.h"
39 #include "loan.h"
40 #include "nsc.h"
41 #include "nuke.h"
42 #include "plane.h"
43 #include "ship.h"
44 #include "land.h"
45 #include "sect.h"
46 #include "trade.h"
47 #include "treaty.h"
48 #include "file.h"
49 #include "power.h"
50 #include "news.h"
51 #include "nat.h"
52 #include "lost.h"
53 #include "product.h"
54
55 #include "commodity.h"
56 #include "nsc.h"
57
58 /* Number of elements in ARRAY.  */
59 #define SZ(array) (sizeof(array) / sizeof((array)[0]))
60
61 /* Initializers for members flags... */
62 /* Unmapped cache */
63 #define UNMAPPED_CACHE(type, flags) \
64     sizeof(type), flags, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL
65 /*
66  * Mapped cache, array with known size.
67  * Members cids, fids are not set.
68  */
69 #define ARRAY_CACHE(array, flags) \
70     sizeof(*(array)), (flags), (char *)(array), \
71     SZ((array)), 0, 0, 0, -1, NULL, NULL, NULL
72 /*
73  * Mapped cache, array with unknown size.
74  * Members csize, cids, fids are not set.
75  */
76 #define PTR_CACHE(ptr, flags) \
77     sizeof(*(ptr)), (flags), (char *)(ptr), \
78     0, 0, 0, 0, -1, NULL, NULL, NULL
79 /*
80  * Array-backed table.
81  * The array's last element is the sentinel.
82  */
83 #define ARRAY_TABLE(array, flags) \
84     sizeof(*(array)), (flags), (char *)(array), \
85     SZ((array)), 0, SZ((array)) - 1, SZ((array)) - 1, -1, NULL, NULL, NULL
86
87 /* Common configuration table flags */
88 #define EFF_CFG (EFF_RDONLY | EFF_MEM | EFF_STATIC)
89
90 struct empfile empfile[] = {
91     /*
92      * How this initializer works:
93      *
94      * Members uid, name, file, size, cadef, and the EFF_IMMUTABLE
95      * bits of flags get their final value.
96      * If flags & EFF_STATIC, the cache is mapped here, and members
97      * cache, csize get their final value.
98      * Members baseid, cids, fids and the EFF_MEM|EFF_RDONLY bits of
99      * flags are initialized according the initial cache contents.
100      * Member fd is initialized to -1.
101      * Members init, postread, prewrite get initialized to NULL, but
102      * that can be changed by users.
103      *
104      * Whatever of the above can't be done here must be done in
105      * ef_init().
106      */
107
108     /*
109      * Keep in mind that player command arguments are matched against
110      * member name; no whitespace please.
111      */
112
113     /* Dynamic game data */
114     {EF_SECTOR, "sect", "sector", sect_ca,
115      UNMAPPED_CACHE(struct sctstr, EFF_XY | EFF_OWNER)},
116     {EF_SHIP, "ship", "ship", ship_ca,
117      UNMAPPED_CACHE(struct shpstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
118     {EF_PLANE, "plane", "plane", plane_ca,
119      UNMAPPED_CACHE(struct plnstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
120     {EF_LAND, "land", "land", land_ca,
121      UNMAPPED_CACHE(struct lndstr, EFF_XY | EFF_OWNER | EFF_GROUP)},
122     {EF_NUKE, "nuke", "nuke", nuke_ca,
123      UNMAPPED_CACHE(struct nukstr, EFF_XY | EFF_OWNER)},
124     {EF_NEWS, "news", "news", news_ca,
125      UNMAPPED_CACHE(struct nwsstr, 0)},
126     {EF_TREATY, "treaty", "treaty", treaty_ca,
127      UNMAPPED_CACHE(struct trtstr, 0)},
128     {EF_TRADE, "trade", "trade", trade_ca,
129      UNMAPPED_CACHE(struct trdstr, 0)},
130     {EF_POWER, "pow", "power", NULL,
131      UNMAPPED_CACHE(struct powstr, 0)},
132     {EF_NATION, "nat", "nation", nat_ca,
133      UNMAPPED_CACHE(struct natstr, EFF_OWNER)},
134     {EF_LOAN, "loan", "loan", loan_ca,
135      UNMAPPED_CACHE(struct lonstr, 0)},
136     {EF_MAP, "map", "map", NULL,
137      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
138     {EF_BMAP, "bmap", "bmap", NULL,
139      0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
140     {EF_COMM, "commodity", "commodity", commodity_ca,
141      UNMAPPED_CACHE(struct comstr, 0)},
142     {EF_LOST, "lost", "lostitems", lost_ca,
143      UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
144     {EF_REALM, "realm", "realms", realm_ca,
145      UNMAPPED_CACHE(struct realmstr, EFF_OWNER)},
146
147     /* Static game data (configuration) */
148     {EF_SECTOR_CHR, "sect-chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},
149     {EF_SHIP_CHR, "ship-chr", "ship_def", mchr_ca, ARRAY_CACHE(mchr, EFF_CFG)},
150     {EF_PLANE_CHR, "plane-chr", "plane_def", plchr_ca, ARRAY_CACHE(plchr, EFF_CFG)},
151     {EF_LAND_CHR, "land-chr", "land_def", lchr_ca, ARRAY_CACHE(lchr, EFF_CFG)},
152     {EF_NUKE_CHR, "nuke-chr", "nuke_def", nchr_ca, ARRAY_CACHE(nchr, EFF_CFG)},
153     {EF_NEWS_CHR, "news-chr", NULL, rpt_ca, ARRAY_TABLE(rpt, EFF_CFG)},
154     {EF_TREATY_FLAGS, "treaty-flags", NULL, symbol_ca,
155      PTR_CACHE(treaty_flags, EFF_CFG)},
156     {EF_ITEM, "item", "item_def", ichr_ca, ARRAY_TABLE(ichr, EFF_CFG)},
157     {EF_INFRASTRUCTURE, "infrastructure", "infrastructure_def", intrchr_ca,
158      ARRAY_TABLE(intrchr, EFF_CFG)},
159     {EF_PRODUCT, "product", "product_def", pchr_ca, ARRAY_TABLE(pchr, EFF_CFG)},
160     {EF_TABLE, "table", NULL, empfile_ca, ARRAY_TABLE(empfile, EFF_CFG)},
161     {EF_SHIP_CHR_FLAGS, "ship-chr-flags", NULL, symbol_ca,
162      PTR_CACHE(ship_chr_flags, EFF_CFG)},
163     {EF_PLANE_CHR_FLAGS, "plane-chr-flags", NULL, symbol_ca,
164      PTR_CACHE(plane_chr_flags, EFF_CFG)},
165     {EF_LAND_CHR_FLAGS, "land-chr-flags", NULL, symbol_ca,
166      PTR_CACHE(land_chr_flags, EFF_CFG)},
167     {EF_NUKE_CHR_FLAGS, "nuke-chr-flags", NULL, symbol_ca,
168      PTR_CACHE(nuke_chr_flags, EFF_CFG)},
169     {EF_META, "meta", NULL, mdchr_ca, PTR_CACHE(mdchr_ca, EFF_CFG)},
170     {EF_META_TYPE, "meta-type", NULL, symbol_ca,
171      PTR_CACHE(meta_type, EFF_CFG)},
172     {EF_META_FLAGS, "meta-flags", NULL, symbol_ca,
173      PTR_CACHE(meta_flags, EFF_CFG)},
174     {EF_MISSIONS, "missions", NULL, symbol_ca, PTR_CACHE(missions, EFF_CFG)},
175     {EF_PLANE_FLAGS, "plane-flags", NULL, symbol_ca,
176      PTR_CACHE(plane_flags, EFF_CFG)},
177     {EF_RETREAT_FLAGS, "retreat-flags", NULL, symbol_ca,
178      PTR_CACHE(retreat_flags, EFF_CFG)},
179     {EF_NATION_FLAGS, "nation-flags", NULL, symbol_ca,
180      PTR_CACHE(nation_flags, EFF_CFG)},
181     {EF_NATION_RELATIONS, "nation-relationships", NULL, symbol_ca,
182      PTR_CACHE(nation_relations, EFF_CFG)},
183     {EF_LEVEL, "level", NULL, symbol_ca, PTR_CACHE(level, EFF_CFG)},
184     {EF_AGREEMENT_STATUS, "agreement-status", NULL, symbol_ca,
185      PTR_CACHE(agreement_statuses, EFF_CFG)},
186     {EF_PLAGUE_STAGES, "plague-stages", NULL, symbol_ca,
187      PTR_CACHE(plague_stages, EFF_CFG)},
188     {EF_PACKING, "packing", NULL, symbol_ca, PTR_CACHE(packing, EFF_CFG)},
189     {EF_RESOURCES, "resources", NULL, symbol_ca, PTR_CACHE(resources, EFF_CFG)},
190     {EF_NATION_STATUS, "nation-status", NULL, symbol_ca,
191      PTR_CACHE(nation_status, EFF_CFG)},
192     {EF_SECTOR_NAVIGATION, "sector-navigation", NULL, symbol_ca,
193      PTR_CACHE(sector_navigation, EFF_CFG)},
194
195     /* Views */
196     {EF_COUNTRY, "country", NULL, cou_ca, UNMAPPED_CACHE(struct natstr, 0)},
197
198     /* Sentinel */
199     {EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL},
200 };