(ef_init): Remove cadef member from fileinit,

insert directly into the empfile structure.
Add ef_type member to fileinit to identify rows with data.
Remove unused rows of fileinit.
This commit is contained in:
Ron Koenderink 2005-10-22 13:55:04 +00:00
parent 29d21997b9
commit cf4faac293
3 changed files with 27 additions and 40 deletions

View file

@ -113,10 +113,10 @@ struct empfile {
instead of bmap or map. */
struct fileinit {
int ef_type;
void (*init) (int, char *);
int (*postread) (int, char *);
int (*prewrite) (int, char *);
struct castr *cadef;
};
extern struct castr *ef_cadef(int);

View file

@ -57,37 +57,37 @@ struct empfile empfile[] = {
/* Dynamic game data */
{"sect", "sector", EFF_XY | EFF_OWNER,
0, sizeof(struct sctstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, sect_ca},
{"ship", "ship", EFF_XY | EFF_OWNER | EFF_GROUP,
0, sizeof(struct shpstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, ship_ca},
{"plane", "plane", EFF_XY | EFF_OWNER | EFF_GROUP,
0, sizeof(struct plnstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, plane_ca},
{"land", "land", EFF_XY | EFF_OWNER | EFF_GROUP,
0, sizeof(struct lndstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, land_ca},
{"nuke", "nuke", EFF_XY | EFF_OWNER,
0, sizeof(struct nukstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, nuke_ca},
{"news", "news", 0,
0, sizeof(struct nwsstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, news_ca},
{"treaty", "treaty", 0,
0, sizeof(struct trtstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, treaty_ca},
{"trade", "trade", 0,
0, sizeof(struct trdstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, trade_ca},
{"pow", "power", 0,
0, sizeof(struct powstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
{"nat", "nation", EFF_OWNER,
0, sizeof(struct natstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, nat_ca},
{"loan", "loan", 0,
0, sizeof(struct lonstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, loan_ca},
{"map", "map", 0,
0, DEF_WORLD_X * DEF_WORLD_Y / 2, NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
@ -96,10 +96,10 @@ struct empfile empfile[] = {
-1, -1, 0, 0, NULL, 0, NULL},
{"commodity", "commodity", 0,
0, sizeof(struct comstr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, commodity_ca},
{"lost", "lostitems", EFF_OWNER,
0, sizeof(struct loststr), NULL, NULL, NULL,
-1, -1, 0, 0, NULL, 0, NULL},
-1, -1, 0, 0, NULL, 0, lost_ca},
/* Static game data (configuation) */
{"sect chr", NULL, EFF_MEM,

View file

@ -25,10 +25,12 @@
*
* ---
*
* fileinit.c: Stuff that ef_init uses to initialize the ca pointers and
* the pre/post i/o calls.
* fileinit.c: Fill the empfile[] with function pointers only required for
* full server operations. This allows the empfile[] to be
* used in files and fairland.
*
* Known contributors to this file:
* Ron Koenderink, 2005
*
*/
@ -39,38 +41,23 @@
#include "prototypes.h"
#include "optlist.h"
struct fileinit fileinit[EF_MAX] = {
{NULL, sct_postread, sct_prewrite, sect_ca},
{shp_init, shp_postread, shp_prewrite, ship_ca},
{pln_init, pln_postread, pln_prewrite, plane_ca},
{lnd_init, lnd_postread, lnd_prewrite, land_ca},
{nuk_init, nuk_postread, nuk_prewrite, nuke_ca},
{NULL, NULL, NULL, news_ca},
{NULL, NULL, NULL, treaty_ca},
{NULL, NULL, NULL, trade_ca},
{NULL, NULL, NULL, NULL}, /* power */
{NULL, NULL, NULL, nat_ca}, /* nation */
{NULL, NULL, NULL, loan_ca},
{NULL, NULL, NULL, NULL}, /* map, a.k.a. true bmap */
{NULL, NULL, NULL, NULL}, /* (working) bmap */
{NULL, NULL, NULL, commodity_ca},
{NULL, NULL, NULL, lost_ca}
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}
};
void
ef_init(void)
{
int i;
struct empfile *ef;
struct fileinit *fi;
ef = empfile;
fi = fileinit;
for (i = 0; i < EF_MAX; i++, ef++, fi++) {
ef->init = fi->init;
ef->postread = fi->postread;
ef->prewrite = fi->prewrite;
ef->cadef = fi->cadef;
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[EF_MAP].size = empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;