]> git.pond.sub.org Git - empserver/commitdiff
edit: Refuse to move planes and land units on carriers
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2013 13:40:36 +0000 (14:40 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:02 +0000 (19:55 +0200)
They really need to stay with their carrier.  Else, cargo gets
silently teleported to its carrier when the carrier moves.

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

index bea5d312d84ebfcd41470f9fdf89934bef64a3dc..5cda12de8fbd63c6fa258750a018a3452fe30b35 100644 (file)
@@ -736,7 +736,7 @@ edit_nat(struct natstr *np, char *key, char *p)
 
 static int
 edit_unit(struct empobj *unit, char *key, char *p,
-         int mineff, char *group_name)
+         int mineff, char *group_name, int on_carrier)
 {
     int arg = atoi(p);
     coord newx, newy;
@@ -779,6 +779,10 @@ edit_unit(struct empobj *unit, char *key, char *p,
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
            return RET_SYN;
+       if (on_carrier && (newx != unit->x || newy != unit->y)) {
+           pr("Can't move %s while it's loaded\n", unit_nameof(unit));
+           return RET_FAIL;
+       }
        unit->x = newx;
        unit->y = newy;
        break;
@@ -823,7 +827,7 @@ edit_ship(struct shpstr *ship, char *key, char *p)
     case 'M':
     case 'F':
        return edit_unit((struct empobj *)ship, key, p,
-                        SHIP_MINEFF, "fleet");
+                        SHIP_MINEFF, "fleet", 0);
     case 'T':
        arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
        shp_set_tech(ship, arg);
@@ -887,7 +891,8 @@ edit_land(struct lndstr *land, char *key, char *p)
     case 'M':
     case 'a':
        return edit_unit((struct empobj *)land, key, p,
-                        LAND_MINEFF, "army");
+                        LAND_MINEFF, "army",
+                        land->lnd_ship >= 0 || land->lnd_land >= 0);
     case 't':
        arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
        lnd_set_tech(land, arg);
@@ -979,7 +984,8 @@ edit_plane(struct plnstr *plane, char *key, char *p)
     case 'm':
     case 'w':
        return edit_unit((struct empobj *)plane, key, p,
-                        PLANE_MINEFF, "wing");
+                        PLANE_MINEFF, "wing",
+                        plane->pln_ship >= 0 || plane->pln_land >= 0);
     case 't':
        arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
        pln_set_tech(plane, arg);
index f5f168ff37d502536f2b6a633fd05a15663efc42..c81bef2366b2e05f2d6154e169b2df3a6d7408ad 100755 (executable)
@@ -308,6 +308,9 @@ sub unit_carrier {
 unit_carrier('plane', 's', 'y');
 unit_carrier('land', 'S', 'Y');
 
+# special case: move carrier's cargo away
+edit('plane', 4, 'l', '5,1');
+
 # interactive edit
 iedit('ship', 0, 'M 2', 'm 1', 'f 1');
 iedit('ship', 0, 'R n', 'R ""');
index ce8d0e05a1f61341651fd2ceb0790571722a578b..df353a58c81b201ce00d8c10c1bda66c190a057d 100644 (file)
     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 p 4 l 5,1
+    Play#0 command edit
+    Play#0 output Play#0 1 Can't move f1   Sopwith Camel #4 while it's loaded
+    Play#0 output Play#0 1 command failed
+    Play#0 output Play#0 6 0 640
     Play#0 input edit s 0
     Play#0 command edit
     Play#0 output Play#0 1 POGO (#0) cs   cargo ship (#0)