]> git.pond.sub.org Git - empserver/commitdiff
New relations_with()
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 25 Jan 2011 19:13:41 +0000 (20:13 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 13 Feb 2011 16:48:58 +0000 (17:48 +0100)
Relations checking with getrel() often needs a special case for "is
same country".  If you forget, you get behavior appropriate for a
neutral foreign country, which is usually very wrong (see commit
16c68eb4 for an example).

Unlike getrel(), relations_with() considers countries allied to
themselves.  Less dangerous.  In fact, allied behavior is typically
just right, so the special case isn't even needed.

include/nat.h
src/lib/common/nat.c

index e8c0d736e81270d2767d68229ca3d6f1241bac29..f44d30d20f93e6dc8e4e29d180b60e5f774881c1 100644 (file)
@@ -170,6 +170,7 @@ 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 relations_with(natid, natid);
 extern int getrejects(natid them, struct natstr *np);
 extern int getcontact(struct natstr *np, natid them);
 extern void putrel(struct natstr *np, natid them, int relate);
index e71e1cf81e8a2eb5ad45ae138c00ac4e214bd775..1efc5b192196dc2f4e973e189b67ea067f12b1da 100644 (file)
@@ -104,6 +104,16 @@ getrel(struct natstr *np, natid them)
     return np->nat_relate[them];
 }
 
+/*
+ * Return relations US has with THEM.
+ * Countries are considered allied to themselves.
+ */
+int
+relations_with(natid us, natid them)
+{
+    return us == them ? ALLIED : getrel(getnatp(us), them);
+}
+
 int
 getrejects(natid them, struct natstr *np)
 {