]> git.pond.sub.org Git - empserver/commitdiff
edit: Report loading/unloading of planes & land units properly
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2013 12:28:26 +0000 (13:28 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:02 +0000 (19:55 +0200)
Print a message, send bulletin to owner.  Affects plane keys 's', 'y',
and land unit keys 'S', 'Y'.  The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player loading a
plane right before the deity edits it.  Watching out for such changes
is especially important with non-interactive edit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/actofgod.h
src/lib/commands/edit.c
src/lib/subs/actofgod.c
tests/actofgod/journal.log

index c7be022dc067d0bec7fd9dd4a7efbe80925dfd7a..9f991c61a23b82fb40f6188f1277464445ad4e17 100644 (file)
@@ -38,6 +38,8 @@
 
 extern void report_god_takes(char *, char *, natid);
 extern void report_god_gives(char *, char *, natid);
+extern void divine_load(struct empobj *, int, int);
+extern void divine_unload(struct empobj *, int, int);
 extern void divine_sct_change(struct sctstr *, char *, int, int, char *, ...)
     ATTRIBUTE((format (printf, 5, 6)));
 #define divine_sct_change_quiet(sp, name, change, ...) \
index 8dea60900fdc5866356123005b8a5a2a4a8e709f..bea5d312d84ebfcd41470f9fdf89934bef64a3dc 100644 (file)
@@ -898,15 +898,31 @@ edit_land(struct lndstr *land, char *key, char *p)
     case 'S':
        if (arg < -1 || arg >= ef_nelem(EF_SHIP))
            return RET_SYN;
-       if (arg >= 0 && arg != land->lnd_ship)
+       if (arg == land->lnd_ship) {
+           pr("Ship of %s unchanged\n", prland(land));
+           break;
+       }
+       divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
+       if (arg >= 0) {
+           divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
            land->lnd_land = -1;
+       }
+       divine_load((struct empobj *)land, EF_SHIP, arg);
        land->lnd_ship = arg;
        break;
     case 'Y':
        if (arg < -1 || arg >= ef_nelem(EF_LAND))
            return RET_SYN;
-       if (arg >= 0 && arg != land->lnd_land)
+       if (arg == land->lnd_land) {
+           pr("Land unit of %s unchanged\n", prland(land));
+           break;
+       }
+       divine_unload((struct empobj *)land, EF_LAND, land->lnd_land);
+       if (arg >= 0) {
+           divine_unload((struct empobj *)land, EF_SHIP, land->lnd_ship);
            land->lnd_ship = -1;
+       }
+       divine_load((struct empobj *)land, EF_LAND, arg);
        land->lnd_land = arg;
        break;
     case 'Z':
@@ -975,15 +991,31 @@ edit_plane(struct plnstr *plane, char *key, char *p)
     case 's':
        if (arg < -1 || arg >= ef_nelem(EF_SHIP))
            return RET_SYN;
-       if (arg >= 0 && arg != plane->pln_ship)
+       if (arg == plane->pln_ship) {
+           pr("Ship of %s unchanged\n", prplane(plane));
+           break;
+       }
+       divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
+       if (arg >= 0) {
+           divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
            plane->pln_land = -1;
+       }
+       divine_load((struct empobj *)plane, EF_SHIP, arg);
        plane->pln_ship = arg;
        break;
     case 'y':
        if (arg < -1 || arg >= ef_nelem(EF_LAND))
            return RET_SYN;
-       if (arg >= 0 && arg != plane->pln_land)
+       if (arg == plane->pln_land) {
+           pr("Land unit of %s unchanged\n", prplane(plane));
+           break;
+       }
+       divine_unload((struct empobj *)plane, EF_LAND, plane->pln_land);
+       if (arg >= 0) {
+           divine_unload((struct empobj *)plane, EF_SHIP, plane->pln_ship);
            plane->pln_ship = -1;
+       }
+       divine_load((struct empobj *)plane, EF_LAND, arg);
        plane->pln_land = arg;
        break;
     case 'f':
index 16a24890c53479e163ff09f37d1aacbb28753acb..5e1c7372121b8998c840b60143e21159f7d9cdd4 100644 (file)
@@ -138,6 +138,34 @@ divine_unit_change(struct empobj *unit, char *name,
     }
 }
 
