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>
This commit is contained in:
Markus Armbruster 2016-06-05 15:35:57 +02:00
parent 2bdb601833
commit 66edd2baca
8 changed files with 29 additions and 29 deletions

View file

@ -532,8 +532,8 @@
Play#0 output Play#0 1 78 happiness, 178 education produced
Play#0 output Play#0 1 total pop was 28106, yielding 14.19 hap, 24.57 edu
Play#0 output Play#0 1 3.4330 tech, 3.3939 research produced
Play#0 output Play#0 1 Army delta $-2810, Navy delta $-3738, Air force delta $-2940
Play#0 output Play#0 1 money delta was $-12051 for this update
Play#0 output Play#0 1 Army delta $-2810, Navy delta $-3738, Air force delta $-2580
Play#0 output Play#0 1 money delta was $-11691 for this update
Play#0 output Play#0 6 0 640
Play#0 input nation 1
Play#0 command nation
@ -541,7 +541,7 @@
Play#0 output Play#0 1 (#1) 1 Nation Report Thu Jan 1 00:00:00 1970
Play#0 output Play#0 1 Nation status is ACTIVE Bureaucratic Time Units: 640
Play#0 output Play#0 1 100% eff capital at 0,0 has 650 civilians & 2 military
Play#0 output Play#0 1 The treasury has $12949.00 Military reserves: 0
Play#0 output Play#0 1 The treasury has $13309.00 Military reserves: 0
Play#0 output Play#0 1 Education.......... 21.09 Happiness....... 12.33
Play#0 output Play#0 1 Technology.........102.79 Research........ 3.37
Play#0 output Play#0 1 Technology factor : 50.46% Plague factor : 1.96%
@ -1433,7 +1433,7 @@
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% 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 -12,-6 * 100% 120 .. .. 26 0 0 99 58% 57 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 - 6% 0 .. .. 0 0 23 99 100% 7 0
Play#0 output Play#0 1 4 -6,-6 - 3% 120 .. .. 26 0 0 100 72% 4 0
@ -1504,7 +1504,7 @@
Play#0 output Play#0 1 4 -1,-7 - .......... .......... 0 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 1 0 -16,-6 - .......... .......... 0 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 1 4 -14,-6 - .......... .......... 0 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 1 4 -12,-6 * .......... .......... 0 0 0 0 0 0 0 3 8 0
Play#0 output Play#0 1 4 -12,-6 * .......... .......... 0 0 0 0 0 0 0 10 10 0
Play#0 output Play#0 1 4 -10,-6 - .......... .......... 0 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 1 0 -8,-6 - .......... .......... 0 0 0 0 0 0 0 0 0 0
Play#0 output Play#0 1 4 -6,-6 - .......... .......... 0 0 0 0 0 0 0 0 0 0
@ -1642,7 +1642,7 @@
Play#0 command plane
Play#0 output Play#0 1 own # type x,y w eff mu def tech ran hard carry special
Play#0 output Play#0 1 1 1 lst landsat -4,-4 100% 60 3 245 41 0 orbit
Play#0 output Play#0 1 1 100 f1 Sopwith Camel -12,-6 100% 60 1 50 4 0
Play#0 output Play#0 1 1 100 f1 Sopwith Camel -12,-6 10% 60 1 50 4 0
Play#0 output Play#0 1 2 planes
Play#0 output Play#0 6 0 640
Play#0 input land -32:-1,-16:-1