]> git.pond.sub.org Git - empserver/commitdiff
actofgod: New divine_unit_change(), similar to divine_sct_change()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2013 11:53:03 +0000 (12:53 +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/subs/actofgod.c

index 79d0b99dbe31600e4a2edb7c18c245a94298073a..c7be022dc067d0bec7fd9dd4a7efbe80925dfd7a 100644 (file)
@@ -42,6 +42,10 @@ 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 divine_unit_change(struct empobj *, char *, int, int, char *, ...)
+    ATTRIBUTE((format (printf, 5, 6)));
+#define divine_unit_change_quiet(unit, name, change, ...) \
+    divine_unit_change((unit), (name), -(change), 0, __VA_ARGS__)
 extern void report_divine_gift(natid, struct ichrstr *, int, char *);
 
 #endif
index 215e944a6b80b10e5795023a966e73ec60867047..16a24890c53479e163ff09f37d1aacbb28753acb 100644 (file)
@@ -40,6 +40,7 @@
 #include "player.h"
 #include "prototypes.h"
 #include "sect.h"
+#include "unit.h"
 
 static void
 nreport_divine_aid(natid whom, int goodness)
@@ -108,6 +109,35 @@ divine_sct_change(struct sctstr *sp, char *name,
     }
 }
 
+/*
+ * Report deity meddling with UNIT.
+ * Just like divine_sct_change(), only for ships, planes, land units,
+ * nukes.
+ */
+void
+divine_unit_change(struct empobj *unit, char *name,
+                  int change, int goodness, char *fmt, ...)
+{
+    va_list ap;
+    char buf[4096];
+
+    va_start(ap, fmt);
+    vsnprintf(buf, sizeof(buf), fmt, ap);
+    va_end(ap);
+
+    if (!change) {
+       pr("%s of %s unchanged\n", name, unit_nameof(unit));
+       return;
+    }
+
+    pr("%s of %s changed %s\n", name, unit_nameof(unit), buf);
+    if (change > 0 && unit->own && unit->own != player->cnum) {
+       wu(0, unit->own, "%s of %s changed %s by an act of %s\n",
+          name, unit_nameof(unit), buf, cname(player->cnum));
+       nreport_divine_aid(unit->own, goodness);
+    }
+}
+
 /*
  * Report deity giving/taking commodities to/from WHOM.
  * Give AMT of IP in PLACE.