]> git.pond.sub.org Git - empserver/commitdiff
relations: New enum relations
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 31 Oct 2016 13:54:21 +0000 (14:54 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:21 +0000 (20:09 +0200)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/nat.h
src/lib/commands/assa.c
src/lib/commands/decl.c
src/lib/commands/spy.c
src/lib/common/nat.c
src/lib/subs/aircombat.c
src/lib/subs/lndsub.c
src/lib/subs/mission.c
src/lib/subs/rej.c

index 6c85ca333c31711450c6457be7c55fe14b40a320..0d5683ae2dbf8d64b3bd7caea1f703fc90be2aaf 100644 (file)
@@ -111,21 +111,27 @@ struct natstr {
     time_t nat_newstim;                /* date news last read */
     time_t nat_annotim;                /* date annos last read */
     float nat_level[4];                /* technology, etc */
-    unsigned char nat_relate[MAXNOC];
+    unsigned char nat_relate[MAXNOC]; /* enum relations */
 };
 
-       /* nation relation codes */
-#define AT_WAR         0
-#define HOSTILE                1
-#define NEUTRAL                2
-#define FRIENDLY       3
-#define ALLIED         4
-
 #define NAT_TLEV       0
 #define NAT_RLEV       1
 #define NAT_ELEV       2
 #define NAT_HLEV       3
 
+/* Diplomatic relations */
+enum relations {
+    /*
+     * Don't change order without checking inequality comparisons and
+     * array initializers!
+     */
+    AT_WAR,
+    HOSTILE,
+    NEUTRAL,
+    FRIENDLY,
+    ALLIED
+};
+
 /*
  * Number of updates contact lasts for various ways of making contact.
  * These are only useful with option LOSE_CONTACT, which implies
@@ -197,8 +203,8 @@ extern double techfact(int level, double mult);
 extern char *cname(natid n);
 extern char *relatename(struct natstr *np, natid other);
 extern char *natstate(struct natstr *np);
-extern int getrel(struct natstr *np, natid them);
-extern int relations_with(natid, natid);
+extern enum relations getrel(struct natstr *np, natid them);
+extern enum relations relations_with(natid, natid);
 extern int nat_accepts(natid, natid, enum rej_comm);
 extern int in_contact(natid, natid);
 extern void agecontact(struct natstr *np);
@@ -215,7 +221,7 @@ extern char *prnatid(natid);
 extern int grant_btus(struct natstr *, int);
 
 /* src/lib/subs/rej.c */
-extern void setrel(natid, natid, int);
+extern void setrel(natid, natid, enum relations);
 extern void setcont(natid, natid, int);
 extern void setrej(natid, natid, int, enum rej_comm);
 
index ba9fccaf0bf4db189209b660bb467e440fd6e160..03e0ac39c66cef9815c20a4a5cd4b0194db7635d 100644 (file)
@@ -192,7 +192,7 @@ sneak_ashore(struct combat off[], struct emp_qelem *olist,
     struct emp_qelem *qp;
     struct ulist *llp;
     struct lndstr *lp;
-    int rel;
+    enum relations rel;
 
     pr("Trying to sneak on shore...\n");
 
index 703b573a5211735dd6c922bc4b538f80a9bddae6..cdf7d6eddb1b324edd152c1bd4b8dd7e49f2349a 100644 (file)
@@ -39,7 +39,7 @@ int
 decl(void)
 {
     struct natstr nat;
-    int rel;
+    enum relations rel;
     int who;
     struct nstr_item ni;
     char *p;
index 4c7b44481687eec8f840bb5d8b8e4e766da65cae..f12442abc10e039a41ca834df516cc33a5a6adf3 100644 (file)
@@ -57,7 +57,7 @@ int
 spy(void)
 {
     natid own;
-    int relat;
+    enum relations relat;
     coord x, y;
     coord nx, ny;
     int military;
@@ -252,7 +252,7 @@ prplanes(int x, int y)
 static char *
 player_relstr(natid them)
 {
-    int rel = relations_with(player->cnum, them);
+    enum relations rel = relations_with(player->cnum, them);
 
     if (rel == ALLIED)
        return "Allied";
index 0760816540839630eb623431fb53eadfe42defbc..35b941fe7d783a8aeedad6e9458d3f9deac1f125 100644 (file)
@@ -42,7 +42,7 @@
 #include "tel.h"
 
 char *relates[] = {
-    /* must follow nation relation defines in nat.h */
+    /* must match enum relations */
     "At War", "Hostile", "Neutral", "Friendly", "Allied"
 };
 
@@ -73,7 +73,7 @@ natstate(struct natstr *np)
 }
 
 /* This returns the relations that np has with them */
-int
+enum relations
 getrel(struct natstr *np, natid them)
 {
     return np->nat_relate[them];
@@ -83,7 +83,7 @@ getrel(struct natstr *np, natid them)
  * Return relations @us has with @them.
  * Countries are considered allied to themselves.
  */
-int
+enum relations
 relations_with(natid us, natid them)
 {
     return us == them ? ALLIED : getrel(getnatp(us), them);
index 09f76c3c80ba6567ed88ee44817746c4e0777e08..a648cf68c73fda136aeb6549d820e5cfd8669425 100644 (file)
@@ -65,7 +65,7 @@ static void ac_doflak(struct emp_qelem *, struct sctstr *);
 static void ac_landflak(struct emp_qelem *, coord, coord);
 static void ac_shipflak(struct emp_qelem *, coord, coord);
 static void ac_fireflak(struct emp_qelem *, natid, int);
-static void getilists(struct emp_qelem *, unsigned char *, natid);
+static void getilists(struct emp_qelem *, enum relations[], natid);
 static int do_evade(struct emp_qelem *, struct emp_qelem *);
 
 void
@@ -76,7 +76,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     int dir;
     unsigned char gotships[MAXNOC];
     unsigned char gotlands[MAXNOC];
-    unsigned char rel[MAXNOC];
+    enum relations rel[MAXNOC];
     int overfly[MAXNOC];
     int flags;
     struct emp_qelem ilist[MAXNOC];
@@ -741,7 +741,7 @@ ac_flak_dam(int guns, int def, int pl_flags)
  * Get planes available for interception duties.
  */
 static void
-getilists(struct emp_qelem *list, unsigned char *rel, natid intruder)
+getilists(struct emp_qelem *list, enum relations rel[], natid intruder)
 {
     natid cn;
     struct plchrstr *pcp;
index eaabfbb7ab15b2e25ed0c55ff5e7e25e9ab4c4f0..59c7574074ff66b845f3e1405cd7dbc6542f39c8 100644 (file)
@@ -987,7 +987,7 @@ lnd_mar_dir(struct emp_qelem *list, int dir, natid actor)
     coord newx;
     coord newy;
     int move;
-    int rel;
+    enum relations rel;
     int oldown;
 
     if (CANT_HAPPEN(QEMPTY(list)))
index fc4f600843d54cb8fefbf6d93cab2edf9ec8d165..9313d5e6c58d98d6e44528d94105ee4032024329 100644 (file)
@@ -179,7 +179,8 @@ int
 unit_interdict(coord x, coord y, natid victim, char *s, int hardtarget,
               int mission)
 {
-    int cn, rel, newdam, osubs;
+    int cn, newdam, osubs;
+    enum relations rel;
     int dam = -1;
     unsigned char plane_act[MAXNOC], other_act[MAXNOC];
     struct genlist mi[MAXNOC];
index 699ad38aebd7999eedf202fddbedd851a9473539..c72fcb32917d020672936777636dc060ba7bb10d 100644 (file)
 #include "update.h"
 
 void
-setrel(natid us, natid them, int rel)
+setrel(natid us, natid them, enum relations rel)
 {
     struct natstr *mynp = getnatp(us);
-    int oldrel;
+    enum relations oldrel;
     char *whichway;
     int n_up = 0;
     int n_down = 0;