edit: Teleport planes and land units to carrier on load

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>
This commit is contained in:
Markus Armbruster 2013-02-03 14:59:00 +01:00
parent 3dceefbbc9
commit ef2e2d08a2
6 changed files with 43 additions and 13 deletions

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Ron Koenderink, 2006-2007 * Ron Koenderink, 2006-2007
* Markus Armbruster, 2006-2011 * Markus Armbruster, 2006-2013
*/ */
#ifndef UNIT_H #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 void unit_put(struct emp_qelem *list, natid actor);
extern char *unit_path(int, struct empobj *, char *, size_t); extern char *unit_path(int, struct empobj *, char *, size_t);
extern void unit_view(struct emp_qelem *); extern void unit_view(struct emp_qelem *);
extern void unit_teleport(struct empobj *, coord, coord);
extern int unit_update_cargo(struct empobj *); extern int unit_update_cargo(struct empobj *);
extern void unit_drop_cargo(struct empobj *, natid); extern void unit_drop_cargo(struct empobj *, natid);
extern void unit_give_away(struct empobj *, natid, natid); extern void unit_give_away(struct empobj *, natid, natid);

View file

@ -157,7 +157,16 @@ divine_load_unload(struct empobj *unit, int type, int uid, char *act)
void void
divine_load(struct empobj *unit, int type, int uid) divine_load(struct empobj *unit, int type, int uid)
{ {
union empobj_storage carrier;
divine_load_unload(unit, type, uid, "loaded onto"); 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 void

View file

@ -28,7 +28,7 @@
* *
* Known contributors to this file: * Known contributors to this file:
* Ron Koenderink, 2007 * Ron Koenderink, 2007
* Markus Armbruster, 2009-2011 * Markus Armbruster, 2009-2013
*/ */
#include <config.h> #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. * Update cargo of CARRIER for movement or destruction.
* If the carrier is destroyed, destroy its cargo (planes, land units, * 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++) { for (cargo_type = EF_PLANE; cargo_type <= EF_NUKE; cargo_type++) {
snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid); snxtitem_cargo(&ni, cargo_type, carrier->ef_type, carrier->uid);
while (nxtitem(&ni, &obj)) { 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)); mpr(obj.gen.own, "%s lost!\n", unit_nameof(&obj.gen));
obj.gen.effic = 0; 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); put_empobj(cargo_type, obj.gen.uid, &obj);
n++; n++;

View 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 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 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 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 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 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 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 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 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 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 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 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 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

View file

@ -311,6 +311,9 @@ unit_carrier('land', 'S', 'Y');
# special case: move carrier's cargo away # special case: move carrier's cargo away
edit('plane', 4, 'l', '5,1'); edit('plane', 4, 'l', '5,1');
# special case: load teleports to carrier
edit('land', 4, 'S', 2);
# interactive edit # interactive edit
iedit('ship', 0, 'M 2', 'm 1', 'f 1'); iedit('ship', 0, 'M 2', 'm 1', 'f 1');
iedit('ship', 0, 'R n', 'R ""'); iedit('ship', 0, 'R n', 'R ""');

View file

@ -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 Can't move f1 Sopwith Camel #4 while it's loaded
Play#0 output Play#0 1 command failed Play#0 output Play#0 1 command failed
Play#0 output Play#0 6 0 640 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 input edit s 0
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 POGO (#0) cs cargo ship (#0) 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 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 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 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 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 1 Money changed from 0 to 2147483647 by an act of POGO
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640