]> git.pond.sub.org Git - empserver/blobdiff - include/file.h
WIP empdump, %a
[empserver] / include / file.h
index 6df412575b86447d01e6b5e08abcf2f20720e95a..1242a660f928b5ff2bf045bcc8dd32b043750b18 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
@@ -34,7 +34,6 @@
 #ifndef FILE_H
 #define FILE_H
 
-#include <stddef.h>
 #include <time.h>
 
 struct empfile {
@@ -47,16 +46,19 @@ struct empfile {
     int size;                  /* size of a table entry */
     int flags;                 /* only EFF_IMMUTABLE immutable, see below
                                   for use of remaining bits */
+
     /* Members whose values are fixed when the cache is mapped */
     char *cache;               /* pointer to cache */
     int csize;                 /* cache size, in entries */
-    /* and flags bit EFF_MEM */
+    /* flags bit EFF_MEM also fixed then */
+
     /* Members whose values may vary throughout operation */
     int baseid;                        /* id of first entry in cache */
     int cids;                  /* # entries in cache */
     int fids;                  /* # entries in table */
     int fd;                    /* file descriptor, -1 if not open */
-    /* and flags bit EFF_RDONLY */
+    /* flags bits EFF_PRIVATE, EFF_CUSTOM also vary */
+
     /* User callbacks */
     void (*init)(int, void *); /* called after entry creation, unless null */
     int (*postread)(int, void *); /* called after read, unless null */
@@ -72,7 +74,7 @@ struct empfile {
 /*
  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
  * group of such a table's entries can be safely obtained by
- * dereferencing entry address cast to struct genitem *.
+ * dereferencing entry address cast to struct empobj *.
  */
 #define EFF_XY         bit(0)
 #define EFF_OWNER      bit(1)
@@ -84,67 +86,86 @@ struct empfile {
 /* Flags set when table contents is mapped */
 /* Table is entirely in memory */
 #define EFF_MEM                bit(8)
-/* Table is read-only */
-#define EFF_RDONLY     bit(9)
+/* Table is privately mapped: changes don't affect the underlying file */
+#define EFF_PRIVATE    bit(9)
+/* Table is customized (configuration tables only) */
+#define EFF_CUSTOM     bit(10)
 /* Transient flags, only occur in argument of ef_open() */
 /* Create table file, clobbering any existing file */
-#define EFF_CREATE     bit(10)
+#define EFF_CREATE     bit(11)
 
 /*
  * Empire `file types'
  * These are really table IDs.  Some tables are backed by files, some
- * are compiled into the server.
+ * are compiled into the server, some initialized from configuration
+ * files.
  */
-/* Error value */
-#define EF_BAD         -1
-/* Dynamic game data tables */
-#define EF_SECTOR      0
-#define EF_SHIP                1
-#define EF_PLANE       2
-#define        EF_LAND         3
-#define EF_NUKE                4
-#define EF_NEWS                5
-#define EF_TREATY      6
-#define EF_TRADE       7
-#define EF_POWER       8
-#define EF_NATION      9
-#define EF_LOAN                10
-#define        EF_MAP          11
-#define EF_BMAP                12
-#define EF_COMM         13
-#define EF_LOST         14
-/* Static game data (configuration) */
-#define EF_SECTOR_CHR  15
-#define EF_SHIP_CHR    16
-#define EF_PLANE_CHR   17
-#define EF_LAND_CHR    18
-#define EF_NUKE_CHR    19
-#define EF_NEWS_CHR    20
-#define EF_TREATY_FLAGS        21
-#define EF_ITEM                22
-#define EF_INFRASTRUCTURE   23
-#define EF_PRODUCT     24
-#define EF_TABLE       25
-#define EF_SHIP_CHR_FLAGS      26
-#define EF_PLANE_CHR_FLAGS     27
-#define EF_LAND_CHR_FLAGS      28
-#define EF_NUKE_CHR_FLAGS      29
-#define EF_META                30
-#define EF_META_TYPE   31
-#define EF_META_FLAGS  32
-#define EF_MISSIONS    33
-#define EF_PLANE_FLAGS 34
-#define EF_RETREAT_FLAGS       35
-#define EF_NATION_FLAGS        36
-#define EF_NATION_RELATIONS 37
-#define EF_LEVEL       38
-#define EF_AGREEMENT_STATUS    39
-#define EF_PLAGUE_STAGES       40
-#define EF_PACKING     41
-#define EF_RESOURCES   42
-#define EF_MAX         43
+enum {
+    /* Error value */
+    EF_BAD = -1,
+    /* Dynamic game data tables */
+    EF_SECTOR,
+    EF_SHIP,
+    EF_PLANE,
+    EF_LAND,
+    EF_NUKE,
+    EF_NEWS,
+    EF_TREATY,
+    EF_TRADE,
+    EF_POWER,
+    EF_NATION,
+    EF_LOAN,
+    EF_MAP,
+    EF_BMAP,
+    EF_COMM,
+    EF_LOST,
+    EF_REALM,
+    EF_GAME,
+    EF_DYNMAX = EF_GAME,
+    /* Static game data (configuration) */
+    /* Order is relevant; see read_builtin_tables() */
+    EF_ITEM,
+    EF_PRODUCT,
+    EF_SECTOR_CHR,
+    EF_SHIP_CHR,
+    EF_PLANE_CHR,
+    EF_LAND_CHR,
+    EF_NUKE_CHR,
+    EF_NEWS_CHR,
+    EF_INFRASTRUCTURE,
+    EF_UPDATES,                        /* not actually static */
+    EF_TABLE,
+    EF_META,                   /* not really configuration */
+    /* Symbol tables */
+    EF_AGREEMENT_STATUS,
+    EF_LAND_CHR_FLAGS,
+    EF_LEVEL,
+    EF_META_FLAGS,
+    EF_META_TYPE,
+    EF_MISSIONS,
+    EF_NATION_FLAGS,
+    EF_NATION_REJECTS,
+    EF_NATION_RELATIONS,
+    EF_NATION_STATUS,
+    EF_NUKE_CHR_FLAGS,
+    EF_PACKING,
+    EF_PAGE_HEADINGS,
+    EF_PLAGUE_STAGES,
+    EF_PLANE_CHR_FLAGS,
+    EF_PLANE_FLAGS,
+    EF_RESOURCES,
+    EF_RETREAT_FLAGS,
+    EF_SECTOR_NAVIGATION,
+    EF_SHIP_CHR_FLAGS,
+    EF_TREATY_FLAGS,
+    /* Views */
+    EF_COUNTRY,
+    /* Number of types: */
+    EF_MAX
+};
 
-#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST)
+#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_DYNMAX)
+#define EF_IS_VIEW(type) (EF_COUNTRY <= (type) && (type) < EF_MAX)
 
 extern struct castr *ef_cadef(int);
 extern int ef_read(int, int, void *);
@@ -162,10 +183,11 @@ extern int ef_nelem(int);
 extern int ef_flags(int);
 extern int ef_byname(char *);
 extern int ef_byname_from(char *, int *);
-extern void ef_init(void);
-extern int ef_load(void);
 extern int ef_verify(void);
+extern int ef_elt_byname(int, char *);
 
 extern struct empfile empfile[EF_MAX + 1];
+extern void empfile_init(void);
+extern void empfile_fixup(void);
 
 #endif