Commit graph

93 commits

Author SHA1 Message Date
c5a2d136ec Correct spelling as one word and as two words
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
2bcd875715 Spell BTU and ETU consistently
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
e6ce36df64 Spelling corrections
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
92693cba65 relations: Move relations state from struct natstr to relatstr
Relations state is relatively bulky: it's a big chunk of struct
natstr, and adds 200 bytes per country to xdump nat.

Relations change rarely.  Rewriting it to disk on every nation update
and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move relations state to its own struct relatstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:22 +02:00
de24545963 relations: Create EF_RELAT table of struct relatstr
New struct relatstr is basically empty so far.  The next commit will
move relations state from struct natstr to struct relatstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
eaa678c903 reject: Move reject state from struct natstr to rejectstr
Reject state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat.

Reject state changes rarely.  Rewriting it to disk on every nation
update and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move reject state to its own struct rejectstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f35f16c0a2 reject: Create EF_REJECT table of struct rejectstr
New struct rejectstr is basically empty so far.  The next commit will
move reject state from struct natstr to struct rejectstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
c8e7548f24 contact: Move contact state from struct natstr to contactstr
Contact state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat for deities.

Contact changes rarely.  Since we avoid unnecessary updates, it
doesn't change at all unless option HIDDEN is enabled.  Rewriting it
to disk on every nation update and retransmitting it in every deity
xdump nat is wasteful.

To avoid this waste, move contact state to its own struct contactstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
4b4df53485 contact: Create EF_CONTACT table of struct contactstr
New struct contactstr is basically empty so far.  The next commit will
move contact state from struct natstr to struct contactstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
cf4e9bc89d contact: Initialize contact state properly
A country must always be in contact of itself when option HIDDEN is
enabled.  The code ensures this by establishing contact whenever a
player logs in, in init_nats().  This is not the proper place.  Game
state should be initialized in empfile's oninit() callback, in this
case nat_oninit().  Do that, and drop the putcontact() from
init_nats().

Note that option LOSE_CONTACT only affects contact to other countries:
agecontact() doesn't age the country's contact to itself.

Use the opportunity to initialize contact so that getcontact() works
even when HIDDEN is disabled.  Just cleanup, it isn't actually called
then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
a89e6e73b0 tests/smoke: Omit redundant data from fairland.xdump
Belatedly update fairland.xdump for commit f4f0482, v4.3.33.

The commit made empdump omit redundant data, shortening the
final.xdump.  The matching manual update to fairland.xdump was
forgotten.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
2402f3f2a2 lost: Fix to track more than one lost sector per owner
makelost() overwrites an existing entry for the same thing, else
creates a new one.  It calls findlost() to find existing entries.
findlost() means to look up by coordinates if it's looking for a
sector entry, and by ID if it's looking for a ship, plane, land unit
or nuke entry.  It actually does both for sectors.  Since callers pass
zero ID for sectors, sector entries always match, so at most one gets
created, and additional ones overwrite it.

Broken since the lost table was introduced in 4.0.7.  Fix the flawed
comparison in findlost().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:18 +02:00
729eaa7934 tests/smoke: Run news
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
7b5bd13767 nsc: Drop deprecated nat and country selector hostname
Deprecated since commit 199388b, v4.3.33.

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
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
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
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
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
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
6fcbc16adf update: Limit avail roll over to about half the update's work
Traditionally, unused unused available work is discarded at the
update.  Since commit d7a054c (v4.2.13), deities can configure (some)
unused work to "roll over", i.e. available work = some unused work +
this update's work.

Not discarding unused work reduces micromanagement incentives.
However, it also leads to unobvious behavior.

For instance, here's the obvious way to build a radar station: move in
enough people to make 200 work.  Half of it is available for sector
building, and increases efficiency to 100%.  Here's a not-so-obvious
way: move in enough people to make 134 work.  67 will be used to
increase efficiency to 67%.  Now move your workers elsewhere.  The
unused available work is enough to finish the job at the next update.

Similarly, neighbors could be surprised by sectors building bridges
despite having no visible workers.

