From 654335c62159b7d1a441126eeab5065efa071b93 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 14 Jul 2007 14:49:58 +0000 Subject: [PATCH] New Empire table game, to be used for global stuff: (gamestr, EF_GAME, game_ca): New. (empfile): Declare the table. (ef_open_srv, ef_close_srv): Open and close it. (main): Create it. (empobj_storage): New member game. (EF_DYNMAX): New. (EF_IS_GAME_STATE): Use it. --- include/empobj.h | 2 ++ include/file.h | 4 +++- include/game.h | 46 +++++++++++++++++++++++++++++++++++++++++ include/nsc.h | 1 + include/types.h | 1 + src/lib/global/file.c | 3 +++ src/lib/global/nsc.c | 4 ++++ src/lib/subs/fileinit.c | 2 ++ src/util/files.c | 6 ++++++ 9 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 include/game.h diff --git a/include/empobj.h b/include/empobj.h index d84da0c63..785926ed4 100644 --- a/include/empobj.h +++ b/include/empobj.h @@ -36,6 +36,7 @@ #define EMPOBJ_H #include "commodity.h" +#include "game.h" #include "land.h" #include "loan.h" #include "lost.h" @@ -70,6 +71,7 @@ union empobj_storage { short ef_type; struct empobj gen; struct comstr comm; + struct gamestr game; struct lndstr land; struct lonstr loan; struct loststr lost; diff --git a/include/file.h b/include/file.h index 7e9b362c8..3011a13f8 100644 --- a/include/file.h +++ b/include/file.h @@ -116,6 +116,8 @@ enum { 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, @@ -157,7 +159,7 @@ enum { EF_MAX }; -#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_REALM) +#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); diff --git a/include/game.h b/include/game.h new file mode 100644 index 000000000..c49258eb5 --- /dev/null +++ b/include/game.h @@ -0,0 +1,46 @@ +/* + * Empire - A multi-player, client/server Internet based war game. + * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak, + * Ken Stevens, Steve McClure + * + * This program 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 + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 + * + * --- + * + * 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. + * + * --- + * + * game.h: The game file + * + * Known contributors to this file: + * Markus Armbruster, 2007 + */ + +#ifndef GAME_H +#define GAME_H + +struct gamestr { + /* initial part must match struct empobj */ + short ef_type; + /* end of part matching struct empobj */ +}; + +#define putgame() ef_write(EF_GAME, 0, ef_ptr(EF_GAME, 0)) +#define getgamep() ((struct gamestr *)ef_ptr(EF_GAME, 0)) + +#endif diff --git a/include/nsc.h b/include/nsc.h index c666f27f7..5ba06a9bb 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -216,6 +216,7 @@ extern struct castr trade_ca[]; extern struct castr nat_ca[]; extern struct castr cou_ca[]; extern struct castr realm_ca[]; +extern struct castr game_ca[]; extern struct castr intrchr_ca[]; extern struct castr rpt_ca[]; extern struct castr empfile_ca[]; diff --git a/include/types.h b/include/types.h index b76e75ab8..04d6f5b85 100644 --- a/include/types.h +++ b/include/types.h @@ -40,6 +40,7 @@ typedef short coord; struct bp; struct emp_qelem; struct empobj; +struct gamestr; struct lndstr; struct lndstr; struct lonstr; diff --git a/src/lib/global/file.c b/src/lib/global/file.c index 530fbff2d..9f91ebb7b 100644 --- a/src/lib/global/file.c +++ b/src/lib/global/file.c @@ -36,6 +36,7 @@ #include #include "commodity.h" #include "file.h" +#include "game.h" #include "land.h" #include "loan.h" #include "lost.h" @@ -139,6 +140,8 @@ struct empfile empfile[] = { UNMAPPED_CACHE(struct loststr, EFF_OWNER)}, {EF_REALM, "realm", "realms", realm_ca, UNMAPPED_CACHE(struct realmstr, EFF_OWNER)}, + {EF_GAME, "game", "game", game_ca, + UNMAPPED_CACHE(struct gamestr, 0)}, /* Static game data (configuration) */ {EF_ITEM, "item", "item.config", ichr_ca, diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 9382d571b..a1acdacf5 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -544,6 +544,10 @@ struct castr realm_ca[] = { {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD} }; +struct castr game_ca[] = { + {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD} +}; + struct castr intrchr_ca[] = { /* no need for uid as long as it's not referenced from other tables */ {NSC_STRING, NSC_CONST, 0, offsetof(struct sctintrins, in_name), "name", diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index 0778d6bb7..aac64c527 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -104,6 +104,7 @@ ef_open_srv(void) failed |= !ef_open(EF_SHIP, EFF_MEM); failed |= !ef_open(EF_PLANE, EFF_MEM); failed |= !ef_open(EF_LAND, EFF_MEM); + failed |= !ef_open(EF_GAME, EFF_MEM); failed |= !ef_open(EF_NEWS, 0); failed |= !ef_open(EF_LOAN, 0); failed |= !ef_open(EF_TREATY, 0); @@ -132,6 +133,7 @@ ef_close_srv(void) ef_close(EF_SHIP); ef_close(EF_PLANE); ef_close(EF_LAND); + ef_close(EF_GAME); ef_close(EF_NEWS); ef_close(EF_LOAN); ef_close(EF_TREATY); diff --git a/src/util/files.c b/src/util/files.c index 9da0132b3..01a44b151 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -47,6 +47,7 @@ #endif #include "file.h" +#include "game.h" #include "land.h" #include "misc.h" #include "nat.h" @@ -82,6 +83,7 @@ main(int argc, char *argv[]) char buf[255]; char *filename; int x, y; + struct gamestr *game; struct natstr nat; struct realmstr realm; struct sctstr sct; @@ -143,6 +145,10 @@ main(int argc, char *argv[]) exit(1); } } + game = getgamep(); + memset(game, 0, sizeof(*game)); + game->ef_type = EF_GAME; + putgame(); memset(&nat, 0, sizeof(nat)); nat.ef_type = EF_NATION; strcpy(nat.nat_cnam, "POGO"); -- 2.43.0