]> git.pond.sub.org Git - empserver/blobdiff - include/nat.h
Extend the common header of struct empobj to include uid
[empserver] / include / nat.h
index 5b94b89f47296ab47165bfc785f388203cfdbf3b..b54c8bf9ebde001422ccfa564bb8a97f68f07da9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  nat.h: Definitions for things having to do with nations
  * 
  *  Known contributors to this file:
- *     Thomas Rushack
+ *     Thomas Ruschak
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
  */
 
-#ifndef _NAT_H_
-#define _NAT_H_
+#ifndef NAT_H
+#define NAT_H
 
-#include "sect.h"
+#include <time.h>
+#include "types.h"
+
+#define NATID_BAD 255
 
 #define        MAXNOR          50      /* max # realms */
 
-struct boundstr {
-    short b_xl, b_xh;          /* horizontal bounds */
-    short b_yl, b_yh;          /* vertical bounds */
+/* Nation status */
+typedef enum {
+    /*
+     * Don't change order without checking inequality comparisons and
+     * array initializers!
+     */
+    STAT_UNUSED,               /* not in use */
+    STAT_NEW,                  /* just initialized */
+    STAT_VIS,                  /* visitor */
+    STAT_SANCT,                        /* still in sanctuary */
+    STAT_ACTIVE,               /* active (sanctuary broken) */
+    STAT_GOD                   /* deity powers */
+} nat_status;
+
+
+/*
+ * TODO
+ *
+ * One of (r_cnum, r_realm) and r_uid is redundant, provided MAXNOR is known.
+ *
+ * The only user of r_cnum and r_realm appears to be xdump.
+ * If we had working virtual selectors, we could remove r_cnum and r_realm.
+ */
+struct realmstr {
+    /* initial part must match struct empobj */
+    short ef_type;
+    short r_uid;               /* realm table index */
+    natid r_cnum;              /* country number */
+    /* end of part matching struct empobj */
+    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 {
+    /* initial part must match struct empobj */
     short ef_type;
-    s_char nat_cnam[20];       /* country name */
-    s_char nat_pnam[20];       /* representative */
-    s_char nat_hostaddr[32];   /* host addr of last user */
-    s_char nat_hostname[512];  /* hostname of last user */
-    s_char nat_userid[32];     /* userid of last user */
-    coord nat_xstart, nat_ystart;      /* cap location at start */
+    short nat_uid;             /* equals nat_cnum */
+    natid nat_cnum;            /* our country number */
+    /* end of part matching struct empobj */
+    nat_status nat_stat;
+    char nat_cnam[20];         /* country name */
+    char nat_pnam[20];         /* representative */
+    char nat_hostaddr[32];     /* host addr of last user */
+    char nat_hostname[512];    /* hostname of last user, may be empty */
+    char nat_userid[32];       /* userid of last user, may be empty */
     coord nat_xcap, nat_ycap;  /* cap location in abs coords */
     coord nat_xorg, nat_yorg;  /* origin location in abs coords */
-    natid nat_cnum;            /* our country number */
-    s_char nat_stat;           /* inuse, norm, god, abs */
-    s_char nat_dayno;          /* day of the year mod 128 */
-    s_char nat_connected;      /* connected or not? */
-    s_char nat_update;         /* Want an update or not. */
-    u_char nat_missed;         /* How many updates missed */
-    u_short nat_tgms;          /* # of telegrams to be announced */
-    u_short nat_ann;           /* # of annos pending */
-    u_short nat_minused;       /* number of minutes used today */
+    signed char nat_dayno;     /* day of the year mod 128 */
+    signed char nat_update;    /* Want an update or not. */
+    unsigned short nat_tgms;   /* # of telegrams to be announced */
+    unsigned short nat_ann;    /* # of annos pending */
+    unsigned short nat_minused;        /* number of minutes used today */
     short nat_btu;             /* bureaucratic time units */
+    short nat_access;          /* The tick when BTUs were last updated */
     long nat_reserve;          /* military reserves */
     long nat_money;            /* moola */
-    time_t nat_last_login;     /* time of last login */
-    time_t nat_last_logout;    /* time of last logout */
+    time_t nat_last_login;     /* time of last login, 0 menas never */
+    time_t nat_last_logout;    /* time of last logout, 0 means never */
     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];
-    short nat_contact[MAXNOC];
-    short nat_rejects[(MAXNOC + 3) / 4];       /* four bits for each country */
-    s_char nat_priorities[SCT_MAXDEF + 8];     /* priority for each SCT_MAXDEF+8 */
+    unsigned char nat_relate[MAXNOC];
+    unsigned char nat_contact[MAXNOC];
+    unsigned char nat_rejects[MAXNOC];
     long nat_flags;            /* nation flags */
-    char nat_spare[15];
 };
 
-       /* Priorities */
-#define        PRI_SMAINT      SCT_MAXDEF+2
-#define PRI_PMAINT     SCT_MAXDEF+3
-#define PRI_LMAINT     SCT_MAXDEF+4
-#define PRI_SBUILD     SCT_MAXDEF+5
-#define PRI_PBUILD     SCT_MAXDEF+6
-#define PRI_LBUILD     SCT_MAXDEF+7
-
-       /* nation status types */
-#define STAT_INUSE     bit(0)  /* cnum in use */
-#define STAT_SANCT     bit(1)  /* country in sanctuary */
-#define STAT_NORM      bit(2)  /* normal country */
-#define STAT_GOD       bit(3)  /* deity powers */
-#define STAT_ABS       bit(4)  /* abs coords */
-#define STAT_NEW       bit(5)  /* just initialized */
-
-       /* Update fields. */
-#define        WUPD_WANT       bit(0)
-
-       /* nstat values */
-#define VIS            STAT_INUSE
-#define        NORM            (STAT_INUSE|STAT_NORM)
-#define        GOD             (STAT_INUSE|STAT_GOD)
-#define        SANCT           (STAT_INUSE|STAT_SANCT)
-#define        CAP             bit(6)
-#define        MONEY           bit(7)
-
        /* nation relation codes */
 #define        AT_WAR          0
 #define SITZKRIEG       1
@@ -128,31 +132,39 @@ struct natstr {
 #define        NAT_ELEV        2
 #define        NAT_HLEV        3
 
-#define FOUND_FLY      3       /* Number of updates contact lasts */
-#define FOUND_LOOK     5       /* These are only useful with the */
-#define FOUND_SPY      6       /* LOSE_CONTACT option (and HIDDEN) */
+/*
+ * Number of updates contact lasts for various ways of making contact.
+ * These are only useful with option LOSE_CONTACT option, which
+ * implies option HIDDEN.
+ */
+/* Planes spotting and being spotted */
+#define FOUND_FLY      3
+/* Lookout */
+#define FOUND_LOOK     5
+/* Spies and ground combat */
+#define FOUND_SPY      6
+/* Communication */
 #define FOUND_TELE     3
+/* Coastwatch and skywatch */
 #define FOUND_COAST    3
 
-extern s_char *relates[];
+extern char *relates[];
 
 /* procedures relating to nation stuff */
 
-#define putnat(n) \
-       ef_write(EF_NATION, n->nat_cnum, (caddr_t)n)
-#define getnatp(n) \
-       (struct natstr *) ef_ptr(EF_NATION, (int)n)
+#define putnat(p) ef_write(EF_NATION, (p)->nat_cnum, (p))
+#define getnatp(n) ((struct natstr *)ef_ptr(EF_NATION, (n)))
+
+#define getrealm(r, n, p) ef_read(EF_REALM, ((r) + ((n) * MAXNOR)), (p))
+#define putrealm(p) ef_write(EF_REALM, (p)->r_uid, (p))
 
 extern double tfact(natid cn, double mult);
-extern double tfactfire(natid cn, double mult);
 extern double techfact(int level, double mult);
-extern double techfactfire(int level, double mult);
-extern double reltech(int level1, int level2, double mult);
 
-extern s_char *cname(natid n);
-extern s_char *relatename(struct natstr *np, natid other);
-extern s_char *rejectname(struct natstr *np, natid other);
-extern s_char *natstate(struct natstr *np);
+extern char *cname(natid n);
+extern char *relatename(struct natstr *np, natid other);
+extern char *rejectname(struct natstr *np, natid other);
+extern char *natstate(struct natstr *np);
 extern int getrel(struct natstr *np, natid them);
 extern int getrejects(natid them, struct natstr *np);
 extern int getcontact(struct natstr *np, natid them);
@@ -160,6 +172,9 @@ extern void putrel(struct natstr *np, natid them, int relate);
 extern void putreject(struct natstr *np, natid them, int how, int what);
 extern void putcontact(struct natstr *np, natid them, int contact);
 extern void agecontact(struct natstr *np);
+extern int influx(struct natstr *np);
+
+extern int grant_btus(struct natstr *, int );
 
 /* nation flags */
 #define NF_INFORM      bit(0)  /* Inform me of telegrams right away */
@@ -170,4 +185,4 @@ extern void agecontact(struct natstr *np);
 #define NF_TECHLISTS    bit(5) /* Sort lists by tech not type */
 #define NF_SACKED       bit(6) /* Capital was sacked, and hasn't been reset yet */
 
-#endif /* _NAT_H_ */
+#endif