]> git.pond.sub.org Git - empserver/commitdiff
march: Don't scatter land units on crossing border
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 28 Dec 2014 19:32:16 +0000 (20:32 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Feb 2015 15:12:54 +0000 (16:12 +0100)
When attempting to enter a sector with a land unit that can't go there
while the marching land units are all in the same sector, march stops
and prompts without removing the incapable land unit from the group.
If another land unit has already entered the sector, the group becomes
scattered.

This can happen when marching a mixed group of spies and non-spies
into a non-allied sector.  Same for marching a mixed group of trains
and non-trains into a sector without rail, except such groups have
been disallowed since commit 36e41e5 (v4.3.7).  Both screwed up when
spies and trains were added in 4.0.0

Remove the incapable land unit from the group when another land unit
can enter the sector.  This avoids scattering land units.

Don't remove incapable land units when no land unit can enter the
sector.  Without this, march would remove everyone and end then.

It can also happen when sectors or land units change while we're
sitting at the "Do you really want to abandon X,Y" prompt.  I'm going
to fix that differently.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/subs/lndsub.c
tests/navi-march/02-march-1
tests/navi-march/final.xdump
tests/navi-march/journal.log

index 1acc57d1bb87917cb2646225176e3c27647e7f46..677022a56bbcfe81f18bc0ff29b60a3ffb24cd25 100644 (file)
@@ -977,6 +977,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
     coord dy;
     coord newx;
     coord newy;
+    int move;
     enum lnd_stuck stuck;
     int stopping = 0;
     int visible;
@@ -991,6 +992,25 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
     }
     dx = diroff[dir][0];
     dy = diroff[dir][1];
