From: Markus Armbruster Date: Sat, 4 Jun 2016 15:36:24 +0000 (+0200) Subject: update: Fix revert to deity and "no civilians" corner cases X-Git-Tag: v4.4.0~243 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=41d0a791180ead7054036ad6c16b08f9fc921829 update: Fix revert to deity and "no civilians" corner cases We maintain a few sector invariants in sct_prewrite(). Since the update bypasses sct_prewrite(), it needs to maintain them itself. The two should be consistent. The update reverts deserted sectors to deity in three places: do_plague(), populace() and produce_sect(). None of them is consistent with sct_prewrite(). populace() can revert unowned sectors to deity. This creates bogus entries in the "lost" file. Harmless; messed up when the lost items were added in 4.0.7. Visible in tests/smoke/final.xdump. populace() fails to revert when there are only uw left. If PLAGUE is enabled, do_plague() already reverted. Else, produce_sect() will. This is the only case where they add value to populace(). Can be traced back all the way to BSD Empire 1.1. All three neglect to clear mobility. Harmless. Fix populace()'s condition for reverting to deity, and make it clear mobility. Drop the reverting from do_plague() and produce_sect(). populace() also resets state that applies to civilians when there are none: work percentage, loyalty and old owner. However, it resets on different conditions than sct_prewrite(). Messed up in Chainsaw; before, populace() didn't reset at all. For sectors without military, populace() fails to reset. This can happen when the update wipes out civilians and military, say by plague or fallout. The now bogus work percentage, loyalty and old owner persist until sct_prewrite() runs on the next non-update sector update. Except old owner is reset correctly by populace() when the sector reverts to deity. It doesn't when the owner has a land unit there. Most of the time, this doesn't matter, as moving civilians into a sector without civilians overwrites the sector's work percentage, loyalty and old owner. However, airlifting and unloading civilians fail when the old owner differs from the owner. Else they adopt the sector's loyalty and work percentage (bug#49 and bug#255). Fix populace() to reset any sector without civilians, like sct_prewrite(). Signed-off-by: Markus Armbruster --- diff --git a/src/lib/update/plague.c b/src/lib/update/plague.c index 05a40c1b0..ac526750b 100644 --- a/src/lib/update/plague.c +++ b/src/lib/update/plague.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Steve McClure, 1998-2000 - * Markus Armbruster, 2004-2014 + * Markus Armbruster, 2004-2016 */ #include @@ -99,12 +99,6 @@ do_plague(struct sctstr *sp, struct natstr *np, int etu) break; } } - if (sp->sct_item[I_CIVIL] == 0 && sp->sct_item[I_MILIT] == 0 - && !has_units(sp->sct_x, sp->sct_y, sp->sct_own)) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - } sp->sct_pstage = pstage; sp->sct_ptime = ptime; } diff --git a/src/lib/update/populace.c b/src/lib/update/populace.c index 04c501bb8..a3b02d3f9 100644 --- a/src/lib/update/populace.c +++ b/src/lib/update/populace.c @@ -45,18 +45,21 @@ populace(struct natstr *np, struct sctstr *sp, int etu) int civ = sp->sct_item[I_CIVIL]; int mil = sp->sct_item[I_MILIT]; - if (civ == 0 && mil > 0) { + if (!civ) { sp->sct_work = 100; sp->sct_loyal = 0; sp->sct_oldown = sp->sct_own; } - if (!civ && !mil && !sp->sct_item[I_UW] + if (sp->sct_own && !civ && !mil && !has_units(sp->sct_x, sp->sct_y, sp->sct_own)) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; sp->sct_oldown = 0; - return; + sp->sct_mobil = 0; } + if (!civ && !mil && !sp->sct_item[I_UW]) + return; + if (sp->sct_own != sp->sct_oldown && sp->sct_loyal == 0) { sp->sct_oldown = sp->sct_own; } diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index d3127f46a..24d311ad8 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -268,17 +268,8 @@ produce_sect(struct natstr *np, int etu, struct bp *bp, int p_sect[][2]) sp = &scratch_sect; } - /* If everybody is dead, the sector reverts to unowned. - * This is also checked at the end of the production in - * they all starved or were plagued off. - */ if (sp->sct_item[I_CIVIL] == 0 && sp->sct_item[I_MILIT] == 0 && !has_units(sp->sct_x, sp->sct_y, sp->sct_own)) { - if (!player->simulation) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - } continue; } diff --git a/tests/smoke/final.xdump b/tests/smoke/final.xdump index a935a85a4..581e02a12 100644 --- a/tests/smoke/final.xdump +++ b/tests/smoke/final.xdump @@ -1108,11 +1108,10 @@ uid owner type amount price maxbidder markettime xbuy ybuy xsell ysell /config config lost timestamp owner type id x y -0 0 0 0 -1 -1 +0 0 1 2 11 -13 0 1 3 1 11 -13 0 1 3 2 10 -14 0 0 1 3 10 -14 -0 0 0 0 -1 -1 /config config realm cnum realm xl xh yl yh diff --git a/tests/update/99-POGO b/tests/update/99-POGO index 167f53747..ddcd11862 100644 --- a/tests/update/99-POGO +++ b/tests/update/99-POGO @@ -187,15 +187,10 @@ land 0:31,-16:-1 | che take over -16:-14,-8 and spread; -14,-8 is a bank | plague stage 4 (dying) -16:-1,-6 ship#10 land#10 | -16,-6 reverts to deity -| BUG mob not reset -| BUG work etc. not reset | -14,-6 resets work etc. | -12,-6 mil all die | -10,-6 resets work etc -| BUG work etc. not reset | -8,-6 reverts to deity -| BUG mob not reset -| BUG work etc. not reset | plague stage 3..1 -16:-1,-5:-3 ship#11..19 land#10..19 | plague stage 0 (healthy) -16:-9,-2, 50% chance to become exposed | -5,-1 tech too low diff --git a/tests/update/final.xdump b/tests/update/final.xdump index 4c3fc5e16..abccd0d8f 100644 --- a/tests/update/final.xdump +++ b/tests/update/final.xdump @@ -187,11 +187,11 @@ owner xloc yloc des effic mobil off loyal terr0 terr1 terr2 terr3 dterr xdist yd 3 10 -6 4 13 120 0 112 0 0 0 0 0 10 -6 14 0 55 0 4 0 0 0 0 0 3 130 0 0 0 0 0 0 0 97 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 3 12 -6 4 11 120 0 127 0 0 0 0 0 12 -6 11 0 43 0 4 0 0 0 0 0 3 130 0 0 0 0 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 -0 -8 -6 4 0 60 0 0 0 0 0 0 0 -8 -6 0 0 50 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 20 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 79 0 0 0 0 0 0 0 +4 -10 -6 4 0 120 0 0 0 0 0 0 0 -10 -6 0 0 100 0 4 0 0 0 0 0 4 0 0 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 healthy 48 0 0 0 0 0 0 0 +0 -8 -6 4 0 0 0 0 0 0 0 0 0 -8 -6 0 0 100 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 0 0 0 20 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 79 0 0 0 0 0 0 0 4 -6 -6 4 3 120 0 0 0 0 0 0 0 -6 -6 4 0 72 0 4 0 0 0 0 0 4 26 0 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 healthy 75 0 0 0 0 0 0 0 4 -4 -6 4 3 120 0 0 0 0 0 0 0 -4 -6 4 0 70 0 4 0 0 0 0 0 4 26 0 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 dying 1 0 0 0 0 0 0 0 4 -2 -6 4 3 120 0 0 0 0 0 0 0 -2 -6 4 0 69 0 4 0 0 0 0 0 4 26 0 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 dying 1 0 0 0 0 0 0 0 @@ -428,7 +428,6 @@ uid owner type amount price maxbidder markettime xbuy ybuy xsell ysell config lost timestamp owner type id x y 0 4 0 0 -8 -6 -0 0 0 0 -8 -6 /config config realm cnum realm xl xh yl yh diff --git a/tests/update/journal.log b/tests/update/journal.log index 590746b7c..9c5f2ab66 100644 --- a/tests/update/journal.log +++ b/tests/update/journal.log @@ -1432,11 +1432,11 @@ Play#0 output Play#0 1 4 -5,-7 - 39% 120 .. .. 130 0 0 96 100% 39 0 Play#0 output Play#0 1 4 -3,-7 - 39% 120 .. .. 130 0 0 97 100% 39 0 Play#0 output Play#0 1 4 -1,-7 - 39% 120 .. .. 130 0 0 97 100% 39 0 - Play#0 output Play#0 1 0 -16,-6 - 0% 60 .. .. 0 0 0 100 50% 0 0 1 + Play#0 output Play#0 1 0 -16,-6 - 0% 0 .. .. 0 0 0 100 100% 0 0 1 Play#0 output Play#0 1 4 -14,-6 - 0% 120 .. .. 0 2 0 100 100% 0 0 Play#0 output Play#0 1 4 -12,-6 * 100% 120 .. .. 26 0 0 99 58% 28 0 - Play#0 output Play#0 1 4 -10,-6 - 0% 120 .. .. 0 0 0 100 61% 0 0 - Play#0 output Play#0 1 0 -8,-6 - 0% 60 .. .. 0 0 20 100 50% 0 0 + Play#0 output Play#0 1 4 -10,-6 - 0% 120 .. .. 0 0 0 100 100% 0 0 + Play#0 output Play#0 1 0 -8,-6 - 0% 0 .. .. 0 0 20 100 100% 0 0 Play#0 output Play#0 1 4 -6,-6 - 3% 120 .. .. 26 0 0 100 72% 4 0 Play#0 output Play#0 1 4 -4,-6 - 3% 120 .. .. 26 0 0 100 70% 4 0 Play#0 output Play#0 1 4 -2,-6 - 3% 120 .. .. 26 0 0 100 69% 4 0