]> git.pond.sub.org Git - empserver/commitdiff
edit: Report sector loss and gain properly for key 'L'
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Jan 2013 07:58:14 +0000 (08:58 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:00 +0000 (19:55 +0200)
Send bulletin to owner and report news exactly like for key 'o'.

Also print a "sector duplicated" message, just for consistency with
other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/actofgod.h [new file with mode: 0644]
include/prototypes.h
src/lib/commands/edit.c
src/lib/subs/actofgod.c [new file with mode: 0644]
tests/actofgod/actofgod.xdump
tests/actofgod/journal.log

diff --git a/include/actofgod.h b/include/actofgod.h
new file mode 100644 (file)
index 0000000..a28030a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
+ *
+ *  Empire is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  ---
+ *
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  actofgod.h: Deity meddling
+ *
+ *  Known contributors to this file:
+ *     Markus Armbruster, 2013
+ */
+
+#ifndef ACTOFGOD_H
+#define ACTOFGOD_H
+
+#include "item.h"
+#include "nat.h"
+
+extern void report_god_takes(char *, char *, natid);
+extern void report_god_gives(char *, char *, natid);
+
+#endif
index 9548c146ca6e34f9f2e6ccc09c6c34390a472bef..517a142fe1e848b171c60356a970cb361e4fa3a5 100644 (file)
@@ -384,6 +384,8 @@ extern void stop_service(void);
 /*
  * src/lib/subs/ *.c
  */
+/* actofgod.c */
+/* in actofgod.h */
 /* askyn.c */
 extern int confirm(char *);
 extern int askyn(char *);
index fd286a8ab4deac44e2d7a4a935875d00fcfab0a9..519a271fd5ba3577b45e4cddde0b572a3e6e9526 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <ctype.h>
 #include <limits.h>
+#include "actofgod.h"
 #include "commands.h"
 #include "item.h"
 #include "land.h"
@@ -421,6 +422,7 @@ edit_sect(struct sctstr *sect, char *key, int arg, char *p)
 {
     coord newx, newy;
     int new;
+    struct sctstr newsect;
 
     switch (*key) {
     case 'o':
@@ -431,21 +433,13 @@ edit_sect(struct sctstr *sect, char *key, int arg, char *p)
           prnatid(sect->sct_own), prnatid(arg));
        if (arg == sect->sct_own)
            break;
-       if (sect->sct_own && sect->sct_own != player->cnum) {
-           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, -1);
+       report_god_takes("Sector ",
+                        xyas(sect->sct_x, sect->sct_y, sect->sct_own),
+                        sect->sct_own);
+       report_god_gives("Sector ",
+                        xyas(sect->sct_x, sect->sct_y, arg),
+                        arg);
        sect->sct_own = arg;
-       if (arg && arg != player->cnum) {
-           wu(0, arg,
-              "Sector %s given to you by an act of %s!\n",
-              xyas(sect->sct_x, sect->sct_y, arg),
-              cname(player->cnum));
-       }
-       benefit(arg, 1);
        break;
     case 'O':
        if (arg < 0 || arg >= MAXNOC)
@@ -553,6 +547,14 @@ edit_sect(struct sctstr *sect, char *key, int arg, char *p)
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
            return RET_SYN;
+       getsect(newx, newy, &newsect);
+       pr("Sector %s duplicated to %s\n",
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          xyas(newx, newy, player->cnum));
+       report_god_takes("Sector ", xyas(newx, newy, newsect.sct_own),
+                        newsect.sct_own);
+       report_god_gives("Sector ", xyas(newx, newy, sect->sct_own),
+                        sect->sct_own);
        sect->sct_x = newx;
        sect->sct_y = newy;
        ef_set_uid(EF_SECTOR, &sect, XYOFFSET(newx, newy));
diff --git a/src/lib/subs/actofgod.c b/src/lib/subs/actofgod.c
new file mode 100644 (file)
index 0000000..1a189bb
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ *  Empire - A multi-player, client/server Internet based war game.
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
+ *
+ *  Empire is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  ---
+ *
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
+ *
+ *  ---
+ *
+ *  actofgod.c: Deity meddling subroutines
+ *
+ *  Known contributors to this file:
+ *     Markus Armbruster, 2013
+ */
+
+#include <config.h>
+
+#include "actofgod.h"
+#include "file.h"
+#include "news.h"
+#include "optlist.h"
+#include "player.h"
+#include "prototypes.h"
+
+static void
+nreport_divine_aid(natid whom, int goodness)
+{
+    if (opt_GODNEWS && getnatp(whom)->nat_stat != STAT_GOD && goodness)
+       nreport(player->cnum, goodness > 0 ? N_AIDS : N_HURTS, whom, 1);
+}
+
+void
+report_god_takes(char *prefix, char *what, natid from)
+{
+    if (from && from != player->cnum) {
+       wu(0, from, "%s%s taken from you by an act of %s!\n",
+          prefix, what, cname(player->cnum));
+       nreport_divine_aid(from, -1);
+    }
+}
+
+void
+report_god_gives(char *prefix, char *what, natid to)
+{
+    if (to && to != player->cnum) {
+       wu(0, to, "%s%s given to you by an act of %s!\n",
+          prefix, what, cname(player->cnum));
+       nreport_divine_aid(to, 1);
+    }
+}
index c24b973e6d6132b4e0da9bd4989e6cb87479a37b..4275ec7e2882beabca1859bcd80a871b0fa6b56d 100644 (file)
@@ -360,12 +360,15 @@ 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 3 1 0 0
+0 43 3 1 0 0
 0 44 1 19 0 0
 0 43 2 1 0 0
+0 44 3 2 0 0
+0 43 3 2 0 0
 0 43 1 54 0 0
 0 42 1 4 0 0
 1 45 0 1 0 0
-0 43 3 1 0 0
 /config
 config treaty
 uid cna cnb status acond bcond exp
index 55b93449a0d565111d766f8bceb150714c5cea9c..58f99e10d59b0d515bcc33f9a62590576a31168c 100644 (file)
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 1,7 L 1,-7
     Play#0 command edit
+    Play#0 output Play#0 1 Sector 1,7 duplicated to 1,-7
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 3,-7 L 3,-7 L 1,0
     Play#0 command edit
+    Play#0 output Play#0 1 Sector 3,-7 duplicated to 3,-7
     Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 1,1 e 0
     Play#0 command read
     Play#0 output Play#0 1 
     Play#0 output Play#0 1 > BULLETIN from POGO, (#0)  dated Thu Jan  1 00:00:00 1970
+    Play#0 output Play#0 1 Sector 1,-7 taken from you by an act of POGO!
+    Play#0 output Play#0 1 Sector 3,-7 taken from you by an act of POGO!
+    Play#0 output Play#0 1 Sector 3,-7 given to you by an act of POGO!
     Play#0 output Play#0 1 cs   cargo ship (#0) taken from you by an act of POGO!
     Play#0 output Play#0 1 cs   cargo ship (#1) taken from you by an act of POGO!
     Play#0 output Play#0 1 cs   cargo ship (#2) taken from you by an act of POGO!