empserver
22 months agofairland: Rename INFINITY to INFINITE_ELEVATION
Markus Armbruster [Sat, 8 Aug 2020 11:59:37 +0000 (13:59 +0200)]
fairland: Rename INFINITY to INFINITE_ELEVATION

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Simplify search for next wilderness to elevate
Markus Armbruster [Sun, 16 Aug 2020 15:42:02 +0000 (17:42 +0200)]
fairland: Simplify search for next wilderness to elevate

To find the wilderness sector to elevate next, elevate_land() searches
the non-mountain, non-capital sectors of the island for one that
maximizes a function of its distance to mountains and to sea.

The search ignores already elevated sectors in a less than obvious
way: 1. it never picks a sector where the function yields -INFINITY or
less, and 2. when elevating a wilderness, its (cached) distances get
reset to values that make the function return a more negative value.

Use a more direct check of "not yet elevated": elevation is still the
initial -INFINITY.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Use INT_MAX as initial minimal distance in iso()
Markus Armbruster [Sun, 26 Jul 2020 05:30:58 +0000 (07:30 +0200)]
fairland: Use INT_MAX as initial minimal distance in iso()

Simpler and more obviously correct than WORLD_X + WORLD_Y.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Nicer & much faster replacement for next_vector()
Markus Armbruster [Sat, 25 Jul 2020 12:08:38 +0000 (14:08 +0200)]
fairland: Nicer & much faster replacement for next_vector()

next_vector() is kind of cute, but it is also unobvious, cumbersome to
use, and slow for arguments greater than one.

Replace it by hexagon_first(), hexagon_next().  The new code takes
O(1) time, whereas the old code takes O(n).  Iterating over a hexagon
changes from

       for (i = 0; i < n; ++i)
           vector[i] = 0;
       do {
           x = x0;
           y = y0;
           for (i = 0; i < n; ++i) {
               x = new_x(x + dirx[vector[i]]);
               y = new_y(y + diry[vector[i]]);
           }
   do stuff with @x, @y...
       } while (next_vector(n));

to

       hexagon_first(&hexit, x0, y0, n, &x, &y);
       do {
   do stuff with @x, @y...
       } while (hexagon_next(&hexit, &x, &y));

In my measurements, it's ~8% slower for n == 1, 25% faster for n == 2,
and more than three times faster for n == 6.

fairland's performance is dominated by it.  Creating worlds for the
Common Fever blitz (distance arguments 3 and 2) and the Hvy Fever
Blitz (distance arguments 6 and 3) on my machine speeds up by a factor
of 1.6 and 2.1, respectively.

Of course, fairland performance is hardly an issue on today's
machines: it takes fairly impractical setups to push run time over a
second.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Report missing and stunted islands
Markus Armbruster [Sat, 25 Jul 2020 06:13:54 +0000 (08:13 +0200)]
fairland: Report missing and stunted islands

fairland can create fewer and smaller islands than the user requested.
Report like this:

    No room for island #13
    6 stunted islands

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Check first two continent sectors properly
Markus Armbruster [Tue, 11 Aug 2020 05:52:45 +0000 (07:52 +0200)]
fairland: Check first two continent sectors properly

grow_continents() places the first two continent sectors without
checking for collisions or minimum distance.  Unlikely to be an issue
in practice, as growing such a continent will almost certainly fail.
Fix it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move "is water" check into try_to_grow()
Markus Armbruster [Tue, 11 Aug 2020 05:51:30 +0000 (07:51 +0200)]
fairland: Move "is water" check into try_to_grow()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move capital initialization to drift() & simplify
Markus Armbruster [Mon, 10 Aug 2020 15:55:15 +0000 (17:55 +0200)]
fairland: Move capital initialization to drift() & simplify

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move initialization of elev into create_elevations()
Markus Armbruster [Mon, 10 Aug 2020 15:48:21 +0000 (17:48 +0200)]
fairland: Move initialization of elev into create_elevations()

Move it so the next commit can inline init() into drift().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move global variables mc[] into stable(), eliminate mcc
Markus Armbruster [Sun, 26 Jul 2020 10:35:15 +0000 (12:35 +0200)]
fairland: Move global variables mc[] into stable(), eliminate mcc

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Fix "Only managed to grow" error message off by one
Markus Armbruster [Sat, 25 Jul 2020 07:20:09 +0000 (09:20 +0200)]
fairland: Fix "Only managed to grow" error message off by one

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Eliminate global variable @fl_status
Markus Armbruster [Sat, 25 Jul 2020 07:01:56 +0000 (09:01 +0200)]
fairland: Eliminate global variable @fl_status

grow_one_sector() sets @fl_status when it fails to grow a continent.
grow_continents() uses @fl_status to find out whether
grow_one_sector() succeeded, and main() uses it to find out whether
grow_continents() succeeded.

Change grow_continents() to return success / failure.
grow_one_sector() already does.  Use the return values, and eliminate
@fl_status.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Eliminate global variable @secs
Markus Armbruster [Sat, 25 Jul 2020 15:40:19 +0000 (17:40 +0200)]
fairland: Eliminate global variable @secs

