]> git.pond.sub.org Git - empserver/log
empserver
3 years agoclient: Unbreak standalone build changeling master v4.4.1
Markus Armbruster [Sun, 21 Feb 2021 14:46:28 +0000 (15:46 +0100)]
client: Unbreak standalone build

Broken in commit 8447fc1cd "w32: Provide getopt() for Visual Studio".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Empire4.4: Improve a few change log entries
Markus Armbruster [Sun, 21 Feb 2021 13:21:37 +0000 (14:21 +0100)]
info/Empire4.4: Improve a few change log entries

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Empire4.4: Update change log again for 4.4.1
Markus Armbruster [Sat, 13 Feb 2021 18:26:01 +0000 (19:26 +0100)]
info/Empire4.4: Update change log again for 4.4.1

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agow32: Drop snprintf(), vsnprintf() macros for Visual Studio
Ron Koenderink [Thu, 4 Feb 2021 22:46:21 +0000 (16:46 -0600)]
w32: Drop snprintf(), vsnprintf() macros for Visual Studio

The Visual Studio ANSI C compatibility flag now covers these functions
so now the defines create a conflict.

Signed-off-by: Ron Koenderink <rkoenderink@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agow32: Drop a warning suppression pragma we no longer need
Markus Armbruster [Tue, 9 Feb 2021 10:07:30 +0000 (11:07 +0100)]
w32: Drop a warning suppression pragma we no longer need

Signed-off-by: Ron Koenderink <rkoenderink@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agow32: Work around a Visual Studio deprecation warning
Ron Koenderink [Thu, 4 Feb 2021 22:30:54 +0000 (16:30 -0600)]
w32: Work around a Visual Studio deprecation warning

Visual Studio warns on use of certain POSIX functions.  Compiler
option /D_CRT_NONSTDC_NO_WARNINGS suppresses this, except for variable
tzname.  Work around with a macro.

Signed-off-by: Ron Koenderink <rkoenderink@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years ago.gitignore: Add Visual Studio directories for building
Ron Koenderink [Mon, 1 Feb 2021 22:33:34 +0000 (16:33 -0600)]
.gitignore: Add Visual Studio directories for building

Signed-off-by: Ron Koenderink <rkoenderink@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agow32: Provide getopt() for Visual Studio
Ron Koenderink [Tue, 19 Jan 2021 18:48:23 +0000 (12:48 -0600)]
w32: Provide getopt() for Visual Studio

getopt() does not exist in the Visual Studio 2019 CRT.  Provide one.

Signed-off-by: Ron Koenderink <rkoenderink@gmail.com
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agow32: Modernize for MinGW 6.0.0, and clean up
Markus Armbruster [Wed, 27 Jan 2021 07:20:05 +0000 (08:20 +0100)]
w32: Modernize for MinGW 6.0.0, and clean up

We provide gettimeofday() only #ifdef _MSC_VER, but declare it
unconditionally in our own sys/time.h.  This is asking for trouble.
Declare it only #ifdef _MSC_VER, else pull in MinGW's sys/time.h with
#include_next.

Likewise, define macros ftruncate(), S_IRUSR & friends in our own
unistd.h only #ifdef _MSC_VER, else pull in MinGW's unistd.h with
#include_next.  The #include <getopt.h> is now useless, drop.

src/lib/commands/info.c relies on sys/time.h including windows.h.
Unclean, and no longer the case with MinGW.  Include it directly.

MinGW provides EWOULDBLOCK.  Drop our replacement.

MinGW provides inet_ntop() in ws2tcpip.h, but only if feature test
macro _WIN32_WINNT >= 0x600, i.e. Windows Vista or later.  It defaults
to 0x0502 (Windows Server 2003).  Make configure #define _WIN32_WINNT
0x0601 in config.h.  This requests Windows 7.  Trying to support Vista
feels unwise.  Include ws2tcpip.h, and drop our replacement.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoshow: Drop Windows-specific fmttime2822() code
Markus Armbruster [Wed, 27 Jan 2021 07:43:24 +0000 (08:43 +0100)]
show: Drop Windows-specific fmttime2822() code

fmttime2822() works around Windows strftime() lacking %z and %T.  This
is no longer the case, although MinGW still warns about %T.  Replace
%T by the %H:%M:%S, and drop the work-around.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agochance: Avoid abuse of O_NONBLOCK for Windows
Markus Armbruster [Wed, 27 Jan 2021 07:36:34 +0000 (08:36 +0100)]
chance: Avoid abuse of O_NONBLOCK for Windows

O_NONBLOCK from src/lib/w32/w32misc.h is stricly for use with our
fcntl().  pick_seed() passes it to open(), which is wrong.  With any
luck, open() fails as it should anyway (the files being opened are not
expected to exist under Windows).  Messed up in commit 9102ecce5 "Fix
PRNG seeding to resist guessing", v4.3.31.

Clean up: guard with #ifndef _WIN32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoship: Unbreak MOB_ACCESS real-time mobility update for ships
Markus Armbruster [Sun, 24 Jan 2021 16:11:26 +0000 (17:11 +0100)]
ship: Unbreak MOB_ACCESS real-time mobility update for ships

Ships owned by countries with even country number don't gain mobility
in real-time.  This is due to a classic brown-paperbag typo in the
condition guarding mob_inc_ship() in shp_postread(): & instead of &&.
Fix it.

Fixes: dd9e393b3 "subs: Simplify MOB_ACCESS mobility update", v4.4.0
Reported-by: Phil Miron <Philthy74@hotmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agosubs/wu: Avoid "may be used uninitialized" warnings
Markus Armbruster [Sat, 23 Jan 2021 09:06:49 +0000 (10:06 +0100)]
subs/wu: Avoid "may be used uninitialized" warnings

