edit: Refuse to move planes and land units on carriers

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>
This commit is contained in:
Markus Armbruster 2013-02-03 14:40:36 +01:00
parent cbe9897bfa
commit 3dceefbbc9
3 changed files with 18 additions and 4 deletions

View file

@ -736,7 +736,7 @@ edit_nat(struct natstr *np, char *key, char *p)
static int static int
edit_unit(struct empobj *unit, char *key, char *p, 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); int arg = atoi(p);
coord newx, newy; coord newx, newy;
@ -779,6 +779,10 @@ edit_unit(struct empobj *unit, char *key, char *p,
case 'L': case 'L':
if (!sarg_xy(p, &newx, &newy)) if (!sarg_xy(p, &newx, &newy))
return RET_SYN; 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->x = newx;
unit->y = newy; unit->y = newy;
break; break;
@ -823,7 +827,7 @@ edit_ship(struct shpstr *ship, char *key, char *p)
case 'M': case 'M':
case 'F': case 'F':
return edit_unit((struct empobj *)ship, key, p, return edit_unit((struct empobj *)ship, key, p,
SHIP_MINEFF, "fleet"); SHIP_MINEFF, "fleet", 0);
case 'T': case 'T':
arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX); arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
shp_set_tech(ship, arg); shp_set_tech(ship, arg);
@ -887,7 +891,8 @@ edit_land(struct lndstr *land, char *key, char *p)
case 'M': case 'M':
case 'a': case 'a':
return edit_unit((struct empobj *)land, key, p, return edit_unit((struct empobj *)land, key, p,
LAND_MINEFF, "army"); LAND_MINEFF, "army",
land->lnd_ship >= 0 || land->lnd_land >= 0);
case 't': case 't':
arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX); arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
lnd_set_tech(land, arg); lnd_set_tech(land, arg);
@ -979,7 +984,8 @@ edit_plane(struct plnstr *plane, char *key, char *p)
case 'm': case 'm':
case 'w': case 'w':
return edit_unit((struct empobj *)plane, key, p, return edit_unit((struct empobj *)plane, key, p,
PLANE_MINEFF, "wing"); PLANE_MINEFF, "wing",
plane->pln_ship >= 0 || plane->pln_land >= 0);
case 't': case 't':
arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX); arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
pln_set_tech(plane, arg); pln_set_tech(plane, arg);

View file

@ -308,6 +308,9 @@ sub unit_carrier {
unit_carrier('plane', 's', 'y'); unit_carrier('plane', 's', 'y');
unit_carrier('land', 'S', 'Y'); unit_carrier('land', 'S', 'Y');
# special case: move carrier's cargo away
edit('plane', 4, 'l', '5,1');
# 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

@ -1229,6 +1229,11 @@
Play#0 output Play#0 1 sup supply #4 unloaded from ship #4 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 1 sup supply #4 loaded onto land #4
Play#0 output Play#0 6 0 640 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 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)