]> git.pond.sub.org Git - empserver/log
empserver
6 years agoupdate: Use a scratch sctstr for unit repair simulation
Markus Armbruster [Sun, 5 Jun 2016 14:03:39 +0000 (16:03 +0200)]
update: Use a scratch sctstr for unit repair simulation

If player->simulation, shiprepair(), planerepair(), landrepair() must
use the bp map, and must not change game state.

Copy the sector to a scratch buffer, update it from the bp map, work
on the sector normally, then write back to the bp map.  This is
simpler and safer.

Since get_materials() loses its connection to the bp map, move its
declaration out of budg.h.

While there, drop an ancient debugging logerror() from landrepair().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Don't use materials and work destroyed by che or plague
Markus Armbruster [Sun, 5 Jun 2016 13:35:57 +0000 (15:35 +0200)]
update: Don't use materials and work destroyed by che or plague

Update code shared with budget uses the bp map instead of the sector,
so that budget can track materials and work available in sectors for
ship, plane and land unit building without updating the sector file.
Unfortunately, the bp map can become stale during the update.

prepare_sects() doesn't update the bp map for sea sectors, unlike
budget's calc_all().  Instead, we rely on calloc()'s initialization.
Works, but is a bit unclean.

prepare_sects() updates the bp map after fallout, but neglects to
update it for any of the later sector updates (steps 1b to 1f in info
Update-sequence).  Che can destroy materials and available work, and
the plague can kill military.  The bp map stays out of date until
produce_sect() updates it again.

Since we deal with sector production and countries in increasing order
of country number, foreign ships, planes and land units owned by
countries with lesser numbers get built before their sector produces.
Building uses the stale bp map then, and can use materials and
available work destroyed by che or the plague.  The update test
demonstrates the former case.

For stopped sectors or when the owner is broke, produce_sect() updates
only materials in the bp map, not available work.  Nothing builds in a
stopped sector, but allies may build in your sectors even when you're
broke.  They can use available work destroyed by che then.

Screwed up when Empire 3 made the update code work for budget.

Note that budget bypasses the flawed code: it prepares its bp map
itself instead of calling prepare_sects().

Rather than fixing prepare_sects(), use a null bp map for the update:
writes become no-ops, and reads read from the underlying sector.  Not
only does this remove the possibility of the bp map going stale during
the update, it saves a bit of memory, too.

calloc()'s initialization is now dead.  Switch to malloc().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate/bp: bp_ref() is trivial, inline it
Markus Armbruster [Sun, 5 Jun 2016 13:19:01 +0000 (15:19 +0200)]
update/bp: bp_ref() is trivial, inline it

Trivial since commit a0fa455, v4.3.12.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate/ship: Don't let stopped sectors repair foreign ships
Markus Armbruster [Sun, 5 Jun 2016 13:13:11 +0000 (15:13 +0200)]
update/ship: Don't let stopped sectors repair foreign ships

Stopping a sector disables repairs of own ships completely.  Foreign
ships, however, repair just fine, consuming the sector's materials
and, if it's a harbor, its available work.

Disable repair of all ships in stopped sectors.  This is consistent
with plane and land unit repair.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Reorder ship, plane, land repair code for consistency
Markus Armbruster [Sun, 5 Jun 2016 13:00:42 +0000 (15:00 +0200)]
update: Reorder ship, plane, land repair code for consistency

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Fix unowned uw to eat, procreate and produce
Markus Armbruster [Sun, 5 Jun 2016 12:37:41 +0000 (14:37 +0200)]
update: Fix unowned uw to eat, procreate and produce

produce_sect() skips sectors without civilians, military and land
units.  These are unowned.  Any uw there are frozen in time: they
don't eat, procreate or produce.  Has always been broken.  Don't skip
such sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agobudget: Fix level prod. forecast when required level is too low
Markus Armbruster [Sun, 5 Jun 2016 10:15:58 +0000 (12:15 +0200)]
budget: Fix level prod. forecast when required level is too low

When the required level is too low for production, produce() returns
early.  Except when simulating.  Messed up when Empire 3 made the
update code work for budget.

This can make budget show level production even when it's not actually
possible.  In the stock game, this can happen for tech and research,
which require education > 5.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Fix income and level use after revolt or revert to deity
Markus Armbruster [Sat, 4 Jun 2016 15:59:52 +0000 (17:59 +0200)]
update: Fix income and level use after revolt or revert to deity

prepare_sects() caches the sector owner's getnatp() across
guerrilla(), do_plague() and populace().  This is wrong, because the
owner may change.  The mistake can be traced back all the way back to
BSD Empire 1.1.

If the sector revolts or reverts to deity, the ex-owner still receives
taxes and bank interest.  The update test demonstrates this bug.

If the sector revolts, we use the ex-owner's instead of the owner's
tech and research for plague, and we use the ex-owners happiness and
required happiness instead of the owner's for loyalty update and civil
unrest.

Change do_plague() and populace() to call getnatp() themselves.  Call
it in prepare_sects() only after we're done messing with the sector
owner.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Lift populace() from tax into prepare_sects()
Markus Armbruster [Sat, 4 Jun 2016 15:56:41 +0000 (17:56 +0200)]
update: Lift populace() from tax into prepare_sects()

This way, tax() is more focused, and populace() doesn't need to be
guarded with !player->simulation.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agosubs: Oops on makelost() / makenotlost() with no owner
Markus Armbruster [Sat, 4 Jun 2016 15:38:25 +0000 (17:38 +0200)]
subs: Oops on makelost() / makenotlost() with no owner

This catches bogus entries in the "lost" file like the ones fixed in
the previous commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Fix revert to deity and "no civilians" corner cases
Markus Armbruster [Sat, 4 Jun 2016 15:36:24 +0000 (17:36 +0200)]
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>
6 years agosect: Fix revert to deity and "no civilians" corner cases
Markus Armbruster [Sat, 4 Jun 2016 15:14:25 +0000 (17:14 +0200)]
sect: 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.