+static void
+divine_load_unload(struct empobj *unit, int type, int uid, char *act)
+{
+    if (uid < 0)
+       return;
+
+    pr("%s %s %s #%d\n",
+       unit_nameof(unit), act, ef_nameof(type), uid);
+    if (unit->own && unit->own != player->cnum)
+       wu(0, unit->own,
+          "%s %s %s #%d by an act of %s!\n",
+          unit_nameof(unit), act, ef_nameof(type), uid,
+          cname(player->cnum));
+    /* carrier owner could differ; can't be bothered to report to him */
+}
+
+void
+divine_load(struct empobj *unit, int type, int uid)
+{
+    divine_load_unload(unit, type, uid, "loaded onto");
+}
+
+void
+divine_unload(struct empobj *unit, int type, int uid)
+{
+    divine_load_unload(unit, type, uid, "unloaded from");
+}
+
 /*
  * Report deity giving/taking commodities to/from WHOM.
  * Give AMT of IP in PLACE.
index 397cedd5c212dee559fe4562ec26bb941557bb7b..ce8d0e05a1f61341651fd2ceb0790571722a578b 100644 (file)
     Play#0 output Play#0 6 0 640
     Play#0 input edit p 2 s -1 s 9999
     Play#0 command edit
+    Play#0 output Play#0 1 Ship of f1   Sopwith Camel #2 unchanged
     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 p 3 s 3
     Play#0 command edit
+    Play#0 output Play#0 1 f1   Sopwith Camel #3 loaded onto ship #3
     Play#0 output Play#0 6 0 640
     Play#0 input edit p 4 s 4 y 4
     Play#0 command edit
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 loaded onto ship #4
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 unloaded from ship #4
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 loaded onto land #4
     Play#0 output Play#0 6 0 640
     Play#0 input edit u 2 S -1 S 9999
     Play#0 command edit
+    Play#0 output Play#0 1 Ship of sup  supply #2 unchanged
     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 u 3 S 3
     Play#0 command edit
+    Play#0 output Play#0 1 sup  supply #3 loaded onto ship #3
     Play#0 output Play#0 6 0 640
     Play#0 input edit u 4 S 4 Y 4
     Play#0 command edit
+    Play#0 output Play#0 1 sup  supply #4 loaded onto ship #4
+    Play#0 output Play#0 1 sup  supply #4 unloaded from ship #4
+    Play#0 output Play#0 1 sup  supply #4 loaded onto land #4
     Play#0 output Play#0 6 0 640
     Play#0 input edit s 0
     Play#0 command edit
     Play#0 input m 2
     Play#0 output Play#0 4 %c xxxxx -- thing value : 
     Play#0 input y -1
+    Play#0 output Play#0 1 Land unit of f1   Sopwith Camel #0 unchanged
     Play#0 output Play#0 4 %c xxxxx -- thing value : 
     Play#0 input 
     Play#0 output Play#0 1 POGO (#0) f1   Sopwith Camel #0
     Play#0 input M 2
     Play#0 output Play#0 4 %c xxxxx -- thing value : 
     Play#0 input Y -1
+    Play#0 output Play#0 1 Land unit of sup  supply #0 unchanged
     Play#0 output Play#0 4 %c xxxxx -- thing value : 
     Play#0 input 
     Play#0 output Play#0 1 POGO (#0) sup  supply #0
     Play#0 output Play#0 1 POGO gave you 50 military in cs   cargo ship (#5)
     Play#0 output Play#0 1 POGO gave you 25 military in sup  supply #4
     Play#0 output Play#0 1 POGO gave you 25 military in sup  supply #5
+    Play#0 output Play#0 1 f1   Sopwith Camel #3 loaded onto ship #3 by an act of POGO!
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 loaded onto ship #4 by an act of POGO!
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 unloaded from ship #4 by an act of POGO!
+    Play#0 output Play#0 1 f1   Sopwith Camel #4 loaded onto land #4 by an act of POGO!
+    Play#0 output Play#0 1 sup  supply #3 loaded onto ship #3 by an act of POGO!
+    Play#0 output Play#0 1 sup  supply #4 loaded onto ship #4 by an act of POGO!
+    Play#0 output Play#0 1 sup  supply #4 unloaded from ship #4 by an act of POGO!
+    Play#0 output Play#0 1 sup  supply #4 loaded onto land #4 by an act of POGO!
     Play#0 output Play#0 1 Military reserves changed from 0 to 2147483647 by an act of POGO
     Play#0 output Play#0 1 Money changed from 0 to 2147483647 by an act of POGO
     Play#0 output Play#0 6 0 640