From f5514cb452743cc7e0f750895dc4ba6b734083b1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 10 May 2018 18:32:54 +0200 Subject: [PATCH] edit: Fix fortification limit of embarked planes and land units We generally preserve the invariant "land units and missiles loaded on a land unit or ship are never fortified / hardened": fortify and harden refuse to touch embarked land units and missiles, load and lload zap land unit fortification on load, and refuse to load hardened missiles. The exception is edit, which happily fortifies embarked land units (edit u key 'F'), hardens embarked missiles (edit p key 'F'), loads fortified land units (edit u keys 'S' and 'Y') and hardened planes (edit p keys 's' and 'y'). Fix the first two by correcting the new value's upper limit to zero for embarked land units and planes. The next commit will take care of the rest. The fix is visible in tests where test setup fortifies land units with "edit u * F ?..." without excepting embarked ones. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 9 +++++++-- tests/navi-march/final.xdump | 4 ++-- tests/navi-march/journal.log | 4 ++-- tests/retreat/final.xdump | 4 ++-- tests/retreat/journal.log | 6 ++++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index c345f168..f843d2b8 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -31,7 +31,7 @@ * Chad Zabel, 1994 * Steve McClure, 1998-2000 * Ron Koenderink, 2003-2009 - * Markus Armbruster, 2003-2017 + * Markus Armbruster, 2003-2018 */ #include @@ -1001,6 +1001,8 @@ edit_land(struct lndstr *land, char *key, char *p) break; case 'F': arg = LIMIT_TO(arg, 0, 127); + if (land->lnd_ship >= 0 || land->lnd_land >= 0) + arg = 0; divine_unit_change((struct empobj *)land, "Fortification", arg != land->lnd_harden, arg - land->lnd_harden, "from %d to %d", land->lnd_harden, arg); @@ -1134,7 +1136,10 @@ edit_plane(struct plnstr *plane, char *key, char *p) pln_set_tech(plane, arg); break; case 'F': - arg = LIMIT_TO(arg, 0, pcp->pl_flags & P_M ? 127 : 0); + arg = LIMIT_TO(arg, 0, 127); + if (!(pcp->pl_flags & P_M) + || plane->pln_ship >= 0 || plane->pln_land >= 0) + arg = 0; divine_unit_change((struct empobj *)plane, "Fortification", arg != plane->pln_harden, arg - plane->pln_harden, "from %d to %d", plane->pln_harden, arg); diff --git a/tests/navi-march/final.xdump b/tests/navi-march/final.xdump index 89882198..e0603ad6 100644 --- a/tests/navi-march/final.xdump +++ b/tests/navi-march/final.xdump @@ -213,8 +213,8 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h 11 2 1 1 0 100 127 0 30 1 1 reserve 3 "" -1 127 42 (bombed) "hhhhn" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 12 1 1 1 0 100 127 0 30 1 1 reserve 3 "" -1 127 42 (bombed) "hhhhn" 0 5 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 13 1 1 1 0 100 127 0 30 1 1 reserve 3 "" -1 127 42 (bombed) "hhhhn" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -14 1 1 1 0 100 127 0 30 1 1 reserve 3 "" 1 127 42 (bombed) "hhhhn" 0 2 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -15 1 1 1 0 100 127 0 30 1 1 reserve 3 "" -1 127 42 (bombed) "hhhhn" 0 2 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 1 0 +14 1 1 1 0 100 127 0 30 1 1 reserve 3 "" 1 0 42 (bombed) "hhhhn" 0 2 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +15 1 1 1 0 100 127 0 30 1 1 reserve 3 "" -1 0 42 (bombed) "hhhhn" 0 2 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 1 0 20 1 3 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 21 1 2 4 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 22 1 3 3 7 100 60 0 40 0 0 none 0 "" -1 0 42 () "" 0 5 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 f6e94d1d..c98402f0 100644 --- a/tests/navi-march/journal.log +++ b/tests/navi-march/journal.log @@ -1575,8 +1575,8 @@ Play#0 output Play#0 1 2 11 cav cavalry 1,1 100% 5 127 127 0 30 42% 0 0 Play#0 output Play#0 1 1 12 cav cavalry 1,1 100% 5 127 127 0 30 42% 0 0 Play#0 output Play#0 1 1 13 cav cavalry 1,1 100% 0 127 127 0 30 42% 0 0 - Play#0 output Play#0 1 1 14 cav cavalry 1,1 100% 2 127 127 0 30 42% 0 0 1S - Play#0 output Play#0 1 1 15 cav cavalry 1,1 100% 2 127 127 0 30 42% 0 0 1L + Play#0 output Play#0 1 1 14 cav cavalry 1,1 100% 2 0 127 0 30 42% 0 0 1S + Play#0 output Play#0 1 1 15 cav cavalry 1,1 100% 2 0 127 0 30 42% 0 0 1L Play#0 output Play#0 1 1 20 cav cavalry 3,3 100% 5 0 105 0 30 42% 0 0 Play#0 output Play#0 1 1 21 cav cavalry 2,4 100% 5 0 105 0 30 42% 0 0 Play#0 output Play#0 1 1 22 tra train 3,3 100% 5 0 60 0 40 42% 0 0 diff --git a/tests/retreat/final.xdump b/tests/retreat/final.xdump index 2cbcb8df..e5836501 100644 --- a/tests/retreat/final.xdump +++ b/tests/retreat/final.xdump @@ -125,10 +125,10 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h 28 2 2 2 0 100 107 0 50 3 1 none 3 "g" -1 0 42 (group injured) "g" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 29 2 4 0 0 100 127 0 50 4 0 reserve 3 "g" -1 127 42 (group bombed) "bhg" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 30 0 0 2 0 0 105 0 50 0 2 reserve 3 "c" -1 127 42 (group bombed) "j" 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -31 2 0 2 0 100 127 0 50 0 2 reserve 3 "c" 35 127 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +31 2 0 2 0 99 126 0 50 0 2 reserve 3 "c" 35 0 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 32 2 0 2 0 100 127 0 50 0 2 reserve 3 "c" -1 127 42 (group bombed) "j" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 33 2 -1 1 0 85 108 0 50 -1 1 reserve 3 "" -1 127 42 (bombed) "j" 0 9 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -34 2 0 2 0 100 127 0 50 0 2 reserve 3 "c" -1 127 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 9 0 +34 2 0 2 0 99 126 0 50 0 2 reserve 3 "c" -1 0 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 9 0 35 2 0 2 0 100 0 0 50 0 2 reserve 3 "c" -1 127 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 36 2 0 2 0 100 127 0 50 0 2 reserve 3 "c" -1 127 42 (group bombed) "j" 0 10 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 37 2 1 1 7 82 105 0 50 0 0 none 0 "" -1 127 42 (bombed) "j" 0 9 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 96438e58..a849edf3 100644 --- a/tests/retreat/journal.log +++ b/tests/retreat/journal.log @@ -1427,6 +1427,8 @@ Play#0 output Play#0 1 cav cavalry #36 is on the trading block, and can't retreat! Play#0 output Play#0 1 0,2 takes 4% collateral damage Play#0 output Play#0 1 tra train #9 takes 1 + Play#0 output Play#0 1 cav cavalry #31 takes 1 + Play#0 output Play#0 1 cav cavalry #34 takes 1 Play#0 output Play#0 1 1 planes spotted over -1,1 Play#0 output Play#0 1 1 bombs did 40% damage to cav cavalry #33 at -1,1 Play#0 output Play#0 1 cav cavalry #33 takes 15 @@ -1681,10 +1683,10 @@ Play#0 output Play#0 1 2 27 cav cavalry 3,1 g 100% 10 127 127 0 50 42% 0 0 Play#0 output Play#0 1 2 28 cav cavalry 2,2 g 100% 10 0 107 0 50 42% 0 0 Play#0 output Play#0 1 2 29 cav cavalry 4,0 g 100% 10 127 127 0 50 42% 0 0 - Play#0 output Play#0 1 2 31 cav cavalry 0,2 c 100% 10 127 127 0 50 42% 0 0 35S + Play#0 output Play#0 1 2 31 cav cavalry 0,2 c 99% 10 0 126 0 50 42% 0 0 35S Play#0 output Play#0 1 2 32 cav cavalry 0,2 c 100% 0 127 127 0 50 42% 0 0 Play#0 output Play#0 1 2 33 cav cavalry -1,1 85% 9 127 108 0 50 42% 0 0 - Play#0 output Play#0 1 2 34 cav cavalry 0,2 c 100% 10 127 127 0 50 42% 0 0 9L + Play#0 output Play#0 1 2 34 cav cavalry 0,2 c 99% 10 0 126 0 50 42% 0 0 9L Play#0 output Play#0 1 2 35 cav cavalry 0,2 c 100% 10 127 0 0 50 42% 0 0 Play#0 output Play#0 1 2 36 cav cavalry 0,2 c 100% 10 127 127 0 50 42% 0 0 Play#0 output Play#0 1 2 37 tra train 1,1 82% 9 127 105 0 50 42% 0 0