When a deserted sector reverts to the deity, sct_prewrite() clears
owner and mobility.  It neglects to clear the old owner, unlike
populace().  Harmless, but fix it anyway for consistency.  Visible in
tests/navi-march/final.xdump.

Work percentage, loyalty and old owner apply to civilians.  When there
are none, sct_prewrite() sets work percentage to 100 and old owner to
owner.  It neglects to clear loyalty, unlike populace().  Loyalty
persists until populace() clears it.  Most of the time, this doesn't
matter, as moving civilians into a sector without civilians ignores
the sector's loyalty.  However, airlifted and unloaded civilians adopt
the sector's loyalty (bug#49 and bug#255).

Fix sct_prewrite() to clear loyalty for consistency, and to mitigate
these bugs.

Note that populace() may not always clear loyalty right away.  This
will be fixed in the next commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agosect: Keep work percentage without civilians at 100%
Markus Armbruster [Sat, 4 Jun 2016 12:32:58 +0000 (14:32 +0200)]
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>
6 years agoneweff prod work: Use update code instead of duplicating it
Markus Armbruster [Sat, 4 Jun 2016 08:55:44 +0000 (10:55 +0200)]
neweff prod work: Use update code instead of duplicating it

The code to build sectors got quadruplicated in Chainsaw.  We've since
fixed numerous inconsistencies, but still have four copies of the
code.  Thanks to the recent work on upd_buildeff(), we can now use it
to replace the other three copies.  Rename it back to to buildeff()
while there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoneweff production: Consider insufficient food
Markus Armbruster [Sat, 4 Jun 2016 07:50:09 +0000 (09:50 +0200)]
neweff production: Consider insufficient food

newe() and prod() duplicate parts of the update's do_feed(), except
they round babies down instead of randomly, to get a stable,
conservative forecast.  Unlike the update, they assume sufficient
food.  Inaccurate for sectors that are going to starve or have
suboptimal population growth.  Not documented.  Has always been that
way.

Eliminate the undocumented assumption by replacing the duplicate code
by a call of do_feed().  Add a suitable parameter to do_feed() to
preserve the different rounding.

The update test shows the improvement.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop redundant produce() parameters desig, neweff
Markus Armbruster [Sat, 4 Jun 2016 06:56:57 +0000 (08:56 +0200)]
update: Drop redundant produce() parameters desig, neweff

Its caller passes sp->sct_type and sp->sct_effic, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop upd_buildeff() parameter desig
Markus Armbruster [Sat, 4 Jun 2016 06:50:40 +0000 (08:50 +0200)]
update: Drop upd_buildeff() parameter desig

Since changing *sp is safe now, we can move the update of
sp->sct_type into upd_buildeff(), and drop the parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Make upd_buildeff() return cost, drop parameter
Markus Armbruster [Sat, 4 Jun 2016 06:24:54 +0000 (08:24 +0200)]
update: Make upd_buildeff() return cost, drop parameter

Since changing *sp is safe now, we can move the update of
sp->sct_effic into upd_buildeff().  This frees the return value; use
it to return cost, and drop the parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop produce() return value and parameters work, amount
Markus Armbruster [Sat, 4 Jun 2016 06:12:12 +0000 (08:12 +0200)]
update: Drop produce() return value and parameters work, amount

Since changing *sp is safe now, we can move the update of
sp->sct_avail into produce().  This frees the return value; use it to
return the amount produced.  Drop the parameters.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop upd_buildeff() parameter workp
Markus Armbruster [Sat, 4 Jun 2016 06:07:03 +0000 (08:07 +0200)]
update: Drop upd_buildeff() parameter workp

Since changing *sp is safe now, we can move the update of
sp->sct_avail into upd_buildeff(), and drop the parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Move work percentage update into do_feed()
Markus Armbruster [Sat, 4 Jun 2016 05:30:40 +0000 (07:30 +0200)]
update: Move work percentage update into do_feed()

Since changing *sp is safe now, we can move the update of sp->sct_work
into do_feed(), use the return value for work, and drop parameter
workp.

The sp->sct_avail update looks similar, but there's a subtle
difference: it's skipped when the sector is stopped or its owner is
broke.  The caller already checks that, so leave the update there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop produce_sect() variable neweff
Markus Armbruster [Fri, 3 Jun 2016 19:24:48 +0000 (21:24 +0200)]
update: Drop produce_sect() variable neweff

Since changing *sp is safe now, we can update sp->sct_effic
unconditionally, and eliminate neweff.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop unnecessary "not simulation" guards
Markus Armbruster [Fri, 3 Jun 2016 21:09:56 +0000 (23:09 +0200)]
update: Drop unnecessary "not simulation" guards

Since changing *sp is safe now, we can update sp->sct_work,
sp->sct_loyal, sp->sct-che unconditionally in do_feed(), and likewise
sp->sct_item and sp's resource in produce().

Output of budget in smoke test and update test changes slightly,
because it now executes more code, and the PRNs this consumes affect
random rounding.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop redundant upd_buildeff() parameter vec[]
Markus Armbruster [Fri, 3 Jun 2016 19:14:49 +0000 (21:14 +0200)]
update: Drop redundant upd_buildeff() parameter vec[]

Its caller passes sp->sct_item, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop redundant produce() parameter vec[]
Markus Armbruster [Fri, 3 Jun 2016 19:11:25 +0000 (21:11 +0200)]
update: Drop redundant produce() parameter vec[]

Its caller passes sp->sct_item, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate/human: Drop redundant parameters vec[]
Markus Armbruster [Fri, 3 Jun 2016 19:07:10 +0000 (21:07 +0200)]
update/human: Drop redundant parameters vec[]

All callers of growfood(), trunc_people() and grow_people() pass
sp->sct_item, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop redundant do_feed() parameter vec[]
Markus Armbruster [Fri, 3 Jun 2016 19:03:19 +0000 (21:03 +0200)]
update: Drop redundant do_feed() parameter vec[]

