]> git.pond.sub.org Git - empserver/commitdiff
reject: Replace getrejects() by nat_accepts()
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 31 Oct 2016 10:39:05 +0000 (11:39 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:21 +0000 (20:09 +0200)
All callers of getrejects() also check whether the sender is a deity.
Factor out the common code into nat_accepts(), and drop getrejects().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/nat.h
src/lib/commands/acce.c
src/lib/commands/offe.c
src/lib/commands/rea.c
src/lib/commands/tele.c
src/lib/common/nat.c
src/lib/subs/rej.c
src/lib/subs/wu.c

index f233253acd7bcd503572f92518780a9d1aabfb75..e4f70a5ecd1f253ecf85c90a873699b04531b97e 100644 (file)
@@ -181,7 +181,7 @@ 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 int getrejects(natid them, struct natstr *np);
+extern int nat_accepts(struct natstr *, natid, int);
 extern int in_contact(natid, natid);
 extern void putrel(struct natstr *np, natid them, int relate);
 extern void agecontact(struct natstr *np);
index e15aa23a8a5daf5766f43ae94ea11c8fef5b9fb2..8ebbcef6e40762909bb585636515998e053c299d 100644 (file)
@@ -80,11 +80,9 @@ static void
 pr_accept(struct natstr *to, natid from)
 {
     static char *yes_no[] = { "YES", " NO" };
-    int rej = getrejects(from, to);
-    int from_deity = getnatp(from)->nat_stat == STAT_GOD;
 
     pr("   %s  %s  %s",
-       yes_no[!from_deity && (rej & REJ_TELE)],
-       yes_no[!from_deity && (rej & REJ_ANNO)],
-       yes_no[!from_deity && (rej & REJ_LOAN)]);
+       yes_no[!nat_accepts(to, from, REJ_TELE)],
+       yes_no[!nat_accepts(to, from, REJ_ANNO)],
+       yes_no[!nat_accepts(to, from, REJ_LOAN)]);
 }
index 0a76bede26dc17e311fda2cab874f6f5d33b307e..c302213826dd3a3961b352a59b67500a2f3a2990 100644 (file)
@@ -78,7 +78,7 @@ do_loan(void)
        return RET_FAIL;
     }
     natp = getnatp(recipient);
-    if (!player->god && (getrejects(player->cnum, natp) & REJ_LOAN)) {
+    if (!nat_accepts(natp, player->cnum, REJ_LOAN)) {
        pr("%s is rejecting your loans.\n", cname(recipient));
        return RET_SYN;
     }
index baa103ee206f820ae27f9c9ae796c75189e6e5b1..cbb0968a5a5edd15158a154ae6470a4b010ee76d 100644 (file)
@@ -107,8 +107,7 @@ rea(void)
        if (res <= 0)
            break;
        if (*kind == 'a') {
-           if ((getnatp(tgm.tel_from)->nat_stat != STAT_GOD
-                && (getrejects(tgm.tel_from, np) & REJ_ANNO))
+           if ((!nat_accepts(np, tgm.tel_from, REJ_ANNO))
                || tgm.tel_date < then) {
                res = tel_read_body(telfp, mbox, &tgm, NULL, NULL);
                if (res < 0)
index 05f6446fc5dc2a985ab66b3ade142786a5db61ab..a5e5e904d9b091e227a9ca08cf31afcea9425a6a 100644 (file)
@@ -92,8 +92,7 @@ tele(void)
                kk++;
                continue;
            }
-           if (!player->god
-               && (getrejects(player->cnum, natp) & REJ_TELE)) {
+           if (!nat_accepts(natp, player->cnum, REJ_TELE)) {
                pr("%s is rejecting your telegrams.\n", cname(to));
                return RET_SYN;
            }
index 265a0401aa924d8146ecb7096808d1467bc97155..87f0cff94e6fb89e05b57436b14138ee0940505c 100644 (file)
@@ -90,9 +90,10 @@ relations_with(natid us, natid them)
 }
 
 int
-getrejects(natid them, struct natstr *np)
+nat_accepts(struct natstr *np, natid them, int what)
 {
-    return np->nat_rejects[them];
+    return getnatp(them)->nat_stat == STAT_GOD
+       || !(np->nat_rejects[them] & what);
 }
 
 void
index 279ea36f2801160eaded34e76a19f8d11ba8e423..d0a0abca6916aed92d855fd09cfbf0af81d55cd9 100644 (file)
@@ -88,7 +88,7 @@ setrel(natid us, natid them, int rel)
        pr("%s\n", addendum);
     mpr(us, "Diplomatic relations with %s %s to \"%s\".\n",
        cname(them), whichway, relates[rel]);
-    if (mynp->nat_stat == STAT_GOD || !(getrejects(us, themnp) & REJ_TELE))
+    if (nat_accepts(themnp, us, REJ_TELE))
        mpr(them,
            "Country %s has %s their relations with you to \"%s\"!\n",
            prnat(mynp), whichway, relates[rel]);
index d97b3c9f033fb175e9f1e44f5825acc5cd452ddf..18088cc751725617747e689da5ecd9fabe4ebb4c 100644 (file)
@@ -153,8 +153,7 @@ typed_wu(natid from, natid to, char *message, int type)
        for (to = 0; NULL != (np = getnatp(to)); to++) {
            if (np->nat_stat < STAT_SANCT)
                continue;
-           if (getnatp(from)->nat_stat != STAT_GOD
-               && (getrejects(from, np) & REJ_ANNO))
+           if (!nat_accepts(np, from, REJ_ANNO))
                continue;
            if (!np->nat_ann || !tel.tel_cont) {
                np->nat_ann++;