]> git.pond.sub.org Git - empserver/commitdiff
actofgod: Factor report_divine_gift() out of give()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2013 11:24:32 +0000 (12:24 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:01 +0000 (19:55 +0200)
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/actofgod.h
src/lib/commands/give.c
src/lib/subs/actofgod.c

index 786c53973da231cfde1ebc6cb7e1bf8491f7616d..79d0b99dbe31600e4a2edb7c18c245a94298073a 100644 (file)
@@ -42,5 +42,6 @@ extern void divine_sct_change(struct sctstr *, char *, int, int, char *, ...)
     ATTRIBUTE((format (printf, 5, 6)));
 #define divine_sct_change_quiet(sp, name, change, ...) \
     divine_sct_change((sp), (name), -(change), 0, __VA_ARGS__)
+extern void report_divine_gift(natid, struct ichrstr *, int, char *);
 
 #endif
index 4de98b87b65b3cf78ca0c61df5d542688c46f63a..4e1b4a0b0c7b752b2e69dfeb318c67b54b6e5d07 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <config.h>
 
+#include "actofgod.h"
 #include "commands.h"
 #include "item.h"
 #include "news.h"
@@ -74,23 +75,8 @@ give(void)
            m = n + amt;
        sect.sct_item[ip->i_uid] = m;
        putsect(&sect);
-       if (sect.sct_own != 0 && sect.sct_own != player->cnum && m != n) {
-           if (m > n) {
-               if (opt_GODNEWS
-                   && getnatp(sect.sct_own)->nat_stat != STAT_GOD)
-                   nreport(player->cnum, N_GIFT, sect.sct_own, 1);
-               wu(0, sect.sct_own, "%s gave you %d %s in %s\n",
-                  cname(player->cnum), m - n, ip->i_name,
-                  xyas(sect.sct_x, sect.sct_y, sect.sct_own));
-           } else {
-               if (opt_GODNEWS
-                   && getnatp(sect.sct_own)->nat_stat != STAT_GOD)
-                   nreport(sect.sct_own, N_TAKE, player->cnum, 1);
-               wu(0, sect.sct_own, "%s stole %d %s from %s\n",
-                  cname(player->cnum), n - m, ip->i_name,
-                  xyas(sect.sct_x, sect.sct_y, sect.sct_own));
-           }
-       }
+       report_divine_gift(sect.sct_own, ip, m - n,
+                          xyas(sect.sct_x, sect.sct_y, sect.sct_own));
        if (m - n != amt)
            pr("Only %d %s in %s\n", abs(m - n),
               m - n >= 0 ? "given" : "taken",
index c71b2d00a057a8d2c651162a21ee9d32dc41c5c8..215e944a6b80b10e5795023a966e73ec60867047 100644 (file)
@@ -107,3 +107,25 @@ divine_sct_change(struct sctstr *sp, char *name,
        nreport_divine_aid(sp->sct_own, goodness);
     }
 }
+
+/*
+ * Report deity giving/taking commodities to/from WHOM.
+ * Give AMT of IP in PLACE.
+ */
+void
+report_divine_gift(natid whom, struct ichrstr *ip, int amt, char *place)
+{
+    if (whom && whom != player->cnum && amt) {
+       if (amt > 0) {
+           if (opt_GODNEWS && getnatp(whom)->nat_stat != STAT_GOD)
+               nreport(player->cnum, N_GIFT, whom, 1);
+           wu(0, whom, "%s gave you %d %s in %s\n",
+              cname(player->cnum), amt, ip->i_name, place);
+       } else {
+           if (opt_GODNEWS && getnatp(whom)->nat_stat != STAT_GOD)
+               nreport(whom, N_TAKE, player->cnum, 1);
+           wu(0, whom, "%s stole %d %s from %s\n",
+              cname(player->cnum), -amt, ip->i_name, place);
+       }
+    }
+}