Its caller passes sp->sct_item, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Drop redundant bp_put_items() parameter vec[]
Markus Armbruster [Fri, 3 Jun 2016 18:58:54 +0000 (20:58 +0200)]
update: Drop redundant bp_put_items() parameter vec[]

All its callers pass sp->sct_item, so use that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Use a scratch sctstr for production simulation
Markus Armbruster [Fri, 3 Jun 2016 18:49:05 +0000 (20:49 +0200)]
update: Use a scratch sctstr for production simulation

If player->simulation, produce_sect() must not change game state,
except for sct_updated.  To avoid changing sectors, it copies each
sector's sct_item[] to a scratch buffer, and tracks new designation,
efficiency and available work in local variables.

Copy the complete sector to a scratch buffer instead.  This is safer,
and will permit code simplifications.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Eliminate produce_sect()'s getnatp()
Markus Armbruster [Fri, 3 Jun 2016 18:24:04 +0000 (20:24 +0200)]
update: Eliminate produce_sect()'s getnatp()

Make callers pass struct natstr * instead of a country number.  All
callers have it already.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Fix work inconsistency with neweff, production
Markus Armbruster [Wed, 1 Jun 2016 20:37:28 +0000 (22:37 +0200)]
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>
6 years agoupdate: Enforce sector population limit only right after growth
Markus Armbruster [Wed, 1 Jun 2016 20:05:41 +0000 (22:05 +0200)]
update: Enforce sector population limit only right after growth

The update kills people to enforce sector population limits, right
after growing people.

However, the population limit may decrease between that killing and
the end of the update:

* Research declines (only with RES_POP), but the lower population
  limit isn't enforced.  Even with an insanely fast decline of 60%
  (level_age_rate = 1, etu_per_update = 60), the population limit
  decreases by less than 10%.

  Not applying the new level to this update is consistent with how we
  use levels elsewhere.

* upd_buildeff() changes sector type and efficiency, but a lower new
  population limit is enforced only when this changes the sector type
  from big city to not big city (since option BIG_CITY was added in
  Empire 2).

  It isn't enforced on other sector type changes.  Might change the
  population limit since the type's limit became configurable in
  commit 153527a (v4.2.20).  Sane configurations don't let players
  redesignate sectors to a type with different maximum population.
  The server doesn't enforce this, though.

  It isn't enforced when a big city's efficiency decreases, but sector
  type change isn't achieved.  Having population exceed the new limit
  without having produced enough work to change the type seems
  unlikely, as 25 will do even in the worst case, but should be
  possible with a sufficiently low work percentage.

  None of this is documented in info Update-sequence.  Inconsistent
  mess.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate neweff production: Limit work in big cities
Markus Armbruster [Wed, 1 Jun 2016 19:35:24 +0000 (21:35 +0200)]
update neweff production: Limit work in big cities

Civilians, military and uw work only up to their sector's population
limit.  The population limit depends on the sector type's maximum
population, research if RES_POP is enabled, and the sector's
efficiency for big cities.

The population limit may decrease between computation of work in
do_feed() and the end of the update:

* Research declines (only relevant with RES_POP).  Work is not
  corrected.  The declined research will apply at the next update.

  Since levels age after production is done, any work corrections
  could only affect leftover available work.  Wouldn't make sense.

  The effect is negligible anyway.  Even with an insanely fast decline
  of 60% (level_age_rate = 1, etu_per_update = 60), the population
  limit decreases by less than 10% in the worst case.

* upd_buildeff() changes sector type and efficiency.  Work is
  corrected only when this changes the sector type from big city to
  not big city.

  It isn't corrected on other sector type changes.  These can affect
  maximum population since the sector type's maximum became
  configurable in commit 153527a (v4.2.20).  Sane configurations don't
  let players redesignate sectors to a type with different maximum
  population.  The server doesn't enforce this, though.

  It isn't corrected when a big city's efficiency decreases, but
  sector type change isn't achieved.  Harmless, because tearing down a
  city takes very little work (25 for 100%), so efficiency decrease
  without type change means the work we have must be safely below any
  sane population limit's work.

Good enough.  However, the code implementing the work correction for
big cities is unclean.  Get rid of it by tweaking the rules: a big
city's extra population does not work.  City slickers, tsk, tsk, tsk.
At least they still pay their taxes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoupdate: Avoid unnecessary inexactness in total_work()
Markus Armbruster [Wed, 1 Jun 2016 19:29:55 +0000 (21:29 +0200)]
update: Avoid unnecessary inexactness in total_work()

Commit 5ba8cab (v4.2.20) replaced milit * 2 / 5.0 by milit * 0.4.  Not
so smart; 0.4 isn't exact.  Go back to milit / 2.5.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agotests: Make update robust against variations in PRNG use
Markus Armbruster [Sun, 5 Jun 2016 12:36:15 +0000 (14:36 +0200)]
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>
6 years agoindent-emp: Take files to indent from command line
Markus Armbruster [Tue, 31 May 2016 19:34:33 +0000 (21:34 +0200)]
indent-emp: Take files to indent from command line

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agols-sources.pl: Fix for directory relative to root of tree
Markus Armbruster [Tue, 31 May 2016 19:28:00 +0000 (21:28 +0200)]
ls-sources.pl: Fix for directory relative to root of tree

Given and argument like tests/xdump, the script looks for
tests/xdump/.git, tests/.git, /.git.  The last one is wrong.  Make it
look for ./.git then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agonsc: Expose generalized build materials in xdump and conditionals
Markus Armbruster [Mon, 30 May 2016 21:43:10 +0000 (23:43 +0200)]
nsc: Expose generalized build materials in xdump and conditionals

Ship, plane, land unit and nuke types require lcms and hcms to build.
Planes also require military, and nukes also require oil and rads.
These build materials are exposed as ship-chr, plane-chr, land-chr,
nuke-chr selectors l_build, h_build, crew, o_build, r_build.

