From bdf7cbce38ff222b9c0e182f1ed1b59058ac313d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 22 Jan 2013 21:33:40 +0100 Subject: [PATCH] edit &c: Suppress news and bulletins on no-op acts of god give already suppresses when the new value equals the old one, but edit, setresource and setsector don't. Make them. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 34 ++++++++++++++++------------- src/lib/commands/setsect.c | 20 ++++++------------ tests/actofgod/actofgod.xdump | 3 +-- tests/actofgod/journal.log | 40 ----------------------------------- 4 files changed, 27 insertions(+), 70 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 85a876102..f8d4f99ca 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -225,18 +225,10 @@ edit(void) } static void -benefit(natid who, int good) +benefit(natid who, int goodness) { - if (!opt_GODNEWS) - return; - - if (good) { - if (who) - nreport(player->cnum, N_AIDS, who, 1); - } else { - if (who) - nreport(player->cnum, N_HURTS, who, 1); - } + if (opt_GODNEWS && who && goodness) + nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, who, 1); } static void @@ -244,12 +236,12 @@ 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) + if (sptr->sct_own && new != old) wu(0, sptr->sct_own, "%s in %s was 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, old < new); + benefit(sptr->sct_own, new - old); } static void @@ -437,13 +429,15 @@ edit_sect(struct sctstr *sect, char *key, int arg, char *p) pr("Owner of %s changed from %s to %s.\n", xyas(sect->sct_x, sect->sct_y, player->cnum), prnatid(sect->sct_own), prnatid(arg)); + if (arg == sect->sct_own) + break; if (sect->sct_own) { wu(0, sect->sct_own, "Sector %s taken from you by an act of %s!\n", xyas(sect->sct_x, sect->sct_y, sect->sct_own), cname(player->cnum)); } - benefit(sect->sct_own, 0); + benefit(sect->sct_own, -1); sect->sct_own = arg; if (arg) { wu(0, arg, @@ -644,9 +638,11 @@ edit_nat(struct natstr *np, char *key, int arg, char *p) break; case 'm': arg = LIMIT_TO(arg, 0, INT_MAX); - benefit(nat, np->nat_reserve < arg); + benefit(nat, arg - np->nat_reserve); pr("Military reserves changed from %d to %d\n", np->nat_reserve, arg); + if (arg == np->nat_reserve) + break; wu(0, nat, "Military reserves changed from %d to %d by an act of %s\n", np->nat_reserve, arg, cname(player->cnum)); @@ -681,6 +677,8 @@ edit_nat(struct natstr *np, char *key, int arg, char *p) break; case 'M': pr("Money changed from %d to %d\n", np->nat_money, arg); + if (arg == np->nat_money) + break; wu(0, nat, "Money changed from %d to %d by an act of %s\n", np->nat_money, arg, cname(player->cnum)); np->nat_money = arg; @@ -746,6 +744,8 @@ edit_ship(struct shpstr *ship, char *key, int arg, char *p) case 'O': if (arg < 0 || arg >= MAXNOC) return RET_SYN; + if (arg == ship->shp_own) + break; if (ship->shp_own) wu(0, ship->shp_own, "%s taken from you by an act of %s!\n", prship(ship), cname(player->cnum)); @@ -827,6 +827,8 @@ edit_land(struct lndstr *land, char *key, int arg, char *p) case 'O': if (arg < 0 || arg >= MAXNOC) return RET_SYN; + if (arg == land->lnd_own) + break; if (land->lnd_own) wu(0, land->lnd_own, "%s taken from you by an act of %s!\n", prland(land), cname(player->cnum)); @@ -925,6 +927,8 @@ edit_plane(struct plnstr *plane, char *key, int arg, char *p) case 'O': if (arg < 0 || arg >= MAXNOC) return RET_SYN; + if (arg == plane->pln_own) + break; if (plane->pln_own) wu(0, plane->pln_own, "%s taken from you by an act of %s!\n", prplane(plane), cname(player->cnum)); diff --git a/src/lib/commands/setsect.c b/src/lib/commands/setsect.c index 0a7dedc79..686913f25 100644 --- a/src/lib/commands/setsect.c +++ b/src/lib/commands/setsect.c @@ -103,6 +103,8 @@ setsector(void) pr("Owner of %s changed from %s to %s.\n", xyas(sect.sct_x, sect.sct_y, player->cnum), prnatid(sect.sct_own), prnatid(amt)); + if (amt == sect.sct_own) + break; if (sect.sct_own) { wu(0, sect.sct_own, "Sector %s taken from you by an act of %s!\n", @@ -202,18 +204,10 @@ setsector(void) } static void -resbenefit(natid who, int good) +resbenefit(natid who, int goodness) { - if (!opt_GODNEWS) - return; - - if (good) { - if (who) - nreport(player->cnum, N_AIDS, who, 1); - } else { - if (who) - nreport(player->cnum, N_HURTS, who, 1); - } + if (opt_GODNEWS && who && goodness) + nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, who, 1); } void @@ -221,10 +215,10 @@ resnoise(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) + if (sptr->sct_own && new != old) wu(0, sptr->sct_own, "%s in %s was 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)); - resbenefit(sptr->sct_own, (old < new)); + resbenefit(sptr->sct_own, new - old); } diff --git a/tests/actofgod/actofgod.xdump b/tests/actofgod/actofgod.xdump index cf3315da1..6927d1b25 100644 --- a/tests/actofgod/actofgod.xdump +++ b/tests/actofgod/actofgod.xdump @@ -360,13 +360,12 @@ actor action victim times duration time 0 42 3 49 0 0 0 42 2 38 0 0 0 42 1 39 0 0 -0 44 1 58 0 0 +0 44 1 19 0 0 0 43 98 1 0 0 0 43 2 1 0 0 0 43 1 54 0 0 0 42 1 4 0 0 1 45 0 1 0 0 -0 44 2 1 0 0 0 43 3 1 0 0 /config config treaty diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index f52ebade9..af7b1ca34 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -1479,79 +1479,52 @@ Play#0 output Play#0 1 Sector 7,7 taken from you by an act of POGO! Play#0 output Play#0 1 Sector 9,7 taken from you by an act of POGO! Play#0 output Play#0 1 Sector 11,7 taken from you by an act of POGO! - Play#0 output Play#0 1 Efficiency in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Efficiency in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Efficiency in 5,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Efficiency in 7,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Mobility in 1,1 was changed from 0 to -127 by an act of POGO Play#0 output Play#0 1 Mobility in 3,1 was changed from 0 to -127 by an act of POGO Play#0 output Play#0 1 Mobility in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Mobility in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Iron ore content in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Iron ore content in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Iron ore content in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Iron ore content in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Iron ore content in 2,2 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Iron ore content in 4,2 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Iron ore content in 6,2 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Iron ore content in 8,2 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Iron ore content in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Iron ore content in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Iron ore content in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Iron ore content in 7,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Iron ore content in 5,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Iron ore content in 7,3 was changed from 1 to 0 by an act of POGO - Play#0 output Play#0 1 Gold content in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Gold content in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Gold content in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Gold content in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Gold content in 2,2 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Gold content in 4,2 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Gold content in 6,2 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Gold content in 8,2 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Gold content in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Gold content in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Gold content in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Gold content in 7,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Gold content in 5,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Gold content in 7,3 was changed from 1 to 0 by an act of POGO - Play#0 output Play#0 1 Fertility in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Fertility in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Fertility in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Fertility in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Fertility content in 2,2 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Fertility content in 4,2 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Fertility content in 6,2 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Fertility content in 8,2 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Fertility content in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Fertility content in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Fertility content in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Fertility content in 7,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Fertility content in 5,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Fertility content in 7,3 was changed from 1 to 0 by an act of POGO - Play#0 output Play#0 1 Oil content in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Oil content in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Oil content in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Oil content in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Oil content in 2,2 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Oil content in 4,2 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Oil content in 6,2 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Oil content in 8,2 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Oil content in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Oil content in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Oil content in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Oil content in 7,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Oil content in 5,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Oil content in 7,3 was changed from 1 to 0 by an act of POGO - Play#0 output Play#0 1 Uranium content in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Uranium content in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Uranium content in 5,1 was changed from 0 to 127 by an act of POGO Play#0 output Play#0 1 Uranium content in 7,1 was changed from 0 to 127 by an act of POGO - Play#0 output Play#0 1 Uranium content in 2,2 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Uranium content in 4,2 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Uranium content in 6,2 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Uranium content in 8,2 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Uranium content in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Uranium content in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Uranium content in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Uranium content in 7,3 was changed from 0 to 1 by an act of POGO @@ -1559,28 +1532,17 @@ Play#0 output Play#0 1 Uranium content in 7,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Workforce percentage in 1,1 was changed from 100 to 0 by an act of POGO Play#0 output Play#0 1 Workforce percentage in 3,1 was changed from 100 to 0 by an act of POGO - Play#0 output Play#0 1 Workforce percentage in 5,1 was changed from 100 to 100 by an act of POGO - Play#0 output Play#0 1 Workforce percentage in 7,1 was changed from 100 to 100 by an act of POGO - Play#0 output Play#0 1 Available workforce in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Available workforce in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Available workforce in 5,1 was changed from 0 to 9999 by an act of POGO Play#0 output Play#0 1 Available workforce in 7,1 was changed from 0 to 9999 by an act of POGO - Play#0 output Play#0 1 Mines in 1,3 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Mines in 3,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Mines in 5,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Mines in 7,3 was changed from 0 to 1 by an act of POGO Play#0 output Play#0 1 Mines in 5,3 was changed from 1 to 0 by an act of POGO Play#0 output Play#0 1 Mines in 7,3 was changed from 1 to 0 by an act of POGO - Play#0 output Play#0 1 Road percentage in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Road percentage in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Road percentage in 5,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Road percentage in 7,1 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Rail percentage in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Rail percentage in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Rail percentage in 5,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Rail percentage in 7,1 was changed from 0 to 100 by an act of POGO - Play#0 output Play#0 1 Defense percentage in 1,1 was changed from 0 to 0 by an act of POGO - Play#0 output Play#0 1 Defense percentage in 3,1 was changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Defense percentage in 5,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Defense percentage in 7,1 was changed from 0 to 100 by an act of POGO Play#0 output Play#0 1 Mobility in 1,5 was changed from 0 to 1 by an act of POGO @@ -1592,7 +1554,6 @@ Play#0 output Play#0 1 POGO gave you 1 civilians in 8,6 Play#0 output Play#0 1 POGO gave you 9997 civilians in 6,6 Play#0 output Play#0 1 POGO stole 1 civilians from 8,6 - Play#0 output Play#0 1 Military reserves changed from 0 to 0 by an act of POGO Play#0 output Play#0 1 Money changed from 0 to -2147483648 by an act of POGO Play#0 output Play#0 6 0 640 Play#0 input read 2 @@ -1604,7 +1565,6 @@ Play#0 output Play#0 1 cs cargo ship (#2) given to you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #2 given to you by an act of POGO! Play#0 output Play#0 1 sup supply #2 given to you by an act of POGO! - Play#0 output Play#0 1 Military reserves changed from 0 to 0 by an act of POGO Play#0 output Play#0 6 0 640 Play#0 input read 3 Play#0 command read -- 2.43.0