/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* fileinit.c: Initialize Empire tables for full server operations.
- *
+ *
* Known contributors to this file:
* Ron Koenderink, 2005
+ * Markus Armbruster, 2005-2008
*/
#include <config.h>
#include "file.h"
+#include "nsc.h"
#include "prototypes.h"
+#include "unit.h"
struct fileinit {
int ef_type;
- void (*init) (int, void *);
- int (*postread) (int, void *);
- int (*prewrite) (int, void *);
+ void (*postread)(int, void *);
+ void (*prewrite)(int, void *, void *);
+ void (*onresize)(int);
};
static struct fileinit fileinit[] = {
- {EF_SECTOR, NULL, sct_postread, sct_prewrite},
- {EF_SHIP, shp_init, shp_postread, shp_prewrite},
- {EF_PLANE, pln_init, pln_postread, pln_prewrite},
- {EF_LAND, lnd_init, lnd_postread, lnd_prewrite},
- {EF_NUKE, nuk_init, nuk_postread, nuk_prewrite}
+ {EF_SECTOR, sct_postread, sct_prewrite, NULL},
+ {EF_SHIP, shp_postread, shp_prewrite, unit_onresize},
+ {EF_PLANE, pln_postread, pln_prewrite, unit_onresize},
+ {EF_LAND, lnd_postread, lnd_prewrite, unit_onresize},
+ {EF_NUKE, nuk_postread, nuk_prewrite, unit_onresize}
};
static void ef_open_srv(void);
static void ef_close_srv(void);
-static int ef_init_view(int, int);
-static void ef_fina_view(int);
/*
* Initialize empfile for full server operations.
- * ef_init() must be called first.
*/
void
ef_init_srv(void)
{
- unsigned i, flags;
+ unsigned i;
for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
- empfile[fileinit[i].ef_type].init = fileinit[i].init;
empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
+ empfile[fileinit[i].ef_type].onresize = fileinit[i].onresize;
}
- for (i = 0; cou_ca[i].ca_name; i++) {
- nat_ca[i] = cou_ca[i];
- flags = nat_ca[i].ca_flags;
- if (flags & NSC_EXTRA)
- flags &= ~NSC_EXTRA;
- else if (i != 0)
- flags |= NSC_DEITY;
- nat_ca[i].ca_flags = flags;
- }
- nat_ca[i] = cou_ca[i];
-
+ nsc_init();
ef_open_srv();
- if (ef_verify() < 0)
+ if (ef_verify(1) < 0)
exit(EXIT_FAILURE);
global_init();
+ unit_cargo_init();
}
void
failed |= !ef_open(EF_LOST, 0);
failed |= !ef_open(EF_REALM, EFF_MEM);
if (!failed)
- failed |= ef_init_view(EF_COUNTRY, EF_NATION);
+ failed |= ef_open_view(EF_COUNTRY);
if (failed) {
logerror("Missing files, giving up");
exit(EXIT_FAILURE);
static void
ef_close_srv(void)
{
- ef_fina_view(EF_COUNTRY);
+ ef_close(EF_COUNTRY);
ef_close(EF_NATION);
ef_close(EF_SECTOR);
ef_close(EF_SHIP);
ef_close(EF_LOST);
ef_close(EF_REALM);
}
-
-static int
-ef_init_view(int type, int base)
-{
- if (CANT_HAPPEN(!(empfile[base].flags & EFF_MEM)))
- return -1;
- empfile[type].cache = empfile[base].cache;
- empfile[type].csize = empfile[base].csize;
- empfile[type].flags |= EFF_MEM;
- empfile[type].baseid = empfile[base].baseid;
- empfile[type].cids = empfile[base].cids;
- empfile[type].fids = empfile[base].fids;
- return 0;
-}
-
-static void
-ef_fina_view(int type)
-{
- empfile[type].cache = NULL;
-}