Commit graph

5281 commits

Author SHA1 Message Date
db055aa8bc configure: Bump required autoconf version to 2.69
2.69 is more than four years old now.  Nobody has tested with 2.64 in
quite some time.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
ce002a5096 build-aux: Refresh from automake 1.15
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
b4b65f0c35 nsc filetable: Get rid of untidy use of PACKAGE_STRING
Table version selector version shows the version string stored in
version[].  Its implementation is a bit of a hack:
empfile[EF_VERSION].cache is set to version[], so it gets passed as
context object to nstr_eval().  This permits reading version[] with an
NSC_STRINGY selector at offset 0, which is what nsc_init()'s
version_ca0 is.

Both empfile[] and version_ca need the size of version[].  Since
version.h provides only an incomplete type for version[], they use
sizeof(PACKAGE_STRING), which isn't exactly clean.

Redo version_ca0 as virtual selector.  Takes a bit more code, but it's
easier to understand.

The context object is now unused.  Setting empfile[EF_VERSION].cache
to a null pointer would trip assertions, so make it point to a dummy.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
89a06ec2d4 xdump: Make meta-type numbers portable, get rid of meta-type "c"
The xdump field data types are abstract symbols "d", "f", "s" and "c".
However, the abstraction leaks: we dump the enum nsc_type ca_type
values verbatim in meta table field "type", and have symbol table
meta-type map all integer types to "d", and both floating-point types
to "f".  Not a problem for well-behaved clients, since all they do
with the dumped value is referencing table meta-type.  It is a problem
for version-test: since the integer type compatible with an
enumeration type is implementation-defined, the type value of
selectors of enumeration type can vary between compilers.  It also
makes table meta-type a somewhat ugly exception to the rule that a
symbol table maps integers to names 1:1.

Virtual selectors let us seal the abstraction: dump the promoted
ca_type value.

The integer types get all promoted to NSC_LONG.  This takes care of
version-test.

The floating-point types get all promoted to NSC_DOUBLE.  Makes sense.

NSC_STRINGY gets promoted to NSC_STRING.  This changes all field data
types "c" to "s".  Getting rid of "c" is a welcome simplification,
because now the meaning of meta type field "len" no longer depends on
"type", but always means that the array is dumped as that many fields.
We lose string length limit information, though.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
6e9f256c68 ef_verify: Run verify_row() even for tables without selectors
verify_table() skips verify_row() when the table doesn't have
selectors.  But verify_row()'s test for corrupt headers in EFF_TYPED
tables doesn't require selectors.  Harmless, since the two tables that
don't have selectors (EF_MAP and EF_BMAP) aren't EFF_TYPED.  Clean it
up anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
18b5d16248 ef_verify: Fix test for undumpable tables
Virtual selectors can't be used in xundump, since we lack a setter to
go with ca_get().  verify_ca() verifies they don't occur in tables
that can be xundumped.

When I restricted xundump to tables with a file name (commit 029d929,
v4.3.28), I neglected to update the test in verify_ca().

Factor out the correct test into xundumpable().  Use it to fix
verify_ca().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
bb0f3a656e Make: Tidy up distribution and cleaning of generated makefiles
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
cd3c362a57 info/toc: Tidy up last line
mksubj.pl neglects to terminate info/toc's last line with a newline.
info-test doesn't care.  Tidy up anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
88698d73c7 Make: Drop $(ttop), use its value directly
info/TOP.t is easier to understand than $(ttop).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
93903e319c info/Update-sequence: Belatedly update for removal of SLOW_WAR
Missed in commit 439f111, v4.3.27.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
10c131549e update: Move sector type test into bank_income()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
9a2e1ccd6c update: Delivery abandons sectors incorrectly, fix it not to
Deliver fails to abandon sectors when it ships out all civilians and
military.  The sector remains owned until the next non-update sector
update abandons it.  Has always been broken.

Distribution had the same bug until commit d0f3847 (v4.3.20) fixed it.
Fix it the same way for delivery: adjust the amount moved to avoid
moving out the last civilian, or the last military if there are no
civilians.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
43a0a4a451 update: Reorder feeding, tax & plague for consistency
People in sectors get plagued, then taxed or paid, then fed.  People
on ships and land units get paid, then fed, then plagued.  Sectors
were messed up when Empire 3 made the update code work for budget.

Change sectors back to how they worked before Empire 3: move do_feed()
from produce_sect() to prepare_sects(), and delay do_plague() until
after do_feed().  People in sectors now get taxed, paid and fed even
when they die of the plague, just like they do on ships and land
units.

