]> git.pond.sub.org Git - empserver/blob - include/file.h
(ichr, pchr, dchr, intrchr): Move initializer to new builtin config
[empserver] / include / file.h
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.h: Describes Empire tables (`files' for historical reasons)
29  * 
30  *  Known contributors to this file:
31  *     Markus Armbruster, 2005
32  */
33
34 #ifndef FILE_H
35 #define FILE_H
36
37 #include <stddef.h>
38 #include <time.h>
39
40 struct empfile {
41     /* Members with immutable values */
42     int uid;                    /* Table ID */
43     char *name;                 /* Empire name (e.g., "treaty") */
44     char *file;                 /* if backed by file, file name relative to
45                                    data directory */
46     struct castr *cadef;        /* table column selectors (column meta-data) */
47     int size;                   /* size of a table entry */
48     int flags;                  /* only EFF_IMMUTABLE immutable, see below
49                                    for use of remaining bits */
50     /* Members whose values are fixed when the cache is mapped */
51     char *cache;                /* pointer to cache */
52     int csize;                  /* cache size, in entries */
53     /* and flags bit EFF_MEM */
54     /* Members whose values may vary throughout operation */
55     int baseid;                 /* id of first entry in cache */
56     int cids;                   /* # entries in cache */
57     int fids;                   /* # entries in table */
58     int fd;                     /* file descriptor, -1 if not open */
59     /* and flags bit EFF_RDONLY */
60     /* User callbacks */
61     void (*init)(int, void *);  /* called after entry creation, unless null */
62     int (*postread)(int, void *); /* called after read, unless null */
63     int (*prewrite)(int, void *); /* called before write, unless null */
64 };
65
66 /*
67  * Flag bits for struct empfile member flags
68  * Immutable flags are properties of the table and thus cannot change.
69  * The remaining flags record how the table is being used.
70  */
71 /* Immutable flags, fixed at compile-time */
72 /*
73  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
74  * group of such a table's entries can be safely obtained by
75  * dereferencing entry address cast to struct genitem *.
76  */
77 #define EFF_XY          bit(0)
78 #define EFF_OWNER       bit(1)
79 #define EFF_GROUP       bit(2)
80 /* Table is allocated statically */
81 #define EFF_STATIC      bit(3)
82 /* All the immutable flags */
83 #define EFF_IMMUTABLE   (EFF_XY | EFF_OWNER | EFF_GROUP | EFF_STATIC)
84 /* Flags set when table contents is mapped */
85 /* Table is entirely in memory */
86 #define EFF_MEM         bit(8)
87 /* Table is read-only */
88 #define EFF_RDONLY      bit(9)
89 /* Table is customized (configuration tables only) */
90 #define EFF_CUSTOM      bit(10)
91 /* Transient flags, only occur in argument of ef_open() */
92 /* Create table file, clobbering any existing file */
93 #define EFF_CREATE      bit(11)
94
95 /*
96  * Empire `file types'
97  * These are really table IDs.  Some tables are backed by files, some
98  * are compiled into the server.
99  */
100 enum {
101     /* Error value */
102     EF_BAD = -1,
103     /* Dynamic game data tables */
104     EF_SECTOR,
105     EF_SHIP,
106     EF_PLANE,
107     EF_LAND,
108     EF_NUKE,
109     EF_NEWS,
110     EF_TREATY,
111     EF_TRADE,
112     EF_POWER,
113     EF_NATION,
114     EF_LOAN,
115     EF_MAP,
116     EF_BMAP,
117     EF_COMM,
118     EF_LOST,
119     EF_REALM,
120     /* Static game data (configuration) */
121     /* Order is relevant; see read_builtin_tables() */
122     EF_ITEM,
123     EF_PRODUCT,
124     EF_SECTOR_CHR,
125     EF_SHIP_CHR,
126     EF_PLANE_CHR,
127     EF_LAND_CHR,
128     EF_NUKE_CHR,
129     EF_NEWS_CHR,
130     EF_INFRASTRUCTURE,
131     EF_TABLE,
132     EF_META,
133     /* Symbol tables */
134     EF_AGREEMENT_STATUS,
135     EF_LAND_CHR_FLAGS,
136     EF_LEVEL,
137     EF_META_FLAGS,
138     EF_META_TYPE,
139     EF_MISSIONS,
140     EF_NATION_FLAGS,
141     EF_NATION_REJECTS,
142     EF_NATION_RELATIONS,
143     EF_NATION_STATUS,
144     EF_NUKE_CHR_FLAGS,
145     EF_PACKING,
146     EF_PAGE_HEADINGS,
147     EF_PLAGUE_STAGES,
148     EF_PLANE_CHR_FLAGS,
149     EF_PLANE_FLAGS,
150     EF_RESOURCES,
151     EF_RETREAT_FLAGS,
152     EF_SECTOR_NAVIGATION,
153     EF_SHIP_CHR_FLAGS,
154     EF_TREATY_FLAGS,
155     /* Views */
156     EF_COUNTRY,
157     /* Number of types: */
158     EF_MAX
159 };
160
161 #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_REALM)
162
163 extern struct castr *ef_cadef(int);
164 extern int ef_read(int, int, void *);
165 extern void *ef_ptr(int, int);
166 extern char *ef_nameof(int);
167 extern time_t ef_mtime(int);
168 extern int ef_open(int, int);
169 extern int ef_check(int);
170 extern int ef_close(int);
171 extern int ef_flush(int);
172 extern int ef_write(int, int, void *);
173 extern int ef_extend(int, int);
174 extern int ef_ensure_space(int, int, int);
175 extern int ef_nelem(int);
176 extern int ef_flags(int);
177 extern int ef_byname(char *);
178 extern int ef_byname_from(char *, int *);
179 extern void ef_init(void);
180 extern int ef_verify(void);
181 extern int ef_elt_byname(int, char *);
182
183 extern struct empfile empfile[EF_MAX + 1];
184
185 #endif