Commit 7f4e59f (v4.2.15) let deities limit the amount rolled over:
unused work above rollover_avail_max is discarded.  This became the
default with a value of 50 in commit 81a3e4c4, v4.3.31.

Limit it further so that "roll over" can increase the update's work by
no more than half, plus one.  The extra point is there so that even a
tiny work force has a chance to eventually eke out the second point of
work needed to increase efficiency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:59 +02:00
d3c1da354d update: Round the people's work randomly rather than down
Rounding work down can lead to a bit of work micromanagement.  For
instance, four military on a lonely island accomplish nothing in 60
ETU updates, but five will make one point of work per update.  They
can build a 2% harbor in four updates, as long as rollover_avail_max
is at least 3.  Six to eight will be no faster.

The people's work used to be rounded randomly until Empire 3's big
effort to make the update code work for budget switched to rounding it
down, perhaps accidentally.

Switch back to rounding randomly, so that players don't have to get it
exactly right.  Four military now get to 2% in five updates on
average, five in four, six or seven in three, and so forth.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:59 +02:00
8b1cc6cb47 update: Saner rounding of sector building money and work
buildeff() rounds work and money up.  Until recently, fractions could
only occur on tear-down, but with customized costs they can now also
occur on build-up.

The previous commit changed unit building to round money and work
randomly.  Before, money was rounded down, and work was rounded up.

Round them randomly for sectors as well, for consistency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:58 +02:00
ae2ae938b5 update: Saner rounding of unit building money and work
shiprepair() limits the efficiency gain to how much the workers can
build, rounding randomly.  It charges work, money and materials for
the efficiency actually gained, rounding work up, money down, and
materials randomly.  Same for planerepair() and landrepair().  Has
always been that way.

If you get lucky with the random rounding, you may get a bit of extra
work done for free.

The budget command runs the update code, and can be off by one due to
different random rounding.

Sector production used to have the same issue, only more serious,
because a single unit of tech production matters much more for the
budget than a single point of unit efficiency gain.  I fixed it in
commit 6f7c93c, v4.3.31.

Fix it for unit building the same way: limit efficiency gain to the
amount the workers can produce (no rounding).  Work becomes a hard
limit, not subject to random fluctuations.  Randomly round work and
money charged for actual gain, like we do for materials.  On average,
this charges exactly the work and money that's used.

This lets budget predict how much gets built a bit more accurately.
It's still not exact, as the amount of work available for building
remains slightly random, and the build cost is randomly rounded.

The old rounding of work for ships carries the comment "I didn't use
roundavg here, because I want to penalize the player with a large
number of ships."  Likewise for planes.  Rounding work up rather than
randomly increases the work cost by 0.5 per ship, plane or land unit
on average.  I could keep the penalty by adding 0.5 before random
rounding.  Not worth it, since the effect is actually pretty trivial.
Let's examine a fairly extreme case: an airfield with 600 available
work repairing a huge number of lightly damaged planes, say f2 with
81% average efficiency.  The old code lets the airfield repair roughly
600 / 6.5 = ~92 planes, the new code 600 / 6 = 100.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:58 +02:00
cb32c60294 power: Include sector maximum population in power factor
Replace the term

    power value of materials and cost + 9

by

    power value of materials and cost + maximum population / 1000 * 8 + 1

The value of ordinary sectors (maximum population 1000) doesn't
change.  The stock game's mountains, plains and bridges are now worth
only 28% as much.

This concludes my tweaking of the power factor for now.  I tested it
with data from a real game (Hvy Metal II).  The effect is small: #5
overtakes #4, and the lead of #1 over #2 and #3 shrinks some.  Closer
analysis finds the following reasons.  The game had very expensive big
cities.  Valuing them correctly gives countries with many cities a
noticeable boost.  Planes are worth less than before, but the
difference is much larger for cheap planes.  Big piles of construction
materials are worth much less, and shells, guns and bars are worth
more.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:58 +02:00
e8451c7343 power: Include sector materials and cost in power factor
Building sectors can make you rate *lower* on the power chart, because
the power factor treats all sectors the same, regardless of build
materials and cost.