We want to optionally support more build materials in the future.  To
help clients prepare for that, provide selectors for all other item
types.  Use CA_DUMP_ONLY to keep them out of configuration tables
until they actually work.

Rename selector crew to m_build for consistency.  This is an xdump
compatibility break.  We could easily add m_build and deprecate crew
to provide the customary grace period for such breaks.  However, more
xdump changes are coming down the pipe, and for some of them providing
a grace period wouldn't be as easy.  Ron Koenderink assures us WinACE
doesn't need a grace period.  So don't bother with maintaining xdump
compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agonsc: New enum ca_dump member CA_DUMP_ONLY
Markus Armbruster [Mon, 30 May 2016 21:33:03 +0000 (23:33 +0200)]
nsc: New enum ca_dump member CA_DUMP_ONLY

CA_DUMP_ONLY selectors are like CA_DUMP_NONE, except the xdump command
still has them.  This will permit adding selectors for conditional
selector and xdump command forward compatibility without also adding
them to configuration tables.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agonsc: Replace NSC_EXTRA, NSC_CONST by enum ca_dump
Markus Armbruster [Sun, 29 May 2016 21:31:31 +0000 (23:31 +0200)]
nsc: Replace NSC_EXTRA, NSC_CONST by enum ca_dump

struct castr ca_flag NSC_EXTRA was introduced in commit 3e5c064
(v4.2.18) to permit selectors that aren't in xdump.

Flag NSC_CONST was introduced in commit 445dfec, and put to use in
commit d8422ca (both v4.3.0) to protect certain table elements that
should not be changed in customized tables.

Both flags apply only to xdump, not to other uses of struct castr,
such as conditionals.

Combining NSC_EXTRA | NSC_CONST makes no sense.

I'll shortly need a way to keep selectors out of configuration tables
for conditional selector and xdump command forward compatibility.
Doing it as a third flag would add more nonsensical combinations.

Convert the flags to a separate enum ca_dump instead:

    neither   -> CA_DUMP
    NSC_CONST -> CA_DUMP_CONST
    NSC_EXTRA -> CA_DUMP_NONE

Bonus: unlike the flags it replaces, ca_dump is not visible in xdump.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agonsc: Correct element type in NSC_IELT()
Markus Armbruster [Sun, 29 May 2016 20:58:37 +0000 (22:58 +0200)]
nsc: Correct element type in NSC_IELT()

Commit 9989c5b (v4.2.14) switched item storage from unsigned short to
short, but missed a type cast in the offset computation for
distribution and delivery selectors.  Offset computation was factored
out into NSC_IELT() in commit 4366c5a (v4.2.15).  Correct it there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agodoc/xdump: Document hidden flag
Markus Armbruster [Sun, 29 May 2016 16:08:25 +0000 (18:08 +0200)]
doc/xdump: Document hidden flag

Missed in commit 41f00fd, v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agobomb: Simplify after previous commit
Markus Armbruster [Sun, 29 May 2016 10:16:25 +0000 (12:16 +0200)]
bomb: Simplify after previous commit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agobomb: Eliminate bombcomm[], it's redundant
Markus Armbruster [Sun, 29 May 2016 10:14:05 +0000 (12:14 +0200)]
bomb: Eliminate bombcomm[], it's redundant

bombcomm[] used to contain the commodities that can be p-bombed.  In
BSD Empire 1.1, it contained I_SHELL, I_GUN, I_MILIT, I_PETROL, I_OIL,
I_RAD.  In Chainsaw, it contained either everything or everything but
I_BAR, depending on option preprocessor symbol SUPER_BARS.  When
Empire 2 replaced the compile time variable SUPER_BARS by the run time
variable opt_SUPER_BARS, bombcomm[] became a redundant indirection.
Eliminate it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agobomb: Don't list bombable commodities on invalid selection
Markus Armbruster [Sun, 29 May 2016 09:58:32 +0000 (11:58 +0200)]
bomb: Don't list bombable commodities on invalid selection

comm_bomb() first lists commodities that can be bombed and are
present, then prompts for the one to bomb.  If the player selects a
bomb-proof one, it rejects it, lists the bombable ones, and prompts
again.  This can only happen when option SUPER_BARS is enabled, and
the player selects bars.  Looks like this:

    Bomb what? (ship, plane, land unit, efficiency, commodities) c
    some civilians
    some military
    commodity to bomb? b
    You can't bomb bars of gold!
    Bombable: civilians, military, shells, guns, petrol, iron ore, dust (gold), food, oil, light products, heavy products, uncompensated workers, radioactive materials
    commodity to bomb?

The list is of marginal value.  It was more useful back when
comm_bomb() didn't list commodities before prompting (BSD Empire 1.1).
It's also illegible.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoplnsub: Let crewless planes spread the plague, too
Markus Armbruster [Sat, 28 May 2016 17:21:12 +0000 (19:21 +0200)]
plnsub: Let crewless planes spread the plague, too

Commit 612ec62 (v4.3.31) made plane crew and cargo spread the plague.
This requires looking for crew in build materials.  Awkward if we ever
permit non-military crew.

Simply drop the "has crew" condition.  If a plane's cargo can spread
it, then servicing and refueling the plane can spread it, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agotransport: Don't hardcode material weights
Markus Armbruster [Sat, 28 May 2016 14:21:08 +0000 (16:21 +0200)]
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>
6 years agopower: Include nukes in power factor, like other units
Markus Armbruster [Sat, 28 May 2016 05:42:36 +0000 (07:42 +0200)]
power: Include nukes in power factor, like other units

Building nukes makes you rate *lower* on the power chart, because the
power factor ignores nukes.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agopower: Saner power for items, ships, planes and land units
Markus Armbruster [Fri, 27 May 2016 15:41:45 +0000 (17:41 +0200)]
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>
6 years agoshow: Extend show item to show the power value
Markus Armbruster [Fri, 27 May 2016 19:40:11 +0000 (21:40 +0200)]
show: Extend show item to show the power value

Also update "info power" to point to "show item" instead of the
formerly hardcoded values.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agopower: Make item power value configurable
Markus Armbruster [Fri, 27 May 2016 19:18:47 +0000 (21:18 +0200)]
power: Make item power value configurable

Custom games may want to tweak how items contribute to the power
factor, in particular when products are also customized.  Add ichrstr
member i_power and item selector power for that.

"info power" doesn't reflect this change, yet.  It'll be updated in
the next commit.

The current item power values are problematic.  This will be addressed
later.

For straightforward configurations, reasonable item power values could
perhaps be derived from the configuration automatically.  However,
this is surprisingly hard in the general case: since producing things
should not decrease power, the efficiency of processing products into
other products needs to be considered, and estimating these
efficiencies can be difficult.

Deities can create multiple products making the same item, or multiple
sector types with the same product, but different process efficiency
(sect-chr selector peffic).  Providing differently efficient ways to
make the same item can be reasonable when the sector types involved
have different terrain.  To average them, you'd need to know the map.

The stock game has one example: gold mines produce dust with 100%
process efficiency, mountains produce it with 75%.  Mountains are
normally rare enough not to matter.

Level p.e. (product selectors nlmin, nllag) may have to be considered.
In the stock game, level p.e. variations are minor, because it reaches
0.9 pretty quickly.  In games where it doesn't, you might have to
increase the power value of the product.

Resources (sect selectors min, gold, fert, ocontent, uran) and
resource depletion (product selectors nrndx and nrdep) further
complicate things: you might want to increase the power value of
products depending on unusually scarce resources, but you can't know
what's scarce without understanding the map.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agopower: Use ship, plane, land unit tech instead of nation's
Markus Armbruster [Fri, 27 May 2016 18:08:39 +0000 (20:08 +0200)]
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>
6 years agopower: Saner power value for tech, particularly at low tech
Markus Armbruster [Fri, 27 May 2016 17:58:58 +0000 (19:58 +0200)]
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>
6 years agoinfo/power: Rewrite power formula for clarity
Markus Armbruster [Fri, 27 May 2016 15:36:35 +0000 (17:36 +0200)]
info/power: Rewrite power formula for clarity

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agopower: Drop the RES_POP factor
Markus Armbruster [Fri, 27 May 2016 14:58:04 +0000 (16:58 +0200)]
power: Drop the RES_POP factor

If option RES_POP is enabled, the power factor is multiplied by a
"research factor" of 1.0 + maxpop / 10000.0, where maxpop is the
maximum population of a mine sector.

Back when this code was written (Chainsaw 3), all sectors had the same
population limit, so using a mine sector was as good as any.  Since
then, it has become configurable, and the stock game has both sector
types with lower (mountains, plains) and with higher (cities)
population limits.

Space for people is worth considering for power, but multiplying total
power by a fudge factor based on the most common sector type's maximum
population is silly.  Drop it.

Adjusting each sector's value for maximum population would make more
sense, with and without RES_POP.  Perhaps later.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agopower: Simplify tallying the power value of items
Markus Armbruster [Fri, 27 May 2016 13:42:17 +0000 (15:42 +0200)]
power: Simplify tallying the power value of items

Item power value is basically number of items times the item power
weight.  For some item types, we add up the item numbers, then apply
the weight.  For lcms and hcms, we apply the weight, then add up the
weighted numbers.

Adopt the latter method for all types: change addtopow() to tally the
power value for all types instead of just lcms and hcms, and drop
gen_power()'s item power value computation.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoconfig: Generalize unit build materials storage
Markus Armbruster [Fri, 27 May 2016 12:17:08 +0000 (14:17 +0200)]
config: Generalize unit build materials storage

Use a single array member instead of multiple scalar members.  Only
the array elements that replace scalar members are can be non-zero for
now.

This is a first step to permitting more build materials.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoconfig: Make work to build units independently configurable
Markus Armbruster [Fri, 27 May 2016 11:39:11 +0000 (13:39 +0200)]
config: Make work to build units independently configurable

The work required for build and repairs is traditionally a function of
build materials: 20 + lcm + 2*hcm for ships, planes and land units,
and (lcm + 2*hcm + oil + rad)/5 for nukes.  Make it independently
configurable instead, via new ship-chr, plane-chr, land-chr, nuke-chr
selector bwork, backed by new struct mchrstr member m_bwork, struct
plchrstr member pl_bwork, struct lchrstr member l_bwork, struct
nchrstr member n_bwork.  Keep the required work exactly the same for
now.

Clients that compute work from materials need to be updated.  Easy,
since build work is now exposed in xdump.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agotests/update: New; exercises the update
Markus Armbruster [Tue, 28 Jun 2016 18:29:18 +0000 (20:29 +0200)]
tests/update: New; exercises the update

Notable gaps in its coverage are fallout, most of guerrilla, delivery,
distribution, ALL_BLEED and LOSE_CONTACT.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoedit: Add editing of land unit plague
Markus Armbruster [Tue, 28 Jun 2016 17:34:27 +0000 (19:34 +0200)]
edit: Add editing of land unit plague

Add edit u keys 'A' for plague stage, and 'b' for plague time.
Admittedly unobvious, but at least they match edit s keys 'a' and 'b'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agotests/version: New; exercises config introspection commands
Markus Armbruster [Sun, 29 May 2016 17:27:13 +0000 (19:27 +0200)]
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>
6 years agoship.config plane.config: Drop obsolete notes on auto-set flags
Markus Armbruster [Fri, 27 May 2016 08:58:58 +0000 (10:58 +0200)]
ship.config plane.config: Drop obsolete notes on auto-set flags

Flags monkey-patching is gone since commit c0c5822 and commit a4a25df,
v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoinfo/launch: Clean up description of satellites a bit
Markus Armbruster [Thu, 19 May 2016 19:25:49 +0000 (21:25 +0200)]
info/launch: Clean up description of satellites a bit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoplnsub: Make takeoff/landing in mountains consistent
Markus Armbruster [Tue, 17 May 2016 20:03:40 +0000 (22:03 +0200)]
plnsub: Make takeoff/landing in mountains consistent

One-way sorties (fly, recon and sweep) reject mountain destinations
with a "Nowhere to land" message.  However, planes can land there just
fine when they return to base (bomb, drop, paradrop, missions).
Already inconsistent in BSD Empire 1.1.

Fix the inconsistency by changing pln_where_to_land() to permit only
helicopters to land in mountains, and pln_airbase_ok() to permit only
helicopters and missiles to take off there, i.e. reject fixed-wing
aircraft.

The flying commands now reject fixed-wing planes based in mountains
with an "is in a mountain and can't take off" message.

Commands flying to a mountain now select only helicopters and silently
ignore the rest, exactly like they select only VTOL planes for flying
to a non-airfield.  If no planes can be selected, the command fails
with a "No planes could be equipped" message.  This is admittedly less
clear than the "Nowhere to land" message we got before.

Missions now ignore fixed-wing planes based in mountains, exactly like
they ignore non-VTOL planes outside airfields.  This may make players
wonder why the fixed-wing VTOL planes they transported up that
mountain don't obey missions.  Missions are always quiet unless they
execute.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoplnsub: Add missing newline to two messages
Markus Armbruster [Mon, 16 May 2016 16:43:07 +0000 (18:43 +0200)]
plnsub: Add missing newline to two messages

The two "while it is carrying a nuclear weapon" messages lack
newlines.  Add them.  Screwed up in commit a269cdd, v4.3.23.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agobomb: Disallow bombing spy units
Markus Armbruster [Sat, 14 May 2016 20:15:21 +0000 (22:15 +0200)]
bomb: Disallow bombing spy units

When bombing land units, the bombers get a chance to spot spies.  They
can target one even when it wasn't spotted.  This makes no sense.
Screwed up when spy units were added in 4.0.0.  Hide them completely.
They can still be killed via collateral damage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoRevert "subs: Add unitsatxy() parameter only_count"
Markus Armbruster [Sat, 14 May 2016 20:13:57 +0000 (22:13 +0200)]
Revert "subs: Add unitsatxy() parameter only_count"

This reverts commit 9b33a4c59824a249ee6f04a94045bcb1f93f4f77.

Parameter only_count was introduced so would_abandon() could use
unitsatxy(), but that was a flawed idea, fixed in the previous commit.
No callers passing non-zero remain, so get rid of it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agomarch: Fix check for sector abandonment
Markus Armbruster [Sat, 14 May 2016 20:00:36 +0000 (22:00 +0200)]
march: Fix check for sector abandonment

sct_prewrite() makes an owned sector revert to the deity when there
are no civilians, military or own land units.

would_abandon() tries to predict that, but gets it wrong: it ignores
land units that evade spy detection or are loaded on ships, and it
fails to ignore land units loaded on land units marching out.

Broken in commit 7c1b166, v4.3.33.  Fix by counting manually rather
than with unitsatxy().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agofire: Fix damage and ammunition use of return fire
Markus Armbruster [Sat, 14 May 2016 17:53:02 +0000 (19:53 +0200)]
fire: Fix damage and ammunition use of return fire

quiet_bigdef() runs for each attacker.  It lets each eligible defender
fire at most once.  The first time a defender is eligible, it fires
and is saved in the list of defenders, along with its firing damage.
If it's eligible again for a later attacker, it's found in the list of
defenders, and the damage is reused.  The list of defenders searched
with search_flist().  Unfortunately, search_flist() compares only uid,
not type, and therefore can return a previously found defender of
another type.

If there are multiple attackers and multiple defenders with the same
uid, total damage can be off, damage can be spread to attackers out of
range, and defenders may not be charged shells.  Abuse is possible,
but complicated to set up, and probably not worth the trouble.

Broken in commit f89edc7, v4.3.12.  Fix by comparing the type as well.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agollook: Drop useless "spy loaded" conditional
Markus Armbruster [Sat, 14 May 2016 14:51:39 +0000 (16:51 +0200)]
llook: Drop useless "spy loaded" conditional

The "loaded on ship" condition was useless from the start (v4.2.0).
The "loaded on land" condition became useless in commit 45d090b,
v4.3.28.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agoUpdate copyright notice
Markus Armbruster [Sat, 2 Jan 2016 08:19:50 +0000 (09:19 +0100)]
Update copyright notice

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
6 years agocommon/rdsched: Document why we need _XOPEN_SOURCE
Markus Armbruster [Fri, 25 Dec 2015 15:56:12 +0000 (16:56 +0100)]
common/rdsched: Document why we need _XOPEN_SOURCE

It's for strptime().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoman/empire: Trim unwanted space in synopsis
Markus Armbruster [Sun, 13 Dec 2015 08:18:54 +0000 (09:18 +0100)]
man/empire: Trim unwanted space in synopsis

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agodoc/contributing: Fix git format-patch topic branch example
Markus Armbruster [Sun, 13 Dec 2015 07:27:26 +0000 (08:27 +0100)]
doc/contributing: Fix git format-patch topic branch example

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotravis: Enable OS X
Markus Armbruster [Sun, 29 Nov 2015 13:53:40 +0000 (14:53 +0100)]
travis: Enable OS X

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march: Fix abort not to wipe out concurrent updates
Markus Armbruster [Sun, 29 Nov 2015 10:30:45 +0000 (11:30 +0100)]
navigate march: Fix abort not to wipe out concurrent updates

When the player aborts the command at the movement prompt, we write
back stale ships or land units, triggering a generation oops.  Any
updates made by other threads meanwhile are wiped out, triggering a
seqno mismatch oops.

Broken in commit 24000b4, v4.3.33.  Fix by restoring the lost
shp_nav_stay_behind() and lnd_mar_stay_behind() calls.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests/navi-march: Cover abort at movement prompt
Markus Armbruster [Sun, 29 Nov 2015 09:53:14 +0000 (10:53 +0100)]
tests/navi-march: Cover abort at movement prompt

This exposes generation oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agomarch: Fix concurrent updates at sector abandon prompt
Markus Armbruster [Sun, 29 Nov 2015 09:37:40 +0000 (10:37 +0100)]
march: Fix concurrent updates at sector abandon prompt

When the player declines to abandon a sector, we write back stale land
units, triggering a generation oops.  Any updates made by other
threads meanwhile are wiped out, triggering a seqno mismatch oops.

The culprit is lnd_abandon_askyn(): when the player declines, it
returns without calling check_sect_ok(), check_land_ok().  Broken in
commit 7c1b166, v4.3.33.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agorecvclient: Track potential yield on input
Markus Armbruster [Sun, 29 Nov 2015 09:20:52 +0000 (10:20 +0100)]
recvclient: Track potential yield on input

recvclient() calls ef_make_stale() only when it does actual I/O, via
io_output() and io_input().  Missed in commit 2fa5f652, v4.3.24.  Call
it directly when it doesn't do actual I/O.

This makes navi-march-test expose a bug in march: when the player
declines to abandon a sector, we write back stale land units,
triggering a generation oops.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Use -fstack-protector-strong when available
Markus Armbruster [Sun, 22 Nov 2015 09:38:24 +0000 (10:38 +0100)]
configure: Use -fstack-protector-strong when available

Testing whether the compiler supports it is a bit tricky.

The obvious AX_APPEND_COMPILE_FLAGS([-fstack-protector-strong])
doesn't suffice, since some ports of the GNU toolchain reportedly pass
this test, then fail to link.  That's because the compiler accepts the
flag, duly emits references to helper code in libc, but libc doesn't
provide, and linking fails.

Instead, use AX_APPEND_LINK_FLAGS with an input source that makes the
compiler emit the extra stack checking code.  This requires the latest
version from the autoconf-archive, so update m4/ax* to commit e3d948b.
Also update m4/my_append_compile_flags.m4 to keep it in sync with
upstream's ax_append_compile_flags.m4.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoscripts/savecore: Report nicely when there's no core dump
Markus Armbruster [Sun, 15 Nov 2015 07:40:36 +0000 (08:40 +0100)]
scripts/savecore: Report nicely when there's no core dump

When savecore can't find a core dump, it reports something like

    ls: cannot access core.*: No such file or directory

to stderr, and fails.  If privlog is set, it also mails out a "Could
not save core dump" note.

Suppress the error message, and mail out "Could not find core dump to
save" instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoconfigure: Use -fno-strict-aliasing -fno-strict-overflow
Markus Armbruster [Sun, 18 Oct 2015 15:48:15 +0000 (17:48 +0200)]
configure: Use -fno-strict-aliasing -fno-strict-overflow

Contemporary compilers can squeeze out some extra performance by
assuming the program never executes code that has undefined behavior
according to the C standard.  Unfortunately, this can break programs.
Pointing out that these programs are non-conforming is as correct as
it is unhelpful, at least as long as the compiler is unable to
diagnose the non-conformingness.

Since keeping our programs working is a lot more important to us than
running them as fast as possible, forbid some assumptions that are
known to break real-world programs:

* Aliasing: perfectly clean programs don't engage in type-punning, and
  perfectly conforming programs do it only in full accordance with the
  standard's (subtle!) aliasing rules.  Neither kind of perfection is
  realistic for us, therefore -fno-strict-aliasing.

* Signed integer overflow: perfectly clean programs won't ever do
  signed integer arithmetic that overflows.  This is an imperfect
  program, therefore -fno-strict-overflow.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests: Enable GNU libc memory allocation error checking
Markus Armbruster [Sun, 27 Sep 2015 07:56:21 +0000 (09:56 +0200)]
tests: Enable GNU libc memory allocation error checking

MALLOC_CHECK_=3 makes glibc check for memory allocation programming
errors.  It's the factory default, but set it anyway just in case
someone disabled it for speed.

Non-zero MALLOC_PERTURB_ makes glibc wipe memory value on allocation
and deallocation.  The actual value determines the bit pattern.  Set
it to the value of environment variable EMPIRE_CHECK_MALLOC_PERTURB or
else a pseudo-random number, and record it in sandbox/malloc-perturb.

See mallopt(3) for more information.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march: Plug memory leaks
Markus Armbruster [Sun, 20 Sep 2015 13:24:22 +0000 (15:24 +0200)]
navigate march: Plug memory leaks

When the player aborts the command at the movement prompt, or declines
to abandon a sector, unit_move() returns without freeing the list.
Found with valgrind.  Broken in commit 24000b4 and commit 7c1b166,
both v4.3.33.

Free the list on these returns, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agonavigate march retreat lretreat: Fix read beyond buffer
Markus Armbruster [Sun, 20 Sep 2015 11:17:33 +0000 (13:17 +0200)]
navigate march retreat lretreat: Fix read beyond buffer

shp_nav_gauntlet() and lnd_mar_gauntlet() read beyond the list head
when the list is empty.  The values read aren't used then.  Could
conceivably crash the server anyway, but it's unlikely.

Empty list happens when shp_nav_dir(), lnd_mar_dir() empty the list
and return zero.  Broken in commit beedf8d, v4.3.33.  Occurs in
navi-march-test (since the last commit) and in retreat-test.

Change shp_nav_dir() and lnd_mar_dir() to return one then.  For
additional safety, make shp_nav_gauntlet() and lnd_mar_gauntlet() oops
on empty list and recover safely.

I think I originally found this bug with -fsanitize, but I've since
upgraded, and I can't diagnose it that way anymore.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agotests/navi-march: Cover running out of mobility completely
Markus Armbruster [Sun, 20 Sep 2015 10:30:33 +0000 (12:30 +0200)]
tests/navi-march: Cover running out of mobility completely

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agobomb drop fly paradrop recon sweep: Fix read before array
Markus Armbruster [Sun, 26 Jul 2015 18:28:34 +0000 (20:28 +0200)]
bomb drop fly paradrop recon sweep: Fix read before array