Move global variable @secs into grow_islands() and grow_continents().
Its other users can use isecs[c] instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move global variable @spike into grow_one_sector()
Markus Armbruster [Sat, 25 Jul 2020 15:30:51 +0000 (17:30 +0200)]
fairland: Move global variable @spike into grow_one_sector()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Global variable @mind is write-only, drop
Markus Armbruster [Sat, 25 Jul 2020 07:22:35 +0000 (09:22 +0200)]
fairland: Global variable @mind is write-only, drop

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Set isecs[] for continents as well & simplify
Markus Armbruster [Sat, 25 Jul 2020 05:28:28 +0000 (07:28 +0200)]
fairland: Set isecs[] for continents as well & simplify

isecs[] is left zero for continents.  Set it to @sc instead, and
simplify two loops over land sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: De-duplicate map from elevation to sector type
Markus Armbruster [Sat, 8 Aug 2020 11:26:43 +0000 (13:26 +0200)]
fairland: De-duplicate map from elevation to sector type

Both write_sects() and map_symbol() map from elevation to sector type.
Factor out as elev_to_sct_type().  Inline map_symbol() into output()
and simplify.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Fix checking of distance arguments
Markus Armbruster [Mon, 10 Aug 2020 13:39:45 +0000 (15:39 +0200)]
fairland: Fix checking of distance arguments

main() rejects the distance between continents when it exceeds WORLD_X
/ 2 and WORLD_Y / 2, and the distance between continents and islands
when it exceeds WORLD_Y and WORLD_Y.  Nuts.  Has always been that way.

Reject either when it exceeds the maximum distance between sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoRevert "Make fairland finish argument parsing before reading econfig"
Markus Armbruster [Mon, 10 Aug 2020 13:39:45 +0000 (15:39 +0200)]
Revert "Make fairland finish argument parsing before reading econfig"

This reverts commit d2a7bb6b6fed02d2cf48682d7d2a52a16d5d90e9.

parse_args() uses WORLD_X and WORLD_Y to check the distance arguments.
Calling it before reading econfig is wrong, because at that time
WORLD_X and WORLD_Y still have the compiled-in default values instead
of the actual ones set in econfig.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Reject continent size 1
Markus Armbruster [Sun, 26 Jul 2020 11:47:44 +0000 (13:47 +0200)]
fairland: Reject continent size 1

fairland creates continents of size 1 just fine, but the newcap_script
it emits doesn't work: the newcap command requires a second wilderness
sector to the right of the first sector.

Reject continent size 1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Simplify defaulting optional positional arguments
Markus Armbruster [Mon, 10 Aug 2020 13:24:30 +0000 (15:24 +0200)]
fairland: Simplify defaulting optional positional arguments

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Check positional arguments more thoroughly
Markus Armbruster [Mon, 10 Aug 2020 13:24:30 +0000 (15:24 +0200)]
fairland: Check positional arguments more thoroughly

fairland silently "corrects" some bad arguments.  Reject them instead.
It neglects to check others completely.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Consistent error message format
Markus Armbruster [Sun, 26 Jul 2020 11:15:03 +0000 (13:15 +0200)]
fairland: Consistent error message format

fairland prefixes error messages with several variations of "fairland:
error -- ", but also with "ERROR: " and nothing at all.  Consistently
prefix them with just the program name.

Some error messages end with a period, most don't.  Drop the periods.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Report errors to stderr, not stdout
Markus Armbruster [Sun, 26 Jul 2020 11:15:03 +0000 (13:15 +0200)]
fairland: Report errors to stderr, not stdout

fairland reports some errors to stdout instead of stderr.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Tweak progress messages
Markus Armbruster [Sat, 8 Aug 2020 11:34:02 +0000 (13:34 +0200)]
fairland: Tweak progress messages

"fairland: unstable drift -- try increasing DRIFT_MAX" is confusing:
it looks like an error, but isn't, and increasing DRIFT_MAX requires a
recompile.  I'm not sure it can happen.  Replace by just "unstable
drift".

"fairland: error -- continent %c had no room to grow!" is pretty
redundant: it's always followed by "Only managed to grow %d out of %d
sectors."  and then "ERROR: World not large enough to hold
continents".  All it adds is which of the continents failed to grow,
and that's not actionable.  Drop the message.

The message sequence "designating sectors...", "adding resources...",
"setting coastal flags...", and "writing to sectors file..." is a bit
of a lie as these four tasks aren't actually done one after the other.
Replace by just "writing to sectors file..."

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Drop "might be too small to fit continents" warning
Markus Armbruster [Sun, 2 Aug 2020 05:02:20 +0000 (07:02 +0200)]
fairland: Drop "might be too small to fit continents" warning

Commit de81e4e20 "Change fairland not to reject small worlds without
trying" (v4.3.25) downgraded it from error to warning, pointing out it
the size may well work, and when it doesn't, fairland fails cleanly.

When it works, the warning is pointless.  When it doesn't, it's
redundant.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Collect command line global variables in one place
Markus Armbruster [Sun, 2 Aug 2020 06:23:16 +0000 (08:23 +0200)]
fairland: Collect command line global variables in one place

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoman/fairland: Fix typos, polish markup, clarify text
Markus Armbruster [Sun, 26 Jul 2020 15:24:24 +0000 (17:24 +0200)]
man/fairland: Fix typos, polish markup, clarify text

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Drop option -o
Markus Armbruster [Tue, 11 Aug 2020 11:11:15 +0000 (13:11 +0200)]
fairland: Drop option -o