To avoid that, replace the term

   efficiency / 10.0

by

   (power value of materials + power value of cost + 9)
   * efficiency/100.0

The value of ordinary sectors, which take no materials and cost $100,
doesn't change.  The stock game's fortress is now worth 80% more due
to its materials and higher cost.  The stock game's wilderness is
worth 10% less, because it costs nothing.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:58 +02:00
41d0a79118 update: Fix revert to deity and "no civilians" corner cases
We maintain a few sector invariants in sct_prewrite().  Since the
update bypasses sct_prewrite(), it needs to maintain them itself.  The
two should be consistent.

The update reverts deserted sectors to deity in three places:
do_plague(), populace() and produce_sect().  None of them is
consistent with sct_prewrite().

populace() can revert unowned sectors to deity.  This creates bogus
entries in the "lost" file.  Harmless; messed up when the lost items
were added in 4.0.7.  Visible in tests/smoke/final.xdump.

populace() fails to revert when there are only uw left.  If PLAGUE is
enabled, do_plague() already reverted.  Else, produce_sect() will.
This is the only case where they add value to populace().  Can be
traced back all the way to BSD Empire 1.1.

All three neglect to clear mobility.  Harmless.

Fix populace()'s condition for reverting to deity, and make it clear
mobility.  Drop the reverting from do_plague() and produce_sect().

populace() also resets state that applies to civilians when there are
none: work percentage, loyalty and old owner.  However, it resets on
different conditions than sct_prewrite().  Messed up in Chainsaw;
before, populace() didn't reset at all.

For sectors without military, populace() fails to reset.  This can
happen when the update wipes out civilians and military, say by plague
or fallout.  The now bogus work percentage, loyalty and old owner
persist until sct_prewrite() runs on the next non-update sector
update.  Except old owner is reset correctly by populace() when the
sector reverts to deity.  It doesn't when the owner has a land unit
there.

Most of the time, this doesn't matter, as moving civilians into a
sector without civilians overwrites the sector's work percentage,
loyalty and old owner.  However, airlifting and unloading civilians
fail when the old owner differs from the owner.  Else they adopt the
sector's loyalty and work percentage (bug#49 and bug#255).

Fix populace() to reset any sector without civilians, like
sct_prewrite().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:57 +02:00
0bdcb5ee19 sect: Keep work percentage without civilians at 100%
We maintain a few sector invariants in sct_prewrite().  Since the
update bypasses sct_prewrite(), it needs to maintain them itself.  The
two should be consistent.

sct_prewrite() resets work percentage of owned sectors to 100% when
there are no civilians.  The update's populace() resets it for unowned
sectors as well, if they have military.

Change sct_prewrite() to reset sct_work = 100 regardless of owner.
Also change sct_oninit() to initialize sct_work = 100, so it doesn't
change on first write.  Update tests/smoke/fairland.xdump for the same
reason.

The massive test output differences are all due to sct_work.

Inconsistencies with the update remain.  They will be fixed next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:57 +02:00
60450f1637 update: Fix work inconsistency with neweff, production
In Empire, even babies work.

neweff and production compute the projected population's work,
discarding fractions.

The update first computes the adults' work (discarding fractions),
then newborns' work (discarding fractions), then adds them together.
Double rounding.  Moreover, it uses the old work percentage for the
adults' work, and the new one for the newborns' work.  Broken in
Empire 3.

Fix by recomputing work after grow_people().  This is how things
worked before the regression.  Also restores a bug: growfood()'s work
use is ignored.  Harmless, because fcrate and fgrate are too low for
growfood() to produce anything, and nobody customizes them.  Mark
FIXME anyway.

Update test output changes as expected: available work differs in
sectors where double rounding discards work, an in sectors with
changing work percentage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +02:00
876d061875 tests: Make update robust against variations in PRNG use
Tests need repeatable pseudo-random numbers to yield repeatable
results.  Commit 73f1ac8 (v4.3.33) reseeds the PRNG with the count of
commands right before executing a command when running_test_suite is
on.  This doesn't help the update: whenever update code exercised by a
test is changed to consume fewer or more PRNs, all subsequent users
get different numbers regardless.  The ensuing test result changes are
extremely tedious to review.