Because do_plague() now runs after populace(), the latter's handling
of people dying off doesn't cover plague anymore.  Delay it to the
very end of prepare_sects().

Additionally, move feeding and plaguing from upd_ship(), upd_land() to
prep_ship(), prep_land(), for consistency with sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:16 +02:00
2fea2a7cb8 update: Collect fallout code in fallout.c
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:16 +02:00
b6509b7309 budget: Avoid unnecessary work
Ship, plane and land unit repairs depend on and change the state of
the sector.  To predict repairs, we need to predict the state of the
sector before repairs.  The obvious way to do that is to simulate the
sector update and all ship, plane and land unit updates there in the
correct order.

Until recently, we simulated only own sectors, ships, planes and land
units.  Wrong when foreign sectors, ships, planes or land units are
involved.  The fix (commit 70f6964) makes budget simulate all
countries.  Correct, but does much more work than necessary.  With a
little effort, we can track what needs to be simulated.

Use the bp map for tracking.  We need to mark the player's sectors and
all sectors where he has ships, planes or land units.  Do the former
in bp_alloc(), and the latter in prep_ships(), prep_planes(),
prep_lands().

Skip sectors not so marked.  This requires delaying prepare_sects()
until after prep_ships(), prep_planes(), prep_lands().  Their order
doesn't actually matter: prep_ships() & friends only spend money, and
nothing in preparation depends on whether the country is still
solvent.

Skip ships, planes and land units in sectors not so marked.

This speeds up budget by around a third in my testing, more for small
countries.  Roughly 15% slower than before the fix for repairs abroad.
The update has to do a bit more work than before, but the performance
difference is lost in the noise.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:06 +02:00
549561ff03 Include "file.h" where it's needed
Several headers define macros that use ef_ptr() without including
"file.h".  Fix that.  Drop redundant inclusions elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
b49c2f56af sect: Fix insufficiently parenthesized macro expansion
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
5a548c9901 update: Reorder sector production for speed
The update visits sectors in increasing order of country number.
Within a country, it visits in increasing order of sector number,
which is effectively top to bottom, left to right, starting with
absolute 0,0.

The order doesn't actually matter.  Before Chainsaw's option BUDGET,
the update simply visited the sectors in sector number order.  Go back
to that order, because it's faster.  For the update, it's a few
percent in my testing.  For budget, it's more than a third.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
c5df505c98 update: Reorder unit building and maintenance for fairness
The update visits ships, planes and land units in increasing order of
country number.  Within a country, it visits first ships, then planes,
then land units, each in increasing order of unit number.

The order is relevant when money, materials and work don't suffice to
build everything.

Money is charged to the owner, so only the relative order for the same
owner matters there.  One order is as good as any.

Work and materials come from the sector, so only the relative order in
each sector matters.  The current order unfairly prefers countries
with lower country numbers.  Mitigating factor: the affected countries
need to be friendly (ships only) or allied.

The unfairness goes back to Chainsaw's option BUDGET.  See the commit
before previous for more detailed historical notes.

The update test demonstrates the unfair behavior: sector 14,6 builds
ships 95/97 owned by country#1, but not 96 owned by country#7.
Likewise, planes 95/96/97 and land units 95/96/97.

Go back to the the pre-BUDGET order: first ships, then planes, then
land units, all in increasing order of unit number, regardless of
owner.

The update test now builds ship, plane and land unit 96 instead of 97.

Bonus: speeds up both the update and budget by a similar absolute
amount.  For budget, this is roughly a factor of two in my testing.
For the update, which does much more, it's around 10%.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
70f69640e1 budget: Fix for ship, plane, land unit building abroad
The budget command simulates an update by running selected parts of
the update code.  It skips parts that depend on hidden information
such as guerrilla warfare.  For speed, it also skips parts it doesn't
need, such as distribution and foreign sectors, ships, planes and land
units.

Skipping foreign sectors is wrong when any of the player's ships,
planes or land units will be repaired in foreign sectors, because it
makes budget use old materials and work instead of new.

Skipping foreign ships, planes and land units is wrong when they
compete with the player's for materials and work.

The bug goes back to Chainsaw's option BUDGET.  See the previous
commit for more detailed historical notes.  The update test
demonstrates it in several variations.

