2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * fileinit.c: Initialize Empire tables for full server operations.
30 * Known contributors to this file:
31 * Ron Koenderink, 2005
38 #include "prototypes.h"
42 void (*init) (int, void *);
43 int (*postread) (int, void *);
44 int (*prewrite) (int, void *);
47 static struct fileinit fileinit[] = {
48 {EF_SECTOR, NULL, sct_postread, sct_prewrite},
49 {EF_SHIP, shp_init, shp_postread, shp_prewrite},
50 {EF_PLANE, pln_init, pln_postread, pln_prewrite},
51 {EF_LAND, lnd_init, lnd_postread, lnd_prewrite},
52 {EF_NUKE, nuk_init, nuk_postread, nuk_prewrite}
55 static void ef_open_srv(void);
56 static void ef_close_srv(void);
57 static int ef_init_view(int, int);
58 static void ef_fina_view(int);
61 * Initialize empfile for full server operations.
62 * ef_init() must be called first.
69 for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
70 empfile[fileinit[i].ef_type].init = fileinit[i].init;
71 empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
72 empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
75 for (i = 0; cou_ca[i].ca_name; i++) {
76 nat_ca[i] = cou_ca[i];
77 flags = nat_ca[i].ca_flags | NSC_CONST;
78 if (flags & NSC_EXTRA)
82 nat_ca[i].ca_flags = flags;
84 nat_ca[i] = cou_ca[i];
103 failed |= journal_startup() < 0;
104 failed |= !ef_open(EF_NATION, EFF_MEM);
105 failed |= !ef_open(EF_SECTOR, EFF_MEM);
106 failed |= !ef_open(EF_SHIP, EFF_MEM);
107 failed |= !ef_open(EF_PLANE, EFF_MEM);
108 failed |= !ef_open(EF_LAND, EFF_MEM);
109 failed |= !ef_open(EF_NEWS, 0);
110 failed |= !ef_open(EF_LOAN, 0);
111 failed |= !ef_open(EF_TREATY, 0);
112 failed |= !ef_open(EF_NUKE, EFF_MEM);
113 failed |= !ef_open(EF_POWER, 0);
114 failed |= !ef_open(EF_TRADE, 0);
115 failed |= !ef_open(EF_MAP, EFF_MEM);
116 failed |= !ef_open(EF_BMAP, EFF_MEM);
117 failed |= !ef_open(EF_COMM, 0);
118 failed |= !ef_open(EF_LOST, 0);
119 failed |= !ef_open(EF_REALM, EFF_MEM);
121 failed |= ef_init_view(EF_COUNTRY, EF_NATION);
123 logerror("Missing files, giving up");
131 ef_fina_view(EF_COUNTRY);
152 ef_init_view(int type, int base)
154 if (CANT_HAPPEN(!(empfile[base].flags & EFF_MEM)))
156 empfile[type].cache = empfile[base].cache;
157 empfile[type].csize = empfile[base].csize;
158 empfile[type].flags |= EFF_MEM;
159 empfile[type].baseid = empfile[base].baseid;
160 empfile[type].cids = empfile[base].cids;
161 empfile[type].fids = empfile[base].fids;
166 ef_fina_view(int type)
168 empfile[type].cache = NULL;