/*
* struct empfile flags
*/
+/* Immutable flags */
/*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
* group of such a table's entries can be safely obtained by
#define EFF_XY bit(0)
#define EFF_OWNER bit(1)
#define EFF_GROUP bit(2)
+/* Table is allocated statically */
+#define EFF_STATIC bit(3)
+/* Flags set when table contents is mapped */
/* Table is entirely in memory */
-#define EFF_MEM bit(3)
+#define EFF_MEM bit(4)
/* Table is read-only */
-#define EFF_RDONLY bit(4)
+#define EFF_RDONLY bit(5)
+/* Transient flags, just to control ef_open() */
/* Create table file, clobbering any existing file */
-#define EFF_CREATE bit(5)
-/* Table is allocated statically */
-#define EFF_STATIC bit(6)
+#define EFF_CREATE bit(6)
/* Flags that may be passed to ef_open() */
#define EFF_OPEN (EFF_MEM | EFF_RDONLY | EFF_CREATE)
* Empire `file types'
* These are really table IDs. Some tables are backed by files, some
* are compiled into the server.
- * Historically, only table IDs 0..EF_MAX-1 existed. All the
- * functions operating on table IDs still reject the new indexes >=
- * EF_MAX. This needs to be rectified, carefully checking existing
- * code, which could rely on unspoken assumptions about these tables.
*/
/* Error value */
#define EF_BAD -1
-/* Dynamic game data tables: 0..EF_MAX-1 */
+/* Dynamic game data tables */
#define EF_SECTOR 0
#define EF_SHIP 1
#define EF_PLANE 2
#define EF_BMAP 12
#define EF_COMM 13
#define EF_LOST 14
-#define EF_MAX 15
-/* Static game data (configuration): EF_MAX.. */
+/* Static game data (configuration) */
#define EF_SECTOR_CHR 15
#define EF_SHIP_CHR 16
#define EF_PLANE_CHR 17
#define EF_META 29
#define EF_META_TYPE 30
#define EF_META_FLAGS 31
+#define EF_MAX 32
+
+#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST)
struct fileinit {
int ef_type;
extern int ef_byname(char *);
extern int ef_byname_from(char *, int *);
-extern struct empfile empfile[];
+extern struct empfile empfile[EF_MAX];
#endif /* _FILE_H_ */
/* FIXME document dump format */
/* FIXME don't dump stuff that's useless due to options */
-/*
- * Search empfile[] for element named NAME, return its index.
- * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
- * several.
- * FIXME Merge into ef_byname(). ef_byname() stops at EF_MAX!
- */
-static int
-my_ef_byname(char *name)
-{
- return stmtch(name, empfile, offsetof(struct empfile, name),
- sizeof(empfile[0]));
-}
-
/*
* Evaluate a attribute of an object into VAL, return VAL.
* TYPE is the attribute's type.
if (!p)
return RET_SYN;
- type = my_ef_byname(p);
- if (type >= EF_MAX || (meta && type >=0))
- return xdchr(type, meta);
- else if (type >= 0) {
- return xditem(type, player->argp[2]);
+ type = ef_byname(p);
+ if (type >= 0) {
+ if (meta || !EF_IS_GAME_STATE(type))
+ return xdchr(type, meta);
+ else
+ return xditem(type, player->argp[2]);
} else if (!strncmp(p, "opt", strlen(p))) {
return xdopt();
} else if (!strncmp(p, "ver", strlen(p))) {
exit(1);
}
for (i = 0; i < EF_MAX; i++) {
+ if (!EF_IS_GAME_STATE(i))
+ continue;
if (!ef_open(i, EFF_CREATE)) {
perror("ef_open");
exit(1);
ef_write(EF_BMAP, i, map);
}
for (i = 0; i < EF_MAX; i++) {
+ if (!EF_IS_GAME_STATE(i))
+ continue;
ef_close(i);
}