Fix it with the sledgehammer: don't skip foreign sectors, ships,
planes and land units.  This makes budget almost twenty times slower
in my testing.  Probably tolerable on a reasonably beefy machine, but
we can do better; the next few commits will claw back most of the lost
performance.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
459dec0af0 update: Fix ship, plane, land unit repair work use abroad
Ship, plane and land unit repair uses new work, except in sectors
owned by countries with a higher country number.

This inconsistency is an artifact of how the update is sequenced: we
work on countries one after the other.  A country's ships, planes and
land units get repaired before higher-numbered countries' sectors
produce.  Any ship, plane and land unit repairs in such sectors use
old work instead of new work.

Repair work use changed several times during Empire's history.

In BSD Empire, repairs use old work, because it updates ships and
planes before sectors.

Chainsaw added budget priorities and the budget command as option
BUDGET.  Budget priorities let players choose separately for ships,
planes and land units whether to use old or new work for repairs.

The option also changed the update to work on countries one after the
other, presumably to permit a more efficient implementation of the
budget command.

Chainsaw also introduced repairs in foreign sectors under option
ALLYHARBORWORK.

With BUDGET disabled, all repairs still use old work, whether at home
or abroad.  With BUDGET enabled, work use of repairs at home depends
on budget priorities, but work use abroad depend on country numbers.

Both options became standard in Empire 2.

Since v4.3.6, repairs at home always use new work (commit 967299a and
commit 520446e).

To make repairs abroad always use new work as well, we need to update
all sectors before any ship repair.  This is straightforward: split
the loop over countries between sectors and unit building.  For
symmetry, also split it between unit maintenance and sectors.

The budget command is differently broken, and will be fixed next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
a97ac7a401 update: Treat sanctuaries more consistently
Land unit maintenance and building ignore land units in sanctuary
sectors.  Leftovers from undocumented compile-time option START_UNITS,
which is gone since commit dab1f0b, v4.3.0.  Feeding, paying military
and fallout don't ignore them.  Change maintenance and building to
match.

Sector preparation (except for the fallout part) and production ignore
even non-sanctuary sectors owned by nations in sanctuary.  Fallout,
delivery, distribution and mobility growth don't check the sector
owner's status.  Change preparation and production to ignore just
sanctuary sectors, without checking the sector owner's status.  Except
don't bother for most of fallout, as we already avoid spreading
fallout into sanctuaries; still ignore sanctuaries when doing fallout
damage mostly for completeness.

Delivery and distribution ignore unowned sectors.  Ignore sanctuaries,
too.

Feeding and mobility growth ignore sanctuaries.  Ignore sea, too.

None of this should matter in sane game states.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
e15e7f6bf8 update: Drop dead check for land unit destroyed by starvation
Starving military don't damage their land unit since 4.0.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
c87044dd8b info/Update-sequence: Document when loaded military are paid
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
5df43a5b3f update: Rearrange code to pay non-sector military
Split upd_slmilcosts() into prep_ships() and prep_lands().  Move the
sanity check for dead ships and land units from prod_ships() and
prod_lands() there.  Move their call from prepare_sects() to its
caller, along with pay_reserve().

Create prep_planes() for symmetry.  Pilots are now paid at the same
time as other military.  Can matter only when the country goes broke
during the update.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
7951e91e3f update: Factor out ship and land unit plague plague code
Factor plague_ship() out of upd_ship(), and plague_land() out of
upd_land().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
1dfe91ca96 update: Factor out common plague reporting
No functional change, except the "PLAGUE deaths" message for sectors
loses its period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
391778e09c update: Make ships produce after eating and building
People in sectors first eat, then build the sector, then produce.
People in ships produce, eat, then build.

The starvation command can be off for fishing vessels, because it
doesn't consider the food they produce.

Change ships to match sectors.  "Fixes" starvation.  Fishing boats and
oil derricks being repaired at sea become a bit more productive.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
da14a03231 update: Don't let stopped ships produce
Ships fish and drill for oil even when stopped.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
f5c9e232e8 update: Fix sector maintenance when stopped or broke
No maintenance is paid when the sector is stopped or the owner is
broke.  Broken in commit 44c36fa, v4.3.23.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
ac1a755e33 update: Fix plane maintenance in orbit
No maintenance is paid when a satellite is in orbit.  Broken in 4.2.2.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
55be3c7105 update server: Move update_running from server/ to update/
update.h is a more logical home for update_running than server.h.
Move the definition and the assignments along, from server/update.c to
lib/update/main.c.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
dd9e393b38 subs: Simplify MOB_ACCESS mobility update
The do_upd_checking recursion guard is superfluous: do_mob_sect()
doesn't call anything.  Has been that way since MOB_ACCESS was added
in Empire 3.

