]> git.pond.sub.org Git - empserver/blob - include/file.h
(ef_init, ef_init_srv): Rename old ef_init() ef_init_srv(), call new
[empserver] / include / file.h
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.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     int ef_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     int flags;                  /* EFF_XY, ... */
46     int size;                   /* size of a table entry */
47     void (*init)(int, char *);  /* called after entry creation, unless null */
48     int (*postread)(int, char *); /* called after read, unless null */
49     int (*prewrite)(int, char *); /* called before write, unless null */
50     int fd;                     /* file descriptor, -1 if not open */
51     int baseid;                 /* id of first entry in cache */
52     int cids;                   /* # entries in cache */
53     int csize;                  /* cache size, in entries */
54     char *cache;                /* pointer to cache */
55     int fids;                   /* # entries in table */
56     struct castr *cadef;        /* table column selectors (column meta-data) */
57 };
58
59 /*
60  * struct empfile flags
61  */
62 /* Immutable flags */
63 /*
64  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
65  * group of such a table's entries can be safely obtained by
66  * dereferencing entry address cast to struct genitem *.
67  */
68 #define EFF_XY          bit(0)
69 #define EFF_OWNER       bit(1)
70 #define EFF_GROUP       bit(2)
71 /* Table is allocated statically */
72 #define EFF_STATIC      bit(3)
73 /* Flags set when table contents is mapped */
74 /* Table is entirely in memory */
75 #define EFF_MEM         bit(4)
76 /* Table is read-only */
77 #define EFF_RDONLY      bit(5)
78 /* Transient flags, just to control ef_open() */
79 /* Create table file, clobbering any existing file */
80 #define EFF_CREATE      bit(6)
81
82 /* Flags that may be passed to ef_open() */
83 #define EFF_OPEN        (EFF_MEM | EFF_RDONLY | EFF_CREATE)
84
85 /*
86  * Empire `file types'
87  * These are really table IDs.  Some tables are backed by files, some
88  * are compiled into the server.
89  */
90 /* Error value */
91 #define EF_BAD          -1
92 /* Dynamic game data tables */
93 #define EF_SECTOR       0
94 #define EF_SHIP         1
95 #define EF_PLANE        2
96 #define EF_LAND         3
97 #define EF_NUKE         4
98 #define EF_NEWS         5
99 #define EF_TREATY       6
100 #define EF_TRADE        7
101 #define EF_POWER        8
102 #define EF_NATION       9
103 #define EF_LOAN         10
104 #define EF_MAP          11
105 #define EF_BMAP         12
106 #define EF_COMM         13
107 #define EF_LOST         14
108 /* Static game data (configuration) */
109 #define EF_SECTOR_CHR   15
110 #define EF_SHIP_CHR     16
111 #define EF_PLANE_CHR    17
112 #define EF_LAND_CHR     18
113 #define EF_NUKE_CHR     19
114 #define EF_NEWS_CHR     20
115 #define EF_TREATY_FLAGS 21
116 #define EF_ITEM         22
117 #define EF_INFRASTRUCTURE   23
118 #define EF_PRODUCT      24
119 #define EF_TABLE        25
120 #define EF_SHIP_CHR_FLAGS       26
121 #define EF_PLANE_CHR_FLAGS      27
122 #define EF_LAND_CHR_FLAGS       28
123 #define EF_NUKE_CHR_FLAGS       29
124 #define EF_META         30
125 #define EF_META_TYPE    31
126 #define EF_META_FLAGS   32
127 #define EF_MAX          33
128
129 #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST)
130
131 extern struct castr *ef_cadef(int);
132 extern int ef_read(int, int, void *);
133 extern void *ef_ptr(int, int);
134 extern char *ef_nameof(int);
135 extern time_t ef_mtime(int);
136 extern int ef_open(int, int);
137 extern int ef_check(int);
138 extern int ef_close(int);
139 extern int ef_flush(int);
140 extern int ef_write(int, int, void *);
141 extern int ef_extend(int, int);
142 extern int ef_ensure_space(int, int, int);
143 extern int ef_nelem(int);
144 extern int ef_flags(int);
145 extern int ef_byname(char *);
146 extern int ef_byname_from(char *, int *);
147 extern void ef_init(void);
148
149 extern struct empfile empfile[EF_MAX + 1];
150
151 #endif /* _FILE_H_ */