]> git.pond.sub.org Git - empserver/commitdiff
(flee, army, wing): Print how many new members were added.
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 30 May 2005 14:56:02 +0000 (14:56 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 30 May 2005 14:56:02 +0000 (14:56 +0000)
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
src/lib/commands/army.c
src/lib/commands/flee.c
src/lib/commands/wing.c

index 0e57fda60b08f4ef62b831d48b2b63d494d63bdc..2e01fde767883557068f5ca747514bef5ae9314e 100644 (file)
@@ -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
index acfbe113809d637adc7c6b2e4525a4beb6a6925a..0ab8996f4c0a4cd93f9070abbab8e57f48b620b5 100644 (file)
@@ -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++;
     }
index 533ad1127e94a1118d34a4e4525c42b5f64a8355..6be34bd4c0cfda8d820e86f08ef3b5c6d18d7809 100644 (file)
@@ -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++;
     }
index 8da8f6f6dd0984505cfe2433c3be12505d89575d..91cfd0e7b8e576676cfe1c5228d7c40839f70d91 100644 (file)
@@ -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;