]> git.pond.sub.org Git - empserver/blob - include/file.h
(ef_init): Remove cadef member from fileinit,
[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 files and their contents
29  * 
30  *  Known contributors to this file:
31  *    
32  */
33
34 #ifndef _FILE_H_
35 #define _FILE_H_
36
37 #include <stddef.h>
38
39 struct empfile {
40     char *name;                 /* Empire name (e.g., "treaty") */
41     char *file;                 /* file name (relative to data directory) */
42     int flags;                  /* misc stuff */
43     int mode;                   /* O_flags */
44     int size;                   /* size of object */
45     void (*init) (int, char *); /* call this when object is created */
46     int (*postread) (int, char *);      /* specific massage routines for items */
47     int (*prewrite) (int, char *);
48     int fd;                     /* file descriptor */
49     int baseid;                 /* starting item in cache */
50     int cids;                   /* # ids in cache */
51     int csize;                  /* size of cache in bytes */
52     char *cache;                /* pointer to cache */
53     int fids;                   /* # of ids in file */
54     struct castr *cadef;        /* ca defs selection list */
55 };
56
57 /*
58  * struct empfile flags
59  *
60  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
61  * group of such a file's record can be safely obtained by
62  * dereferencing its memory address cast to struct genitem *.
63  */
64 #define EFF_XY          bit(0)  /* has location */
65 #define EFF_MEM         bit(1)  /* stored entirely in-memory */
66 #define EFF_OWNER       bit(2)  /* has concept of owner */
67 #define EFF_GROUP       bit(3)  /* has concept of group */
68
69 /*
70  * Empire `file types'
71  * These are really table IDs.  Some tables are backed by files, some
72  * are compiled into the server.
73  * Historically, only table IDs 0..EF_MAX-1 existed.  All the
74  * functions operating on table IDs still reject the new indexes >=
75  * EF_MAX.  This needs to be rectified, carefully checking existing
76  * code, which could rely on unspoken assumptions about these tables.
77  */
78 /* Error value */
79 #define EF_BAD          -1
80 /* Dynamic game data tables: 0..EF_MAX-1 */
81 #define EF_SECTOR       0
82 #define EF_SHIP         1
83 #define EF_PLANE        2
84 #define EF_LAND         3
85 #define EF_NUKE         4
86 #define EF_NEWS         5
87 #define EF_TREATY       6
88 #define EF_TRADE        7
89 #define EF_POWER        8
90 #define EF_NATION       9
91 #define EF_LOAN         10
92 #define EF_MAP          11
93 #define EF_BMAP         12
94 #define EF_COMM         13
95 #define EF_LOST         14
96 #define EF_MAX          15
97 /* Static game data (configuation): EF_MAX.. */
98 #define EF_SECTOR_CHR   15
99 #define EF_SHIP_CHR     16
100 #define EF_PLANE_CHR    17
101 #define EF_LAND_CHR     18
102 #define EF_NUKE_CHR     19
103 #if 0 /* doesn't exist yet */
104 #define EF_NEWS_CHR
105 #endif
106 #define EF_TREATY_CHR   20
107 #define EF_ITEM         21
108 #define EF_INFRASTRUCTURE   22
109 #define EF_PRODUCT      23
110 #define EF_TABLE        24
111
112 #define EF_NMAP         222     /* Kinda bogus, but used to describe a newdesmap
113                                    instead of bmap or map. */
114
115 struct fileinit {
116     int ef_type;
117     void (*init) (int, char *);
118     int (*postread) (int, char *);
119     int (*prewrite) (int, char *);
120 };
121
122 extern struct castr *ef_cadef(int);
123 extern int ef_read(int, int, void *);
124 extern char *ef_ptr(int, int);
125 extern char *ef_nameof(int);
126 extern time_t ef_mtime(int);
127 extern int ef_open(int, int, int);
128 extern int ef_check(int);
129 extern int ef_close(int);
130 extern int ef_flush(int);
131 extern int ef_write(int, int, void *);
132 extern int ef_extend(int, int);
133 extern int ef_ensure_space(int, int, int);
134 extern void ef_zapcache(int);
135 extern int ef_nelem(int);
136 extern int ef_flags(int);
137 extern int ef_byname(char *);
138
139 extern struct empfile empfile[];
140
141 #endif /* _FILE_H_ */