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

@ -30,7 +30,7 @@
* Dave Pare, 1986
* Thomas Ruschak, 1993
* Steve McClure, 1998
* Markus Armbruster, 2004-2011
* Markus Armbruster, 2004-2016
*/
#include <config.h>
@ -52,7 +52,6 @@ finish_sects(int etu)
{
static double *import_cost;
struct sctstr *sp;
struct natstr *np;
int n;
struct rusage rus1, rus2;
@ -72,8 +71,7 @@ finish_sects(int etu)
continue;
if (sp->sct_own == 0)
continue;
np = getnatp(sp->sct_own);
if (np->nat_money < 0)
if (nat_budget[sp->sct_own].money < 0)
continue;
dodeliver(sp);
}
@ -93,8 +91,7 @@ finish_sects(int etu)
for (n = 0; NULL != (sp = getsectid(n)); n++) {
if (!sp->sct_own)
continue;
np = getnatp(sp->sct_own);
if (np->nat_money < 0)
if (nat_budget[sp->sct_own].money < 0)
continue;
dodistribute(sp, EXPORT, import_cost[n]);
}
@ -105,8 +102,7 @@ finish_sects(int etu)
sp->sct_off = 0;
if (!sp->sct_own)
continue;
np = getnatp(sp->sct_own);
if (np->nat_money < 0)
if (nat_budget[sp->sct_own].money < 0)
continue;
dodistribute(sp, IMPORT, import_cost[n]);
}