update: Don't double-round money, fixing mil pay and more

The update tallies income and expenses in full dollars.  Each debit or
credit is rounded before it is added to the tally.  Different things
are rounded differently.  Examples:

* Each sector's military pay is rounded down.  In the stock game, 1m
  is paid $4.999998, so n mil cost n*$5 -$1, for all practical n.  10m
  in one sector cost $49, but spread over ten sectors they cost only
  $40.

* Total pay for military in ships and land units is rounded down.

* Each plane's military pay is rounded down (used to be rounded up
  except for broke countries until recent commit 2eb08f4).  In the
  stock game, flight pay is 5 * $4.999998 = $24.99999.  For a plane
  with n mil, that's n * $25 - $1.  Filed under plane maintenance, not
  military payroll.

* Each sector's civilian tax is rounded.  In the stock game, 1c pays
  $0.499998.  10c in one sector pay $5, but spread over ten sectors
  they pay nothing.

* An occupied sector's civilian tax is first rounded, then divided by
  four and rounded down *boggle*.

* Each sector's uw tax is rounded.  In the stock game, 1u pays
  $0.106662.  1-4u in one sector pay nothing.  5-14u pay $1.

This is madness.  Has always been that way.

Drop the rounding and track money in type double throughout the
update.  Round only the final amount, randomly.  This is similar to
how commands accumulate a money delta in player->dolcost.

Likewise, tally the subtotals for budget in type double.  Display them
rounded to full dollars.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2016-07-06 19:36:33 +02:00
parent 10789a0365
commit 25a6cf92b2
14 changed files with 760 additions and 758 deletions

View file

@ -108,10 +108,9 @@ void
tax(struct sctstr *sp, int etu, int *pop)
{
struct budget *budget = &nat_budget[sp->sct_own];
int civ_tax, uw_tax, mil_pay;
double civ_tax, uw_tax, mil_pay;
civ_tax = (int)(0.5 + sp->sct_item[I_CIVIL] * sp->sct_effic *
etu * money_civ / 100);
civ_tax = sp->sct_item[I_CIVIL] * etu * money_civ * sp->sct_effic / 100;
/*
* captured civs only pay 1/4 taxes
*/
@ -121,8 +120,7 @@ tax(struct sctstr *sp, int etu, int *pop)
budget->civ.money += civ_tax;
budget->money += civ_tax;
uw_tax = (int)(0.5 + sp->sct_item[I_UW] * sp->sct_effic *
etu * money_uw / 100);
uw_tax = sp->sct_item[I_UW] * etu * money_uw * sp->sct_effic / 100;
budget->uw.count += sp->sct_item[I_UW];
budget->uw.money += uw_tax;
budget->money += uw_tax;
@ -144,7 +142,8 @@ upd_slmilcosts(int etu, natid n)
{
struct shpstr *sp;
struct lndstr *lp;
int mil, i, mil_pay;
int mil, i;
double mil_pay;
mil = 0;
@ -169,18 +168,18 @@ upd_slmilcosts(int etu, natid n)
void
bank_income(struct sctstr *sp, int etu)
{
int inc;
double income;
inc = (int)(sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100);
income = sp->sct_item[I_BAR] * etu * bankint * sp->sct_effic / 100;
nat_budget[sp->sct_own].bars.count += sp->sct_item[I_BAR];
nat_budget[sp->sct_own].bars.money += inc;
nat_budget[sp->sct_own].money += inc;
nat_budget[sp->sct_own].bars.money += income;
nat_budget[sp->sct_own].money += income;
}
void
pay_reserve(struct natstr *np, int etu)
{
int pay = (int)(np->nat_reserve * money_res * etu);
double pay = np->nat_reserve * money_res * etu;
nat_budget[np->nat_cnum].mil.money += pay;
nat_budget[np->nat_cnum].money += pay;