diff --git a/include/file.h b/include/file.h index 57db5210..7f8a847e 100644 --- a/include/file.h +++ b/include/file.h @@ -114,6 +114,7 @@ enum { EF_BMAP, EF_COMM, EF_LOST, + EF_REALM, /* Static game data (configuration) */ EF_SECTOR_CHR, EF_SHIP_CHR, @@ -147,7 +148,7 @@ enum { 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 *); diff --git a/include/nat.h b/include/nat.h index b2142a08..e5fb9300 100644 --- a/include/nat.h +++ b/include/nat.h @@ -65,9 +65,24 @@ enum { /* Priorities */ 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 { @@ -97,7 +112,6 @@ 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 */ @@ -162,6 +176,11 @@ extern char *relates[]; #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); diff --git a/include/nsc.h b/include/nsc.h index dbc0aaa5..da0d96f8 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 realm_ca[]; extern struct castr intrchr_ca[]; extern struct castr rpt_ca[]; extern struct castr empfile_ca[]; diff --git a/src/lib/commands/add.c b/src/lib/commands/add.c index 819f229f..7dbe65c2 100644 --- a/src/lib/commands/add.c +++ b/src/lib/commands/add.c @@ -66,6 +66,8 @@ add(void) 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) @@ -202,7 +204,12 @@ add(void) 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; diff --git a/src/lib/commands/new.c b/src/lib/commands/new.c index cb18115a..5fbc270d 100644 --- a/src/lib/commands/new.c +++ b/src/lib/commands/new.c @@ -60,13 +60,14 @@ new(void) { 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) { @@ -182,10 +183,15 @@ new(void) 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; @@ -195,8 +201,6 @@ new(void) 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); diff --git a/src/lib/commands/real.c b/src/lib/commands/real.c index ea66e2d1..b5b959ed 100644 --- a/src/lib/commands/real.c +++ b/src/lib/commands/real.c @@ -42,19 +42,19 @@ #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); @@ -63,7 +63,7 @@ list_realm(int curr, struct natstr *natp) int real(void) { - register struct boundstr *rp; + struct realmstr realm; struct natstr *natp; int curr; int lastr; @@ -97,14 +97,14 @@ real(void) 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; } diff --git a/src/lib/global/file.c b/src/lib/global/file.c index ec5a7b5a..62446c99 100644 --- a/src/lib/global/file.c +++ b/src/lib/global/file.c @@ -141,6 +141,8 @@ struct empfile empfile[] = { 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)}, diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index f2506137..1f46de48 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -526,6 +526,17 @@ struct castr nat_ca[] = { {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}, diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index ce86006e..c1ab7ec4 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -106,6 +106,7 @@ ef_open_srv(void) 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); @@ -130,4 +131,5 @@ ef_close_srv(void) ef_close(EF_COMM); ef_close(EF_BMAP); ef_close(EF_LOST); + ef_close(EF_REALM); } diff --git a/src/lib/subs/sarg.c b/src/lib/subs/sarg.c index acb7ec25..9c931294 100644 --- a/src/lib/subs/sarg.c +++ b/src/lib/subs/sarg.c @@ -100,6 +100,7 @@ sarg_getrange(char *str, struct range *rp) { long rlm; struct natstr *np; + struct realmstr realm; char *end; if (*str == '#') { @@ -114,11 +115,11 @@ sarg_getrange(char *str, struct range *rp) 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 diff --git a/src/util/files.c b/src/util/files.c index 27f83b0a..bd782635 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -79,8 +79,9 @@ main(int argc, char *argv[]) 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; @@ -151,6 +152,17 @@ main(int argc, char *argv[]) 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");