From 5e54219606569a10da388c30577e9c7362bb204e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Jun 2016 17:14:25 +0200 Subject: [PATCH] sect: 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. When a deserted sector reverts to the deity, sct_prewrite() clears owner and mobility. It neglects to clear the old owner, unlike populace(). Harmless, but fix it anyway for consistency. Visible in tests/navi-march/final.xdump. Work percentage, loyalty and old owner apply to civilians. When there are none, sct_prewrite() sets work percentage to 100 and old owner to owner. It neglects to clear loyalty, unlike populace(). Loyalty persists until populace() clears it. Most of the time, this doesn't matter, as moving civilians into a sector without civilians ignores the sector's loyalty. However, airlifted and unloaded civilians adopt the sector's loyalty (bug#49 and bug#255). Fix sct_prewrite() to clear loyalty for consistency, and to mitigate these bugs. Note that populace() may not always clear loyalty right away. This will be fixed in the next commit. Signed-off-by: Markus Armbruster --- src/lib/subs/sect.c | 2 ++ tests/navi-march/final.xdump | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index d392d3dc..a0069733 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -80,6 +80,7 @@ sct_prewrite(int id, void *old, void *new) if (!civs) { sp->sct_work = 100; + sp->sct_loyal = 0; sp->sct_oldown = own; } @@ -90,6 +91,7 @@ sct_prewrite(int id, void *old, void *new) if (own && !civs && !mil && !has_units(sp->sct_x, sp->sct_y, own) && !(sp->sct_flags & MOVE_IN_PROGRESS)) { own = sp->sct_own = 0; + sp->sct_oldown = 0; sp->sct_mobil = 0; if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT) caploss(sp, prev_own, ""); diff --git a/tests/navi-march/final.xdump b/tests/navi-march/final.xdump index baec8447..fb1d4346 100644 --- a/tests/navi-march/final.xdump +++ b/tests/navi-march/final.xdump @@ -101,7 +101,7 @@ owner xloc yloc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