From b8601235902a3087eb09835c9b18f5dc5aa83955 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 20 Jan 2014 21:47:17 +0100 Subject: [PATCH] retreat: Retreat groups in a more sensible order A group retreat is executed in increasing UID order. The resulting bulletin can be confusing. Instead, retreat the ship that had its retreat conditions satisfied first, and only then its group, if any. Signed-off-by: Markus Armbruster --- src/lib/subs/retreat.c | 30 ++++++++++++------------------ tests/retreat/final.xdump | 8 ++++---- tests/retreat/journal.log | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/src/lib/subs/retreat.c b/src/lib/subs/retreat.c index ca95bd5d..d11bee93 100644 --- a/src/lib/subs/retreat.c +++ b/src/lib/subs/retreat.c @@ -28,6 +28,8 @@ * * Known contributors to this file: * Steve McClure, 2000 + * Ron Koenderink, 2005-2006 + * Markus Armbruster, 2006-2014 */ #include @@ -94,15 +96,15 @@ retreat_ship(struct shpstr *sp, char code) struct nstr_item ni; struct shpstr ship; + retreat_ship1(sp, code, 1); + if (sp->shp_rpath[0] == 0) + sp->shp_rflags = 0; + if (sp->shp_rflags & RET_GROUP) { snxtitem_group(&ni, EF_SHIP, sp->shp_fleet); while (nxtitem(&ni, &ship)) if (ship.shp_own == sp->shp_own) { - if (ship.shp_uid == sp->shp_uid) { - retreat_ship1(sp, code, 1); - if (sp->shp_rpath[0] == 0) - sp->shp_rflags = 0; - } else { + if (ship.shp_uid != sp->shp_uid) { retreat_ship1(&ship, code, 0); getship(ship.shp_uid, &ship); if (ship.shp_rpath[0] == 0) { @@ -111,10 +113,6 @@ retreat_ship(struct shpstr *sp, char code) } } } - } else { - retreat_ship1(sp, code, 1); - if (sp->shp_rpath[0] == 0) - sp->shp_rflags = 0; } } @@ -354,15 +352,15 @@ retreat_land(struct lndstr *lp, char code) struct nstr_item ni; struct lndstr land; + retreat_land1(lp, code, 1); + if (lp->lnd_rpath[0] == 0) + lp->lnd_rflags = 0; + if (lp->lnd_rflags & RET_GROUP) { snxtitem_group(&ni, EF_LAND, lp->lnd_army); while (nxtitem(&ni, &land)) if (land.lnd_own == lp->lnd_own) { - if (land.lnd_uid == lp->lnd_uid) { - retreat_land1(lp, code, 1); - if (lp->lnd_rpath[0] == 0) - lp->lnd_rflags = 0; - } else { + if (land.lnd_uid != lp->lnd_uid) { retreat_land1(&land, code, 0); getland(land.lnd_uid, &land); if (land.lnd_rpath[0] == 0) { @@ -371,10 +369,6 @@ retreat_land(struct lndstr *lp, char code) } } } - } else { - retreat_land1(lp, code, 1); - if (lp->lnd_rpath[0] == 0) - lp->lnd_rflags = 0; } } diff --git a/tests/retreat/final.xdump b/tests/retreat/final.xdump index 37377840..818b4e94 100644 --- a/tests/retreat/final.xdump +++ b/tests/retreat/final.xdump @@ -190,8 +190,8 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius fleet xstar 40 2 1 3 10 91 -7 0 45 0 2 none 1 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 40 "" -3 1 1 (injured) "nnnh" 41 2 1 3 10 96 108 0 45 0 2 none 1 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 41 "" -3 1 1 (injured) "h" 42 2 -4 2 10 95 120 0 45 -4 2 interdiction 1 "" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 42 "" -3 1 1 (injured) "gggh" -43 2 -6 4 16 71 80 0 40 0 0 none 0 "m" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 2 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 43 "" -3 1 1 (group injured) "g" -44 2 -6 4 16 69 74 0 40 0 0 none 0 "m" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 44 "" -3 1 1 (group injured) "g" +43 2 -6 4 16 76 86 0 40 0 0 none 0 "m" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 43 "" -3 1 1 (group injured) "g" +44 2 -6 4 16 63 70 0 40 0 0 none 0 "m" 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 2 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 44 "" -3 1 1 (group injured) "g" 45 0 0 0 0 0 127 0 0 0 0 none 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 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () "" 46 0 0 0 0 0 127 0 0 0 0 none 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 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () "" 47 0 0 0 0 0 127 0 0 0 0 none 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 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 0 0 "" 0 "" 0 0 0 () "" @@ -396,8 +396,8 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h 40 2 2 2 0 89 -15 0 50 1 1 none 3 "" -1 127 42 (bombed) "u" 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 41 2 3 1 0 86 99 0 50 1 1 none 3 "" -1 127 42 () "" 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 42 2 1 1 0 83 105 0 50 1 1 reserve 3 "" -1 127 42 () "" 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -43 2 0 0 15 97 111 0 130 0 0 none 0 "m" -1 127 42 (group bombed) "u" 0 10 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -44 2 0 0 15 89 102 0 130 0 0 none 0 "m" -1 127 42 (group bombed) "u" 0 10 2 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +43 2 0 0 15 96 110 0 130 0 0 none 0 "m" -1 127 42 (group bombed) "u" 0 10 2 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +44 2 0 0 15 90 103 0 130 0 0 none 0 "m" -1 127 42 (group bombed) "u" 0 10 3 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 45 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 46 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 47 0 0 0 0 0 127 0 0 0 0 none 0 "" -1 127 0 () "" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 diff --git a/tests/retreat/journal.log b/tests/retreat/journal.log index 92bd0e77..57228286 100644 --- a/tests/retreat/journal.log +++ b/tests/retreat/journal.log @@ -1303,14 +1303,14 @@ Play#0 output Play#0 1 but could not retreat to -3,1! Play#0 output Play#0 1 Country #1 shelled ms minesweeper (#44) in -4,4 for 11 damage. Play#0 output Play#0 1 ms minesweeper (#44) takes 10 - Play#0 output Play#0 1 ms minesweeper (#43) cleared 3 mines in -6,4 while retreating - Play#0 output Play#0 1 ms minesweeper (#43) retreated with a damaged friend, - Play#0 output Play#0 1 and hit a mine in -6,4 while retreating! - Play#0 output Play#0 1 ms minesweeper (#43) takes 29 Play#0 output Play#0 1 ms minesweeper (#44) cleared 3 mines in -6,4 while retreating Play#0 output Play#0 1 ms minesweeper (#44) was damaged, Play#0 output Play#0 1 and hit a mine in -6,4 while retreating! - Play#0 output Play#0 1 ms minesweeper (#44) takes 24 + Play#0 output Play#0 1 ms minesweeper (#44) takes 29 + Play#0 output Play#0 1 ms minesweeper (#43) cleared 3 mines in -6,4 while retreating + Play#0 output Play#0 1 ms minesweeper (#43) retreated with a damaged friend, + Play#0 output Play#0 1 and hit a mine in -6,4 while retreating! + Play#0 output Play#0 1 ms minesweeper (#43) takes 24 Play#0 output Play#0 1 Country #1 shelled cs cargo ship (#10) in 0,2 for 11 damage. Play#0 output Play#0 1 cs cargo ship (#10) takes 9 Play#0 output Play#0 1 cs cargo ship (#10) was damaged, and retreated to 1,3 @@ -1453,12 +1453,12 @@ Play#0 output Play#0 1 Flak! Firing flak guns from unit eng engineer #44 (aa rating 1) Play#0 output Play#0 1 1 pinpoint bombing raid did 28 damage to eng engineer #44 Play#0 output Play#0 1 eng engineer #44 takes 7 - Play#0 output Play#0 1 eng engineer #43 retreated with a bombed friend, - Play#0 output Play#0 1 and hit a mine in 0,0 while retreating! - Play#0 output Play#0 1 eng engineer #43 takes 3 Play#0 output Play#0 1 eng engineer #44 was bombed, Play#0 output Play#0 1 and hit a mine in 0,0 while retreating! - Play#0 output Play#0 1 eng engineer #44 takes 4 + Play#0 output Play#0 1 eng engineer #44 takes 3 + Play#0 output Play#0 1 eng engineer #43 retreated with a bombed friend, + Play#0 output Play#0 1 and hit a mine in 0,0 while retreating! + Play#0 output Play#0 1 eng engineer #43 takes 4 Play#0 output Play#0 1 1,1 takes 3% collateral damage Play#0 output Play#0 1 tra train #9 takes 1 Play#0 output Play#0 1 1 planes spotted over 1,1 @@ -1504,8 +1504,8 @@ Play#0 output Play#0 1 2 40 lc light cruis 1,3 91% 0 9 0 0 0 0 0 0 -7 45 Play#0 output Play#0 1 2 41 lc light cruis 1,3 96% 0 10 0 0 0 0 0 0 108 45 Play#0 output Play#0 1 2 42 lc light cruis -4,2 95% 0 10 0 0 0 0 0 0 120 45 - Play#0 output Play#0 1 2 43 ms minesweeper -6,4 m 71% 0 7 0 0 0 0 0 0 80 40 - Play#0 output Play#0 1 2 44 ms minesweeper -6,4 m 69% 0 7 0 0 0 0 0 0 74 40 + Play#0 output Play#0 1 2 43 ms minesweeper -6,4 m 76% 0 7 0 0 0 0 0 0 86 40 + Play#0 output Play#0 1 2 44 ms minesweeper -6,4 m 63% 0 7 0 0 0 0 0 0 70 40 Play#0 output Play#0 1 2 50 sb submarine -9,1 67% 0 7 0 0 0 0 0 0 33 60 Play#0 output Play#0 1 2 51 sb submarine -9,1 64% 0 6 0 0 0 0 0 0 27 60 Play#0 output Play#0 1 2 52 sb submarine -9,1 73% 0 7 0 0 0 0 0 0 44 60 @@ -1598,8 +1598,8 @@ Play#0 output Play#0 1 2 40 cav cavalry 2,2 89% 9 127 -15 0 50 42% 0 0 Play#0 output Play#0 1 2 41 cav cavalry 3,1 86% 9 127 99 0 50 42% 0 0 Play#0 output Play#0 1 2 42 cav cavalry 1,1 83% 9 127 105 0 50 42% 0 0 - Play#0 output Play#0 1 2 43 eng engineer 0,0 m 97% 10 127 111 0 130 42% 0 0 - Play#0 output Play#0 1 2 44 eng engineer 0,0 m 89% 10 127 102 0 130 42% 0 0 + Play#0 output Play#0 1 2 43 eng engineer 0,0 m 96% 10 127 110 0 130 42% 0 0 + Play#0 output Play#0 1 2 44 eng engineer 0,0 m 90% 10 127 103 0 130 42% 0 0 Play#0 output Play#0 1 2 60 cav cavalry 3,1 73% 7 127 71 0 50 42% 0 0 Play#0 output Play#0 1 2 61 cav cavalry 0,0 100% 10 127 127 0 50 42% 0 0 Play#0 output Play#0 1 2 62 cav cavalry 0,0 100% 10 127 127 0 50 42% 0 0