+
+    move = 0;
+    for (qp = list->q_back; qp != list; qp = next) {
+       next = qp->q_back;
+       llp = (struct ulist *)qp;
+       getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, &osect);
+       oldown = osect.sct_own;
+       newx = xnorm(llp->unit.land.lnd_x + dx);
+       newy = ynorm(llp->unit.land.lnd_y + dy);
+       getsect(newx, newy, &sect);
+       stuck = lnd_check_mar(&llp->unit.land, &sect);
+       if (stuck == LND_STUCK_NOT
+           && (relations_with(sect.sct_own, actor) == ALLIED
+               || !sect.sct_own
+               || (lchr[llp->unit.land.lnd_type].l_flags & L_SPY))) {
+           move = 1;
+       }
+    }
+
     for (qp = list->q_back; qp != list; qp = next) {
        next = qp->q_back;
        llp = (struct ulist *)qp;
@@ -1006,7 +1026,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
                && !(lchr[llp->unit.land.lnd_type].l_flags & L_SPY))) {
            if (stuck == LND_STUCK_NO_RAIL
                && (!sect.sct_own || rel == ALLIED)) {
-               if (together) {
+               if (together && !move) {
                    mpr(actor, "no rail system in %s\n",
                        xyas(newx, newy, actor));
                    return 1;
@@ -1017,7 +1037,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
                    continue;
                }
            } else {
-               if (together) {
+               if (together && !move) {
                    mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
                    return 1;
                } else {
index 387d0d773fc69bb483ef1ea370cac5d589653b0a..a4ca71a320af286194c4611696387e6455e77bfa 100644 (file)
@@ -41,7 +41,6 @@ ijjh
 __cmd added -1 0 0
 march 55/54 g
 ijjh
-| BUG: 52/53 moves nothing g, cav/spy jj, 53/54 moves spy g, spy/cav jj
 | enter hostile 10,4
 march 56/57/58/59 jh
 | enter sea
index f4383455ebbcc7c57c8552f8255a2b79f6df0a25..c7570a35ebd61eb78009b549a70e8d8385831127 100644 (file)
@@ -231,9 +231,9 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h
 39 1 7 5 0 84 93 0 30 6 6 none 3 "" -1 0 42 () "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 50 1 11 3 0 100 105 0 30 9 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 51 1 -1 3 0 100 105 0 30 1 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
-52 1 1 3 0 100 84 0 30 -3 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
-53 1 1 3 8 100 85 0 40 -3 3 none 3 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
-54 1 1 3 0 100 84 0 30 -3 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
+52 1 -3 3 0 100 127 0 30 -3 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
+53 1 -1 3 8 100 64 0 40 -3 3 none 3 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
+54 1 -3 3 0 100 127 0 30 -3 3 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 55 1 -1 3 8 100 64 0 40 -3 3 none 3 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 56 1 10 4 8 60 116 0 40 8 4 none 3 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
 57 1 10 4 8 60 116 0 40 8 4 none 3 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0
index a0ecf9c475f9c1a6c921036024ba77085419ae67..4d66635964b85cb6e9854df23d30b47e1488c80a 100644 (file)
     Play#1 input march 52/53 g
     Play#1 command march
     Play#1 output Play#1 1 Leader is cav  cavalry #52
-    Play#1 output Play#1 1 can't go to -5,3
+    Play#1 output Play#1 1 cav  cavalry #52 can't go to -5,3 & stays in -3,3
+    Play#1 output Play#1 1 Changing leader to spy  infiltrator #53
     Play#1 output Play#1 1  c c
     Play#1 output Play#1 1 + + +
     Play#1 output Play#1 1  m m
-    Play#1 output Play#1 4 <127.0:127.0: -3,3>
+    Play#1 output Play#1 4 <106.3:106.3: -5,3>
     Play#1 input ijjh
     Play#1 output Play#1 1 lnd#     land type       x,y    a  eff mil  sh gun xl ln  mu tech retr
-    Play#1 output Play#1 1   52 cav  cavalry       -3,3      100%   5   0   0  0  0 127  30  42%
-    Play#1 output Play#1 1   53 spy  infiltrator   -3,3      100%   0   0   0  0  0 127  40  42%
-    Play#1 output Play#1 1 cav  cavalry #52 stopped at 1,3
-    Play#1 output Play#1 1 spy  infiltrator #53 stopped at 1,3
+    Play#1 output Play#1 1   53 spy  infiltrator   -5,3      100%   0   0   0  0  0 106  40  42%
+    Play#1 output Play#1 1 spy  infiltrator #53 stopped at -1,3
     Play#1 output Play#1 6 0 578
     Play#1 input __cmd added -1 0 0
     Play#1 command __cmd
     Play#1 input march 55/54 g
     Play#1 command march
     Play#1 output Play#1 1 Leader is spy  infiltrator #55
-    Play#1 output Play#1 1 can't go to -5,3
+    Play#1 output Play#1 1 cav  cavalry #54 can't go to -5,3 & stays in -3,3
     Play#1 output Play#1 1  c c
     Play#1 output Play#1 1 + + +
     Play#1 output Play#1 1  m m
-    Play#1 output Play#1 4 <127.0:106.3: -5,3>
+    Play#1 output Play#1 4 <106.3:106.3: -5,3>
     Play#1 input ijjh
     Play#1 output Play#1 1 lnd#     land type       x,y    a  eff mil  sh gun xl ln  mu tech retr
     Play#1 output Play#1 1   55 spy  infiltrator   -5,3      100%   0   0   0  0  0 106  40  42%
-    Play#1 output Play#1 1   54 cav  cavalry       -3,3      100%   5   0   0  0  0 127  30  42%
     Play#1 output Play#1 1 spy  infiltrator #55 stopped at -1,3
-    Play#1 output Play#1 1 cav  cavalry #54 stopped at 1,3
     Play#1 output Play#1 6 0 577
     Play#1 input march 56/57/58/59 jh
     Play#1 command march
     Play#0 output Play#0 1   1   39 cav  cavalry       7,5        84%   1   0  93   0  30  42%  0  0
     Play#0 output Play#0 1   1   50 cav  cavalry      11,3       100%   5   0 105   0  30  42%  0  0
     Play#0 output Play#0 1   1   51 cav  cavalry      -1,3       100%   5   0 105   0  30  42%  0  0
-    Play#0 output Play#0 1   1   52 cav  cavalry       1,3       100%   5   0  84   0  30  42%  0  0
-    Play#0 output Play#0 1   1   53 spy  infiltrato    1,3       100%   0   0  85   0  40  42%  0  0
-    Play#0 output Play#0 1   1   54 cav  cavalry       1,3       100%   5   0  84   0  30  42%  0  0
+    Play#0 output Play#0 1   1   52 cav  cavalry      -3,3       100%   5   0 127   0  30  42%  0  0
+    Play#0 output Play#0 1   1   53 spy  infiltrato   -1,3       100%   0   0  64   0  40  42%  0  0
+    Play#0 output Play#0 1   1   54 cav  cavalry      -3,3       100%   5   0 127   0  30  42%  0  0
     Play#0 output Play#0 1   1   55 spy  infiltrato   -1,3       100%   0   0  64   0  40  42%  0  0
     Play#0 output Play#0 1   1   56 spy  infiltrato   10,4        60%   0   0 116   0  40  42%  0  0
     Play#0 output Play#0 1   1   57 spy  infiltrato   10,4        60%   0   0 116   0  40  42%  0  0