EF_BMAP,
EF_COMM,
EF_LOST,
+ EF_REALM,
/* Static game data (configuration) */
EF_SECTOR_CHR,
EF_SHIP_CHR,
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 int ef_read(int, int, void *);
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 {
time_t nat_newstim; /* date news last read */
time_t nat_annotim; /* date annos last read */
float nat_level[4]; /* technology, etc */
- struct boundstr nat_b[MAXNOR]; /* realm bounds */
short nat_relate[MAXNOC];
unsigned char nat_contact[MAXNOC];
short nat_rejects[(MAXNOC + 3) / 4]; /* four bits for each country */
#define getnatp(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 tfactfire(natid cn, double mult);
extern double techfact(int level, double mult);
extern struct castr commodity_ca[];
extern struct castr trade_ca[];
extern struct castr nat_ca[];
+extern struct castr realm_ca[];
extern struct castr intrchr_ca[];
extern struct castr rpt_ca[];
extern struct castr empfile_ca[];
int stat;
struct nstr_item ni;
struct lndstr land;
+ struct realmstr realm;
+ time_t current_time = time(NULL);
for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) {
if (natp->nat_stat == STAT_UNUSED)
natp->nat_xorg = 0;
natp->nat_dayno = 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_money = 0;
natp->nat_level[NAT_TLEV] = start_technology;
{
struct sctstr sect;
struct natstr *natp;
- struct boundstr newrealms;
+ struct realmstr newrealm;
struct range absrealm;
natid num;
coord x, y;
int i;
char *p;
char buf[1024];
+ time_t current_time = time(NULL);
natp = getnatp(player->cnum);
if (natp->nat_xorg != 0 || natp->nat_yorg != 0) {
natp->nat_xorg = x;
natp->nat_yorg = y;
xyabsrange(natp, &defrealm, &absrealm);
- newrealms.b_xl = absrealm.lx;
- newrealms.b_xh = absrealm.hx;
- newrealms.b_yl = absrealm.ly;
- newrealms.b_yh = absrealm.hy;
+ for (i = 0; i < MAXNOR; i++) {
+ getrealm(i, num, &newrealm);
+ newrealm.r_xl = absrealm.lx;
+ 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) {
natp->nat_xorg = 0;
natp->nat_yorg = 0;
natp->nat_level[NAT_RLEV] = start_research;
natp->nat_level[NAT_TLEV] = start_technology;
natp->nat_level[NAT_ELEV] = start_education;
- for (i = 0; i < MAXNOR; i++)
- natp->nat_b[i] = newrealms;
natp->nat_tgms = 0;
(void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660));
putnat(natp);
#include "commands.h"
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 rel;
abs.width = 0;
abs.height = 0;
- b = &natp->nat_b[curr];
- abs.lx = b->b_xl;
- abs.hx = b->b_xh;
- abs.ly = b->b_yl;
- abs.hy = b->b_yh;
+ getrealm(curr, natp->nat_cnum, &realm);
+ abs.lx = realm.r_xl;
+ abs.hx = realm.r_xh;
+ abs.ly = realm.r_yl;
+ abs.hy = realm.r_yh;
xyrelrange(natp, &abs, &rel);
pr("Realm #%d is %d:%d,%d:%d\n", curr, rel.lx, rel.hx, rel.ly, rel.hy);
int
real(void)
{
- register struct boundstr *rp;
+ struct realmstr realm;
struct natstr *natp;
int curr;
int lastr;
abs.height = 0;
if (!sarg_area(player->argp[2], &abs))
return RET_SYN;
- rp = &natp->nat_b[curr];
- rp->b_xl = abs.lx;
- rp->b_xh = abs.hx - 1;
- rp->b_yl = abs.ly;
- rp->b_yh = abs.hy - 1;
- natp->nat_b[curr] = *rp;
+ getrealm(curr, natp->nat_cnum, &realm);
+ realm.r_xl = abs.lx;
+ realm.r_xh = abs.hx - 1;
+ realm.r_yl = abs.ly;
+ realm.r_yh = abs.hy - 1;
list_realm(curr, natp);
- putnat(natp);
+ realm.r_timestamp = time(NULL);
+ putrealm(&realm);
}
return RET_OK;
}
UNMAPPED_CACHE(struct comstr, 0)},
{EF_LOST, "lost", "lostitems", lost_ca,
UNMAPPED_CACHE(struct loststr, EFF_OWNER)},
+ {EF_REALM, "realm", "realms", realm_ca,
+ UNMAPPED_CACHE(struct realmstr, EFF_OWNER)},
/* Static game data (configuration) */
{EF_SECTOR_CHR, "sect-chr", "sect_def", dchr_ca, ARRAY_TABLE(dchr, EFF_CFG)},
{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[] = {
{NSC_STRING, NSC_CONST, 0, offsetof(struct sctintrins, in_name), "name",
EF_BAD},
failed |= !ef_open(EF_BMAP, EFF_MEM);
failed |= !ef_open(EF_COMM, 0);
failed |= !ef_open(EF_LOST, 0);
+ failed |= !ef_open(EF_REALM, EFF_MEM);
if (failed) {
logerror("Missing files, giving up");
exit(EXIT_FAILURE);
ef_close(EF_COMM);
ef_close(EF_BMAP);
ef_close(EF_LOST);
+ ef_close(EF_REALM);
}
{
long rlm;
struct natstr *np;
+ struct realmstr realm;
char *end;
if (*str == '#') {
return 0;
} else
rlm = 0;
- np = getnatp(player->cnum);
- rp->lx = np->nat_b[rlm].b_xl;
- rp->hx = np->nat_b[rlm].b_xh;
- rp->ly = np->nat_b[rlm].b_yl;
- rp->hy = np->nat_b[rlm].b_yh;
+ getrealm(rlm, player->cnum, &realm);
+ rp->lx = realm.r_xl;
+ rp->hx = realm.r_xh;
+ rp->ly = realm.r_yl;
+ rp->hy = realm.r_yh;
} else {
/*
* full map specification
s_char *filename;
int x, y;
struct natstr nat;
+ struct realmstr realm;
struct sctstr sct;
- int i;
+ int i, j;
s_char *map;
int opt;
char *config_file = NULL;
nat.nat_cnum = i;
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) {
perror(teldir);
printf("Can't make telegram directory\n");