With -o, fairland doesn't add resources.  This is pretty redundant;
the deity can unset resources with "edit l * i 0 g 0 f 0 c 0 u 0".
Drop the option.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Drop option -a
Markus Armbruster [Sun, 26 Jul 2020 15:29:09 +0000 (17:29 +0200)]
fairland: Drop option -a

With -a, fairland makes the capital sector an airfield to "mark the
continents [...] so that you can tell them from the islands".  This is
pretty redundant since commit afc0ef94e "Make fairland record the
island number in the deity territory", v4.3.31.  Drop it.

The map fairland prints is not affected.  The continents are clearly
visible there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Make write_newcap_script() failure fatal
Markus Armbruster [Sat, 25 Jul 2020 07:03:03 +0000 (09:03 +0200)]
fairland: Make write_newcap_script() failure fatal

When write_newcap_script() fails, it complains to stderr and fails.
main() doesn't bother to check for failure.  Has always been that way.
Fix main() to check.  Also adjust write_newcap_script() to return one
on success, zero on failure, like the other functions do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Move #include to the beginning where they belong
Markus Armbruster [Sun, 26 Jul 2020 11:48:26 +0000 (13:48 +0200)]
fairland: Move #include to the beginning where they belong

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Add a comment describing how fairland works
Markus Armbruster [Sat, 25 Jul 2020 06:06:19 +0000 (08:06 +0200)]
fairland: Add a comment describing how fairland works

A comment describing how fairland works was lost some time after
Chainsaw 3.31.  This is the last known version:

    The algorithm starts out by placing the "capitols" on the torus in
    such a way so as to maximize their distances from one another (this
    uses the perterbation technique of calculus of variations).  Then from
    these seeds, the continents are grown.  The kind of shape they grow
    into is determined by the "spike" argument <sp>--the higher the spike,
    the more spindly they will be.  If you lower the spike, the continents
    will be more round.  The continents never touch one another, the
    argument <di> specifies how many sectors of water should be between
    the continents at all times.  The continents grow to the size you
    specify with <sc> and they all get the same number of mountains
    (specified by <pm>).  The other arguments should be self explanitory.
    If #define ORE 1, then resources will be placed in the sectors as well.
    You can alter the #define ORE_MAX, IRON_MIN, GOLD_MIN, FERT_MAX and
    URAN_MIN to affect what kind of resources the world gets.

It leaves much to be desired.  Add a more thorough one.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Add print_own_map(), print_elev_map() for debugging
Markus Armbruster [Tue, 11 Aug 2020 06:26:36 +0000 (08:26 +0200)]
fairland: Add print_own_map(), print_elev_map() for debugging

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/fairland: Cover "plenty of space" better
Markus Armbruster [Wed, 29 Jul 2020 04:49:39 +0000 (06:49 +0200)]
tests/fairland: Cover "plenty of space" better

Reduce number of islands in fairland run "plain" so there's plenty of
space for them.  Scarce space is still covered by run "stunted".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/fairland: Improve coverage
Markus Armbruster [Tue, 28 Jul 2020 04:44:08 +0000 (06:44 +0200)]
tests/fairland: Improve coverage

Rename the existing fairland run to "plain".

New run "stunted" to cover larger minimal distances, islands
that can't fully grow, and islands that can't be placed.

New run "no-spike" to cover 0% spike.

New run "spike" to cover high spike percentage, mountains and -i.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agofairland: Show a more useful map
Markus Armbruster [Mon, 17 Aug 2020 10:39:04 +0000 (12:39 +0200)]
fairland: Show a more useful map

The map fairland shows has absolute 0,0 in the top-left corner, while
POGO's map * has it in the center.  Shift fairland's map to match
POGO's.

The map shows sea as '.', island sectors as '%', capitals as '#',
mountains as '^', and other continental sectors as a letter or digit
that encodes the continent number modulo 62.  When a continent has no
"other" sectors, its continent number is not shown.  Remove this
pathological case by using letter/digit for capitals, and '#' for
other continental sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/empdump: Fix to honor "make check-accept"
Markus Armbruster [Tue, 28 Jul 2020 04:41:41 +0000 (06:41 +0200)]
tests/empdump: Fix to honor "make check-accept"

Delete stray EMPIRE_CHECK_ACCEPT=.  Goes back all the way to commit
5a1544f92 "tests/empdump: New; exercising the empdump utility".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests: Make "make check-accept" accept new files
Markus Armbruster [Tue, 28 Jul 2020 04:24:17 +0000 (06:24 +0200)]
tests: Make "make check-accept" accept new files

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests: Drop some dead code from test-common.sh
Markus Armbruster [Tue, 28 Jul 2020 04:21:46 +0000 (06:21 +0200)]
tests: Drop some dead code from test-common.sh

