diff --git a/include/unit.h b/include/unit.h index 267c11da..36b3f23a 100644 --- a/include/unit.h +++ b/include/unit.h @@ -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); diff --git a/src/lib/subs/actofgod.c b/src/lib/subs/actofgod.c index 5e1c7372..71465771 100644 --- a/src/lib/subs/actofgod.c +++ b/src/lib/subs/actofgod.c @@ -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 diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index e7441591..4187fe69 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Ron Koenderink, 2007 - * Markus Armbruster, 2009-2011 + * Markus Armbruster, 2009-2013 */ #include @@ -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++; diff --git a/tests/actofgod/actofgod.xdump b/tests/actofgod/actofgod.xdump index fedfee8d..8474ee46 100644 --- a/tests/actofgod/actofgod.xdump +++ b/tests/actofgod/actofgod.xdump @@ -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 diff --git a/tests/actofgod/geninput.pl b/tests/actofgod/geninput.pl index c81bef23..05755f24 100755 --- a/tests/actofgod/geninput.pl +++ b/tests/actofgod/geninput.pl @@ -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 ""'); diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index df353a58..a49766c7 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -1234,6 +1234,12 @@ 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) @@ -1708,6 +1714,8 @@ 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