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