]> git.pond.sub.org Git - empserver/commitdiff
Move realms from the nation file into a new realms file:
authorRon Koenderink <rkoenderink@yahoo.ca>
Fri, 13 Jan 2006 13:18:56 +0000 (13:18 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Fri, 13 Jan 2006 13:18:56 +0000 (13:18 +0000)
(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.

include/file.h
include/nat.h
include/nsc.h
src/lib/commands/add.c
src/lib/commands/new.c
src/lib/commands/real.c
src/lib/global/file.c
src/lib/global/nsc.c
src/lib/subs/fileinit.c
src/lib/subs/sarg.c
src/util/files.c

index 57db5210cd5d608c3eb93345c032f55392809471..7f8a847eb89a0490108a46798c522ad52e0ff5b7 100644 (file)
@@ -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 *);
index b2142a08b743e22c0534a7706d795672efd9e409..e5fb93005649cd54b8e8e4474d3eaeb78997015e 100644 (file)
@@ -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);
index dbc0aaa537df6725094bf741cf2a02aeec2d14d5..da0d96f81be4788e7acbf27c901cefa7d84fd806 100644 (file)
@@ -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[];
index 819f229f0c95c73ce273ca399b764153df502444..7dbe65c2b8fbc16d8a0cf9f1b65bafad722ecda1 100644 (file)
@@ -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;
index cb18115a50b2a9fb83354ba20b1ff3d11c8e4fcd..5fbc270d9a3ffc2d5739b32f74055015ce6ddd0c 100644 (file)
@@ -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);
index ea66e2d1760f14248daff46bacdb9dd6c65f38fa..b5b959ed2ee3706651f0c1622efa1f9b5862fa6e 100644 (file)
 #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;
 }
index ec5a7b5ab5dfe484b4a9483b92854f87b572358f..62446c9985f36cfc02cb83ff4abb051e7047ef0c 100644 (file)
@@ -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)},
index f25061375ab19f26d1c4afc82134e770637b66fa..1f46de487d29960ed729609bef4cd4ca78c37e1b 100644 (file)
@@ -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},
index ce86006e9e79ff668fe1e7da1b4b4bc2b19284ad..c1ab7ec453cab1f282e2e50d6b62df40d1b03696 100644 (file)
@@ -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);
 }
index acb7ec25861f297601491d8dbf784e0b6dc9dfa1..9c93129447956781333129de4c30286a5d9a0468 100644 (file)
@@ -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
index 27f83b0a148d91ec6fab79a6a468ae9945a92d82..bd782635d77371f2903fdfa81e22d81c17f3b859 100644 (file)
@@ -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");