From f1042f82f1415a69ecded29b541507147f9698ac Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 29 Dec 2014 18:05:30 +0100 Subject: [PATCH] march attack assault: Hit mines like ships do When ships enter a sector with sea mines, any minesweepers sweep, then hit mines, and finally all ships (including the minesweepers) hit mines. Sweeping in a sector (navigate sub-command 'm') works the same without the final step. When land units enter a sector with land mines, any engineers sweep, and then all land units (including the engineers) hit mines. Sweeping in a sector (march sub-command 'm') works the same, which means non-engineers can hit mines then. Broken in Empire 2. Actually broken for ships too then. 4.0.17 fixed ships, but neglected to fix land units. Change the land unit code to work like the ship code. Fixes march sub-command 'm' not to expose non-engineers to mines. Changes march, attack and assault with option INTERDICT_ATT enabled to expose engineers twice. Signed-off-by: Markus Armbruster --- include/land.h | 2 +- src/lib/commands/navi.c | 3 +- src/lib/subs/lndsub.c | 14 ++++++- tests/navi-march/02-march-1 | 1 - tests/navi-march/final.xdump | 18 ++++----- tests/navi-march/journal.log | 77 ++++++++++++++++-------------------- 6 files changed, 58 insertions(+), 57 deletions(-) diff --git a/include/land.h b/include/land.h index e4266477..83cd7322 100644 --- a/include/land.h +++ b/include/land.h @@ -173,7 +173,7 @@ extern int lnd_sabo(struct lndstr *, short *); extern double lnd_fire_range(struct lndstr *); /* src/lib/subs/lndsub.c */ -extern void lnd_sweep(struct emp_qelem *, int, int, natid); +extern int lnd_sweep(struct emp_qelem *, int, int, natid); extern int lnd_interdict(struct emp_qelem *, coord, coord, natid); extern void lnd_sel(struct nstr_item *, struct emp_qelem *); extern struct ulist *lnd_insque(struct lndstr *, struct emp_qelem *); diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index db2b99f9..26ac5413 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -199,8 +199,7 @@ do_unit_move(struct emp_qelem *ulist, double *minmob, double *maxmob) if (type == EF_SHIP) stopping |= shp_sweep(ulist, 1, 1, player->cnum); else { - lnd_sweep(ulist, 1, 1, player->cnum); - stopping |= lnd_check_mines(ulist); + stopping |= lnd_sweep(ulist, 1, 1, player->cnum); } continue; case 'r': diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index f4190720..ab21fc6f 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -52,6 +52,7 @@ #include "unit.h" #include "xy.h" +static int lnd_check_one_mines(struct ulist *, int); static void lnd_stays(natid, char *, struct ulist *); static int lnd_hit_mine(struct lndstr *); static int has_helpful_engineer(coord, coord, natid); @@ -581,7 +582,7 @@ lnd_put_one(struct ulist *llp) * a player. Else it's an automatic "on the move" sweep. * If TAKEMOB is non-zero, require and charge mobility. */ -void +int lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob, natid actor) { @@ -590,6 +591,7 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob, struct ulist *llp; struct sctstr sect; int mines, m, max, sshells, lshells; + int stopping = 0; for (qp = land_list->q_back; qp != land_list; qp = next) { next = qp->q_back; @@ -641,7 +643,13 @@ lnd_sweep(struct emp_qelem *land_list, int explicit, int takemob, sect.sct_item[I_SHELL] = sshells; putland(llp->unit.land.lnd_uid, &llp->unit.land); putsect(§); + if (lnd_check_one_mines(llp, 1)) { + stopping = 1; + emp_remque(qp); + free(qp); + } } + return stopping; } static int @@ -1096,7 +1104,9 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor) } if (QEMPTY(list)) return stopping; - lnd_sweep(list, 0, 1, actor); + stopping |= lnd_sweep(list, 0, 1, actor); + if (QEMPTY(list)) + return stopping; stopping |= lnd_check_mines(list); if (QEMPTY(list)) return stopping; diff --git a/tests/navi-march/02-march-1 b/tests/navi-march/02-march-1 index baff6b74..97202094 100644 --- a/tests/navi-march/02-march-1 +++ b/tests/navi-march/02-march-1 @@ -127,6 +127,5 @@ march 135/130/131/136/137/138/139 j | implicit sweep, not all capable mmmh -| BUG: non-sweeper hits mine | BUG: mobility use low || TODO interdiction diff --git a/tests/navi-march/final.xdump b/tests/navi-march/final.xdump index 6cd302da..0ecbc8e5 100644 --- a/tests/navi-march/final.xdump +++ b/tests/navi-march/final.xdump @@ -89,7 +89,7 @@ owner xloc yloc des effic mobil off loyal terr0 terr1 terr2 terr3 dterr xdist yd 1 2 6 10 100 0 0 0 0 0 0 0 0 2 6 0 0 0 0 10 0 0 0 0 0 1 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0 1 4 6 10 100 0 0 0 0 0 0 0 0 4 6 0 0 0 0 10 0 0 0 0 0 1 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0 1 6 6 10 100 0 0 0 0 0 0 0 0 6 6 0 0 0 0 10 0 0 0 0 0 1 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 healthy 0 0 0 0 0 0 0 0 -1 8 6 10 100 0 0 0 0 0 0 0 0 8 6 0 0 0 0 10 0 0 0 0 0 0 100 0 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 58 healthy 0 0 0 0 0 0 0 0 +1 8 6 10 100 0 0 0 0 0 0 0 0 8 6 0 0 0 0 10 0 0 0 0 0 0 100 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 healthy 0 0 0 0 0 0 0 0 0 10 6 10 100 0 0 0 0 0 0 0 0 10 6 0 0 0 0 10 0 0 0 0 0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0 0 12 6 10 100 0 0 0 0 0 0 0 0 12 6 0 0 0 0 10 0 0 0 0 0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0 0 14 6 10 100 0 0 0 0 0 0 0 0 14 6 0 0 0 0 10 0 0 0 0 0 0 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 0 0 0 0 0 @@ -265,13 +265,13 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h 120 1 2 0 15 100 127 0 130 2 0 none 1 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 121 1 7 7 15 100 52 0 130 7 7 none 1 "" -1 0 42 () "" 0 5 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 128 1 9 7 15 100 -23 0 130 7 7 none 1 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -130 1 8 6 15 94 52 0 130 6 6 none 1 "" -1 0 42 () "" 0 4 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -131 1 8 6 15 100 52 0 130 6 6 none 1 "" -1 0 42 () "" 0 5 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -135 1 8 6 0 85 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -136 1 8 6 0 83 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 4 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -137 1 8 6 0 55 90 0 30 6 6 none 3 "" -1 0 42 () "" 0 3 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -138 1 8 6 0 76 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 4 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -139 1 8 6 0 100 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +130 1 8 6 15 94 52 0 130 6 6 none 1 "" -1 0 42 () "" 0 5 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +131 1 8 6 15 96 48 0 130 6 6 none 1 "" -1 0 42 () "" 0 5 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +135 1 8 6 0 100 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +136 1 8 6 0 100 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +137 1 8 6 0 100 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +138 1 8 6 0 100 104 0 30 6 6 none 3 "" -1 0 42 () "" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +139 1 8 6 0 84 88 0 30 6 6 none 3 "" -1 0 42 () "" 0 4 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 149 0 0 0 0 0 0 0 0 0 0 none 0 "" -1 0 0 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 /config config nuke @@ -280,7 +280,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius stockpile p config news actor action victim times duration time 1 25 0 21 0 0 -1 56 0 15 0 0 +1 56 0 11 0 0 /config config trade uid owner type unitid price maxbidder markettime xloc yloc diff --git a/tests/navi-march/journal.log b/tests/navi-march/journal.log index a8a5a1d6..b2d9d098 100644 --- a/tests/navi-march/journal.log +++ b/tests/navi-march/journal.log @@ -1274,11 +1274,13 @@ Play#1 output Play#1 1 Sweep... Play#1 output Play#1 1 Sweep... Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #137 takes 14 + Play#1 output Play#1 1 eng engineer #131 takes 4 + Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! + Play#1 output Play#1 1 cav cavalry #139 takes 16 Play#1 output Play#1 1 m m Play#1 output Play#1 1 m m m Play#1 output Play#1 1 m m - Play#1 output Play#1 4 <104.7:89.7: 8,6> + Play#1 output Play#1 4 <104.7:86.0: 8,6> Play#1 input mmmh Play#1 output Play#1 1 cav cavalry #135 is not an engineer! Play#1 output Play#1 1 Sweep... @@ -1293,42 +1295,33 @@ Play#1 output Play#1 1 cav cavalry #137 is not an engineer! Play#1 output Play#1 1 cav cavalry #138 is not an engineer! Play#1 output Play#1 1 cav cavalry #139 is not an engineer! - Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #137 takes 18 Play#1 output Play#1 1 cav cavalry #135 is not an engineer! Play#1 output Play#1 1 Sweep... Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 cav cavalry #136 is not an engineer! - Play#1 output Play#1 1 cav cavalry #137 is not an engineer! - Play#1 output Play#1 1 cav cavalry #138 is not an engineer! - Play#1 output Play#1 1 cav cavalry #139 is not an engineer! - Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #137 takes 22 - Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #138 takes 24 - Play#1 output Play#1 1 cav cavalry #135 is not an engineer! - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 Sweep... - Play#1 output Play#1 1 cav cavalry #136 is not an engineer! - Play#1 output Play#1 1 cav cavalry #137 is not an engineer! - Play#1 output Play#1 1 cav cavalry #138 is not an engineer! - Play#1 output Play#1 1 cav cavalry #139 is not an engineer! - Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #135 takes 15 Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! Play#1 output Play#1 1 eng engineer #130 takes 6 - Play#1 output Play#1 1 Blammo! Landmines detected in 8,6! - Play#1 output Play#1 1 cav cavalry #136 takes 17 + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 cav cavalry #136 is not an engineer! + Play#1 output Play#1 1 cav cavalry #137 is not an engineer! + Play#1 output Play#1 1 cav cavalry #138 is not an engineer! + Play#1 output Play#1 1 cav cavalry #139 is not an engineer! + Play#1 output Play#1 1 cav cavalry #135 is not an engineer! + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 Sweep... + Play#1 output Play#1 1 cav cavalry #136 is not an engineer! + Play#1 output Play#1 1 cav cavalry #137 is not an engineer! + Play#1 output Play#1 1 cav cavalry #138 is not an engineer! + Play#1 output Play#1 1 cav cavalry #139 is not an engineer! Play#1 output Play#1 1 cav cavalry #135 stopped at 8,6 Play#1 output Play#1 1 eng engineer #130 stopped at 8,6 Play#1 output Play#1 1 eng engineer #131 stopped at 8,6 @@ -1550,13 +1543,13 @@ Play#0 output Play#0 1 1 120 eng engineer 2,0 100% 5 0 127 0 130 42% 0 0 Play#0 output Play#0 1 1 121 eng engineer 7,7 100% 5 0 52 0 130 42% 0 0 Play#0 output Play#0 1 1 128 eng engineer 9,7 100% 5 0 -23 0 130 42% 0 0 - Play#0 output Play#0 1 1 130 eng engineer 8,6 94% 4 0 52 0 130 42% 0 0 - Play#0 output Play#0 1 1 131 eng engineer 8,6 100% 5 0 52 0 130 42% 0 0 - Play#0 output Play#0 1 1 135 cav cavalry 8,6 85% 5 0 104 0 30 42% 0 0 - Play#0 output Play#0 1 1 136 cav cavalry 8,6 83% 4 0 104 0 30 42% 0 0 - Play#0 output Play#0 1 1 137 cav cavalry 8,6 55% 3 0 90 0 30 42% 0 0 - Play#0 output Play#0 1 1 138 cav cavalry 8,6 76% 4 0 104 0 30 42% 0 0 - Play#0 output Play#0 1 1 139 cav cavalry 8,6 100% 5 0 104 0 30 42% 0 0 + Play#0 output Play#0 1 1 130 eng engineer 8,6 94% 5 0 52 0 130 42% 0 0 + Play#0 output Play#0 1 1 131 eng engineer 8,6 96% 5 0 48 0 130 42% 0 0 + Play#0 output Play#0 1 1 135 cav cavalry 8,6 100% 5 0 104 0 30 42% 0 0 + Play#0 output Play#0 1 1 136 cav cavalry 8,6 100% 5 0 104 0 30 42% 0 0 + Play#0 output Play#0 1 1 137 cav cavalry 8,6 100% 5 0 104 0 30 42% 0 0 + Play#0 output Play#0 1 1 138 cav cavalry 8,6 100% 5 0 104 0 30 42% 0 0 + Play#0 output Play#0 1 1 139 cav cavalry 8,6 84% 4 0 88 0 30 42% 0 0 Play#0 output Play#0 1 68 units Play#0 output Play#0 6 0 637 Play#0 input lcar * ?shell#0 @@ -1564,8 +1557,8 @@ Play#0 output Play#0 1 lnd# unit x,y a eff civ mil uw sh gun pet irn dst bar oil lcm hcm rad Play#0 output Play#0 1 111 eng 6,6 100% 0 5 0 1 0 0 0 0 0 0 0 0 0 Play#0 output Play#0 1 121 eng 7,7 100% 0 5 0 3 0 0 0 0 0 0 0 0 0 - Play#0 output Play#0 1 130 eng 8,6 94% 0 4 0 3 0 0 0 0 0 0 0 0 0 - Play#0 output Play#0 1 131 eng 8,6 100% 0 5 0 3 0 0 0 0 0 0 0 0 0 + Play#0 output Play#0 1 130 eng 8,6 94% 0 5 0 3 0 0 0 0 0 0 0 0 0 + Play#0 output Play#0 1 131 eng 8,6 96% 0 5 0 3 0 0 0 0 0 0 0 0 0 Play#0 output Play#0 1 4 units Play#0 output Play#0 6 0 637 Play#0 input lret * ?rflags#0