Move realms from the nation file into a new realms file:

(boundstr, realmstr): Rename, new members ef_type, r_cnum, r_uid,
r_realm, r_timestamp.
(natstr): Remove member nat_b[].
(EF_REALM, realm_ca): New.
(empfile): Add it.
(ef_open_srv, ef_close_srv, main): Deal with new file.
(getrealm, putrealm): New.
(add, new, real, list_realm, sarg_getrange): Use them.
This commit is contained in:
Ron Koenderink 2006-01-13 13:18:56 +00:00
parent 04a8b84592
commit 45adbdb00e
11 changed files with 94 additions and 34 deletions

View file

@ -114,6 +114,7 @@ enum {
EF_BMAP, EF_BMAP,
EF_COMM, EF_COMM,
EF_LOST, EF_LOST,
EF_REALM,
/* Static game data (configuration) */ /* Static game data (configuration) */
EF_SECTOR_CHR, EF_SECTOR_CHR,
EF_SHIP_CHR, EF_SHIP_CHR,
@ -147,7 +148,7 @@ enum {
EF_MAX EF_MAX
}; };
#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST) #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_REALM)
extern struct castr *ef_cadef(int); extern struct castr *ef_cadef(int);
extern int ef_read(int, int, void *); extern int ef_read(int, int, void *);

View file

