From 18ee9a2f355096cbff7c06a4ea9cd7cf3b3fc86d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 30 May 2005 14:56:02 +0000 Subject: [PATCH] (flee, army, wing): Print how many new members were added. Previously, it printed how many were selected, which can include old members of the group. (flee, army): The rather obscure feature to assign the fleet's / army's retreat orders to members was broken. It ignored ownership, and thus could copy some other player's retreat orders. Abusable. Copying the first member's retreat orders is less than useful, in particular for group ~. The code now chooses the first one in the same sector with RET_GROUP set. RET_GROUP is never set for group ~. --- info/Commands/retreat.t | 5 +++-- src/lib/commands/army.c | 24 +++++++++++++++--------- src/lib/commands/flee.c | 24 +++++++++++++++--------- src/lib/commands/wing.c | 10 ++++++---- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/info/Commands/retreat.t b/info/Commands/retreat.t index 0e57fda6..2e01fde7 100644 --- a/info/Commands/retreat.t +++ b/info/Commands/retreat.t @@ -52,8 +52,9 @@ is Yes, then every ship in that fleet with fleet retreat orders retreats along the specified path. If it is no, then the retreat orders apply to that ship only, and only that ship retreats. .s1 -When a ship is added to a fleet, it is given the retreat orders of that -fleet, if any exist. +When a ship is added to a fleet, it is given the retreat orders of the +first ship in that fleet that has fleet retreat orders and is in the +same sector, if any exist. .s1 Retreat orders are wiped when a ship navigates. .s1 diff --git a/src/lib/commands/army.c b/src/lib/commands/army.c index acfbe113..0ab8996f 100644 --- a/src/lib/commands/army.c +++ b/src/lib/commands/army.c @@ -49,7 +49,6 @@ army(void) struct nstr_item nstr; struct nstr_item ni; struct lndstr land2; - int r; s_char buf[1024]; cp = getstarg(player->argp[1], "army? ", buf); @@ -65,17 +64,24 @@ army(void) if (!snxtitem(&nstr, EF_LAND, player->argp[2])) return RET_SYN; count = 0; - while (nxtitem(&nstr, (s_char *)&land)) { + while (nxtitem(&nstr, &land)) { if (!player->owner) continue; - land.lnd_army = c; - snxtitem(&ni, EF_LAND, cp); - while ((r = nxtitem(&ni, (s_char *)&land2)) && - (land2.lnd_army != c)) ; - if (r) { - memcpy(land.lnd_rpath, land2.lnd_rpath, sizeof(land.lnd_rpath)); - land.lnd_rflags = land2.lnd_rflags; + if (land.lnd_army == c) + continue; + land.lnd_rflags &= ~RET_GROUP; + snxtitem_group(&ni, EF_LAND, c); + while (nxtitem(&ni, &land2)) { + if ((land2.lnd_rflags & RET_GROUP) == 0) + continue; + if (land2.lnd_x == land.lnd_x && land2.lnd_y == land.lnd_y) { + memcpy(land.lnd_rpath, land2.lnd_rpath, + sizeof(land.lnd_rpath)); + land.lnd_rflags = land2.lnd_rflags; + break; + } } + land.lnd_army = c; putland(land.lnd_uid, &land); count++; } diff --git a/src/lib/commands/flee.c b/src/lib/commands/flee.c index 533ad112..6be34bd4 100644 --- a/src/lib/commands/flee.c +++ b/src/lib/commands/flee.c @@ -49,7 +49,6 @@ flee(void) struct nstr_item nstr; struct nstr_item ni; struct shpstr ship2; - int r; s_char buf[1024]; cp = getstarg(player->argp[1], "fleet? ", buf); @@ -65,17 +64,24 @@ flee(void) if (!snxtitem(&nstr, EF_SHIP, player->argp[2])) return RET_SYN; count = 0; - while (nxtitem(&nstr, (s_char *)&ship)) { + while (nxtitem(&nstr, &ship)) { if (!player->owner) continue; - ship.shp_fleet = c; - snxtitem(&ni, EF_SHIP, cp); - while ((r = nxtitem(&ni, (s_char *)&ship2)) - && (ship2.shp_fleet != c)) ; - if (r) { - memcpy(ship.shp_rpath, ship2.shp_rpath, sizeof(ship.shp_rpath)); - ship.shp_rflags = ship2.shp_rflags; + if (ship.shp_fleet == c) + continue; + ship.shp_rflags &= ~RET_GROUP; + snxtitem_group(&ni, EF_SHIP, c); + while (nxtitem(&ni, &ship2)) { + if ((ship2.shp_rflags & RET_GROUP) == 0) + continue; + if (ship2.shp_x == ship.shp_x && ship2.shp_y == ship.shp_y) { + memcpy(ship.shp_rpath, ship2.shp_rpath, + sizeof(ship.shp_rpath)); + ship.shp_rflags = ship2.shp_rflags; + break; + } } + ship.shp_fleet = c; putship(ship.shp_uid, &ship); count++; } diff --git a/src/lib/commands/wing.c b/src/lib/commands/wing.c index 8da8f6f6..91cfd0e7 100644 --- a/src/lib/commands/wing.c +++ b/src/lib/commands/wing.c @@ -61,13 +61,15 @@ wing(void) c = ' '; if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) return RET_SYN; - for (count = 0; nxtitem(&nstr, (s_char *)&plane); count++) { - if (plane.pln_own != player->cnum) { - count--; + count = 0; + while (nxtitem(&nstr, (s_char *)&plane)) { + if (plane.pln_own != player->cnum) + continue; + if (plane.pln_wing == c) continue; - } plane.pln_wing = c; putplane(plane.pln_uid, &plane); + count++; } pr("%d plane%s added to wing `%c'\n", count, splur(count), c); return RET_OK;