Left behind by commit c594b6120 "tests: New helper cmp_out1".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoUpdate copyright notice
Markus Armbruster [Sun, 19 Jul 2020 06:37:48 +0000 (08:37 +0200)]
Update copyright notice

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agodamage: Shield embarked planes and land units from sector damage
Markus Armbruster [Thu, 10 May 2018 15:55:50 +0000 (17:55 +0200)]
damage: Shield embarked planes and land units from sector damage

Damage to a ship or land unit, say via pinpoint bombing, doesn't
damage loaded planes and land units.

Damage to a sector, say via strategic bombing, doesn't damage ships
there, but it does damage planes, even when loaded on a land unit (but
not when loaded on a ship), and land units, even when loaded on a land
unit or a ship.

This makes no sense.  Sector damage spills over to land units that way
since Chainsaw 3 added them, and to planes since 4.0.9.

Change sectdamage() not to damage land units and planes loaded on
ships or land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload lload: Refuse to load satellites in space
Markus Armbruster [Sat, 12 May 2018 07:50:17 +0000 (09:50 +0200)]
load lload: Refuse to load satellites in space

Doesn't affect the stock game, because none of its satellites are
light, let alone x-light.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agolaunch edit: Take satellite off carrier on launch
Markus Armbruster [Sat, 12 May 2018 07:46:51 +0000 (09:46 +0200)]
launch edit: Take satellite off carrier on launch

Doesn't affect the stock game, because none of its satellites are
light, let alone x-light.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload: Move check for hardened plane into plane_loadable()
Markus Armbruster [Fri, 11 May 2018 16:58:51 +0000 (18:58 +0200)]
load: Move check for hardened plane into plane_loadable()

This de-duplicates the check, and skips it when unloading.  It never
made sense there, and can't happen anymore since the previous commit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agosubs: Maintain plane and land unit fortification invariant
Markus Armbruster [Fri, 11 May 2018 05:58:34 +0000 (07:58 +0200)]
subs: Maintain plane and land unit fortification invariant

Make lnd_prewrite() and pln_prewrite() ensure that land units and
missiles loaded on a land unit or ship are never fortified / hardened.

This takes care of edit neglecting to zap fortification on load.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoedit: Fix fortification limit of embarked planes and land units
Markus Armbruster [Thu, 10 May 2018 16:32:54 +0000 (18:32 +0200)]
edit: Fix fortification limit of embarked planes and land units

We generally preserve the invariant "land units and missiles loaded on
a land unit or ship are never fortified / hardened": fortify and
harden refuse to touch embarked land units and missiles, load and
lload zap land unit fortification on load, and refuse to load hardened
missiles.

The exception is edit, which happily fortifies embarked land units
(edit u key 'F'), hardens embarked missiles (edit p key 'F'), loads
fortified land units (edit u keys 'S' and 'Y') and hardened planes
(edit p keys 's' and 'y').

Fix the first two by correcting the new value's upper limit to zero
for embarked land units and planes.  The next commit will take care of
the rest.

The fix is visible in tests where test setup fortifies land units with
"edit u * F ?..." without excepting embarked ones.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/actofgod: Cover loading hardened missiles
Markus Armbruster [Fri, 11 May 2018 06:27:12 +0000 (08:27 +0200)]
tests/actofgod: Cover loading hardened missiles

Demonstrates that edit leaves a missile's hardening intact on load.

Loading fortified land units is already covered, and also leaves
fortification intact.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload: Factor out plane_loadable(), land_loadable()
Markus Armbruster [Sun, 3 Sep 2017 15:58:42 +0000 (17:58 +0200)]
load: Factor out plane_loadable(), land_loadable()

load_plane_ship() and load_plane_land() duplicate code to check
whether a plane can be loaded, except for the phrasing of one message.
Factor out into plane_loadable().  tran_plane() has equivalent code,
but wants different messages, which makes de-duplication unattractive.

load_land_ship() and load_land_land() duplicate code to check whether
a land unit can be loaded.  Factor out into land_loadable().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoRevert "Don't let trains load trains"
Markus Armbruster [Thu, 10 May 2018 15:00:24 +0000 (17:00 +0200)]
Revert "Don't let trains load trains"

This reverts commit b1a0ff2fbd87d3c332de1e0a41b3ddea133c77b1.

Land units with capability heavy can't be loaded on anything, and land
units carrying land units can't be loaded regardless of capabilities.
Commit b1a0ff2fbd8 additionally outlawed loading of trains on land
units, but not on ships.  Bad idea, because it complicates matters for
no good reason.  Revert it.

Doesn't affect the stock game, because its only train is heavy.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agomarket: Simplify check for dead trades and document how it fails
Markus Armbruster [Thu, 10 May 2018 09:15:29 +0000 (11:15 +0200)]
market: Simplify check for dead trades and document how it fails

We fail to delete trades right away when the unit on sale dies.
Instead, we delete trades of the dead whenever we look at the market.
Doesn't work when new builds reuse the IDs of such dead.  If the new
unit's owner differs from the dead one's, we still delete the trade,
and log "Something weird".  If they are the same, the newly built unit
takes the dead one's place on the market.  Has been that way since the
market was added in 4.0.0.

I can't fix this right now, so mark as FIXME, and drop the logerror().
The first of the two trade deletions is now redundant, so drop that,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agobuy set trade: Fix taking lots off the market
Markus Armbruster [Thu, 10 May 2018 08:28:49 +0000 (10:28 +0200)]
buy set trade: Fix taking lots off the market