typed_wu() either sends a telegram to a single recipient @to, or an
announcement.  It initializes @np to getnatp(to) only when sending a
telegram.  It also uses it only then.  Clang is cool with this, but
GCC gets confused and warns "‘np’ may be used uninitialized".  Ron
Koenderink reports Visual Studio 2019 even flags it as an error.

Time to clean this up.  Initialize @np to NULL when sending an
announcement.  Fuse conditionals while there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofire launch: Avoid "may be used uninitialized" warnings
Markus Armbruster [Sat, 23 Jan 2021 07:48:56 +0000 (08:48 +0100)]
fire launch: Avoid "may be used uninitialized" warnings

launch_missile() initializes @n to the target ship number only when
the target is a ship.  It also uses it only then, to re-get the ship.
Clang is cool with this, but GCC gets confused and warns "‘n’ may be
used uninitialized".

Use target_ship.shp_uid instead of @n to avoid the warning.

Similar issue in c_fire(): use vship.shp_uid instead of for @vhsipno.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoload tend: Avoid "may be used uninitialized" warnings
Markus Armbruster [Sat, 23 Jan 2021 07:47:22 +0000 (08:47 +0100)]
load tend: Avoid "may be used uninitialized" warnings

c_load() initializes @ich only when @type is EF_SECTOR.  It also uses
it only then.  Clang is cool with this, but GCC gets confused and
warns "‘ich’ may be used uninitialized".  Ron Koenderink reports
Visual Studio 2019 even flags it as an error.  Same for c_lload() and
c_tend().

Time to clean this up.  Rearrange the code to avoid the warning and
also improve readability a bit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agopathfind: Delete write-only variable in path_find_visualize()
Markus Armbruster [Sat, 23 Jan 2021 07:40:51 +0000 (08:40 +0100)]
pathfind: Delete write-only variable in path_find_visualize()

A useless variable crept into commit 2fc9dfc52 "New
path_find_visualize(), to aid debugging" (v4.3.27).  Delete it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agojournal: Don't immediately flush output events to disk
Markus Armbruster [Fri, 22 Jan 2021 06:17:36 +0000 (07:17 +0100)]
journal: Don't immediately flush output events to disk

Commit 478566258 'New journal event "output"' (v4.3.27) claims "Output
events are *not* flushed to disk immediately."  They are.  Accident.
Implement the missing bit.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agomove_ground: Fix getsect() error checking
Markus Armbruster [Tue, 19 Jan 2021 18:25:03 +0000 (19:25 +0100)]
move_ground: Fix getsect() error checking

move_ground() has code to handle getsect() failure.  It's dead,
because it assumes getsect() returns a negative value on failure.  It
actually returns zero then.  The mistake can be traced back all the
way back to BSD Empire 1.1.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotakeover: Don't stop nukes on takeover
Markus Armbruster [Mon, 18 Jan 2021 07:44:40 +0000 (08:44 +0100)]
takeover: Don't stop nukes on takeover

Nukes can't be repaired, started or stopped.  Except takeover_unit()
stops them.  Don't.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agocommands: Rename the command functions
Markus Armbruster [Mon, 18 Jan 2021 05:00:04 +0000 (06:00 +0100)]
commands: Rename the command functions

Command functions are traditionally named like the command shortened
to four characters.  When this name collides with a keyword or library
function, we abbreviate more: brea(), rea().  A few are unabbreviated,
e.g.  execute().  A few have different names, e.g. explain(), not
list().

Commit 23726b379 (v4.3.0) suppressed a GCC warning about carg()
colliding with its built-in function.

Ron Koenderink reported Microsoft Visual Studio 2019 fails to link:
"_carg already defined in ucrtd.lib(ucrtbased.dll)".

Time to clean this up: rename the functions to c_FOO(), where FOO is
the unabbreviated name of the command.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Empire4.4: Update change log for 4.4.1
Markus Armbruster [Sun, 17 Jan 2021 05:00:53 +0000 (06:00 +0100)]
info/Empire4.4: Update change log for 4.4.1

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobuy: Fix bogus error when lot gets reused at the last prompt
Markus Armbruster [Tue, 12 Jan 2021 20:42:42 +0000 (21:42 +0100)]
buy: Fix bogus error when lot gets reused at the last prompt

When the lot being bid for goes away and gets reused while the player
is at the prompt for the destination sector, comm.com_amount gets
stale.  We use it before we detect the change and fail the command
This can lead to a misleading ""You don't have that much to spend!"
error.  Messed up when the code was fixed to deal with lot changes in
4.0.2.

Fix by checking for lot change earlier.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobuy: Don't continue when lot changes while asking for bid
Markus Armbruster [Tue, 12 Jan 2021 20:42:42 +0000 (21:42 +0100)]
buy: Don't continue when lot changes while asking for bid

When the lot being bid for changes while the player is at the "How
much" prompt, we report "Commodity #%d has changed!", and continue
with the changed lot.

If continuing is okay, we should keep quiet.  We did that until commit
40b11c098 "Fix buy not to wipe out concurrent updates", v4.3.27.  Okay
when only the lot's price changed.

However, the lot could have gone away, or even be reused for something
else.  Failing the command seems safest for the player, so do that.
It's how we use the check_FOO_ok() elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agowork: Don't let embarked engineers work
Markus Armbruster [Fri, 15 Jan 2021 07:16:13 +0000 (08:16 +0100)]
work: Don't let embarked engineers work

Engineers can work even when loaded on a ship or land unit.  They
happily raise sea sector efficiency.  That's just wrong.  It's
questionable even on land, because unloading need not be possible.
Has been that way since the command was added in Empire 2.