Inline the remaining code of sct_do_upd_mob(), shp_do_upd_mob(),
pln_do_upd_mob(), lnd_do_upd_mob() in their only callers
sct_postread(), shp_postread(), pln_postread(), lnd_postread().
Rename do_mob_sect(), do_mob_ship(), do_mob_plane(), do_mob_land() to
mob_sect, mob_ship(), mob_plane(), mob_land() and give them external
linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
25d48124d0 update: Separate MOB_ACCESS from normal mobility update
The update uses mob_sect(), mob_ship(), mob_plane() and mob_land() for
two related, but different jobs: to give the previous turn's remaining
MOB_ACCESS mobility, and to give this update's new mobility.  The two
were probably conflated in an attempt to share code, but it actually
just complicates things.

Collect the MOB_ACCESS code in new function mob_access_all(), and the
normal mobility update code in new function mob_inc_all().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
d861902783 update: Track levels in nat_budget[]
Replace levels[][] by nat_budget[].level[].

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
35d6779e55 update: Clean up share_incr()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
4be4a2c540 update budget produce: Count loaded civilians for TECH_POP
When option TECH_POP is enabled, the cost of tech increases when
civilian population exceeds 50000.  Only civilians in old-owned
sectors count.  This differs from education and happiness, where
civilians loaded on ships and land units count, too.

The update counts population for TECH_POP with count_pop().  This is
an extra pass over all sectors.

produce also uses count_pop(), once per tech center examined.
Wasteful.

budget avoids count_pop(): it uses tax()'s civilian count.  More
efficient, but the difference to the update is ugly.

Change TECH_POP to use the same civilian count as education and
happiness, i.e. count civilians on ships and land units, too.

This count is available in nat_budget[] in time for produce(): it's
computed by tax() and by ship and land unit maintenance.  So use it
there.  This takes care of the update and budget.  produce doesn't run
enough update code to do the same.  Keep calling count_pop() there.
Update it to match the update, and give it internal linkage.
Duplicating update's workings there is ugly, so mark it FIXME.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
14f3bd9717 update budget: Fix civ counting for happiness and education
Per-civilian happiness and education production is raw production
divided by the number of old-owned civilians.  The update reports the
number of old-owned civilians ("total pop was %d").

This number of civilians is also used by budget to predict cost of
tech when option TECH_POP is enabled, but that doesn't match how the
update computes the cost.  To be fixed next.

Civilians loaded on ships are only counted by the update, not by
budget.  Harmless, as budget doesn't compute happiness and education.
Civilians loaded on land units are ignored by both.  None of the stock
game's land units can load civilians.

Civilians in sectors are counted before plague deaths, and in ships
afterwards.

Fix upd_ship() and upd_land() to count civilians the same way as
prepare_sects() does for sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:30 +02:00
6eb4fd3cbf update: Track oldowned civilians in nat_budget[]
Replace pops[] by nat_budget[].oldowned_civs.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:29 +02:00
4a714a37da production: Use update code instead of duplicating it
prod() duplicates the update's sector production code, except it
computes both output with present materials ("make" output) and output
not limited by lack of materials or production backlog ("max" output).
It also rounds materials consumed up instead of randomly.

Factor prod_output() out of produce() for reuse by prod().  prod()
runs it twice: once for "make" output and once for "max" output.

Test output changes are due to random rounding.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:29 +02:00
6013758272 update production: Make sector production a bit more predictable
Sector production computes a number of intermediate values, and rounds
many of them.  We've tinkered with the rounding a few times.  It
currently works as follows.

There are two production efficiencies, both shown by the production
command: sector p.e. (column eff) governs how efficiently work is
converted to units of production, and p.e. (column p.e.)  governs how
much product each unit of production yields.

Production is limited by available work, materials and resource
contents.  These limits are all rounded down.

Example: if a unit takes 16 work (tech or guns), then 600 work at 100%
sector p.e. can make at most 37 units, rounded down from 600 * 100% /
16 = 37.5.  76 work at 76% sector p.e. can make 3, rounded down from
76 * 76% / 16 = 3.61.

Output is units times p.e.  Level output isn't rounded.  Item output
is rounded down.

Example: a tech center making 37 units at p.e. 0.6 (edu=20) yields 37
* 0.6 = 22.2 tech (before tech log).  3 units yield 1.8 tech.