@ -65,9 +65,24 @@ enum { /* Priorities */
PRI_MAX = PRI_LBUILD PRI_MAX = PRI_LBUILD
}; };
struct boundstr {
short b_xl, b_xh; /* horizontal bounds */ /*
short b_yl, b_yh; /* vertical bounds */ * TODO
*
* One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
*
* The only user of b_cnum and b_realm appears to be xdump.
* If we had working virtual selectors, we could remove b_cnum and b_realm.
*
*/
struct realmstr {
short ef_type;
natid r_cnum; /* country number */
short r_uid; /* realm table index */
unsigned short r_realm; /* realm number */
short r_xl, r_xh; /* horizontal bounds */
short r_yl, r_yh; /* vertical bounds */
time_t r_timestamp; /* Last time this realm was touched */
}; };
struct natstr { struct natstr {
@ -97,7 +112,6 @@ struct natstr {
time_t nat_newstim; /* date news last read */ time_t nat_newstim; /* date news last read */
time_t nat_annotim; /* date annos last read */ time_t nat_annotim; /* date annos last read */
float nat_level[4]; /* technology, etc */ float nat_level[4]; /* technology, etc */
struct boundstr nat_b[MAXNOR]; /* realm bounds */
short nat_relate[MAXNOC]; short nat_relate[MAXNOC];
unsigned char nat_contact[MAXNOC]; unsigned char nat_contact[MAXNOC];
short nat_rejects[(MAXNOC + 3) / 4]; /* four bits for each country */ short nat_rejects[(MAXNOC + 3) / 4]; /* four bits for each country */
@ -162,6 +176,11 @@ extern char *relates[];
#define getnatp(n) \ #define getnatp(n) \
(struct natstr *) ef_ptr(EF_NATION, (int)n) (struct natstr *) ef_ptr(EF_NATION, (int)n)
#define putrealm(p) \
ef_write(EF_REALM, (int)(p)->r_uid, p)
#define getrealm(r, n, p) \
ef_read(EF_REALM, (int)(r + (n * MAXNOR)), p)
extern double tfact(natid cn, double mult); extern double tfact(natid cn, double mult);
extern double tfactfire(natid cn, double mult); extern double tfactfire(natid cn, double mult);
extern double techfact(int level, double mult); extern double techfact(int level, double mult);

View file

@ -212,6 +212,7 @@ extern struct castr lost_ca[];
extern struct castr commodity_ca[]; extern struct castr commodity_ca[];
extern struct castr trade_ca[]; extern struct castr trade_ca[];
extern struct castr nat_ca[]; extern struct castr nat_ca[];
extern struct castr realm_ca[];
extern struct castr intrchr_ca[]; extern struct castr intrchr_ca[];
extern struct castr rpt_ca[]; extern struct castr rpt_ca[];
extern struct castr empfile_ca[]; extern struct castr empfile_ca[];

View file

@ -66,6 +66,8 @@ add(void)
int stat; int stat;
struct nstr_item ni; struct nstr_item ni;
struct lndstr land; struct lndstr land;
struct realmstr realm;
time_t current_time = time(NULL);
for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) { for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
if (natp->nat_stat == STAT_UNUSED) if (natp->nat_stat == STAT_UNUSED)
@ -202,7 +204,12 @@ add(void)
natp->nat_xorg = 0; natp->nat_xorg = 0;
natp->nat_dayno = 0; natp->nat_dayno = 0;
natp->nat_minused = 0; natp->nat_minused = 0;
memset(natp->nat_b, 0, sizeof(natp->nat_b)); for (i = 0; i < MAXNOR; i++) {
getrealm(i, coun, &realm);
realm.r_xl = realm.r_xh = realm.r_yl = realm.r_yh = 0;
realm.r_timestamp = current_time;
putrealm(&realm);
}
natp->nat_last_login = natp->nat_last_login = 0; natp->nat_last_login = natp->nat_last_login = 0;
natp->nat_money = 0; natp->nat_money = 0;
natp->nat_level[NAT_TLEV] = start_technology; natp->nat_level[NAT_TLEV] = start_technology;

View file

@ -60,13 +60,14 @@ new(void)
{ {
struct sctstr sect; struct sctstr sect;
struct natstr *natp; struct natstr *natp;
struct boundstr newrealms; struct realmstr newrealm;
struct range absrealm; struct range absrealm;
natid num; natid num;
coord x, y; coord x, y;
int i; int i;
char *p; char *p;
char buf[1024]; char buf[1024];
time_t current_time = time(NULL);
natp = getnatp(player->cnum); natp = getnatp(player->cnum);
if (natp->nat_xorg != 0 || natp->nat_yorg != 0) { if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
@ -182,10 +183,15 @@ new(void)
natp->nat_xorg = x; natp->nat_xorg = x;
natp->nat_yorg = y; natp->nat_yorg = y;
xyabsrange(natp, &defrealm, &absrealm); xyabsrange(natp, &defrealm, &absrealm);
newrealms.b_xl = absrealm.lx; for (i = 0; i < MAXNOR; i++) {
newrealms.b_xh = absrealm.hx; getrealm(i, num, &newrealm);
newrealms.b_yl = absrealm.ly; newrealm.r_xl = absrealm.lx;
newrealms.b_yh = absrealm.hy; newrealm.r_xh = absrealm.hx;
newrealm.r_yl = absrealm.ly;
newrealm.r_yh = absrealm.hy;
newrealm.r_timestamp = current_time;
putrealm(&newrealm);
}
if (players_at_00) { if (players_at_00) {
natp->nat_xorg = 0; natp->nat_xorg = 0;
natp->nat_yorg = 0; natp->nat_yorg = 0;
@ -195,8 +201,6 @@ new(void)
natp->nat_level[NAT_RLEV] = start_research; natp->nat_level[NAT_RLEV] = start_research;
natp->nat_level[NAT_TLEV] = start_technology; natp->nat_level[NAT_TLEV] = start_technology;
natp->nat_level[NAT_ELEV] = start_education; natp->nat_level[NAT_ELEV] = start_education;
for (i = 0; i < MAXNOR; i++)
natp->nat_b[i] = newrealms;
natp->nat_tgms = 0; natp->nat_tgms = 0;
(void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660)); (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
putnat(natp); putnat(natp);

View file

@ -42,19 +42,19 @@
#include "commands.h" #include "commands.h"
static void static void
list_realm(int curr, struct natstr *natp) list_realm(natid curr, struct natstr *natp)
{ {
struct boundstr *b; struct realmstr realm;
struct range abs; struct range abs;
struct range rel; struct range rel;
abs.width = 0; abs.width = 0;
abs.height = 0; abs.height = 0;
b = &natp->nat_b[curr]; getrealm(curr, natp->nat_cnum, &realm);
abs.lx = b->b_xl; abs.lx = realm.r_xl;
abs.hx = b->b_xh; abs.hx = realm.r_xh;
abs.ly = b->b_yl; abs.ly = realm.r_yl;
abs.hy = b->b_yh; abs.hy = realm.r_yh;
xyrelrange(natp, &abs, &rel); xyrelrange(natp, &abs, &rel);
pr("Realm #%d is %d:%d,%d:%d\n", curr, rel.lx, rel.hx, rel.ly, rel.hy); pr("Realm #%d is %d:%d,%d:%d\n", curr, rel.lx, rel.hx, rel.ly, rel.hy);
@ -63,7 +63,7 @@ list_realm(int curr, struct natstr *natp)
int int
real(void) real(void)
{ {
register struct boundstr *rp; struct realmstr realm;
struct natstr *natp; struct natstr *natp;
int curr; int curr;
int lastr; int lastr;
@ -97,14 +97,14 @@ real(void)
abs.height = 0; abs.height = 0;
if (!sarg_area(player->argp[2], &abs)) if (!sarg_area(player->argp[2], &abs))
return RET_SYN; return RET_SYN;
rp = &natp->nat_b[curr]; getrealm(curr, natp->nat_cnum, &realm);
rp->b_xl = abs.lx; realm.r_xl = abs.lx;
rp->b_xh = abs.hx - 1; realm.r_xh = abs.hx - 1;
rp->b_yl = abs.ly; realm.r_yl = abs.ly;
rp->b_yh = abs.hy - 1; realm.r_yh = abs.hy - 1;
natp->nat_b[curr] = *rp;
list_realm(curr, natp); list_realm(curr, natp);
putnat(natp); realm.r_timestamp = time(NULL);
putrealm(&realm);
} }
return RET_OK; return RET_OK;
} }

View file

@ -141,6 +141,8 @@ struct empfile empfile[] = {
UNMAPPED_CACHE(struct comstr, 0)}, UNMAPPED_CACHE(struct comstr, 0)},
{EF_LOST, "lost", "lostitems", lost_ca, {EF_LOST, "lost", "lostitems", lost_ca,
UNMAPPED_CACHE(struct loststr, EFF_OWNER)}, UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
{EF_REALM, "realm", "realms", realm_ca,
UNMAPPED_CACHE(struct realmstr, EFF_OWNER)},
/* Static game data (configuration) */ /* Static game data (configuration) */
{EF_SECTOR_CHR, "sect-chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)}, {EF_SECTOR_CHR, "sect-chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},

View file

@ -526,6 +526,17 @@ struct castr nat_ca[] = {
{NSC_NOTYPE, 0, 0, 0, NULL, 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},
{NSC_USHORT, 0, 0, fldoff(realmstr, r_realm), "realm"},
{NSC_SHORT, 0, 0, fldoff(realmstr, r_xl), "xl"},
{NSC_SHORT, 0, 0, fldoff(realmstr, r_xh), "xh"},
{NSC_SHORT, 0, 0, fldoff(realmstr, r_yl), "yl"},
{NSC_SHORT, 0, 0, fldoff(realmstr, r_yh), "yh"},
{NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
};
struct castr intrchr_ca[] = { struct castr intrchr_ca[] = {
{NSC_STRING, NSC_CONST, 0, offsetof(struct sctintrins, in_name), "name", {NSC_STRING, NSC_CONST, 0, offsetof(struct sctintrins, in_name), "name",
EF_BAD}, EF_BAD},

View file

@ -106,6 +106,7 @@ ef_open_srv(void)
failed |= !ef_open(EF_BMAP, EFF_MEM); failed |= !ef_open(EF_BMAP, EFF_MEM);
failed |= !ef_open(EF_COMM, 0); failed |= !ef_open(EF_COMM, 0);
failed |= !ef_open(EF_LOST, 0); failed |= !ef_open(EF_LOST, 0);
failed |= !ef_open(EF_REALM, EFF_MEM);
if (failed) { if (failed) {
logerror("Missing files, giving up"); logerror("Missing files, giving up");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -130,4 +131,5 @@ ef_close_srv(void)
ef_close(EF_COMM); ef_close(EF_COMM);
ef_close(EF_BMAP); ef_close(EF_BMAP);
ef_close(EF_LOST); ef_close(EF_LOST);
ef_close(EF_REALM);
} }

View file

@ -100,6 +100,7 @@ sarg_getrange(char *str, struct range *rp)
{ {
long rlm; long rlm;
struct natstr *np; struct natstr *np;
struct realmstr realm;
char *end; char *end;
if (*str == '#') { if (*str == '#') {
@ -114,11 +115,11 @@ sarg_getrange(char *str, struct range *rp)
return 0; return 0;
} else } else
rlm = 0; rlm = 0;
np = getnatp(player->cnum); getrealm(rlm, player->cnum, &realm);
rp->lx = np->nat_b[rlm].b_xl; rp->lx = realm.r_xl;
rp->hx = np->nat_b[rlm].b_xh; rp->hx = realm.r_xh;
rp->ly = np->nat_b[rlm].b_yl; rp->ly = realm.r_yl;
rp->hy = np->nat_b[rlm].b_yh; rp->hy = realm.r_yh;
} else { } else {
/* /*
* full map specification * full map specification

View file

@ -79,8 +79,9 @@ main(int argc, char *argv[])
s_char *filename; s_char *filename;
int x, y; int x, y;
struct natstr nat; struct natstr nat;
struct realmstr realm;
struct sctstr sct; struct sctstr sct;
int i; int i, j;
s_char *map; s_char *map;
int opt; int opt;
char *config_file = NULL; char *config_file = NULL;
@ -151,6 +152,17 @@ main(int argc, char *argv[])
nat.nat_cnum = i; nat.nat_cnum = i;
putnat((&nat)); putnat((&nat));
} }
memset(&realm, 0, sizeof(realm));
realm.ef_type = EF_REALM;
for (i = 0; i < MAXNOC; i++) {
realm.r_cnum = i;
for (j = 0; j < MAXNOR; j++) {
realm.r_realm = j;
realm.r_uid = (i * MAXNOR) + j;
realm.r_timestamp = current_time;
putrealm(&realm);
}
}
if (access(teldir, F_OK) < 0 && mkdir(teldir, 0750) < 0) { if (access(teldir, F_OK) < 0 && mkdir(teldir, 0750) < 0) {
perror(teldir); perror(teldir);
printf("Can't make telegram directory\n"); printf("Can't make telegram directory\n");