From 9eba732cc31e060a35e1388b2c241cea1e99ea2e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 14 Jan 2006 16:28:33 +0000 Subject: [PATCH] (EF_COUNTRY, cou_ca): New. (empfile): Add it. (xdvisible): Deal with it. (ef_open_srv, ef_close_srv): Set it up. (ef_init_view, ef_fina_view): New. --- include/file.h | 3 +++ include/nsc.h | 1 + src/lib/commands/xdump.c | 7 +++++-- src/lib/global/file.c | 3 +++ src/lib/global/nsc.c | 12 ++++++++---- src/lib/subs/fileinit.c | 24 ++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/file.h b/include/file.h index 7f8a847e..173293d5 100644 --- a/include/file.h +++ b/include/file.h @@ -145,6 +145,9 @@ enum { EF_PACKING, EF_RESOURCES, EF_NATION_STATUS, + /* Views */ + EF_COUNTRY, + /* Number of types: */ EF_MAX }; diff --git a/include/nsc.h b/include/nsc.h index da0d96f8..850fd6a7 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -212,6 +212,7 @@ extern struct castr lost_ca[]; extern struct castr commodity_ca[]; extern struct castr trade_ca[]; extern struct castr nat_ca[]; +extern struct castr cou_ca[]; extern struct castr realm_ca[]; extern struct castr intrchr_ca[]; extern struct castr rpt_ca[]; diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index de1a1cbb..4382bde7 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -204,8 +204,11 @@ xdvisible(int type, void *p) case EF_LOST: return gp->own != 0 && (gp->own == player->cnum || player->god); case EF_NATION: - return ((struct natstr *)p)->nat_stat != STAT_UNUSED - && (gp->own == player->cnum || player->god); + if (gp->own == player->cnum || player->god) + return 1; + /* fall through */ + case EF_COUNTRY: + return ((struct natstr *)p)->nat_stat != STAT_UNUSED; case EF_NEWS: return ((struct nwsstr *)p)->nws_vrb != 0 && (!opt_HIDDEN || player->god); /* FIXME */ diff --git a/src/lib/global/file.c b/src/lib/global/file.c index 62446c99..f5fd4e25 100644 --- a/src/lib/global/file.c +++ b/src/lib/global/file.c @@ -190,6 +190,9 @@ struct empfile empfile[] = { {EF_NATION_STATUS, "nation-status", NULL, symbol_ca, PTR_CACHE(nation_status, EFF_CFG)}, + /* Views */ + {EF_COUNTRY, "country", NULL, cou_ca, UNMAPPED_CACHE(struct natstr, 0)}, + /* Sentinel */ {EF_BAD, NULL, NULL, NULL, 0, 0, NULL, 0, 0, 0, 0, -1, NULL, NULL, NULL}, }; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 0dd4568f..9dcb44ea 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -400,7 +400,6 @@ struct castr nchr_ca[] = { }; struct castr treaty_ca[] = { - /* FIXME disclose only to cna, cnb */ {NSC_SHORT, 0, 0, fldoff(trtstr, trt_uid), "uid", EF_TREATY}, {NSC_NATID, 0, 0, fldoff(trtstr, trt_cna), "cna", EF_NATION}, {NSC_NATID, 0, 0, fldoff(trtstr, trt_cnb), "cnb", EF_NATION}, @@ -415,7 +414,6 @@ struct castr treaty_ca[] = { }; struct castr loan_ca[] = { - /* FIXME disclose only to loaner, loanee and partially to all if signed */ {NSC_SHORT, 0, 0, fldoff(lonstr, l_uid), "uid", EF_LOAN}, {NSC_NATID, 0, 0, fldoff(lonstr, l_loner), "loaner", EF_NATION}, {NSC_NATID, 0, 0, fldoff(lonstr, l_lonee), "loanee", EF_NATION}, @@ -431,7 +429,6 @@ struct castr loan_ca[] = { }; struct castr news_ca[] = { - /* FIXME if HIDDEN disclose requires contact with actor and victim, and new */ {NSC_SHORT, 0, 0, fldoff(nwsstr, nws_uid), "uid", EF_NEWS}, {NSC_NATID, 0, 0, fldoff(nwsstr, nws_ano), "actor", EF_NATION}, {NSC_CHAR, 0, 0, fldoff(nwsstr, nws_vrb), "action", EF_NEWS_CHR}, @@ -515,7 +512,6 @@ struct castr nat_ca[] = { EF_BAD}, {NSC_FLOAT, 0, 0, fldoff(natstr, nat_level[NAT_HLEV]), "happiness", EF_BAD}, - /* FIXME nat_b[] */ {NSC_SHORT, 0, MAXNOC, fldoff(natstr, nat_relate), "relations", EF_NATION_RELATIONS}, {NSC_UCHAR, NSC_DEITY, MAXNOC, fldoff(natstr, nat_contact), "contacts", @@ -526,6 +522,14 @@ struct castr nat_ca[] = { {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD} }; +struct castr cou_ca[] = { + {NSC_NATID, 0, 0, fldoff(natstr, nat_cnum), "cnum", EF_NATION}, + {NSC_CHAR, 0, 0, fldoff(natstr, nat_stat), "stat", + EF_NATION_STATUS}, + {NSC_STRINGY, 0, 20, fldoff(natstr, nat_cnam), "cname", EF_BAD}, + {NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD} +}; + struct castr realm_ca[] = { {NSC_SHORT, 0, 0, fldoff(realmstr, r_uid), "uid", EF_REALM}, {NSC_NATID, 0, 0, fldoff(realmstr, r_cnum), "cnum", EF_NATION}, diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index c1ab7ec4..30b1d9b0 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -54,6 +54,8 @@ static struct fileinit fileinit[] = { 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. @@ -107,6 +109,7 @@ ef_open_srv(void) failed |= !ef_open(EF_COMM, 0); failed |= !ef_open(EF_LOST, 0); failed |= !ef_open(EF_REALM, EFF_MEM); + failed |= ef_init_view(EF_COUNTRY, EF_NATION); if (failed) { logerror("Missing files, giving up"); exit(EXIT_FAILURE); @@ -116,6 +119,7 @@ ef_open_srv(void) static void ef_close_srv(void) { + ef_fina_view(EF_COUNTRY); ef_close(EF_NATION); ef_close(EF_SECTOR); ef_close(EF_SHIP); @@ -133,3 +137,23 @@ ef_close_srv(void) 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; +}