Example: a defense plant making 37 units at p.e. 0.6 (tech 35) yields
22 guns (rounded down from 22.2).  3 units yield 1.8g, randomly
rounded.

If item output needs to be adjusted downward (production backlog), the
number of units made is likewise adjusted.  It is rounded randomly.

Example: a 100% refinery with 156 work can make 156 units.  Its
p.e. at tech 30 is 5.0, so this yields 780p.  But if it already has
9500p, it can make only 499 more.  That's 99.8 units, rounded randomly
to either 99 or 100.

Materials and money consumed are a multiple of units made.  No
rounding there.

Resource depletion depends on units made and is rounded randomly.

Work consumed is units made times work per unit divided by sector
production efficiency.  Rounded randomly.  Any work left can normally
be used at the next update (it "rolls over").

Example: the tech center making 37 units consumes 37 * 16 / 100% = 592
work, with 8 work left.  It also consumes 37d 185o 370l $11100.

Example: the tech center making 3 units consumes 3 * 16 / 76% = 63.2
work, randomly rounded to 63 or 64, with 13 or 12 work left.  It also
consumes 3d 15o 30l $900.

Example: the defense plant making 3 units consumes work the same.  It
additionally consumes 1o 15l 30h $30 when it makes one gun, and twice
as much when it makes two.

Rounding intermediate values like "units of production" is awkward.
It's better to round only final results.  These are item output,
materials consumed, resource depletion and work consumed.  Round item
output down, and the rest randomly.  Don't round level output (it's a
floating-point value) and money consumed (also floating-point, since
the previous commit).

For item production, this shifts the random variations from number of
products made to materials and work consumed.

Example: the first defense plant again makes 22 guns (now rounded down
from 22.5).  The second one now always makes two guns (rounded down
from 3.61 * 0.6 = 2.166) instead of 1.8 randomly rounded.

This is nice, because budget and production can now predict the number
of items made exactly.  Before, budget fluctuated randomly just like
the update, and production rounded down.

Note that budget used to be even worse: until commit 6f7c93c
(v4.3.31), we rounded units of production randomly rather than down.
The 100% tech center randomly made 37 or 38 units, which is much more
relevant than random rounding of item output.

Furthermore, work is now fully used both for item and level
production, to the limit permitted by materials and resource contents.

Example: the first tech center now makes 37.5 units, yielding 37.5 *
0.6 = 22.5 tech.  It consumes 37.5d 187.5o 375l $11250 and all 600
work (fractions randomly rounded).

Example: the second tech center now makes 3.61 units yielding 1.805
tech, consuming 3.61d 18.05o 36.1l $1083 and all 76 work.

The production command duplicates much of the update's sector
production code, so it needs a matching update.  The next commit will
reduce the duplication.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:29 +02:00
25a6cf92b2 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>
2017-08-06 20:07:55 +02:00
10789a0365 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>
2017-08-06 20:00:00 +02:00
058268595f update: Push budget update into produce(), enlist()
produce() and enlist store the cost through a parameter and return the
amount.  Their caller produce_sect() then updates nat_budget[]
accordingly.  Move the nat_budget[] update into the callees.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
a5314a59c4 update: Get army, navy, air force delta from nat_budget[]
lnd_money[], sea_money[] and air_money[] have become redundant.
Eliminate them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
f27dd4e227 budget: Track bank interest in nat_budget[]
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
c12d1e137f budget: Track taxes in nat_budget[]
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
cfdf52740b budget: Use a loop to show build and maintenance
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
2eb08f40c7 budget: Track ship, plane, land unit expenses in nat_budget[]
Extend struct budget member bm[] to cover ships, planes and land
units, too.

Plane maintenance changes because pilot pay is now consistently
rounded down.  Before it was rounded down for broke countries, else
up.  The stock game's pilots earn a little less than $25, and solvent
countries save $1 per plane.  The rounding doesn't make much sense
either way.  To be be addressed in a later commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00
16f9a393c4 budget: Track sector expenses in nat_budget[]
The update summarizes sector production, building and maintenance for
budget in a two-dimensional array int p_sect[SCT_BUDG_MAX+1][2].  All
references into this array use literals as second subscript.  Bzzzt,
wrong data type.

Add two one-dimensional arrays to nat_budget[], one for production,
and one for building and maintenance.  p_sect[i] becomes
nat_budget[cnum].prod[i] for production, and .bm[j] for building and
maintenance.  p_sect[i][0] becomes .count, and -p_sect[i][1] becomes
.money.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:00:00 +02:00