diff --git a/include/actofgod.h b/include/actofgod.h index a28030a5..767a646f 100644 --- a/include/actofgod.h +++ b/include/actofgod.h @@ -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 diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index fcd2f39b..f2a16440 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -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: diff --git a/src/lib/subs/actofgod.c b/src/lib/subs/actofgod.c index 1a189bb3..e51d72b2 100644 --- a/src/lib/subs/actofgod.c +++ b/src/lib/subs/actofgod.c @@ -32,12 +32,14 @@ #include +#include #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 by an + * act of , where is the deity's name, and 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); + } +}