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_takes(char *, char *, natid);
|
||||||
extern void report_god_gives(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
|
#endif
|
||||||
|
|
|
@ -231,14 +231,8 @@ benefit(natid who, int goodness)
|
||||||
static void
|
static void
|
||||||
noise(struct sctstr *sptr, char *name, int old, int new)
|
noise(struct sctstr *sptr, char *name, int old, int new)
|
||||||
{
|
{
|
||||||
pr("%s of %s changed from %d to %d\n",
|
divine_sct_change(sptr, name, new != old, new - old,
|
||||||
name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
|
"from %d to %d", 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -438,17 +432,9 @@ edit_sect_i(struct sctstr *sect, char *key, int arg)
|
||||||
case 'O':
|
case 'O':
|
||||||
if (arg < 0 || arg >= MAXNOC)
|
if (arg < 0 || arg >= MAXNOC)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
pr("Old owner of %s changed from %s to %s\n",
|
divine_sct_change(sect, "Old owner", arg != sect->sct_oldown, 0,
|
||||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
"from %s to %s",
|
||||||
prnatid(sect->sct_oldown), prnatid(arg));
|
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));
|
|
||||||
sect->sct_oldown = arg;
|
sect->sct_oldown = arg;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
|
@ -618,18 +604,9 @@ edit_sect(struct sctstr *sect, char *key, char *p)
|
||||||
new = sct_typematch(p);
|
new = sct_typematch(p);
|
||||||
if (new < 0)
|
if (new < 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
pr("Designation of %s changed from %c to %c\n",
|
divine_sct_change(sect, "Designation",
|
||||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
new != sect->sct_type, 0, "from %c to %c",
|
||||||
dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
|
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));
|
|
||||||
set_coastal(sect, sect->sct_type, new);
|
set_coastal(sect, sect->sct_type, new);
|
||||||
sect->sct_type = new;
|
sect->sct_type = new;
|
||||||
break;
|
break;
|
||||||
|
@ -637,18 +614,9 @@ edit_sect(struct sctstr *sect, char *key, char *p)
|
||||||
new = sct_typematch(p);
|
new = sct_typematch(p);
|
||||||
if (new < 0)
|
if (new < 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
pr("New designation of %s changed from %c to %c\n",
|
divine_sct_change(sect, "New designation",
|
||||||
xyas(sect->sct_x, sect->sct_y, player->cnum),
|
new != sect->sct_newtype, 0, "from %c to %c",
|
||||||
dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
|
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));
|
|
||||||
sect->sct_newtype = new;
|
sect->sct_newtype = new;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -32,12 +32,14 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include "actofgod.h"
|
#include "actofgod.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "news.h"
|
#include "news.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
#include "sect.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nreport_divine_aid(natid whom, int goodness)
|
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);
|
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