]> git.pond.sub.org Git - empserver/commit - src/lib/update/bp.c
update: Don't use materials and work destroyed by che or plague
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 5 Jun 2016 13:35:57 +0000 (15:35 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 17:59:58 +0000 (19:59 +0200)
commit66edd2bacaf5079473f0724adbdb301a265b3cd2
treed39b23a67fdbbae8d0b6083f7439afa6e1695d12
parent2bdb60183313b6ece177c18e08a3439232930743
update: Don't use materials and work destroyed by che or plague

Update code shared with budget uses the bp map instead of the sector,
so that budget can track materials and work available in sectors for
ship, plane and land unit building without updating the sector file.
Unfortunately, the bp map can become stale during the update.

prepare_sects() doesn't update the bp map for sea sectors, unlike
budget's calc_all().  Instead, we rely on calloc()'s initialization.
Works, but is a bit unclean.

prepare_sects() updates the bp map after fallout, but neglects to
update it for any of the later sector updates (steps 1b to 1f in info
Update-sequence).  Che can destroy materials and available work, and
the plague can kill military.  The bp map stays out of date until
produce_sect() updates it again.

Since we deal with sector production and countries in increasing order
of country number, foreign ships, planes and land units owned by
countries with lesser numbers get built before their sector produces.
Building uses the stale bp map then, and can use materials and
available work destroyed by che or the plague.  The update test
demonstrates the former case.

For stopped sectors or when the owner is broke, produce_sect() updates
only materials in the bp map, not available work.  Nothing builds in a
stopped sector, but allies may build in your sectors even when you're
broke.  They can use available work destroyed by che then.

Screwed up when Empire 3 made the update code work for budget.

Note that budget bypasses the flawed code: it prepares its bp map
itself instead of calling prepare_sects().

Rather than fixing prepare_sects(), use a null bp map for the update:
writes become no-ops, and reads read from the underlying sector.  Not
only does this remove the possibility of the bp map going stale during
the update, it saves a bit of memory, too.

calloc()'s initialization is now dead.  Switch to malloc().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/prototypes.h
src/lib/update/bp.c
src/lib/update/main.c
src/lib/update/prepare.c
tests/update/01-1
tests/update/99-POGO
tests/update/final.xdump
tests/update/journal.log