budget: Fix treasury tracking

The update simply updates each nation's nat_money as it goes.  Works.
Except it doesn't update when it runs on behalf of budget.  But it
still checks nat_money to determine whether the nation is solvent.
These checks are all broken.  Leads to massive mispredictions when
you'd go broke or solvent during a real update.

Track money unconditionally in nat_budget[].money.  Delay update of
nat_money until prod_nat().  Replace separate money[] by new
nat_budget[].start_money.  Closes bug#235.

Remaining difference between budget and update in the update test:

* #1: budget mispredicts plane #100 gets built (to be fixed)

* #2: budget shows ship, plane and land unit maintenance when broke,
      but update damages them instead (correct)

* #2: sector -14,0 converts, quadrupling its taxes (correct)

* #4 & #5: bank with dust and bars taken over by che (correct)

* #4: plague deaths (correct)

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-06-19 11:32:36 +02:00
parent 058268595f
commit 10789a0365
14 changed files with 78 additions and 99 deletions

View file

@ -206,6 +206,7 @@ prod_nat(int etu)
np->nat_level[NAT_RLEV] += rlev;
if (tlev != 0.0)
np->nat_level[NAT_TLEV] += tlev;
bm = nat_budget[n].bm;
sea_money = bm[BUDG_SHP_MAINT].money + bm[BUDG_SHP_BUILD].money;
air_money = bm[BUDG_PLN_MAINT].money + bm[BUDG_PLN_BUILD].money;
@ -214,8 +215,12 @@ prod_nat(int etu)
wu(0, n,
"Army delta $%d, Navy delta $%d, Air force delta $%d\n",
lnd_money, sea_money, air_money);
if (CANT_HAPPEN(np->nat_money != nat_budget[n].start_money))
nat_budget[n].money += np->nat_money - nat_budget[n].start_money;
wu(0, n, "money delta was $%d for this update\n",
np->nat_money - money[n]);
nat_budget[n].money - nat_budget[n].start_money);
np->nat_money = nat_budget[n].money;
if (opt_LOSE_CONTACT) {
for (cn = 1; cn < MAXNOC; cn++) {
if ((cnp = getnatp(cn)) != NULL)