Add the missing check.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoneweff production work: Fix crash for sea sector
Markus Armbruster [Fri, 15 Jan 2021 06:47:59 +0000 (07:47 +0100)]
neweff production work: Fix crash for sea sector

The work required for building sea sectors is zero in sect.config.
When a deity runs neweff or production on a sea sector, e.g. with
"neweff *", buildeff() divides by zero.  Same when a player or deity
runs work with an engineer in a sea sector.  Broken in commit
2ffd7b948 "config: Make work to build sectors configurable", v4.4.0

Fix buildeff() to avoid the division.  Change the required work to 100
in sect.config for good measure.

Cover deity use of neweff and production in tests/update.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfig: Increase mountain process efficiency from 75% to 100%
Markus Armbruster [Thu, 7 Jan 2021 09:48:46 +0000 (10:48 +0100)]
config: Increase mountain process efficiency from 75% to 100%

Each point of gold resource is worth 5d.  Except for mountains, where
it's just 3.75d.  This is because a mountain's process efficiency is
only 75%.  Has been that way since Empire 3 made mountains mine gold.

This is actually a needless complication: a sector with 75% process
efficiency produces just like one with 100% process efficiency and 75%
of the resource.

Increase mountain process efficiency to 100%.  Deities may want to
compensate by adjusting mountains' gold resources.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfig: Make product work independently configurable
Markus Armbruster [Thu, 7 Jan 2021 06:14:27 +0000 (07:14 +0100)]
config: Make product work independently configurable

The work required for a product is traditionally the amount of raw
materials, plus 1 for resource usage, or 1 if using neither.  Make it
independently configurable instead, via new product selector bwork,
backed by new struct pchrstr member p_bwork.  Keep the required work
exactly the same in the default configuration.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agotests/version: Cover show product and show news
Markus Armbruster [Fri, 15 Jan 2021 05:14:18 +0000 (06:14 +0100)]
tests/version: Cover show product and show news

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoupdate: Give a few helpers internal linkage
Markus Armbruster [Thu, 7 Jan 2021 06:10:53 +0000 (07:10 +0100)]
update: Give a few helpers internal linkage

External use of prod_materials_cost(), prod_resource_limit() went away
in commit 4a714a37d "production: Use update code instead of
duplicating it", v4.4.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/power: Fix commodity power formula
Markus Armbruster [Thu, 7 Jan 2021 05:21:08 +0000 (06:21 +0100)]
info/power: Fix commodity power formula

Messed up in commit 1307a3be6 "show: Extend show item to show the
power value", v4.4.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Products: Don't call sector p.e. "level p.e."
Markus Armbruster [Wed, 6 Jan 2021 06:29:15 +0000 (07:29 +0100)]
info/Products: Don't call sector p.e. "level p.e."

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoarm: Rework "cannot carry nukes" test for robustness
Markus Armbruster [Fri, 11 May 2018 16:57:47 +0000 (18:57 +0200)]
arm: Rework "cannot carry nukes" test for robustness

We reject satellites, ABMs, anti-ship missiles, and SAMs.  That's
enumerating badness.  More robust replacement: accept only bomber,
tactical, cargo, except for anti-ship missiles.

Throw in PLN_LAUNCHED sanity checking while there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoef_verify: Reject invalid plane flag combinations
Markus Armbruster [Mon, 4 Jan 2021 10:09:38 +0000 (11:09 +0100)]
ef_verify: Reject invalid plane flag combinations

Any plane may have capabilities VTOL, helo, light.

Capability missile requires VTOL.

Anti-ballistic missiles have capabilities missile, SDI.

Anti-satellite missiles have capabilities missile, satellite.

Surface-to-air missiles have capabilities missile, intercept.

Anti-ship missiles have capabilities missile, marine, and may have
tactical.

Surface-to-surface missiles have capability missile, and may have
tactical.

Satellites have capability satellite, and may have spy, image.

Ordinary planes may have capabilities bomber, tactical, intercept,
cargo, spy, image, ASW, para, escort, mine, sweep.  Capability para
requires cargo; see para().

Only "missile requires VTOL" is enforced.  Enforce the rest.

Excluding P_O when asking for P_N is now redundant.  Drop that from
msl_abm_intercept().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolaunch interception: Drop support for ABM, a-sat consuming shells
Markus Armbruster [Mon, 4 Jan 2021 09:58:31 +0000 (10:58 +0100)]
launch interception: Drop support for ABM, a-sat consuming shells

