2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * file.h: Describes Empire tables (`files' for historical reasons)
30 * Known contributors to this file:
31 * Markus Armbruster, 2005-2008
40 /* Members with immutable values */
41 int uid; /* Table ID */
42 char *name; /* Empire name (e.g., "treaty") */
43 char *file; /* if backed by file, file name relative to
45 struct castr *cadef; /* table column selectors (column meta-data) */
46 int size; /* size of a table entry */
47 int flags; /* only EFF_IMMUTABLE immutable, see below
48 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 /* flags bit EFF_MEM also fixed then */
55 /* Members whose values may vary throughout operation */
56 int baseid; /* id of first entry in cache */
57 int cids; /* # entries in cache */
58 int fids; /* # entries in table */
59 int fd; /* file descriptor, -1 if not open */
60 /* flags bits EFF_PRIVATE, EFF_CUSTOM also vary */
63 int (*postread)(int, void *); /* called after read, unless null */
64 int (*prewrite)(int, void *); /* called before write, unless null */
75 * Flag bits for struct empfile member flags
76 * Immutable flags are properties of the table and thus cannot change.
77 * The remaining flags record how the table is being used.
79 /* Immutable flags, fixed at compile-time */
80 /* Dereferencing entry address cast to struct emptypedstr * is safe */
81 #define EFF_TYPED bit(0)
83 * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
84 * group of such a table's entries can be safely obtained by
85 * dereferencing the entry's address cast to struct empobj *.
88 #define EFF_OWNER bit(2)
89 #define EFF_GROUP bit(3)
90 /* Table is allocated statically */
91 #define EFF_STATIC bit(4)
92 /* All the immutable flags */
93 #define EFF_IMMUTABLE \
94 (EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP | EFF_STATIC)
95 /* Flags set when table contents is mapped */
96 /* Table is entirely in memory */
97 #define EFF_MEM bit(8)
98 /* Table is privately mapped: changes don't affect the underlying file */
99 #define EFF_PRIVATE bit(9)
100 /* Table is customized (configuration tables only) */
101 #define EFF_CUSTOM bit(10)
102 /* Don't update timestamps */
103 #define EFF_NOTIME bit(11)
104 /* Transient flags, only occur in argument of ef_open() */
105 /* Create table file, clobbering any existing file */
106 #define EFF_CREATE bit(16)
109 * Empire `file types'
110 * These are really table IDs. Some tables are backed by files, some
111 * are compiled into the server, some initialized from configuration
117 /* Dynamic game data tables */
136 /* Static game data (configuration) */
137 /* Order is relevant; see read_builtin_tables() */
147 EF_UPDATES, /* not actually static */
150 EF_META, /* not really configuration */
170 EF_SECTOR_NAVIGATION,
175 /* Number of types: */
179 #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_DYNMAX)
180 #define EF_IS_VIEW(type) (EF_COUNTRY <= (type) && (type) < EF_MAX)
182 extern struct castr *ef_cadef(int);
183 extern int ef_read(int, int, void *);
184 extern void *ef_ptr(int, int);
185 extern char *ef_nameof(int);
186 extern time_t ef_mtime(int);
187 extern int ef_open(int, int, int);
188 extern int ef_check(int);
189 extern int ef_close(int);
190 extern int ef_flush(int);
191 extern void ef_blank(int, int, void *);
192 extern int ef_write(int, int, void *);
193 extern void ef_set_uid(int, void *, int);
194 extern int ef_extend(int, int);
195 extern int ef_ensure_space(int, int, int);
196 extern int ef_truncate(int, int);
197 extern int ef_nelem(int);
198 extern int ef_flags(int);
199 extern int ef_byname(char *);
200 extern int ef_byname_from(char *, int *);
201 extern int ef_verify(void);
202 extern int ef_elt_byname(int, char *);
204 extern struct empfile empfile[EF_MAX + 1];
205 extern void empfile_init(void);
206 extern void empfile_fixup(void);