To find out whether a lot is in use, some places check for zero
trd_owner, others for negative trd_unitid.  The former is reliable,
the latter is not: set() fails to change trd_unitid when it takes a
lot off the market.  The next trade-related command then runs
check_trade(), which logs "Something weird" and cleans up the mess.
Broken in commit e16e38dfabc (v4.2.18).

Replace the unreliable checks by reliable ones.

Clean up set() not to implictly rely on unused lots having negative
trd_unitid.

The trd_unitid = -1 are unnecessary now, so drop them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoset: Use the first unused lot instead of the last
Markus Armbruster [Thu, 10 May 2018 08:16:10 +0000 (10:16 +0200)]
set: Use the first unused lot instead of the last

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload unload: Don't treat unowned sectors specially
Markus Armbruster [Tue, 1 May 2018 16:54:14 +0000 (18:54 +0200)]
load unload: Don't treat unowned sectors specially

load and unload silently skip unowned sectors, unlike lload and
lunload.  Probably goes back to Chainsaw option ALLYHARBOR.

Drop that.  Deities can now load and unload in unowned harbors and
canals.  Mortals are now notified they can't.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload lload unload lunload: Tweak suppression of error messages
Markus Armbruster [Tue, 1 May 2018 08:59:33 +0000 (10:59 +0200)]
load lload unload lunload: Tweak suppression of error messages

These commands suppress some error messages when ships, planes or land
units involved aren't explicitly selected by UID.  Without this, a
command like "unload plane 80 *" would complain about every plane not
on ship#80.

Correct a few issues with this error suppression:

1. We don't suppress the error when we can't load/unload a ship or
land unit because it's on the trading block.  Do suppress it.

2. We suppress the error message when we can't load/unload due to
foreign sector ownership in all but one places.  Fix that place.

3. Messages about explicitly selected planes and land units to load
are still suppressed when the carrier isn't selected explicitly.
Change this to suppress regardless of the carrier.

3. We suppress the error when a carrier has no room.  Don't, because
it's a potentially confusing silent failure.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload: Drop dead recomputation of load_spy
Markus Armbruster [Tue, 1 May 2018 08:03:30 +0000 (10:03 +0200)]
load: Drop dead recomputation of load_spy

load_land_ship() recomputes load_spy "since [the carrier] may have
changed".  Has been that way since the feature was added in 4.2.0, but
it's nonsense.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload lload: Drop dead "cannot carry land units" checks
Markus Armbruster [Tue, 1 May 2018 07:19:43 +0000 (09:19 +0200)]
load lload: Drop dead "cannot carry land units" checks

load_land_ship() and load_land_land() fail for carriers that can't
carry any land units before prompting for land units to load.  They
then iterate over land units to load, and fail when the carrrier has
no room.  They either report "cannot carry land units" or "doesn't
have room for any more land units" then.  The former cannot happen.
Crept into load_land_ship() in Empire 2, blindly copied to
load_land_land() in 4.0.0.  load_plane_ship() and load_plane_land()
don't have this issue.

Drop the dead code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agodoc/contributing: Fix a greengrocers' apostrophe
Markus Armbruster [Mon, 4 Dec 2017 18:38:27 +0000 (19:38 +0100)]
doc/contributing: Fix a greengrocers' apostrophe

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agounload lunload: Fail early when carrier can't carry land units
Markus Armbruster [Sun, 17 Sep 2017 04:53:37 +0000 (06:53 +0200)]
unload lunload: Fail early when carrier can't carry land units

Attempting to unload land units from a carrier that can't carry any
prompts for land units to unload, while attempting to unload planes or
load land units or planes fails without prompting.

Fix this inconsistency by making unload and lunload fail early for
land units, just like they do for planes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoship: Drop misleading comment
Markus Armbruster [Sun, 17 Sep 2017 03:05:02 +0000 (05:05 +0200)]
ship: Drop misleading comment

Left behind by comment c0c5822, v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload unload lload lunload: Fix for areas starting with a digit
Markus Armbruster [Sat, 16 Sep 2017 15:07:10 +0000 (17:07 +0200)]
load unload lload lunload: Fix for areas starting with a digit

load and lload skip foreign ships unless explicitly named, and
suppress some error messages for ships not explicitly named.  Makes
sense, except the check for "explicitly named" is flawed: it checks
whether the argument starts with a digit.  Works as intended for lists
like 1/2/3.  Broken for areas that happen to start with a digit, such
as 0:9,0:5.  Visible in the load-tend test.

Screwed up when the feature was added in Empire 2.

Fix the obvious way: test for NS_LIST instead.  While there, drop the
p && *p guard, because it's always true after snxtitem().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agounload lunload: Say "Can't unload" instead of "Can't load"
Markus Armbruster [Sat, 16 Sep 2017 07:59:55 +0000 (09:59 +0200)]
unload lunload: Say "Can't unload" instead of "Can't load"

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoload: Replace variable load_unload by variable loading
Markus Armbruster [Sat, 16 Sep 2017 07:46:47 +0000 (09:46 +0200)]
load: Replace variable load_unload by variable loading

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoltend: Reject zero amount more nicely
Markus Armbruster [Sat, 16 Sep 2017 07:30:07 +0000 (09:30 +0200)]
ltend: Reject zero amount more nicely