Their impact on the target does not depend on shell load (it sometimes
did for a-sats until commit cf960a573 "Make anti-sat launch consistent
with interception", v4.3.23).  The shell use is logistical busy-work,
and economically irrelevant.  Remove it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfig: Change asat not to consume shells
Markus Armbruster [Mon, 4 Jan 2021 09:42:42 +0000 (10:42 +0100)]
config: Change asat not to consume shells

The asat's impact on the target does not depend on its shell load (it
sometimes did until commit cf960a573 "Make anti-sat launch consistent
with interception", v4.3.23).  The shell use is logistical busy-work,
and economically irrelevant.  Remove it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agomission: Don't permit marine missiles on support missions
Markus Armbruster [Mon, 4 Jan 2021 09:29:29 +0000 (10:29 +0100)]
mission: Don't permit marine missiles on support missions

Marine missiles can't actually support, see perform_mission().  Make
the mission command reject them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agomission: Fix an error message pasto going back to Chainsaw 3
Markus Armbruster [Mon, 4 Jan 2021 09:02:26 +0000 (10:02 +0100)]
mission: Fix an error message pasto going back to Chainsaw 3

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agomission: Don't permit SAMs on escort missions
Markus Armbruster [Mon, 4 Jan 2021 08:58:52 +0000 (09:58 +0100)]
mission: Don't permit SAMs on escort missions

The mission code doesn't treat SAMs specially: they take off, fly out,
maybe fight, fly home, and land.  Landing triggers the oops in
pln_put1().

Letting SAMs escort makes no sense.  Fix the mission command to reject
them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Plane-types: Document SAM, ABM and a-sat missile abilities
Markus Armbruster [Mon, 4 Jan 2021 08:36:55 +0000 (09:36 +0100)]
info/Plane-types: Document SAM, ABM and a-sat missile abilities

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo: Clean up references to long-gone options
Markus Armbruster [Mon, 4 Jan 2021 07:52:10 +0000 (08:52 +0100)]
info: Clean up references to long-gone options

Option DEFENSE_INFRA was replaced in commit 4d1dd6fa6, v4.3.6.  Point
to the replacement instead.

Options SHIPCHOPPERS and XLIGHT were made non-optional in Empire 2.
Don't mention them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoretreat: Drop unused parameter @code
Markus Armbruster [Sun, 3 Jan 2021 09:55:55 +0000 (10:55 +0100)]
retreat: Drop unused parameter @code

Unused since commit beedf8dce "retreat: Rewrite automatic retreat code
to fix its many bugs", v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Include signal.h instead of ucontext.h where possible
Markus Armbruster [Sun, 3 Jan 2021 07:37:52 +0000 (08:37 +0100)]
lwp: Include signal.h instead of ucontext.h where possible

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agosubs/attsub: Drop a stale comment
Markus Armbruster [Sat, 2 Jan 2021 07:37:37 +0000 (08:37 +0100)]
subs/attsub: Drop a stale comment

Stale since commit 6ac9ad66e (v4.3.20) silently dropped dead code for
supply of military.  Dead since commit 689f435af (v4.2.14) dropped
option GRAB_THINGS.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoassault attack board lboard paradrop: Fix defending land unit supply
Markus Armbruster [Sat, 2 Jan 2021 07:06:57 +0000 (08:06 +0100)]
assault attack board lboard paradrop: Fix defending land unit supply

get_dlist() collects defending land units in a list, and resupplies
them.  Bug: it uses a local copy instead of the one in the list.  When
att_fight() writes back the list, the commodities supplied get wiped
out, triggering a seqno oops.  Broken in commit 62b9399cd "subs:
Factor lnd_insque() out of lnd_sel(), ask_olist(), ...", v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoUpdate copyright notice
Markus Armbruster [Fri, 1 Jan 2021 08:38:16 +0000 (09:38 +0100)]
Update copyright notice

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoDrop macros AGREE_FREE, AGREE_PROPOSED, AGREE_SIGNED
Markus Armbruster [Thu, 31 Dec 2020 04:45:27 +0000 (05:45 +0100)]
Drop macros AGREE_FREE, AGREE_PROPOSED, AGREE_SIGNED

Commit 555de3100 (v4.3.0) added these macros so xdump tables loan and
treaty can share an agreement_statuses table.  Treaties are gone since
commit a109de948 (v4.3.33).  Drop the macros.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agodoc/coding: Improve section "Portability" a bit
Markus Armbruster [Wed, 30 Dec 2020 17:01:25 +0000 (18:01 +0100)]
doc/coding: Improve section "Portability" a bit

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinclude: Move sarg.c stuff to nsc.h to avoid incomplete enum
Markus Armbruster [Wed, 30 Dec 2020 16:04:12 +0000 (17:04 +0100)]
include: Move sarg.c stuff to nsc.h to avoid incomplete enum

Portability issue: prototypes.h uses enum ns_seltype, defined in
nsc.h.  GCC is fine with that; it supports incomplete enum types as an
extension.  Broken in commit 157ae8ec2 "Clean up superfluous include
of nsc.h in prototypes.h", v4.3.27.  Moving sarg.c stuff to nsc.h
fixes it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agocommon/pathfind: A more portable DPRINTF()
Markus Armbruster [Wed, 30 Dec 2020 12:40:47 +0000 (13:40 +0100)]
common/pathfind: A more portable DPRINTF()

C99 requires at least one argument for the "..." in a variadic macro.
GCC and Clang don't care, but warn with -pedantic.  Solaris cc warns.

The warning is easy to avoid, so do it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfigure: Move terminfo check next to readline check
Markus Armbruster [Tue, 29 Dec 2020 08:56:59 +0000 (09:56 +0100)]
configure: Move terminfo check next to readline check

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agom4/my_lib_readline: Fix check for additional libraries
Markus Armbruster [Tue, 29 Dec 2020 04:56:12 +0000 (05:56 +0100)]
m4/my_lib_readline: Fix check for additional libraries

MY_LIB_READLINE tries each readline-compatible library with a sequence
of additional libraries, starting with none.  If the check with none
fails, all the others checks reuse the cached result, and also fail.
Broken in commit 1cbda2c7d "client: Rewrite readline configuration",
v4.4.0.

Avoid the unwanted chaching.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoMake: Use SHELL to run test scripts, since /bin/sh may suck
Markus Armbruster [Mon, 28 Dec 2020 10:38:20 +0000 (11:38 +0100)]
Make: Use SHELL to run test scripts, since /bin/sh may suck

The test scripts need a POSIX-compliant Bourne shell.  /bin/sh isn't
on some systems, such as Solaris.  Run them with $(SHELL).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoMake: Get SHELL from Autoconf
Markus Armbruster [Mon, 28 Dec 2020 10:30:59 +0000 (11:30 +0100)]
Make: Get SHELL from Autoconf

The default SHELL isn't POSIX on some systems, such as Solaris.  Use
the one Autoconf chooses instead of the default.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoMake: Slighly less verbose "make check" output
Markus Armbruster [Mon, 28 Dec 2020 10:15:46 +0000 (11:15 +0100)]
Make: Slighly less verbose "make check" output

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Empire4.3: Work around "nroff: Out of temp file space"
Markus Armbruster [Mon, 28 Dec 2020 09:21:54 +0000 (10:21 +0100)]
info/Empire4.3: Work around "nroff: Out of temp file space"

Solaris 10's nroff can't deal with the lengthy .NF ... .FI: it
complains, writes truncated output, and terminates
successfully (*boggle*).  Split the .NF ... .FI in two.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfigure: Test GCC-specific compiler flags only when using GCC
Markus Armbruster [Mon, 28 Dec 2020 04:07:50 +0000 (05:07 +0100)]
configure: Test GCC-specific compiler flags only when using GCC

Commit 23373d01d "configure: Test compiler flags" (v4.4.0) made
configure test whether compiler flags work, to let us use flags that
work only for some compilers.

Unfortunately, the Sun C compiler accepts invalid options with a
warning, breaking the test.  Observed on Solaris 10.

Fix by testing the compiler flags only when AC_PROG_CC detected GCC.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobomb: Pass NULL instead of 0 to pln_damage()
Markus Armbruster [Sun, 27 Dec 2020 11:47:20 +0000 (12:47 +0100)]
bomb: Pass NULL instead of 0 to pln_damage()

Neglected in commit 820d755e5 "subs: Change pln_damage()'s parameter
noisy to string prefix", v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobomb launch interdiction: Fix crash on bombs missing target
Markus Armbruster [Sun, 27 Dec 2020 11:43:19 +0000 (12:43 +0100)]
bomb launch interdiction: Fix crash on bombs missing target

plane damage() prints @noisy with snprintf() even when it's null.  It
doesn't actually use the output then.  Some systems (GNU, Windows)
deal gracefully with printing null strings, others crash.  @noisy is
null when bombers or missiles miss and do collateral damage.  Affects
bomb, launch, and interdiction missions.  Broken in commit 820d755e5
"subs: Change pln_damage()'s parameter noisy to string prefix",
v4.3.33.

Fix by guarding the snprintf().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoClarify build requirements
Markus Armbruster [Mon, 28 Dec 2020 09:01:44 +0000 (10:01 +0100)]
Clarify build requirements

Document the need for the XSI Extension.  Don't list curses as
required, it's actually optional.  Correct advice for Solaris.  Add
advice for AIX.  Drop references to C89; we actually require C99, and
POSIX.1-2001 provides it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoFix build for systems that don't provide POSIX.1-2001 by default
Markus Armbruster [Sun, 27 Dec 2020 11:40:05 +0000 (12:40 +0100)]
Fix build for systems that don't provide POSIX.1-2001 by default

We require POSIX.1-2001.  Some systems provide it only with feature
test macro _POSIX_C_SOURCE defined to 200112L.  Since we don't define
it, the build fails there.  Observed on Solaris 10.

We actually require the XSI extension.  The GNU C Library provides it
by default.  With _POSIX_C_SOURCE 200112L, however, you have to define
feature test macro _XOPEN_SOURCE to get it.  But then _POSIX_C_SOURCE
is redundant.

Make configure put #define _XOPEN_SOURCE 600 into config.h.  Drop the
two existing #define _XOPEN_SOURCE 500 in .c files.

Now Solaris cc refuses to play ball unless switched to C99.  Replace
AC_PROG_CC by AC_PROG_CC_STDC to mollify it.

Unfortunately, use of _XOPEN_SOURCE exposes bugs in AIX libc and old
versions of GNU libc:

* AIX defines struct in6_addr's member s6_addr as a macro expanding
  into the actual member.  Without _ALL_SOURCE (the default), the
  expansion is wrong and doesn't compile.  Observed with AIX V7.2.

* GNU lib's IN6_IS_ADDR_V4MAPPED() is unusable without
  _DEFAULT_SOURCE (default) or _GNU_SOURCE.  Observed with Debian 8.
  Tracked at <https://sourceware.org/bugzilla/show_bug.cgi?id=16421>,
  fixed in version 2.25.

Affects just sockaddr_ntop()'s special case from commit 372cdb136 "Use
IPv4 format for IPv4-mapped addresses", v4.3.31.  Disable the special
case and use IPv6 format on such systems.  This is a very minor
usability regression.  Could be avoided, I guess, but it's not worth
the trouble.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: Drop use of getpass()
Markus Armbruster [Sun, 27 Dec 2020 10:57:54 +0000 (11:57 +0100)]
client: Drop use of getpass()

getpass() is traditional Unix, but has been withdrawn from POSIX.  We
still use it when it's available, and fall back to portable code only
when it's not.

The portable code behaves differently: it reads stdin instead of
/dev/tty, and in noncanonical mode.

Simplify things: always use the replacement.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: Make get_password() not echo with POSIX && !HAVE_GETPASS
Markus Armbruster [Sun, 27 Dec 2020 10:48:52 +0000 (11:48 +0100)]
client: Make get_password() not echo with POSIX && !HAVE_GETPASS

getpass() is traditional Unix, but has been withdrawn from POSIX.  We
provide a replacement in case it's missing.  The one for Windows
suppresses echo, like getpass() does.  Implement that for POSIX.  The
other differences to getpass() remain.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: Factor set_echo_if_tty() out of get_password()
Markus Armbruster [Sun, 27 Dec 2020 10:32:48 +0000 (11:32 +0100)]
client: Factor set_echo_if_tty() out of get_password()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: Move get_password() from login.c to getpass.c
Markus Armbruster [Sun, 27 Dec 2020 09:06:08 +0000 (10:06 +0100)]
client: Move get_password() from login.c to getpass.c

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: New get_password()
Markus Armbruster [Sun, 27 Dec 2020 09:06:08 +0000 (10:06 +0100)]
client: New get_password()

I'm going to drop use of getpass().  As a first step, weaken the bond
by hiding it in a separate function.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoclient: Reorder misc.h, and point to the .c
Markus Armbruster [Sun, 27 Dec 2020 08:55:45 +0000 (09:55 +0100)]
client: Reorder misc.h, and point to the .c

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Simplify lwpSigWait() interface
Markus Armbruster [Sun, 27 Dec 2020 08:42:55 +0000 (09:42 +0100)]
lwp: Simplify lwpSigWait() interface

lwpSigWait() was designed to resemble sigwait().  It doesn't anymore.
Drop the awkward argument, and use the return value instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Rename two variables for clarity
Markus Armbruster [Sun, 27 Dec 2020 08:41:41 +0000 (09:41 +0100)]
lwp: Rename two variables for clarity

Rename LwpSigCaught to LwpPendingSig, and lwpCatchAwaitedSig() to
lwpHandleAwaitedSig().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Rewrite signal wait code for portability and safety
Markus Armbruster [Sun, 27 Dec 2020 08:36:54 +0000 (09:36 +0100)]
lwp: Rewrite signal wait code for portability and safety

LWP's use of sigset_t is problematic.

To iterate over a sigset_t, it uses NSIG, which is not portable: BSD
and System V provide it, but it's not POSIX.

To record signals caught, it updates a sigset_t variable from a signal
handler.  The variable isn't volatile, because we'd have to cast away
volatile for sigaddset().

Replace sigset_t by an array of signal numbers terminated with 0.

Since lwpInitSigWait() needs to store the signal set for
lwpCatchAwaitedSig() anyway, there is no need to pass it to
lwpSigWait().  Drop its parameter.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Fix signal wait screwup for multiple different signals
Markus Armbruster [Sun, 27 Dec 2020 08:30:00 +0000 (09:30 +0100)]
lwp: Fix signal wait screwup for multiple different signals

lwpSigWait() clears LwpSigCheck even when signals remain in
LwpSigCaught.  The next empth_wait_for_signal() will then wait until
another one gets caught.  Broken in commit fe2de3d74, v4.3.10.

Fix by clearing it only when LwpSigCaught is empty.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Fix handling of sigismember() failure
Markus Armbruster [Sun, 27 Dec 2020 07:18:27 +0000 (08:18 +0100)]
lwp: Fix handling of sigismember() failure

sigismember() fails when passed an invalid or unsupported signal
number.  lwpInitSigWait() and lwpGetSig() treat sigismember() failure
like "is a member".  lwpInitSigWait() will then sigaction()
unsuccessfully.  Harmless.  lwpGetSig() returns the bad signal number
when it's greater than any caught signal's number.  The bad signal
number then gets returned to main(), which shuts down the server.

Fix by treating failure like "is not a member".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Fix unsafe update of LwpSigCaught
Markus Armbruster [Sun, 27 Dec 2020 07:07:24 +0000 (08:07 +0100)]
lwp: Fix unsafe update of LwpSigCaught

lwpCatchAwaitedSig() is not reentrant.  lwpInitSigWait() attempts to
protect it by setting an appropriate signal mask, but screws up.  This
could conceivably lose signals.  Messed up when it got added in commit
7183516d9, v4.3.6.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agolwp: Drop inappropriate oops in lwpSigWait()
Markus Armbruster [Sun, 27 Dec 2020 07:03:25 +0000 (08:03 +0100)]
lwp: Drop inappropriate oops in lwpSigWait()

lwpSigWait()'s contract specifies failure, which means oopsing is
wrong.  Harmless, as its only caller empth_wait_for_signal() oopses on
failure.  Drop it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo: Use S_ISREG() instead of S_IFREG for readability
Markus Armbruster [Sun, 27 Dec 2020 06:39:46 +0000 (07:39 +0100)]
info: Use S_ISREG() instead of S_IFREG for readability

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo: Add #include <strings.h> for portability
Markus Armbruster [Sun, 27 Dec 2020 06:30:41 +0000 (07:30 +0100)]
info: Add #include <strings.h> for portability

We get strncasecmp() from <string.h>.  This is a BSDism; POSIX
provides it in <strings.h>.  Missed in commit 8fdd0259f2d, v4.2.19.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoMake: Fix build with tool chains that require depcomp
Markus Armbruster [Sat, 26 Dec 2020 08:08:37 +0000 (09:08 +0100)]
Make: Fix build with tool chains that require depcomp

Commit fad8e7f7b "Move auxiliary build tools to build-aux/" moved
depcomp, but neglected to adjust Make.mk.  This broke the build with
tool chains that actually use depcomp.  Modern GCC and Clang don't.
Fix the obvious way.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobuild-aux/git-version-gen: Refresh from Gnulib commit 4f78c231f4
Markus Armbruster [Sat, 26 Dec 2020 07:34:33 +0000 (08:34 +0100)]
build-aux/git-version-gen: Refresh from Gnulib commit 4f78c231f4

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agobuild-aux INSTALL: Refresh from automake 1.16.3
Markus Armbruster [Sat, 26 Dec 2020 07:29:47 +0000 (08:29 +0100)]
build-aux INSTALL: Refresh from automake 1.16.3

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agom4: Refresh macros from autoconf-archive commit fd1d25c148
Markus Armbruster [Sat, 26 Dec 2020 07:20:57 +0000 (08:20 +0100)]
m4: Refresh macros from autoconf-archive commit fd1d25c148

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfig: Enlarge configuration tables that have variable size
Markus Armbruster [Sat, 26 Dec 2020 05:37:07 +0000 (06:37 +0100)]
config: Enlarge configuration tables that have variable size

Configuration tables product, sect-chr, ship-chr, plane-chr, land-chr,
nuke-chr have a bit of extra space deities can use for customizing
their games.  Give them more: enlarge product from 23 to 31
entries (plus one sentinel), sect-chr from 39 to 63, ship-chr from 47
to 127, plane-chr from 47 to 127, land-chr from 31 to 127, and
nuke-chr from 20 to 63.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoconfig: Slightly neater configuration table size macros
Markus Armbruster [Sat, 26 Dec 2020 05:30:24 +0000 (06:30 +0100)]
config: Slightly neater configuration table size macros

Macro SHP_TYPE_MAX is the largest possible ship type number.  It is
only used to size mchr[], and we need + 2 there.  Replace by MCHR_SZ
for simplicity.

Same for LND_TYPE_MAX, PLN_TYPE_MAX, P_MAX, and SCT_TYPE_MAX: replace
by LCHR_SZ, PLCHR_SZ, PCHR_SZ, and DCHR_SZ.

Same for N_MAXNUKE, except that one is more than the largest type
number.  Replace by NCHR_SZ.

For consistency, define ICHR_SZ and INTRCHR_SZ for sizing ichr[] and
intrchr_sz[].

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoAvoid SCT_TYPE_MAX, use ARRAY_SIZE() instead
Markus Armbruster [Sat, 26 Dec 2020 05:27:18 +0000 (06:27 +0100)]
Avoid SCT_TYPE_MAX, use ARRAY_SIZE() instead

The next commit will get rid of SCT_TYPE_MAX.  Prepare.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoNew macro ARRAY_SIZE()
Markus Armbruster [Sat, 26 Dec 2020 05:15:40 +0000 (06:15 +0100)]
New macro ARRAY_SIZE()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoeconfig: Fix documentation of key assault_penalty
Markus Armbruster [Fri, 25 Dec 2020 12:15:14 +0000 (13:15 +0100)]
econfig: Fix documentation of key assault_penalty

Messed up when keys got documented in 4.2.0.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agoinfo/Empire4.4: Fix more 4.4.0 change log entry typos
Markus Armbruster [Mon, 21 Dec 2020 16:01:29 +0000 (17:01 +0100)]
info/Empire4.4: Fix more 4.4.0 change log entry typos

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Tidy up comments
Markus Armbruster [Sun, 26 Jul 2020 05:52:20 +0000 (07:52 +0200)]
fairland: Tidy up comments

Don't use ALL CAPS for headings.  Reformat them in the style
recommended by doc/coding.  Drop a few comments that aren't pulling
their weight, and fix the odd typo.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Rename fl_move() to drift_capital()
Markus Armbruster [Fri, 16 Oct 2020 14:26:10 +0000 (16:26 +0200)]
fairland: Rename fl_move() to drift_capital()

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Move qprint() and NUMTRIES
Markus Armbruster [Mon, 10 Aug 2020 13:52:02 +0000 (15:52 +0200)]
fairland: Move qprint() and NUMTRIES

qprint() was carelessly added at the end of the file in Empire 2,
where it's under the "Write a script for placing capitals" headline.
Move it to a more sensible place.

NUMTRIES was added behind the global variables in Empire 2.  Move it
before them, and reformat its comment.

The order of forward declarations of static functions looks random.
Reorder them to match the order of definitions.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fuse capx[], capy[] into cap[]
Markus Armbruster [Fri, 21 Aug 2020 11:42:51 +0000 (13:42 +0200)]
fairland: Fuse capx[], capy[] into cap[]

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fuse sectx[], secty[] into sect[]
Markus Armbruster [Fri, 21 Aug 2020 11:42:51 +0000 (13:42 +0200)]
fairland: Fuse sectx[], secty[] into sect[]

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Simplify how write_sect() iterates over sectors
Markus Armbruster [Fri, 21 Aug 2020 11:12:11 +0000 (13:12 +0200)]
fairland: Simplify how write_sect() iterates over sectors

Iterating over IDs is slightly simpler than iterating over
coordinates, so do that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Represent sector ownership more efficiently
Markus Armbruster [Fri, 21 Aug 2020 06:41:14 +0000 (08:41 +0200)]
fairland: Represent sector ownership more efficiently

Replace own[x][y] by own[XYOFFSET(x, y)], and narrow the element type
from int to short.  Takes a fourth the space.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Tweak rural iron, fert, oil for simplicity
Markus Armbruster [Fri, 21 Aug 2020 06:31:56 +0000 (08:31 +0200)]
fairland: Tweak rural iron, fert, oil for simplicity

The previous commit's interpolation tables reproduce the historical
linear functions faithfully.  This exact fit requires an awkward data
point in each of the tables for iron fertility and oil.  Drop them.

No double-valued data points remain.  Adjust struct resource_point
member @res to int.

This results in slightly less rural iron (33 elevations down one
point), fertility (10 elevations down one point) and oil (14
elevations down one point, 5 down two points).  Only resource values
less than 100 are affected.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Compute resources by interpolating tables
Markus Armbruster [Fri, 21 Aug 2020 05:32:36 +0000 (07:32 +0200)]
fairland: Compute resources by interpolating tables

The functions mapping elevation to resources are piecewise linear.
Replace them by linear interpolation on data points defined in tables.
Tables are easier to tweak for deities than code.

The data points are a bit awkward because the functions they replace
are.  The next commit will tweak them to address that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Tweak sea oil & mountain gold for simplicity
Markus Armbruster [Fri, 21 Aug 2020 06:18:49 +0000 (08:18 +0200)]
fairland: Tweak sea oil & mountain gold for simplicity

The functions mapping elevation to resources are piecewise linear,
except for set_oil(), which randomly adds 1 to sea oil, and
set_gold(), which is isn't linear for mountains, but very close.

Drop the random oil bit, and replace the non-liner gold function by a
linear one.  Both resources decrease at most by one point.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Rewrite complicated, buggy & boring elevation code
Markus Armbruster [Sat, 5 Sep 2020 04:44:12 +0000 (06:44 +0200)]
fairland: Rewrite complicated, buggy & boring elevation code

Land elevation is computed by first placing mountains, then elevating
land to fit.

Mountains placement is a weighted random sampling.  A sector's weight
is its distance to sea capped at five and squared.

Non-mountain, non-capital sectors get assigned equidistant elevations
from 1 up to 97 rounded to integer in an order that depends on
distance to mountain and distance to sea, both capped at 5.  Mountains
get equidistant elevations starting at 98 (see recent commit
"fairland: Fair mountain resources").  Capitals get 36.

Sea elevation is randomly chosen from a range that depends on the
sector's distance to land.  The range increases from [-27,-1] next to
land to [-127,-1] for distance 5 and up.

Without mountains, the result is boring: elevation increases pretty
much linearly with the distance from the coast, i.e. each islands is a
single cone.  With mountains, we get one cone per mountain.  The sea
sea elevations are basically noise.

Worse, it's buggy: mountain placement can place fewer mountains than
requested.  The weighted random sampling assigns weights even to
sectors that cannot be picked (capitals and sectors that have been
picked already).  When the dice land on such a sector, it instead
picks the next one (in island growth order) that can be picked.  If
there is no next one, the mountain is not placed.  This is a fairness
issue.

Impact varies with fairland parameters.  For 60 sector islands with 5%
mountains, around one in 10000 islands is short one mountain in my
testing.  For 10 sector islands with 50% mountains, some 760 out of
10000 islands are short one sector, 80 short two, and five short
three.  The numbers get worse as spikiness increases.

Undocumented misfeature: the placement loop is limited to 1000
iterations, supposedly to catch a runaway loop.  Since the loop
iterates exactly once per mountain, all this accomplishes it limiting
mountains to 1000 per island.

When too few mountains are placed, the loop assigning elevations to
non-mountain, non-capital decrements elevations below 1.  Since
Chainsaw 3, such elevations then get mapped to 1, plastering over the
bug.  We get non-mountain sectors with elevation 1 instead of
mountains.

Rewrite as follows.

Use a simple random hill algorithm to assign raw elevations:
initialize elevation to zero, then randomly raise circular hills on
land / lower circular depressions at sea.  Their size and height
depends on the distance to the coast, capped at 3.  After a sufficient
number of iterations, the resulting terrain has a "natural" look.
This is elevate_prep().

elevate_land() then sorts non-capital sectors by raw elevation.  The
highest become mountains.  Sectors get assigned the same equidistant
elevations as before, just in raw elevation order.

elevate_sea() simply normalizes raw elevation to [-127,-1].

Elevations now show a nice undulating pattern independent of mountain
percentage.

Implementation detail: replace elev[x][y] by elev[XYOFFSET(x, y)], and
narrow the element type from int to short.  Takes a fourth the space.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Tweak rural elevations for simplicity
Markus Armbruster [Wed, 19 Aug 2020 11:31:09 +0000 (13:31 +0200)]
fairland: Tweak rural elevations for simplicity

elevate_land() computes the sequence of elevations 97, 97 - delta,
... in fixed point with a scaling factor of 100.  Switch to
floating-point, because it's simpler.  Elevations (and thus resources)
change slightly due to reduced rounding errors.

Note that we map elevations less than 1 to 1 both before and after the
patch.  Odd.  Turns out this mitigates a bug: mountain placement can
place fewer mountains than it should, and when that happens,
elevations go below 1 here.  The next commit will fix this.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Drop unused elevation band for coastal mountains
Markus Armbruster [Wed, 19 Aug 2020 11:44:00 +0000 (13:44 +0200)]
fairland: Drop unused elevation band for coastal mountains

Elevations 34 and 35 are reserved for coastal mountains.  When an
elevation computed for a non-mountain falls in that band, it's
adjusted to 36.

This is unnecessary since the previous commit; drop.  Test output
shows the dropped elevation adjustment.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Fair mountain resources
Markus Armbruster [Wed, 19 Aug 2020 12:16:14 +0000 (14:16 +0200)]
fairland: Fair mountain resources

For fairness, fairland aims to make islands of the same size consist
of the exact same sectors, just individually arranged.

It fails to achieve its aim for mountains: their elevation is random,
34 or 35 for coastal mountains, and between 98 and 254 (two dice) for
non-coastal ones.  Elevation determines resources.  Mountains get 89
gold on average (between 80 and 93), except for coastal mountains,
which get none.  It didn't really matter until Empire 3 made mountains
produce gold dust.  Since then, it's unfair.

Set mountain elevation to 98 + i * delta, where i is the mountain
number (starting at zero), delta is (127 - 98) / max_mn, and max_mn is
the maximum number of mountains an island could have.  This puts the
highest mountains on the largest islands.

Non-coastal mountains have slightly less gold than before, coastal
mountains have much more.

Mountains can still be unfair, because fairland can screw up their
number.  To be fixed soon.

Avoid elevations 34 and 35 for non-mountain, non-capital sectors
doesn't make sense anymore.  The next commit will get rid of it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
3 years agofairland: Use zero elevation for "not yet elevated"
Markus Armbruster [Sun, 16 Aug 2020 15:46:54 +0000 (17:46 +0200)]
fairland: Use zero elevation for "not yet elevated"

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