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.
This commit is contained in:
Markus Armbruster 2007-07-14 14:49:58 +00:00
parent 4ba4cd98c6
commit 654335c621
9 changed files with 68 additions and 1 deletions

View file

@ -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;

View file

@ -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);

46
include/game.h Normal file
View file

@ -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

View file

@ -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[];

View file

@ -40,6 +40,7 @@ typedef short coord;
struct bp;
struct emp_qelem;
struct empobj;
struct gamestr;
struct lndstr;
struct lndstr;
struct lonstr;

View file

@ -36,6 +36,7 @@
#include <stddef.h>
#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,

View file

@ -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",

View file

@ -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);

View file

@ -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");