]> git.pond.sub.org Git - empserver/commitdiff
edit: Teleport planes and land units to carrier on load
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 3 Feb 2013 13:59:00 +0000 (14:59 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:55:02 +0000 (19:55 +0200)
Edit lets deities load units onto remote carriers, resulting in a
carriers having cargo in another sector.  Not good.  Cargo gets
teleported to its carrier belatedly when the carrier moves.

Better let edit take care of the teleport.

Also tell the deity that he just caused a teleport.  Necessary to give
the deity a chance to catch unexpected changes, e.g. a player moving 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/unit.h
src/lib/subs/actofgod.c
src/lib/subs/unitsub.c
tests/actofgod/actofgod.xdump
tests/actofgod/geninput.pl
tests/actofgod/journal.log

index 267c11da2442c5772a1990d293635c68c7c02a4d..36b3f23afb07d4bbabf4a092698fcd0e55de08d2 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2006-2007
- *     Markus Armbruster, 2006-2011
+ *     Markus Armbruster, 2006-2013
  */
 
 #ifndef UNIT_H
@@ -59,6 +59,7 @@ extern void unit_list(struct emp_qelem *);
 extern void unit_put(struct emp_qelem *list, natid actor);
 extern char *unit_path(int, struct empobj *, char *, size_t);
 extern void unit_view(struct emp_qelem *);
+extern void unit_teleport(struct empobj *, coord, coord);
 extern int unit_update_cargo(struct empobj *);
 extern void unit_drop_cargo(struct empobj *, natid);
 extern void unit_give_away(struct empobj *, natid, natid);
index 5e1c7372121b8998c840b60143e21159f7d9cdd4..7146577169b48f361bbb1a6376daca187806b8d2 100644 (file)
@@ -157,7 +157,16 @@ divine_load_unload(struct empobj *unit, int type, int uid, char *act)
 void
 divine_load(struct empobj *unit, int type, int uid)
 {
+    union empobj_storage carrier;
+
     divine_load_unload(unit, type, uid, "loaded onto");
+    if (get_empobj(type, uid, &carrier)
+       && (unit->x != carrier.gen.x || unit->y != carrier.gen.y)) {
+       pr("%s teleported from %s to %s!",
+          unit_nameof(unit), xyas(unit->x, unit->y, player->cnum),
+          xyas(carrier.gen.x, carrier.gen.y, player->cnum));
+       unit_teleport(unit, carrier.gen.x, carrier.gen.y);
+    }
 }
 
 void
index e7441591ae9576dae72ee538f64cd2ce64e5991b..4187fe6998414affa72226509f4e728174db9ff3 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Ron Koenderink, 2007
- *     Markus Armbruster, 2009-2011
+ *     Markus Armbruster, 2009-2013
  */
 
 #include <config.h>
@@ -238,6 +238,21 @@ unit_view(struct emp_qelem *list)
     }
 }
 
+/*
+ * Teleport UNIT to X,Y.
+ * If UNIT's mission op-area is centered on it, keep it centered.
+ */
+void
+unit_teleport(struct empobj *unit, coord x, coord y)
+{
+    if (unit->opx == unit->x && unit->opy == unit->y) {
+       unit->opx = x;
+       unit->opy = y;
+    }
+    unit->x = x;
+    unit->y = y;
+}
+
 /*
  * Update cargo of CARRIER for movement or destruction.
  * If the carrier is destroyed, destroy its cargo (planes, land units,
@@ -257,17 +272,11 @@ unit_update_cargo(struct empobj *carrier)
     for (cargo_type = EF_PLANE; cargo_type <= EF_NUKE; cargo_type++) {
        snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid);
        while (nxtitem(&ni, &obj)) {
-           if (!carrier->own) {
+           if (carrier->own)
+               unit_teleport(&obj.gen, carrier->x, carrier->y);
+           else {
                mpr(obj.gen.own, "%s lost!\n", unit_nameof(&obj.gen));
                obj.gen.effic = 0;
-           } else {
-               /* mission op-area centered on the obj travels with it */
-               if (obj.gen.opx == obj.gen.x && obj.gen.opy == obj.gen.y) {
-                   obj.gen.opx = carrier->x;
-                   obj.gen.opy = carrier->y;
-               }
-               obj.gen.x = carrier->x;
-               obj.gen.y = carrier->y;
            }
            put_empobj(cargo_type, obj.gen.uid, &obj);
            n++;
index fedfee8d7d20f66e63035db9b752a5b419270703..8474ee46b24b5eb7543d0ecb6b152984a0545ea6 100644 (file)
@@ -252,7 +252,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius wing range
 1 98 1 -1 0 10 0 0 100 0 0 none 0 "" 9 0 -1 -1 () 0 0.00000
 2 2 3 -1 0 10 -127 0 50 0 0 none 0 "" 0 0 -1 -1 (airburst) 0 0.00000
 3 3 1 -1 0 10 -127 0 50 0 0 none 0 "a" 0 0 3 -1 () 0 0.00000
-4 3 1 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 4 () 0 0.00000
+4 3 3 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 4 () 0 0.00000
 5 3 1 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 -1 () 0 0.00000
 6 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
 7 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
@@ -305,7 +305,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h
 1 98 1 -1 6 10 0 0 100 0 0 none 0 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 2 2 3 -1 6 10 -127 0 50 0 0 none 0 "" -1 0 0 (group) "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 3 3 1 -1 6 10 -127 0 50 0 0 none 0 "a" 3 0 0 (injured) "jj" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
-4 3 1 -1 6 100 127 0 32767 0 0 none 0 "" -1 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 4 0
+4 3 3 -1 6 100 127 0 32767 0 0 none 0 "" 2 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 5 3 1 -1 6 100 127 0 32767 0 0 none 0 "" -1 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 6 0 0 0 0 0 0 0 0 0 0 none 0 "" -1 0 0 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 7 0 0 0 0 0 0 0 0 0 0 none 0 "" -1 0 0 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
index c81bef2366b2e05f2d6154e169b2df3a6d7408ad..05755f243f7d73990439193648ea18b9c567312a 100755 (executable)
@@ -311,6 +311,9 @@ unit_carrier('land', 'S', 'Y');
 # special case: move carrier's cargo away
 edit('plane', 4, 'l', '5,1');
 
+# special case: load teleports to carrier
+edit('land', 4, 'S', 2);
+
 # interactive edit
 iedit('ship', 0, 'M 2', 'm 1', 'f 1');
 iedit('ship', 0, 'R n', 'R ""');
index df353a58c81b201ce00d8c10c1bda66c190a057d..a49766c7ddefa17175401f0bb1772a0935820fa4 100644 (file)
     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 u 4 S 2
+    Play#0 command edit
+    Play#0 output Play#0 1 sup  supply #4 unloaded from land #4
+    Play#0 output Play#0 1 sup  supply #4 loaded onto ship #2
+    Play#0 output Play#0 1 sup  supply #4 teleported from 1,-1 to 3,-1!
+    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)
     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 sup  supply #4 unloaded from land #4 by an act of POGO!
+    Play#0 output Play#0 1 sup  supply #4 loaded onto ship #2 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