actofgod: Factor divine_sct_change() out of edit.c

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-02-03 08:27:31 +01:00
parent 82a59fbcc3
commit 6ff503c288
3 changed files with 48 additions and 43 deletions

View file

@ -32,12 +32,14 @@
#include <config.h>
#include <stdarg.h>
#include "actofgod.h"
#include "file.h"
#include "news.h"
#include "optlist.h"
#include "player.h"
#include "prototypes.h"
#include "sect.h"
static void
nreport_divine_aid(natid whom, int goodness)
@ -65,3 +67,36 @@ report_god_gives(char *prefix, char *what, natid to)
nreport_divine_aid(to, 1);
}
}
/*
* Report deity meddling with sector SP.
* Print a message (always), send a bulletin to the sector owner and
* report news (sometimes).
* NAME names what is being changed in the sector.
* If CHANGE is zero, the meddling is a no-op (bulletin suppressed).
* If a bulletin is sent, report N_AIDS news for positive GOODNESS,
* N_HURTS news for negative GOODNESS
* The bulletin's text is like "NAME of sector X,Y changed <how> by an
* act of <deity>, where <deity> is the deity's name, and <how> comes
* from formatting printf-style FMT with optional arguments.
*/
void
divine_sct_change(struct sctstr *sp, 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);
pr("%s of %s changed %s\n",
name, xyas(sp->sct_x, sp->sct_y, player->cnum), buf);
if (change && sp->sct_own && sp->sct_own != player->cnum) {
wu(0, sp->sct_own, "%s of %s changed %s by an act of %s\n",
name, xyas(sp->sct_x, sp->sct_y, sp->sct_own),
buf, cname(player->cnum));
nreport_divine_aid(sp->sct_own, goodness);
}
}