actofgod: Factor divine_sct_change() out of edit.c
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
82a59fbcc3
commit
6ff503c288
3 changed files with 48 additions and 43 deletions
|
@ -38,5 +38,7 @@
|
|||
|
||||
extern void report_god_takes(char *, char *, natid);
|
||||
extern void report_god_gives(char *, char *, natid);
|
||||
extern void divine_sct_change(struct sctstr *, char *, int, int, char *, ...)
|
||||
ATTRIBUTE((format (printf, 5, 6)));
|
||||
|
||||
#endif
|
||||
|
|
|
@ -231,14 +231,8 @@ benefit(natid who, int goodness)
|
|||
static void
|
||||
noise(struct sctstr *sptr, char *name, int old, int new)
|
||||
{
|
||||
pr("%s of %s changed from %d to %d\n",
|
||||
name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
|
||||
if (sptr->sct_own && sptr->sct_own != player->cnum && new != old)
|
||||
wu(0, sptr->sct_own,
|
||||
"%s of %s changed from %d to %d by an act of %s\n",
|
||||
name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own),
|
||||
old, new, cname(player->cnum));
|
||||
benefit(sptr->sct_own, new - old);
|
||||
divine_sct_change(sptr, name, new != old, new - old,
|
||||
"from %d to %d", old, new);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -438,17 +432,9 @@ edit_sect_i(struct sctstr *sect, char *key, int arg)
|
|||
case 'O':
|
||||
if (arg < 0 || arg >= MAXNOC)
|
||||
return RET_SYN;
|
||||
pr("Old owner of %s changed from %s to %s\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
prnatid(sect->sct_oldown), prnatid(arg));
|
||||
if (arg == sect->sct_oldown)
|
||||
break;
|
||||
if (sect->sct_own && sect->sct_own != player->cnum)
|
||||
wu(0, sect->sct_own,
|
||||
"Old owner of %s changed from %s to %s by an act of %s\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
prnatid(sect->sct_oldown), prnatid(arg),
|
||||
cname(player->cnum));
|
||||
divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
|
||||
"from %s to %s",
|
||||
prnatid(sect->sct_oldown), prnatid(arg));
|
||||
sect->sct_oldown = arg;
|
||||
break;
|
||||
case 'e':
|
||||
|
@ -618,18 +604,9 @@ edit_sect(struct sctstr *sect, char *key, char *p)
|
|||
new = sct_typematch(p);
|
||||
if (new < 0)
|
||||
return RET_SYN;
|
||||
pr("Designation of %s changed from %c to %c\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
|
||||
if (new == sect->sct_type)
|
||||
break;
|
||||
if (sect->sct_own && sect->sct_own != player->cnum)
|
||||
wu(0, sect->sct_own,
|
||||
"Designation of %s changed from %c to %c"
|
||||
" by an act of %s\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
dchr[sect->sct_type].d_mnem, dchr[new].d_mnem,
|
||||
cname(player->cnum));
|
||||
divine_sct_change(sect, "Designation",
|
||||
new != sect->sct_type, 0, "from %c to %c",
|
||||
dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
|
||||
set_coastal(sect, sect->sct_type, new);
|
||||
sect->sct_type = new;
|
||||
break;
|
||||
|
@ -637,18 +614,9 @@ edit_sect(struct sctstr *sect, char *key, char *p)
|
|||
new = sct_typematch(p);
|
||||
if (new < 0)
|
||||
return RET_SYN;
|
||||
pr("New designation of %s changed from %c to %c\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
|
||||
if (new == sect->sct_newtype)
|
||||
break;
|
||||
if (sect->sct_own && sect->sct_own != player->cnum)
|
||||
wu(0, sect->sct_own,
|
||||
"New designation of %s changed from %c to %c"
|
||||
" by an act of %s\n",
|
||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
||||
dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem,
|
||||
cname(player->cnum));
|
||||
divine_sct_change(sect, "New designation",
|
||||
new != sect->sct_newtype, 0, "from %c to %c",
|
||||
dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
|
||||
sect->sct_newtype = new;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue