empserver
7 years agoretreat: Rewrite automatic retreat code to fix its many bugs
Markus Armbruster [Wed, 7 Jan 2015 18:38:53 +0000 (19:38 +0100)]
retreat: Rewrite automatic retreat code to fix its many bugs

Much of the retreat code duplicates navigate and march code.  Worse,
retreat's version is full of bugs:

* Land units can sometimes retreat when they couldn't march: while on
  the trading block (forbidden with march since 4.0.9), crewless
  (likewise since 4.0.0), kidnapped in a foreign sector (inconsistent
  since land units were added in Chainsaw 3), loaded on a ship
  (likewise) or a land unit (inconsistent since trains were added in
  4.0.0).

* Ships can retreat while on the trading block (forbidden with
  navigate since 4.0.9)

* Land units can't retreat into foreign sectors even though they could
  march there, namely when sector is allied or the land unit is a spy.
  They can march there since 4.0.0.

* Land units keep their fortification on retreat.  Has been that way
  since retreat was added in Chainsaw.

Then there's group retreat.  It's basically crazy:

* It triggers retreat for everyone in the same fleet or army, one
  after the other, regardless of retreat path, conditions (including
  group retreat), or even location.  The latter is quite abusable
  since retreats aren't interdicted.  Has been that way since retreat
  was added in Chainsaw.

* Group retreat fails to trigger when the originally retreating ship
  or land unit has no retreat path left when it's done.  Broken in
  commit b860123.

Finally, the reporting to the owner is sub-par:

* When a retreat is cut short by insufficient mobility or
  obstructions, its end sector isn't reported, leaving the player
  guessing.

* Non-retreats can be confusingly reported as retreat to the same
  sector.  Can happen when the retreat path starts with 'h' (obscure
  feature to suppress a single retreat), or when a group retreat
  includes a ship or land unit without retreat orders.

* Interaction with mines during retreat is reported before the retreat
  itself, which can be quite confusing.

* Sweeping landmines isn't reported at all.

* Much code and much bulletin text is dedicated to reporting what
  caused the retreat, even though it should be perfectly obvious.

Rewrite this on top of common navigate and march code.  Reuse of
common code fixes the "can retreat when it couldn't navigate/march"
and the "can't retreat into sectors it could navigate or march into"
bugs, and improves the reporting.

One special case isn't a bug fix but a rule change: mountains.  The
old code forbids that explicitly, and it's clearly intentional, if
undocumented.  The new code allows it by not doing anything special.

Turn group retreat into an actual group retreat: everyone in the same
fleet and sector with the the same retreat path and group retreat
condition joins the group.  The group retreats together, just like in
navigate and march.

Take care to always report the end sector.  When retreat is
impossible, report "can't retreat".  When retreat is partial, report
"and stays in X,Y".  When it's complete, report "stopped at X,Y".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Test mission clearing more thoroughly
Markus Armbruster [Wed, 7 Jan 2015 16:45:26 +0000 (17:45 +0100)]
tests/retreat: Test mission clearing more thoroughly

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Cover spies
Markus Armbruster [Wed, 7 Jan 2015 14:26:04 +0000 (15:26 +0100)]
tests/retreat: Cover spies

This exposes yet another bug.  It's marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Cover trains
Markus Armbruster [Wed, 7 Jan 2015 13:54:21 +0000 (14:54 +0100)]
tests/retreat: Cover trains

This exposes yet another bug.  It's marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Cover canals
Markus Armbruster [Wed, 7 Jan 2015 13:36:53 +0000 (14:36 +0100)]
tests/retreat: Cover canals

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Cover ships and land units on sale
Markus Armbruster [Wed, 7 Jan 2015 13:29:32 +0000 (14:29 +0100)]
tests/retreat: Cover ships and land units on sale

This exposes more bugs.  They're marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoretreat: Don't report a destroyed ship/land unit couldn't retreat
Markus Armbruster [Wed, 7 Jan 2015 13:16:01 +0000 (14:16 +0100)]
retreat: Don't report a destroyed ship/land unit couldn't retreat

Commit df8a1ff redone without breaking stuff.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoRevert "retreat: Don't report a destroyed ship/land unit couldn't retreat"
Markus Armbruster [Wed, 7 Jan 2015 13:12:40 +0000 (14:12 +0100)]
Revert "retreat: Don't report a destroyed ship/land unit couldn't retreat"

This reverts commit df8a1ffc1bf77567e4972810d5c729a73fcb42e6.

Because it breaks group retreat.  Trivial conflicts due to the removal
of option SAIL.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Conflicts:
src/lib/subs/retreat.c
tests/retreat/journal.log

7 years agotests/retreat: Improve group retreat coverage
Markus Armbruster [Wed, 7 Jan 2015 11:12:04 +0000 (12:12 +0100)]
tests/retreat: Improve group retreat coverage

This exposes more bugs.  They're marked "BUG:" in the test input.  A
few bugs get masked, but I'll unmask them again in the next commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Put some targets in separate locations
Markus Armbruster [Wed, 7 Jan 2015 09:32:50 +0000 (10:32 +0100)]
tests/retreat: Put some targets in separate locations

To reduce coupling between test cases.

Lucky dice expose another bug.  It's marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Drop unused minefields
Markus Armbruster [Wed, 7 Jan 2015 09:18:47 +0000 (10:18 +0100)]
tests/retreat: Drop unused minefields

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/retreat: Clean up setup, improve comments
Markus Armbruster [Wed, 7 Jan 2015 08:44:45 +0000 (09:44 +0100)]
tests/retreat: Clean up setup, improve comments

setup-POGO unintentionally gives dead ships, planes and land units
mobility, which makes them show up in final.xdump.  Rearrange to avoid
that, and for clarity.  While there, improve comments.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: Normalize setup.journal.log and setup.server.log
Markus Armbruster [Wed, 7 Jan 2015 08:40:42 +0000 (09:40 +0100)]
tests: Normalize setup.journal.log and setup.server.log

These logs are saved in the sandbox to help debugging setup.
Normalize them to make them easier to read.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoedit: Fix tech and range adjustment for edit p key 'T'
Markus Armbruster [Tue, 6 Jan 2015 14:22:01 +0000 (15:22 +0100)]
edit: Fix tech and range adjustment for edit p key 'T'

It sets the new type, then falls through to setting tech if the new
type requires more than the plane currently has.  Two problems with
that:

* If we fall through, the plane is invalid: it has less tech than
  required.  Its only use before it gets overwritten is pln_set_tech()
  calling pln_range_max() to find out whether the range is limited.
  Passes a negative number to log().  Not fatal, but pln_set_tech()'s
  range adjustment is unlikely to work.

* If we don't fall through, the range may still need adjustment,
  either up (to keep it unlimited if the new type has more range), or
  down (to keep it within the new type's shorter range).

Screwed up when the key was added in commit 6b0b6f17.  Fix by
adjusting tech first, then setting the type, then adjusting the range.
The latter relies on pln_set_tech() coping with ranges exceeding the
type's maximum, which it does.

Change the other type edits similarly for consistency.

When a type edit triggers a tech change, the tech change is now
silent.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/actofgod: Test plane type change's effect on range
Markus Armbruster [Tue, 6 Jan 2015 13:45:51 +0000 (14:45 +0100)]
tests/actofgod: Test plane type change's effect on range

Demonstrate bugs: doesn't always preserve unlimited range, and doesn't
always cut range back to maximum.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Inline shp_stays(), lnd_stays()
Markus Armbruster [Tue, 6 Jan 2015 13:10:23 +0000 (14:10 +0100)]
subs: Inline shp_stays(), lnd_stays()

Most of the remaining callers need to fool around with snprintf() to
use them.  Not worthwhile anymore.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Stop on non-fatal mine hits, too
Markus Armbruster [Mon, 5 Jan 2015 19:23:46 +0000 (20:23 +0100)]
navigate march: Stop on non-fatal mine hits, too

We stop on mine hits only when they're fatal.  Has always been that
way.  When interdiction was added in Chainsaw, it worked the same.
Empire 2 changed the commands to stop on any interdiction damage.  Now
stop on any mine damage, too.

Interdiction can fail to do damage (all bombs miss), and mines can be
detected without damage (by sweeping).  Perhaps we should stop then as
well.  Left for another day.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Rename unit_path() to unit_move_route() and move it
Markus Armbruster [Mon, 5 Jan 2015 16:58:31 +0000 (17:58 +0100)]
subs: Rename unit_path() to unit_move_route() and move it

Move it next to its only caller unit_move().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Rename shp_nav(), lnd_mar()
Markus Armbruster [Mon, 5 Jan 2015 16:44:26 +0000 (17:44 +0100)]
subs: Rename shp_nav(), lnd_mar()

... to shp_nav_stay_behind(), lnd_mar_stay_behind(), to better reflect
their purpose.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Fix use-after-free and other bugs
Markus Armbruster [Mon, 5 Jan 2015 15:32:25 +0000 (16:32 +0100)]
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>
7 years agosubs: Move shared code from navi.c to subs
Markus Armbruster [Mon, 5 Jan 2015 12:12:38 +0000 (13:12 +0100)]
subs: Move shared code from navi.c to subs

Rename do_unit_move() to unit_move() to blend into unitsub.c.  Give
its helpers static linkage.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Fix "same mob type" and "not on sale" checks
Markus Armbruster [Mon, 5 Jan 2015 12:10:14 +0000 (13:10 +0100)]
navigate march: Fix "same mob type" and "not on sale" checks

Unlike the other "may move" conditions, "same mobility type
(MOB_MARCH, MOB_RAIL) as leader" and "not on sale" are only checked
when collecting ships and land units.

The former breaks when a deity unwisely edits a land unit's type while
it is being marched.  Messed up when the check was added in commit
36e41e5 (v4.3.7).  However, editing has become possible only recently,
in commit 6b0b6f1.

The latter would break if a ship could be put on the market while it
is being navigated, but that's not possible, because only the owner
can navigate (see also commit 8c502d4), and only the owner can sell.
Same for land units.  Messed up in 4.0.9.  Clean it up anyway.  Bonus:
nicer error message, even spelled correctly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Wipe mission and retreat orders less eagerly
Markus Armbruster [Mon, 5 Jan 2015 10:07:50 +0000 (11:07 +0100)]
navigate march: Wipe mission and retreat orders less eagerly

navi() uses shp_sel() to collect ships, then shp_nav() to drop
ineligible ships.  shp_sel() wipes mission and retreat orders.  Stupid
when shp_nav() will drop them right away.

Avoid that by having shp_sel() check shp_nav()'s conditions, too.

navi()'s shp_nav() call won't find anything to drop now.  The call
will be removed shortly.

This drops "& stays in" from some failure reports, since shp_nav()'s
reject messages end with "& stays in X,Y", and shp_sel()'s don't.

Likewise for marc(), lnd_sel(), lnd_mar().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Give up fortification only on actual move or sweep
Markus Armbruster [Mon, 5 Jan 2015 10:14:31 +0000 (11:14 +0100)]
march: Give up fortification only on actual move or sweep

Don't wipe it in lnd_sel(), rely on lnd_mar_one_sector() and
lnd_sweep() to wipe it when the land unit actually moves.

Closes FRE#43.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Factor lnd_may_mar() out of lnd_mar()
Markus Armbruster [Mon, 5 Jan 2015 09:58:49 +0000 (10:58 +0100)]
subs: Factor lnd_may_mar() out of lnd_mar()

lnd_may_mar() uses lp->lnd_own rather than actor, but that's okay,
lnd_mar() ensures they're the same.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Factor shp_may_nav() out of shp_nav()
Markus Armbruster [Mon, 5 Jan 2015 09:57:19 +0000 (10:57 +0100)]
subs: Factor shp_may_nav() out of shp_nav()

shp_may_nav() uses sp->shp_own rather than actor, but that's okay,
shp_nav() ensures they're the same.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Clean up direction code range checks
Markus Armbruster [Sun, 4 Jan 2015 16:52:36 +0000 (17:52 +0100)]
subs: Clean up direction code range checks

Compare with DIR_LAST instead of DIR_VIEW, to avoid assuming DIR_VIEW
is the first non-direction code.

While there, oops on unexpected code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agobomb fire launch torpedo: Don't disclose ship sinking in retreat
Markus Armbruster [Sun, 4 Jan 2015 12:49:38 +0000 (13:49 +0100)]
bomb fire launch torpedo: Don't disclose ship sinking in retreat

These commands report "sunk!" even when the ship survives the attack
but sinks during retreat.  bomb even reports where on the retreat the
ship sinks.  Has been that way since retreat was added in Chainsaw.

Report "sunk!" only when the attack sinks the ship directly.

Similar code exists for land units, but it doesn't report killings.
Change it anyway, to keep it consistent with the ship code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotorpedo: Fix mobility cost of retreat after hit
Markus Armbruster [Sun, 4 Jan 2015 12:12:48 +0000 (13:12 +0100)]
torpedo: Fix mobility cost of retreat after hit

torp() applies torpedo damage after retreat.  Wrong, because mobility
cost increases with damage.  Broken since retreat was added in
Chainsaw.

Fix by applying damage before retreat.  Bonus: bulletins make more
sense.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoUpdate known contributors comments
Markus Armbruster [Wed, 31 Dec 2014 09:42:30 +0000 (10:42 +0100)]
Update known contributors comments

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoempmod: Fix usage string of retreat and lretreat
Markus Armbruster [Wed, 31 Dec 2014 09:26:05 +0000 (10:26 +0100)]
empmod: Fix usage string of retreat and lretreat

Has been wrong since the commands were added in Chainsaw.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/retreat info/lretreat: Fix and clean up
Markus Armbruster [Wed, 31 Dec 2014 09:02:23 +0000 (10:02 +0100)]
info/retreat info/lretreat: Fix and clean up

.SY claims all arguments are individually optional.  Fix that, and
clarify that omitting the optional arguments shows current orders.

Don't complicate syntax with <SECTS>, <SHIP/FLEET> covers sectors.

The two pages are identical apart from header and footer.  They
mention land units briefly, then explain ship retreat.  Lazy.  Drop
the land unit mention from "info retreat", and rewrite "info lretreat"
for land units.

Update example output for current code.

Don't shout retreat conditions.  We've always accepted both lower and
upper case conditions.  Help has been advertising lower case since
commit bb5dfd8, v4.3.16.

While there, fix a few misspellings and such.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/lretreat: Resync with retreat.t
Markus Armbruster [Wed, 31 Dec 2014 08:55:08 +0000 (09:55 +0100)]
info/lretreat: Resync with retreat.t

Commit 18ee9a2f (v4.2.21) and commit 18ee9a2f (v4.3.16) updated only
info/retreat.t, and missed info/lretreat.t.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/retreat: De-document retreat condition help
Markus Armbruster [Wed, 31 Dec 2014 08:54:08 +0000 (09:54 +0100)]
info/retreat: De-document retreat condition help

Documented in commit dc41544, v4.3.16.  It actually worked only at the
condition prompt then.  No longer recognized elsewhere since commit
c699949.  The documentation is now misleading.  Simply drop it; the
prompt points out how to get help,

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Report where exactly ships and land units sweep mines
Markus Armbruster [Mon, 29 Dec 2014 21:45:20 +0000 (22:45 +0100)]
subs: Report where exactly ships and land units sweep mines

shp_sweep() and lnd_sweep() print only a couple of "Sweep...".
Sometimes, the sector isn't obvious, e.g. when you march multiple
sectors in one go, sweeping along the way.

Print "Approaching minefield at X,Y..." right before the first sweep
in a sector.

Note that retreat.c duplicates the sweeping code.  Retreating ships
report sweeping with coordinates since commit dcd0794, v4.2.21.
Retreating land units still sweep silently.  Left for another day.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Drop contains_engineer(), lnd_find_capable() can do
Markus Armbruster [Mon, 29 Dec 2014 19:13:21 +0000 (20:13 +0100)]
subs: Drop contains_engineer(), lnd_find_capable() can do

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Nicer error messages for sub-command 'm'
Markus Armbruster [Mon, 29 Dec 2014 18:49:39 +0000 (19:49 +0100)]
navigate march: Nicer error messages for sub-command 'm'

Don't report every incapable ship or land unit.  Complain only when
there are no capable ships or land units available.

The ships are all in the same sector, so complain about the sector
type just once instead of once per capable ship or land unit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch attack assault: Hit mines like ships do
Markus Armbruster [Mon, 29 Dec 2014 17:05:30 +0000 (18:05 +0100)]
march attack assault: Hit mines like ships do

When ships enter a sector with sea mines, any minesweepers sweep, then
hit mines, and finally all ships (including the minesweepers) hit
mines.  Sweeping in a sector (navigate sub-command 'm') works the same
without the final step.

When land units enter a sector with land mines, any engineers sweep,
and then all land units (including the engineers) hit mines.  Sweeping
in a sector (march sub-command 'm') works the same, which means
non-engineers can hit mines then.  Broken in Empire 2.

Actually broken for ships too then.  4.0.17 fixed ships, but neglected
to fix land units.

Change the land unit code to work like the ship code.  Fixes march
sub-command 'm' not to expose non-engineers to mines.  Changes march,
attack and assault with option INTERDICT_ATT enabled to expose
engineers twice.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Factor lnd_check_one_mines() out of lnd_check_mines()
Markus Armbruster [Mon, 29 Dec 2014 16:55:56 +0000 (17:55 +0100)]
subs: Factor lnd_check_one_mines() out of lnd_check_mines()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Fix 'm' not to leave engineer without mobility behind
Markus Armbruster [Mon, 29 Dec 2014 16:36:36 +0000 (17:36 +0100)]
march: Fix 'm' not to leave engineer without mobility behind

When lnd_sweep() rejects an engineer for want of mobility, it removes
it from the list of units.

Can happen only when sweeping for march sub-command 'm'.  Any engineer
without mobility is dropped from the march immediately.  Broken in
Empire 2.

Fix lnd_sweep() to handle this case just like the others, and like
shp_sweep(): report and continue with the next list member.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch attack assault: Don't sweep with zero mobility
Markus Armbruster [Mon, 29 Dec 2014 16:32:40 +0000 (17:32 +0100)]
march attack assault: Don't sweep with zero mobility

Require positive mobility for sweeping mines, just like ships do.
Screwed up when land units were added in Chainsaw 3.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agounit: Drop ulist member chrp
Markus Armbruster [Mon, 29 Dec 2014 07:41:23 +0000 (08:41 +0100)]
unit: Drop ulist member chrp

Commit cd8d742 mechanically combined struct mlist's mcp and struct
llist's llp into struct ulist's chrp, adding type casts to every use.
Not necessary, simply use mchr[] and lchr[] directly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/mission: Correct land unit missile interdiction limit
Markus Armbruster [Mon, 29 Dec 2014 06:10:31 +0000 (07:10 +0100)]
info/mission: Correct land unit missile interdiction limit

It's not 100 flat, it's 20 per interdicted land unit.  It's been that
way since Empire 2 at least.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/navigate: Correct and clarify
Markus Armbruster [Mon, 29 Dec 2014 06:09:35 +0000 (07:09 +0100)]
info/navigate: Correct and clarify

Don't claim the lowest-numbered land unit is always the leader.

Reword the explanation of the prompt.

Update example output for current code.

Clarify that a destination sector is also accepted interactively, not
just on the command line.

Missiles interdict just the valuable ships, unlike other interdiction.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoinfo/march: Correct and clarify
Markus Armbruster [Mon, 29 Dec 2014 06:02:05 +0000 (07:02 +0100)]
info/march: Correct and clarify

Don't claim the army stops when the leader stops.

Don't claim the lowest-numbered land unit is always the leader.

The prompt shows minimum mobility, not leader mobility.

Clarify that a destination sector is also accepted interactively, not
just on the command line.  Fix the example output, and update for
current code.

Replace incorrect landmine hit chance formula by a reference to "info
Hitchance".

Drop incorrect damage limit for missile interdiction, rely on the
reference to "info mission" instead.

The hit chance of missiles and pin-bombers interdicting land units is
not 100%, but depends on the marching land unit that is easiest to hit.

Clarify that interdiction damage is spread evenly among the marching
land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Clean up convoluted logic in lnd_mar_one_sector()
Markus Armbruster [Sun, 28 Dec 2014 21:51:56 +0000 (22:51 +0100)]
subs: Clean up convoluted logic in lnd_mar_one_sector()

Handle "no movement" before the movement loop instead of relying on
the first iteration of the loop.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Clean up convoluted logic in shp_nav_one_sector()
Markus Armbruster [Sun, 28 Dec 2014 21:50:17 +0000 (22:50 +0100)]
subs: Clean up convoluted logic in shp_nav_one_sector()

Handle "no movement" before the movement loop instead of relying on
the first iteration of the loop.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate: Don't disclose whether unfriendly canal is navigable
Markus Armbruster [Sun, 28 Dec 2014 21:43:47 +0000 (22:43 +0100)]
navigate: Don't disclose whether unfriendly canal is navigable

When you try to navigate a ship without canal capability into an
unfriendly canal, you get "can't go" when it's below 2%, else "too
large to fit".  Always report "can't go" for unfriendly sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Drop unit_path() parameter together
Markus Armbruster [Sun, 28 Dec 2014 21:36:25 +0000 (22:36 +0100)]
subs: Drop unit_path() parameter together

It's always non-zero now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate march: Drop do_unit_move() parameter together
Markus Armbruster [Sun, 28 Dec 2014 21:32:23 +0000 (22:32 +0100)]
navigate march: Drop do_unit_move() parameter together

It's always non-zero now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate: Require all ships to start in the same sector
Markus Armbruster [Sun, 28 Dec 2014 21:27:37 +0000 (22:27 +0100)]
navigate: Require all ships to start in the same sector

The capability to navigate ships spread over several sectors is
obscure and rarely useful.  Accidental use is probably more frequent
than intentional use.  Issues:

* Interactive prompts show only the flagship's position, and give no
  clue that some ships are actually elsewhere.

* Path finding is supported only when all navigating ships are in
  the same sector.

* Interdiction becomes rather complex.  For each movement, every
  sector entered is interdicted independently.  This means the same
  fort, ship, land unit or plane can interdict multiple times.
  Interdiction order depends on the order the code examines
  ships. which the player can control.  This is all pretty much
  undocumented.

* Complicates the code and its maintenance.  Multiplies the number of
  test cases needed to cover navigate.

I feel we're better off without this feature.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Require all land units to start in the same sector
Markus Armbruster [Sun, 28 Dec 2014 21:24:17 +0000 (22:24 +0100)]
march: Require all land units to start in the same sector

The capability to march land units spread over several sectors is
obscure and rarely useful.  Accidental use is probably more frequent
than intentional use.  Issues:

* Interactive prompts show only the leader's position, and give no
  clue that some land units are actually elsewhere.

* Path finding is supported only when all marching land units are in
  the same sector.

* In each step, the bmap is updated for the leader's radar.  The bmap
  is not updated around other marching land units.  Already odd when
  all units are in the leader's sector, and odder still when some are
  elsewhere.

* Interdiction becomes rather complex.  For each movement, every
  sector entered is interdicted independently.  This means the same
  ship, land unit or plane can interdict multiple times.  Interdiction
  order depends on the order the code examines land units. which the
  player can control.  This is all pretty much undocumented.

* Complicates the code and its maintenance.  Multiplies the number of
  test cases needed to cover march.

I feel we're better off without this feature.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Drop has_units() parameter lp, it's always null now
Markus Armbruster [Sun, 28 Dec 2014 20:59:05 +0000 (21:59 +0100)]
subs: Drop has_units() parameter lp, it's always null now

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Check for sector abandonment before anyone marches
Markus Armbruster [Sun, 28 Dec 2014 20:55:44 +0000 (21:55 +0100)]
march: Check for sector abandonment before anyone marches

Unlike the move command, march checks sector abandonment before every
step.

If the player declines, the last land unit stays put and is removed
from the march.

Except when sectors or land units change while we're waiting for the
player's reply.  Then the last unit is not removed from the march.
This can scatter land units.  Screwed up when checking for abandoning
the sector was added in 4.2.2.

Change march to work like move, and to avoid scattering land units: if
the player declines to abandon the sector, the command simply fails.

Put the check into new lnd_abandon_askyn().

Extend would_abandon() and want_to_abandon() from a single land unit
to many.  Rename the latter to abandon_askyn() for consistency.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Move sector abandonment functions to control.c
Markus Armbruster [Sun, 28 Dec 2014 20:42:02 +0000 (21:42 +0100)]
subs: Move sector abandonment functions to control.c

Move them out of commands/move.c, because they're the only thing
involving land units there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agogen: New emp_quelen(), replacing open-coded counting loops
Markus Armbruster [Sun, 28 Dec 2014 20:38:13 +0000 (21:38 +0100)]
gen: New emp_quelen(), replacing open-coded counting loops

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Add unitsatxy() parameter only_count
Markus Armbruster [Sun, 28 Dec 2014 20:34:18 +0000 (21:34 +0100)]
subs: Add unitsatxy() parameter only_count

Like shipsatxy().  To be used shortly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Don't scatter land units on crossing border
Markus Armbruster [Sun, 28 Dec 2014 19:32:16 +0000 (20:32 +0100)]
march: Don't scatter land units on crossing border

When attempting to enter a sector with a land unit that can't go there
while the marching land units are all in the same sector, march stops
and prompts without removing the incapable land unit from the group.
If another land unit has already entered the sector, the group becomes
scattered.

This can happen when marching a mixed group of spies and non-spies
into a non-allied sector.  Same for marching a mixed group of trains
and non-trains into a sector without rail, except such groups have
been disallowed since commit 36e41e5 (v4.3.7).  Both screwed up when
spies and trains were added in 4.0.0

Remove the incapable land unit from the group when another land unit
can enter the sector.  This avoids scattering land units.

Don't remove incapable land units when no land unit can enter the
sector.  Without this, march would remove everyone and end then.

It can also happen when sectors or land units change while we're
sitting at the "Do you really want to abandon X,Y" prompt.  I'm going
to fix that differently.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Make shp_check_nav() more like lnd_check_mar()
Markus Armbruster [Sun, 28 Dec 2014 19:12:01 +0000 (20:12 +0100)]
subs: Make shp_check_nav() more like lnd_check_mar()

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agomarch: Don't permit trains to march out of sectors without rail
Markus Armbruster [Sun, 28 Dec 2014 18:58:52 +0000 (19:58 +0100)]
march: Don't permit trains to march out of sectors without rail

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Factor lnd_check_mar() out of lnd_mar_one_sector()
Markus Armbruster [Sun, 28 Dec 2014 18:47:45 +0000 (19:47 +0100)]
subs: Factor lnd_check_mar() out of lnd_mar_one_sector()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Don't hardcode impassable sector types
Markus Armbruster [Sun, 28 Dec 2014 18:06:16 +0000 (19:06 +0100)]
subs: Don't hardcode impassable sector types

Check for d_mob0 < 0 instead, like we do elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonavigate: Don't scatter ships on canal entry
Markus Armbruster [Sun, 28 Dec 2014 16:42:44 +0000 (17:42 +0100)]
navigate: Don't scatter ships on canal entry

When attempting to enter a sector with a ship that can't go there
while the navigating ships are all in the same sector, navigate stops
and prompts without removing the incapable ship from the group.  If
another ship has already entered the sector, the group becomes
scattered.

This can happen only when navigating a mixed group of ships with and
without canal capability into a canal.  Broken in commit 74e4e281,
v4.3.0.

Remove the incapable ship from the group when another ship can enter
the sector.  This avoids scattering ships.

Don't remove incapable ships when no ship can enter the sector.
Without this, navigate would remove everyone and end then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosubs: Give shp_nav_put(), lnd_mar_put() internal linkage
Markus Armbruster [Fri, 26 Dec 2014 08:53:55 +0000 (09:53 +0100)]
subs: Give shp_nav_put(), lnd_mar_put() internal linkage

With autonav and SAIL gone, shp_nav_put() isn't used externally
anymore.  lnd_mar_put() never was; it got external linkage just for
symmetry.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agosail: Remove option SAIL
Markus Armbruster [Wed, 24 Dec 2014 20:42:51 +0000 (21:42 +0100)]
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>
7 years agoautonav: Remove the feature
Markus Armbruster [Wed, 24 Dec 2014 15:33:51 +0000 (16:33 +0100)]
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>
7 years agonavigate: Fix buffer overrun for impossibly long paths taken
Markus Armbruster [Mon, 22 Dec 2014 14:29:17 +0000 (15:29 +0100)]
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>
7 years agotests/navi-march: New; exercises navigate and march command
Markus Armbruster [Sun, 28 Dec 2014 07:03:28 +0000 (08:03 +0100)]
tests/navi-march: New; exercises navigate and march command

Does not cover scattered navigate and march, RAILWAYS 0, enemy action
while sitting at the prompt, and interdiction.

The test exposes bugs.  They're marked "BUG:" in the test input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: New helper customize
Markus Armbruster [Sun, 28 Dec 2014 07:01:35 +0000 (08:01 +0100)]
tests: New helper customize

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/fire: Drop a stale comment
Markus Armbruster [Mon, 22 Dec 2014 09:06:24 +0000 (10:06 +0100)]
tests/fire: Drop a stale comment

Should have been dropped in commit b7bcf8f.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agodoc/econfig: Belatedly drop paragraph on holes in tables
Markus Armbruster [Mon, 22 Dec 2014 09:03:38 +0000 (10:03 +0100)]
doc/econfig: Belatedly drop paragraph on holes in tables

Holes work since commit 7457573, v4.3.28.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Polish error messages
Markus Armbruster [Tue, 18 Feb 2014 19:21:26 +0000 (20:21 +0100)]
xundump: Polish error messages

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoClean up extra semicolon after block
Markus Armbruster [Sun, 16 Feb 2014 08:10:42 +0000 (09:10 +0100)]
Clean up extra semicolon after block

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoempdump: Omit redundant data from export, new -c includes it
Markus Armbruster [Sun, 9 Feb 2014 16:48:36 +0000 (17:48 +0100)]
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>
7 years agofile: New ef_typedstr_eq(), factored out of obj_changed()
Markus Armbruster [Sun, 9 Feb 2014 16:26:44 +0000 (17:26 +0100)]
file: New ef_typedstr_eq(), factored out of obj_changed()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agofile: Rename struct emptypedstr to ef_typedstr
Markus Armbruster [Sun, 9 Feb 2014 16:24:10 +0000 (17:24 +0100)]
file: Rename struct emptypedstr to ef_typedstr

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Permit omitting non-trailing realms
Markus Armbruster [Sun, 9 Feb 2014 09:20:15 +0000 (10:20 +0100)]
xundump: Permit omitting non-trailing realms

This involves computing the realm ID from fields cnum, realm.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Permit omitting non-trailing sectors
Markus Armbruster [Sun, 9 Feb 2014 09:01:59 +0000 (10:01 +0100)]
xundump: Permit omitting non-trailing sectors

This involves computing the sector ID from fields xloc, yloc.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Eliminate global cur_obj
Markus Armbruster [Sat, 8 Feb 2014 18:28:30 +0000 (19:28 +0100)]
xundump: Eliminate global cur_obj

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Code motion to clean up after previous commit
Markus Armbruster [Sat, 8 Feb 2014 17:25:49 +0000 (18:25 +0100)]
xundump: Code motion to clean up after previous commit

The previous commit avoided code motion to ease review.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Don't require ID field to come first
Markus Armbruster [Sat, 8 Feb 2014 16:51:37 +0000 (17:51 +0100)]
xundump: Don't require ID field to come first

The code needs it first so it can store field values into the object
right away.  Save the values instead, and store them when the row is
complete.

The improvement is hardly worth the trouble by itself, but it'll
simplify supporting keys consisting of multiple fields, like sector
xloc, yloc or realm cnum, realm, so we can omit rows in those tables,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Eliminate global may_trunc, may_omit_id
Markus Armbruster [Sat, 8 Feb 2014 15:52:14 +0000 (16:52 +0100)]
xundump: Eliminate global may_trunc, may_omit_id

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Permit omitting trailing sectors and realms
Markus Armbruster [Sat, 8 Feb 2014 14:11:51 +0000 (15:11 +0100)]
xundump: Permit omitting trailing sectors and realms

We currently require all rows to be present for tables item, sect-chr,
infrastructure, sect, realm.

The first three make sense: the code hard-codes indexes for them, and
malfunctions when entries are blank, so we want to make it hard to
leave any blank by accident.

The last two don't: blank sectors and realms work fine.  There, the
restriction is arbitrary.  Drop it.

Sectors and realms still can't be omitted "in the middle" (can do that
only with an ID selector), but that's coming soon.

See also commit 4a4ec91.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Support splitting any table
Markus Armbruster [Sat, 8 Feb 2014 11:16:34 +0000 (12:16 +0100)]
xundump: Support splitting any table

Each part of a split table needs to supply rows for the same objects.
We currently require each part to name its objects explicitly, with an
object ID field, and don't support splitting tables that don't have
such IDs.  These restrictions became arbitrary when commit 4e23c45
implemented checking each partial table supplies the same rows.  Relax
them.

Affects tables sect, news, lost, realm, game, infrastructure.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoxundump: Report all missing fields, not just first one
Markus Armbruster [Sun, 2 Feb 2014 11:24:22 +0000 (12:24 +0100)]
xundump: Report all missing fields, not just first one

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonsc: Turn NSC_HIDDEN into a flag
Markus Armbruster [Sun, 2 Feb 2014 11:09:18 +0000 (12:09 +0100)]
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>
7 years agonsc: Reject array selectors in conditions
Markus Armbruster [Sun, 2 Feb 2014 09:29:18 +0000 (10:29 +0100)]
nsc: Reject array selectors in conditions

Array selectors were introduced for xdump (commit 612f2da, v4.2.18).
Since there is no syntax for subscripting arrays in conditions and
survey, we silently assume index zero.  Unclean.  Reject the selector
instead.

Affects ship selectors cargostart, cargoend, amtstart, amtend (since
commit 32011f1, v4.2.19), nat selectors relations (commit 0a44c48,
v4.3.0), contacts (commit c345ab8, v4.3.0), rejects (commit 6844c94,
v4.3.4).  The other array selectors aren't visible in conditions.  No
array selectors are visible in survey.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()
Markus Armbruster [Sun, 2 Feb 2014 09:13:41 +0000 (10:13 +0100)]
nsc: Turn common patterns into CA_IS_ARRAY() and CA_ARRAY_LEN()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonsc: Rename nstr_exec_val() to nstr_eval() and tighten contract
Markus Armbruster [Sun, 2 Feb 2014 08:39:35 +0000 (09:39 +0100)]
nsc: Rename nstr_exec_val() to nstr_eval() and tighten contract

nstr_exec_val() can produce three different error values: NSC_NOTYPE
on invalid category, invalid type with zero val_as.lng on invalid type
(this is a bug), and the wanted type with zero val_s when it can't
coerce.  None of these should ever happen.

Fix it to always produce an NSC_NOTYPE error value.  Fix up callers to
check for it.

Specify the result's type is promoted on success.  Ensure it is even
when the argument is NSC_VAL with an unpromoted type, which is
invalid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/empdump: New; exercising the empdump utility
Markus Armbruster [Wed, 29 Jan 2014 19:24:26 +0000 (20:24 +0100)]
tests/empdump: New; exercising the empdump utility

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: New helper cmp_out1
Markus Armbruster [Wed, 29 Jan 2014 20:09:04 +0000 (21:09 +0100)]
tests: New helper cmp_out1

Factor out of cmp_out, then make it optionally take an explicit
expected result.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests/files tests/fairland: Check stderr and exit status
Markus Armbruster [Wed, 29 Jan 2014 19:12:18 +0000 (20:12 +0100)]
tests/files tests/fairland: Check stderr and exit status

New helper run_and_cmp to automate the job: run a program capturing
its standard output, standard error and exit status, then compare the
actual with the expected results.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: Fix missing local in feed_files and cmp_out
Markus Armbruster [Wed, 29 Jan 2014 19:11:25 +0000 (20:11 +0100)]
tests: Fix missing local in feed_files and cmp_out

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: Simplify running cmp_out more than once
Markus Armbruster [Wed, 29 Jan 2014 18:56:38 +0000 (19:56 +0100)]
tests: Simplify running cmp_out more than once

When cmp_out detects a test failure, it returns non-zero status, which
terminates the test script unless caught.

Accumulate failures in a global variable checked at exit instead, so
running it multiple times in a test script just works.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: Feed only logs and xdump to normalize.pl
Markus Armbruster [Tue, 28 Jan 2014 19:33:19 +0000 (20:33 +0100)]
tests: Feed only logs and xdump to normalize.pl

Feeding other test output files (right now tests/files/files.out
tests/fairland/fairland.out fairland/newcap_script) works, but it's
odd, and might not work as well for all future output files.  Only
strip trailing white space there.

There used to be other output files that required normalize.pl: client
output.  Gone since commit 9ca3fa9.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agotests: Define and use some abbreviations
Markus Armbruster [Tue, 28 Jan 2014 18:29:11 +0000 (19:29 +0100)]
tests: Define and use some abbreviations

No functional change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agofile: Provide EF_WITH_CADEF_MAX_ENTRY_SIZE to clean up xditem()
Markus Armbruster [Mon, 27 Jan 2014 19:57:20 +0000 (20:57 +0100)]
file: Provide EF_WITH_CADEF_MAX_ENTRY_SIZE to clean up xditem()

xditem() needs a buffer that can hold entries of any xdumpable table.
It's been 2048 bytes and marked FIXME since day one.  Clean it up so
that if anyone ever goes crazy with entry sizes, we fail an assertion
during startup instead of overrunning the buffer during play.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agoplayer: Drop long-disabled code to resolve IP addresses
Markus Armbruster [Mon, 27 Jan 2014 19:28:39 +0000 (20:28 +0100)]
player: Drop long-disabled code to resolve IP addresses

Disabled since commit 32fac04 (v4.2.13) because it could at the time
use more stack space than we provided.  Additional issues: code still
uses obsolete gethostbyaddr() rather than getnameinfo(), and we
provide only 512 bytes for host names instead of the customary
NI_MAXHOST (1025) bytes.

All three issues would be easy enough to fix.  What's not so easy is
to avoid blocking on the synchronous DNS lookup.  Without that,
connecting repeatedly from a range of addresses with slow reverse
lookup could conceivably be employed as a denial of service attack.

We've been living without reverse lookup for close to ten years.  Bury
the corpse, and move on.

Bonus: sizeof(struct natstr) is cut in half.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
7 years agonat: Deprecate selector hostname, fix value to ""
Markus Armbruster [Mon, 27 Jan 2014 19:03:29 +0000 (20:03 +0100)]
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>