To address this problem, reseed the PRNG in the update's two most
important loops with the iteration count when running_test_suite.
This way, the effect of perturbing the PRN sequence lasts only until
the next iteration.

There are many more loops, but reseeding in all of them seems
impractical.

Perturbs test results across the board.  Hopefully, that'll happen
less frequently now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +02:00
3145e7d8a7 transport: Don't hardcode material weights
tran_plane() computes a plane's weight from its materials.  It
hardcodes lcm weight 1, hcm weight 2, and military weight 0.  Use
ichr[].i_lbs instead, which is 1 in the stock game for all three
materials.

While there, support arbitrary materials, even though they aren't yet
possible, just to avoid unnecessary assumptions on possible build
materials.

Since the stock game's planes use fewer military than hcms, they
become up to 15% lighter, except for zep, which becomes 10% heavier.
Missiles use no military and become 20-33% lighter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +02:00
ea5c8a6598 power: Saner power for items, ships, planes and land units
Items, ships, planes and land units all contribute to the power
factor, which determines position on the power chart.

Items are worth

    amount * item value * (0.5 + nation tech level / 1000.0)

The item values aren't quite right: producing stuff can *hurt* your
position on the power chart.  Food, uw and rads are worth nothng.

Reduce the value of oil, and give rads the same value as oil.  Tweak
value of iron and oil products so that production's power change is
roughly zero around p.e. 0.9 (tech 110), except for construction
materials, where it's zero at p.e. 0.5 (tech 0).  Construction
materials become less valuable, shells, guns and petrol become more
valuable.  Increase value of bars to roughly match the other changes.
It may still be too low.  Halve the value of civilians, and give the
other half to uw.  Results:

            old     new     change
    civ      100     50   / 2
    mil      100    100
    shell     80    125   * 1.5625
    gun      400    950   * 2.375
    pet        2      7   * 3.5
    iron      10     10
    dust     200    200
    bar     1000   2500   * 2.5
    food       0      0
    oil      100     50   / 2
    lcm      100     20   / 5
    hcm      200     40   / 5
    uw         0     50   new
    rad        0     50   new

Ships, planes and land units are worth

    base value * effic/100.0 * (0.5 + unit tech level / 1000.0)

For ships and land units, the base value is

    lcm/5.0 + hcm/5.0

Build cost is ignored, but lcms are valued twice as much "loose" ones
(before this commit).  Therefore, building stuff can change your
position on the power chart in both directions, depending on the type
of build.

For planes, the base value is

    20 * (0.5 + nation tech level / 1000.0)

Build cost and materials are ignored, and tech is squared.  This
is plainly absurd.

Unify to

    (power value of money and materials to build) * effic/100.0

This formula is chosen so that building stuff doesn't change your
power factor.  Bonus: it doesn't assume anything about possible build
materials.

For ships and land units, factoring in build cost overcompensates the
discounted value of construction materials more often than not.

Noteworthy changes for the stock game:

    ship type          old     new    change
    ss   slave ship     20     5.8    * 0.29    largest decrease
    cs   cargo ship     20     7.8    * 0.39
    ts   trade ship     60    25.5    * 0.42
    frg  frigate        12     7.8    * 0.65
    bb   battleship     24    21.8    * 0.91
    cal  light carrier  22    30.4    * 1.38
    can  nuc carrier    30    84.6    * 2.82    largest increase

    land unit type     old     new    change
    hat  hvy artillery  12     9.6    * 0.8     largest decrease
    linf light infantry  2.4   3.32   * 1.38
    cav  cavalry         3     5.4    * 1.8
    inf  infantry        3     5.4    * 1.8
    lar  lt armor        3     6.4    * 2.13
    com  commando        3    15.4    * 5.13
    eng  engineer        3    30.4    * 10.13
    meng mech engineer   3    45.4    * 15.13   largest increase

For planes, the power value change depends on the type.  Below a
certain nation tech level, planes of this type become more valuable,
above less.

