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

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

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