From c9fc05ae5b4028b6bef1000e0fd07a3304d2fb23 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 28 Dec 2014 20:32:16 +0100 Subject: [PATCH] march: Don't scatter land units on crossing border 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 --- src/lib/subs/lndsub.c | 24 ++++++++++++++++++++++-- tests/navi-march/02-march-1 | 1 - tests/navi-march/final.xdump | 6 +++--- tests/navi-march/journal.log | 23 ++++++++++------------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 1acc57d1..677022a5 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -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, §); + stuck = lnd_check_mar(&llp->unit.land, §); + 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 { diff --git a/tests/navi-march/02-march-1 b/tests/navi-march/02-march-1 index 387d0d77..a4ca71a3 100644 --- a/tests/navi-march/02-march-1 +++ b/tests/navi-march/02-march-1 @@ -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 diff --git a/tests/navi-march/final.xdump b/tests/navi-march/final.xdump index f4383455..c7570a35 100644 --- a/tests/navi-march/final.xdump +++ b/tests/navi-march/final.xdump @@ -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 diff --git a/tests/navi-march/journal.log b/tests/navi-march/journal.log index a0ecf9c4..4d666359 100644 --- a/tests/navi-march/journal.log +++ b/tests/navi-march/journal.log @@ -852,17 +852,16 @@ 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 @@ -870,17 +869,15 @@ 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 @@ -1505,9 +1502,9 @@ 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