For the stock game, planes costing at most $1000 become less valuable
at any nation tech level that can build them, and planes costing at
least $1800 become more valuable at any practical tech level,
i.e. under 400.  Noteworthy planes:

    plane type                 new
    sam  Sea Sparrow           2.1              least valuable
    f2   P-51 Mustang          4.34
    lb   TBD-1 Devastator      5.92
    jf1  F-4 Phantom          10.6
    tr   C-56 Lodestar        10.78
    jt   C-141 Starlifter     15.86
    jhb  B-52 Strato-Fortress 33.54
    ss   KH-7 spysat          41.2              most valuable

The old value is a flat 12 at nation tech level 100, 15 at tech level
250, and 18 at tech level 400.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:55 +02:00
5917841bfc power: Use ship, plane, land unit tech instead of nation's
Actual abilities of ships, planes and land units depend almost
completely on the individual unit's tech, not the nation's tech.  The
power factor should reflect that.

The power value of a unit is of the form

    base value * (20 + nation's tech level) / 500

Change it to

    base value * (20 + unit's tech level) / 500

Note that a plane's base value still depends on the nation's tech
level.  This commit merely makes the absurdity stand out a bit more.
To be fixed later.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:05:31 +02:00
d48851c0ac power: Saner power value for tech, particularly at low tech
In the old times, power didn't consider tech at all.  Chainsaw's
option NEWPOWER (mandatory since v4.2.14, on by default before)
changed this dramatically: the power factor gets multiplied by
max(1, tech) / 500.

In the early game, small absolute tech differences yield large power
factor differences.  For instance, if country A has tech level 10, and
B has 5, then A gets a factor two boost.

As the game progresses, tech differences between viable countries tend
to grow, but only slowly.  The influence on power diminishes.  For
instance, if C has tech level 270 and D has 240 (quite a respectable
tech lead), then C gets a modest 1.125x boost over D.

Change the factor to (20 + tech) / 500.  Now A's advantage is only
1.2, and C's is 1.115.

You might think that's rather low.  However, tech is not power unless
you project it, and then it manifests itself as sectors, population
and other stuff power counts.

The same tech term occurs in plane power, except with just tech
instead of max(1, tech) .  Change it there as well, for consistency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:05:30 +02:00
9309670544 tests/version: New; exercises config introspection commands
Exercise version, show and xdump, except for xdump of game state.

The xdump part is mostly factored out of tests/smoke.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:03:55 +02:00
87d08a4584 Bump version to 4.3.34
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-06-04 10:52:11 +02:00
deabb8eda6 Belatedly bump version to 4.3.33
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 21:16:27 +01:00
7be7ad98aa assault attack paradrop: Fix inconsistent support formatting
With offensive support but no defensive support, there's no empty line
separating the support table from the text that follows.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
d5d92caf94 retreat lretreat edit xdump: Change "torped" to "torpedoed"
"torped" comes from symbol table retreat_flags.  Visible in output of
edit, retreat, lretreat and xdump.  Tolerable in edit, but player
commands like retreat should really use proper words.

Fixing it in retreat_flags changes xdump output, thus risks breaking
clients.  Do it anyway, since no known client recognizes this
particular symbol value.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
24000b4855 navigate march: Fix use-after-free and other bugs
unit_move() is too big and has too many paths through its loop.
Maintenance of the (unspoken) loop invariant isn't obvious.  In fact,
it isn't maintained on some paths.  I found several bugs:

* We check prerequisite conditions for moving before the first move
  and around prompts.  When a condition becomes wrong on the move,
  movement continues all the same until the next prompt.  I believe
  the only way this can happen is loss of crew due to hitting a mine.

* We cache ships and land units in a list of struct ulist.  When a
  ship or land unit gets left behind, its node is removed from the
  list and freed.

  We keep pointer flg pointing to the flagship in that list for
  convenience.  However, the pointer isn't updated until the next
  prompt.  It's referenced for automatic radar and all sub-commands
  other than the six directions and 'h'.  Use after free when such a
  sub-command gets processed after a flagship change without a prompt.
  Same for land units.  For instance, navigating a pair of ships "jh"
  where the flagship has no mobility leaves the flagship behind, then
  attempts to radar automatically using the ship in the freed list
  node.  Likewise, marching a similar pair of land units "jl" examines
  the land unit in the freed list node to figure out how to look.

* We cache mobility in the same list to support fractional mobility
  during movement.  Movement deducts from cached mobility and writes
  the result back to the ship or land unit.

  If something else charges it mobility while it's in this list, the
  cache becomes stale.  shp_nav() and lnd_nav() reload stale caches,
  but don't run often enough.  For instance, when a ship hits mines,
  the mine damage makes the cache stale.  If a direction or 'h'
  follows directly, the stale mobility is written back, clobbering the
  mine hit's mobility loss.

This mess dates back to Empire 2, where it replaced a different mess.
There may be more bugs.

unit_move()'s complex control flow makes reasoning about its loop
invariant too error-prone.  Rewrite the mess instead, splitting off
sensible subroutines.

Also fixes a couple of minor annoyances:

* White-space can confuse the parser.  For instance, "jg l" is
  interpreted like "jgll".  Fix to reject the space.  Broken in commit
  0c12d83, v4.3.7.

* The flagship uses radar automatically before any sub-command (since
  Chainsaw), and all ships use it automatically after a move (since
  4.2.2).  Make them all use it before and after each sub-command,
  whether it's a move or not.

* Land units don't use radar automatically.  Make them use it just
  like ships.

* Always report a flagship / leader change right when it happens, not
  only before and after a prompt.

Left for another day, marked FIXME: BTU charging is unclean.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:47 +01:00
dc73207a99 sail: Remove option SAIL
SAIL has issues:

* Sail orders are executed at the update.  Crafty players can use them
  to get around the update window.

* The route is fixed at command time.  You can't let the update find
  the best route, like it does for distribution.

* The info pages documenting it amount to almost 100 non-blank lines
  formatted.  They claim you can follow friendly ships.  This is
  wrong.  They also show incorrect follow syntax.  Unlikely to be the
  only errors.

* Few players use it.  Makes it a nice hidey-hole for bugs.  Here are
  two nice ones:

  - If follow's second argument is negative, the code attempts to
    follow an uninitialized ship.  Could well be a remote hole.

  - If ship #1 follows #2 follows #3 follows #2, the update goes into
    an infinite loop.

* It's more than 500 lines of rather crufty code nobody wants to
  touch.  Thanks to a big effort in Empire 2, it shares some code with
  the navigation command.  It still duplicates other navigation code.
  The sharing complicates fixing the bugs demonstrated by
  navi-march-test.

Reviewing, fixing and testing this mess isn't worth the opportunity
cost.  Remove it instead.  Drop commands follow, mquota, sail and
unsail.  Drop ship selectors mquota, path, follow.

struct shpstr shrinks some more, on my system from 160 to 120 bytes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:11:28 +01:00
48e656c057 autonav: Remove the feature
The autonavigation feature has issues:

* Autonavigation orders are executed at the update.  Crafty players
  can use them to get around the update window.

* Usability is poor:

  - The order command is overly complex, not least because it can do
    five different things: clear, suspend, resume, declare route, set
    cargo levels.

  - Unlike every other command involving movement, order does not let
    you specify routes, only destination sectors.

  - Setting cargo levels can silently swap start and end point of a
    circular route, because "this keeps the load_it() procedure
    happy".  Maybe it does, but it surely keeps players confused.

  - Setting "start" cargo levels actually sets the "end" levels, and
    vice versa.  Has always been broken that way.

  - Predicting what exactly autonavigation will do at the update isn't
    easy.

* The info pages documenting it amount to almost 400 non-blank lines
  formatted.  They claim only merchant ships can be given orders.
  This is wrong.  Unlikely to be the only error.

* Few players use it, and its workings at the update a fairly opaque.
  Makes it a nice hidey-hole for bugs.  Here are two:

  - Unlike the scuttle command, autonavigation happily scuttles trade
    ships while they're on the trading block.

  - Unlike the load command, autonavigation can load in friendly and
    allied sectors.

* It's more than 700 lines of rather crufty code nobody wants to
  touch.  Thanks to a big effort in Empire 2, it shares code with the
  navigation command.  It still duplicates load code.  The sharing
  complicates fixing the bugs demonstrated by navi-march-test.

Reviewing, fixing and testing this mess isn't worth the opportunity
cost.  Remove it instead.  Drop commands order, qorder and sorder.
Drop ship selectors xstart, xend, ystart, yend, cargostart, cargoend,
amtstart, amtend, autonav.

xdump ship sheds almost half its columns.  struct shpstr shrinks, on
my system from 200 to 160 bytes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:10:22 +01:00
a4e519c377 navigate: Fix buffer overrun for impossibly long paths taken
When a player moves more than 1023 sectors in a single navigate
command, we overrun the buffer holding the path taken.  Remote hole,
but it requires a ship that can go that far, and even a ship with
speed 1000 would need a tech level well in excess of 1000 for that.
Thus, the hole is purely theoretical for even remotely sane game
configurations.

First known version with the flaw is 4.0.0.

Fix by going back the older behavior: don't print the total path
taken, but do print what the path finder does.  Context diff of an
example:

     [0:634] Command : nav 3 6,0
     Flagship is od   oil derrick (#3)
    +Using path 'n'
      h =
     k . .
      j d
     <67.2:67.2: 6,0> h
     od   oil derrick (#3) stopped at 6,0
    -Path taken: n

This is how march works.

Removes the only use of shp_nav_one_sector()'s unusual return value 2.
Return 1 instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:01 +01:00
f4f048234c empdump: Omit redundant data from export, new -c includes it
Cuts size of export files in test suite by a factor of four.  Not a
big deal for disk usage, as export files compress very well, and disk
space is cheap anyway.  Export files are simply easier to work with
when they aren't full of redundant crap.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +01:00
41f00fdd33 nsc: Turn NSC_HIDDEN into a flag
More general, and fewer places need to know about it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:59 +01:00
199388b084 nat: Deprecate selector hostname, fix value to ""
Its value has always been "", unless the deity recompiled with
RESOLVE_IPADDRESS defined, or imported another value with empdump.

I'm going to drop the RESOLVE_IPADDRESS code, including struct natstr
member nat_hostname.  To prepare for that, fix the selector's value to
"", so it doesn't need nat_hostname, and deprecate it.

This changes its "len" in xdump meta nat from 512 to 0.  Unlikely to
upset clients.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
eeb62ab280 build scrap: Redo 4.2.3's fix for manufacturing military
scrap has always returned the scrapped planes' full crew, regardless
of efficiency.  build, however, charged only 10%.  If you built ten
planes with one crew each, you used up one military.  Or none, if you
abused random rounding.  If you scrapped them again, you got ten back.
Pretty pricey way to manufacture military, but wrong all the same.

4.2.3 plugged this hole by making build never round military to zero.
Ugly special case, and not documented.  Also doesn't prevent abuse of
random rounding for planes requiring more than 10 crew, but such
planes don't exist in the stock game.

Redo this fix:

1. Make scrap return crew proportional to efficiency, randomly
rounded.  Note that scrap returns only two thirds of the other
materials, rounded down.  Recycling materials isn't perfect, but
recycling aircrew is.

2. Drop the special case from build: treat military just like other
materials.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:48:34 +01:00
1227d2c931 build: Stop abuse of construction material random rounding
Construction materials required for building a ship, plane or land
unit are rounded randomly.  Crafty players exploit this to save
materials: they put just enough materials there so that build succeeds
when it rounds down.  Then they simply keep trying until it succeeds.

Planes and land units are built at 10%, so rounding happens when
materials for 100% aren't multiples of ten.  If they're below ten, you
can even build without materials.  In the stock game, this is the case
for linf, and many plane types.

Ships are built at 20%, so multiples of five aren't rounded.  Ship
building never rounds in the stock game.

Prevent the abuse of random rounding by requiring the required
fractional amount rounded up to be present.  Don't change the actual
charging of materials; that's still randomly rounded.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:43 +01:00