The code computing the length of the flight path checks whether the
path ends with 'h'.  When getpath() returns an empty path, it accesses
flightpath[-1].  This could set the length to -1 (unlikely), or crash
(even less likely).  The former could be abused to gain mobility for
sufficiently inefficient or short-ranged planes.  Found with valgrind.

Broken in commit 404a76f7, v4.3.27.

Historically, getpath() could return paths with or without 'h', and
the check was necessary.  It returned an empty path only when the
player gave no input, aborting the command.  When the player entered
the assembly point's coordinates, it returned "h".

Commit 404a76f7 accidentally changed it to return "" then.  Also broke
flying to the assembly point's coordinates.  Commit 0f1e14f (v4.3.31)
fixed that part by changing getpath()'s contract: always return paths
without 'h' ("" simply means empty path), and return NULL on invalid
input, including no input.

The flawed check is superfluous since then.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoAvoid shifting into sign bit
Markus Armbruster [Sun, 26 Jul 2015 16:00:27 +0000 (18:00 +0200)]
Avoid shifting into sign bit

It's undefined behavior.  Found with gcc -fsanitize=undefined.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoConvert run-time to build-time assertion
Markus Armbruster [Sat, 4 Jul 2015 14:19:16 +0000 (16:19 +0200)]
Convert run-time to build-time assertion

There's just one, in show_product().

Use new BUILD_ASSERT() there, because its contract is even simpler
than BUILD_ASSERT_ONE()'s.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoProvide proper build-time assertions for NSC_SITYPE()
Markus Armbruster [Sat, 4 Jul 2015 12:53:20 +0000 (14:53 +0200)]
Provide proper build-time assertions for NSC_SITYPE()

We want to cause a diagnostic when NSC_SITYPE()'s argument isn't
implemented.  Commit aa6ad9d's solution is to have the macro expand
into 1/0 then.  Works with GCC, but Clang always warns "division by
zero is undefined".

The better, portable way to conditionally break the build is an array
type with a size that's negative when the build should fail, else
positive.  Implement that wrapped in a sizeof() to make it an
expression as macro BUILD_ASSERT_ONE(), and use it in NSC_SITYPE().

No more warnings from Clang 3.5.0.  GCC still produces its "may be
used uninitialized" false positives.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agosubs: Don't squash telegrams together when time goes backwards
Markus Armbruster [Sat, 4 Jul 2015 12:31:28 +0000 (14:31 +0200)]
subs: Don't squash telegrams together when time goes backwards

We've always squashed them when the time difference is smaller than
TEL_SECONDS, regardless of sign.  This involves passing the difference
to abs(), implicitly casting from time_t to int, which triggers a
Clang warning.

I could clean this up to get rid of the warning, but time should never
go backwards, and trying to make things prettier when it does isn't
worthwhile.  Simply drop the abs().

While there, drop the function comment.  It's been inaccurate since
Empire 3 dropped mail.c, and bogus since commit 17223e8 (v4.3.29)
added tel_cont.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Nuke-types: Document show columns avail, res, abilities
Markus Armbruster [Thu, 2 Jul 2015 07:40:34 +0000 (09:40 +0200)]
info/Nuke-types: Document show columns avail, res, abilities

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Unit-types: Belatedly remove capability xlight
Markus Armbruster [Thu, 2 Jul 2015 07:19:48 +0000 (09:19 +0200)]
info/Unit-types: Belatedly remove capability xlight

L_XLIGHT was replaced in commit e28c14f, v4.3.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Plane-types: Belatedly remove stealth and half-stealth
Markus Armbruster [Thu, 2 Jul 2015 07:17:29 +0000 (09:17 +0200)]
info/Plane-types: Belatedly remove stealth and half-stealth

P_X and P_H were removed in commit 61233e4, v4.3.23.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Ship-types: Belatedly remove capability spy
Markus Armbruster [Thu, 2 Jul 2015 07:14:14 +0000 (09:14 +0200)]
info/Ship-types: Belatedly remove capability spy

M_SPY was removed in commit 498d9fb, v4.3.0.  It never did anything.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo: Belatedly update for change of stop prefix to '!'
Markus Armbruster [Thu, 25 Jun 2015 05:19:55 +0000 (07:19 +0200)]
info: Belatedly update for change of stop prefix to '!'

Commit eb1512d (v4.3.6) added the '=' if stopped before efficiency.
Commit 016249c (v4.3.6) changed it to '!' without updating info ship,
plane, land, nuke.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/version: Update example to current output
Markus Armbruster [Sun, 21 Jun 2015 07:10:33 +0000 (09:10 +0200)]
info/version: Update example to current output

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo: Fix option NOMOBCOST misinformation
Markus Armbruster [Sun, 21 Jun 2015 06:59:01 +0000 (08:59 +0200)]
info: Fix option NOMOBCOST misinformation

The cost of firing naval guns is 15 mobility with option NOMOBCOST
disabled.  Mobility.t is correct.

Fix Options.t not to claim submarines pay half the sector movement
cost when NOMOBCOST is enabled.

Fix fire.t not to claim ships pay half the sector movement cost when
NOMOBCOST is disabled.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Options: Nicer markup, more consistent format
Markus Armbruster [Sun, 21 Jun 2015 06:32:47 +0000 (08:32 +0200)]
info/Options: Nicer markup, more consistent format

Don't list options separately for major server versions.  It's only of
historical interest, which "info History" satisfies.

Make it a list (.L) instead of preformatted text (.nf).

Fix up so the option explanations are full sentences, starting with a
capital letter and ending with a period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
8 years agoinfo/Options: Belatedly remove SAIL
Markus Armbruster [Sun, 21 Jun 2015 06:05:24 +0000 (08:05 +0200)]
info/Options: Belatedly remove SAIL

Missed in commit dc73207.

Reported-by: Harald Katzer
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>