Unlike tend, ltend does nothing silently when asked to tend zero
commodities.  This may leave the player guessing why the command did
nothing.  Report the reason and fail the command, just like tend does.
While there, improve the prompt to match tend's.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Fail more nicely when target can't take more commodities
Markus Armbruster [Fri, 15 Sep 2017 14:58:10 +0000 (16:58 +0200)]
tend: Fail more nicely when target can't take more commodities

We silently ignore target ships that can't take any more of the tended
commodity.  This may leave the player guessing why the command did
nothing.  Report the reason like this:

    cs   cargo ship (#150) can't hold more guns

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Report "cannot hold any" when tending to target, too
Markus Armbruster [Fri, 15 Sep 2017 14:51:46 +0000 (16:51 +0200)]
tend: Report "cannot hold any" when tending to target, too

We report

    frg  frigate (#170) cannot hold any uncompensated workers

only when tending from target to tender, not for the other direction.
Report it there, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Refuse to give away civilians more nicely
Markus Armbruster [Fri, 15 Sep 2017 14:47:51 +0000 (16:47 +0200)]
tend: Refuse to give away civilians more nicely

Foreign target ships are silently ignored when tending civilians.
This may leave the player guessing why the command did nothing.
Report the reason similar to load does:

    Your civilians refuse to board cs   cargo ship (#162)!

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Factor can_tend_to() out of tend(), tend_land()
Markus Armbruster [Fri, 15 Sep 2017 14:30:41 +0000 (16:30 +0200)]
tend: Factor can_tend_to() out of tend(), tend_land()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Fail more nicely when ships can't tend
Markus Armbruster [Fri, 15 Sep 2017 08:12:36 +0000 (10:12 +0200)]
tend: Fail more nicely when ships can't tend

Target ships that can't be tended at all are silently ignored.  This
may leave the player guessing why the command did nothing.  Report
them, but only when explicitly named.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend ltend: Fix to skip dead ships and land units for deities
Markus Armbruster [Fri, 15 Sep 2017 07:49:01 +0000 (09:49 +0200)]
tend ltend: Fix to skip dead ships and land units for deities

Tending to a dead ship destroys, and tending from a dead ship revives.
Has always been that way.  Not actually a problem for ltend anymore,
because the dead can't carry or be carried since commit 64a53c90f0,
v4.3.17.

Fix by checking !own in addition to !player->owner

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Factor can_tend_to() out of tend(), tend_land()
Markus Armbruster [Fri, 15 Sep 2017 06:32:10 +0000 (08:32 +0200)]
tend: Factor can_tend_to() out of tend(), tend_land()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Fix the amount tended in bulletin to recipient
Markus Armbruster [Thu, 14 Sep 2017 14:08:22 +0000 (16:08 +0200)]
tend: Fix the amount tended in bulletin to recipient

The bulletin reports the total amount tended to all ships so far.
Broken in commit 1de48e53da (v4.3.0), not fixed in commit 7cc14a2c9a
(v4.3.1).  Fix the bulletin to report the amount tended to this ship.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend ltend: Improve "cannot hold any" message
Markus Armbruster [Thu, 14 Sep 2017 10:18:56 +0000 (12:18 +0200)]
tend ltend: Improve "cannot hold any" message

Report the exact ship, like

    frg  frigate (#170) cannot hold any uncompensated workers

instead of reporting just the ship type, like

    A frg  frigate cannot hold any uncompensated workers

This is a bit more useful when tending to more than one ship.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend ltend: Handle "cannot hold commodity" consistently
Markus Armbruster [Thu, 14 Sep 2017 10:14:14 +0000 (12:14 +0200)]
tend ltend: Handle "cannot hold commodity" consistently

Transferring commodities from tenders to targets continues with the
next tender when a target can't hold this kind of commodity.
Transferring them from targets to tenders fails (ltend) or stops
tending (tend) when a tender can't hold this kind of commodity.  Has
always been that way.

Change the latter to continue with the next tender.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend ltend: Handle "don't have commodity" consistently
Markus Armbruster [Thu, 14 Sep 2017 10:10:07 +0000 (12:10 +0200)]
tend ltend: Handle "don't have commodity" consistently

Transferring commodities from tenders to targets fails when a tender
doesn't have any.  Transferring them from targets to tenders continues
with the next target when a target doesn't have any.  Has always been
that way.

Change the former to continue with the next tender.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend ltend: Reject foreign tenders and land units more nicely
Markus Armbruster [Wed, 13 Sep 2017 16:41:00 +0000 (18:41 +0200)]
tend ltend: Reject foreign tenders and land units more nicely

We silently ignore foreign ships and land units.  This may leave the
player guessing why the command did nothing.  Report explicitly named
ones like this

    You don't own ship #160!

except for tend's target ships.  Nice reporting is a bit more involved
there, because you can tend to foreign target ships as long as they're
friendly.  Left for later.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoltend: Fail more nicely when land unit isn't on tender
Markus Armbruster [Tue, 12 Sep 2017 08:04:25 +0000 (10:04 +0200)]
ltend: Fail more nicely when land unit isn't on tender

Land units not on the tender are silently ignored.  This may leave the
player guessing why the command did nothing.  Reporting them all would
be annoying; I just changed tend to report only explicitly named ones.
Make ltend behave the same.

This does add a related annoyance: ltend can complain "not on ship"
when tending explicitly selected land units from multiple ships.
Tolerable.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Suppress "not on ship" unless land unit is selected by UID
Markus Armbruster [Tue, 12 Sep 2017 07:32:40 +0000 (09:32 +0200)]
tend: Suppress "not on ship" unless land unit is selected by UID

The quickest way to tend all land units on a ship is to select all
land units with '*'.  However, tend then prints a "not on ship"
message for every land unit not on the tender, as the load-tend test
demonstrates.  Annoying.  Suppress this message unless the land unit
was explictly selected by UID.  Similar to how load and unload
suppress messages, only they get the condition wrong (to be fixed
soon).

A related annoyance remains, also visible in the load-tend test: tend
can still complain "not on ship" many times when tending explicitly
selected land units from multiple ships.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotend: Don't tend land units to multiple target ships
Markus Armbruster [Mon, 11 Sep 2017 05:37:49 +0000 (07:37 +0200)]
tend: Don't tend land units to multiple target ships

Each land unit is tended to each target ship in turn, and ends up on
the last one that can take it..  The load-tend test demonstrates this
with command "tend land 173 s 150/165":

    spy  infiltrator #320 transferred from sbc  cargo submarine (#173) to cs   cargo ship (#150)
    spy  infiltrator #320 transferred from sbc  cargo submarine (#173) to ls   landing ship (#165)
    spy  infiltrator #321 is not on sbc  cargo submarine (#173)!
    spy  infiltrator #322 transferred from sbc  cargo submarine (#173) to cs   cargo ship (#150)
    spy  infiltrator #322 transferred from sbc  cargo submarine (#173) to ls   landing ship (#165)

Has been that way ever since Empire 2 added tending of land units.

Fix by breaking tend_land()'s loop over all target ships after a
successful transfer.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/load-tend: New; exercises load and tend commands
Markus Armbruster [Mon, 28 Aug 2017 17:48:27 +0000 (19:48 +0200)]
tests/load-tend: New; exercises load and tend commands

Exercise load, unload, lload, lunload, tend, and ltend.

Notable coverage gaps:

* Effect on land unit fortification

* Effect on mission and retreat orders

* Ships, land units and planes on sale (option MARKET 1)

* Transmission of plague (option NO_PLAGUE 0)

* Land units loading and unloading civilians (need a custom land unit
  type capable of carrying civilians)

* load refusing to load x-light planes (need a custom ship type that
  can carry helo but not x-light)

* load and lload refusing to load land units carrying land units, and
  lload refusing to load land units onto land units that are being
  carried (need a custom non-heavy land unit type that can carry land
  units)

* tend refusing to tend non-light land units to non-supply ships, or
  to supply ships without room (need custom a non-light assault land
  unit type)

This test exposes bugs.  They're marked "BUG:" in the test input.
There are also oddities marked "odd:", and usability issues marked
"usability:".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoedit: Implement editing of missile fortification
Markus Armbruster [Sun, 27 Aug 2017 12:47:31 +0000 (14:47 +0200)]
edit: Implement editing of missile fortification

The edit command doesn't support editing plane fortification.  Has
always been that way.  Implement it as key 'F'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/actofgod: Test integer values more thoroughly
Markus Armbruster [Sun, 27 Aug 2017 12:42:47 +0000 (14:42 +0200)]
tests/actofgod: Test integer values more thoroughly

For integer values, we test lower bound - 1, lower bound, upper bound,
upper bound + 1.  Additionally test lower bound + 1, upper bound -1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/actofgod: Fix owner of plane 7/8
Markus Armbruster [Sun, 27 Aug 2017 12:23:07 +0000 (14:23 +0200)]
tests/actofgod: Fix owner of plane 7/8

Planes 7/8 aren't visible in output, because the test neglects to set
their owner.  Messed up in commit commit efec441, v4.3.33.  Correct
that oversight.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoedit: Implement editing bars on ships and land units
Markus Armbruster [Sun, 27 Aug 2017 11:28:20 +0000 (13:28 +0200)]
edit: Implement editing bars on ships and land units

The edit command doesn't support editing bars on ships and land units.
Has always been that way.  The stock game's ships have always been
unable to load bars.  Not the case for land units.

Unfortunately, the obvious key 'b' for bars was burned on plague time
in 4.0.17.  Use key 'B' instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agotests/actofgod: Test give and edit for each item type
Markus Armbruster [Sun, 27 Aug 2017 11:19:10 +0000 (13:19 +0200)]
tests/actofgod: Test give and edit for each item type

The test covers only 'c' and 'l' with give, 'm' and 'g' with edit.
Cover the other item types, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoedit: Print ship and land unit items with field width 5
Markus Armbruster [Sun, 27 Aug 2017 10:37:53 +0000 (12:37 +0200)]
edit: Print ship and land unit items with field width 5

print_items() uses field widths between 3 and 5.  They go back all the
way to Empire 1, and are fine for the stock game.  Widen the narrower
ones to 5, because a consistent field width looks tidier, and can
avoid misaligned columns with customized ships and land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
22 months agoedit: Factor print_items() out of print_land(), print_ship()
Markus Armbruster [Sun, 27 Aug 2017 10:33:02 +0000 (12:33 +0200)]
edit: Factor print_items() out of print_land(), print_ship()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
4 years agoupdate/revolt: Fix land unit casualties
Markus Armbruster [Tue, 10 Apr 2018 14:31:11 +0000 (16:31 +0200)]
update/revolt: Fix land unit casualties

Fix the bug demonstrated by the previous commit:
take_casualties_from_lands() limits total casualties to @each.  It
should limit each land unit's casualties, and only if !may_kill.  This
can lead to fewer casualties than called for; oops in
take_casualties().  Broken in commit 025e9cc25, v4.4.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
4 years agoUpdate copyright notice
Markus Armbruster [Tue, 10 Apr 2018 14:29:27 +0000 (16:29 +0200)]
Update copyright notice

Signed-off-by: Markus Armbruster <armbru@redhat.com>
4 years agotests/update: Demonstrate take_casualties_from_lands() bug
Markus Armbruster [Tue, 10 Apr 2018 12:17:41 +0000 (14:17 +0200)]
tests/update: Demonstrate take_casualties_from_lands() bug

Tweak military in land units to demonstrate that
take_casualties_from_lands() can kill fewer military than it should.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
4 years agotests/update: Belatedly update for commit 35ecc008c
Markus Armbruster [Tue, 10 Apr 2018 12:04:51 +0000 (14:04 +0200)]
tests/update: Belatedly update for commit 35ecc008c

Commit 35ecc008c fixed take_casualties() to destroy land units only
when casualties demand it.  This test demonstrated the change: inf#29
no longer dies.  Good.  However, this lost coverage of land units
dying in a sucessful defense.  Bad.

I could tweak inf#29 to get destroyed again, but that would lose
coverage of the bug fixed by commit 35ecc008c.  Make linf#28 die
instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoinfo/Empire4.4: Fix a botched 4.4.0 change log entry
Markus Armbruster [Sun, 10 Sep 2017 15:40:07 +0000 (17:40 +0200)]
info/Empire4.4: Fix a botched 4.4.0 change log entry

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoef_verify: Fix error message in verify_land_chr() v4.4.0
Markus Armbruster [Sun, 3 Sep 2017 15:38:34 +0000 (17:38 +0200)]
ef_verify: Fix error message in verify_land_chr()

It points to the wrong table.  Screwed up in commit 33800fc.  Correct
the pasto.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoinfo/Empire4.4: Update release date once more
Markus Armbruster [Sun, 3 Sep 2017 15:18:39 +0000 (17:18 +0200)]
info/Empire4.4: Update release date once more

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoinfo/retreat info/lretreat: Fix truncated glossary list items
Markus Armbruster [Sun, 3 Sep 2017 09:11:50 +0000 (11:11 +0200)]
info/retreat info/lretreat: Fix truncated glossary list items

Text after the first space is missing in the formatted output.  That's
because .L takes just one argument, but we pass several.  Broken in
commit 4e0d02b, v4.3.33.  Fix by quoting the argument text.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoscripts/backup: Fix initialization of $email
Markus Armbruster [Sun, 3 Sep 2017 08:44:02 +0000 (10:44 +0200)]
scripts/backup: Fix initialization of $email

Mostly harmless in practice, since $email is typically unset.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoscripts/savecore: Amend the hint on core_pattern, drop stray ';'
Markus Armbruster [Sun, 3 Sep 2017 08:41:05 +0000 (10:41 +0200)]
scripts/savecore: Amend the hint on core_pattern, drop stray ';'

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoscripts src/scripts: Clean up inconsistent shell variable quoting
Markus Armbruster [Sun, 3 Sep 2017 08:37:11 +0000 (10:37 +0200)]
scripts src/scripts: Clean up inconsistent shell variable quoting

Signed-off-by: Markus Armbruster <armbru@redhat.com>
5 years agoMake: Make src/scripts/gen-tarball-version a bit nicer
Markus Armbruster [Sun, 3 Sep 2017 08:28:06 +0000 (10:28 +0200)]
Make: Make src/scripts/gen-tarball-version a bit nicer

When autoconf is stale, include a reminder how to fix that in the
error message.

While there, cd to $nv like we do in src/scripts/gen-client-configure
for slightly terser code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
5 years agoMake: Fix src/scripts/tarball argument parsing
Markus Armbruster [Sun, 3 Sep 2017 08:07:15 +0000 (10:07 +0200)]
Make: Fix src/scripts/tarball argument parsing

The test for -x uses non-portable operator ==.  Screwed up in commit
63c6dd6.  Fix by using getopts instead.

Missing mandatory arguments aren't diagnosed.  Screwed up in initial
commit 1991652, v4.3.0.  Fix by checking shift's return status.

The error message for missing argument of -C neglects to print $0 and
uses echo in a non-portable way.  Also screwed up in commit 1991652.
Fix the obvious way.

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