Commit graph

5444 commits

Author SHA1 Message Date
89dc5f6d0a info/Empire4.4: Improve a few change log entries
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-02-21 15:10:53 +01:00
774ae95997 info/Empire4.4: Update change log again for 4.4.1
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-02-13 19:26:01 +01:00
Ron Koenderink
3abb8bff60 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>
2021-02-13 19:25:18 +01:00
3aa4f7404c 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>
2021-02-13 19:25:18 +01:00
Ron Koenderink
ca801dec14 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>
2021-02-13 19:25:18 +01:00
Ron Koenderink
3af4a32def .gitignore: Add Visual Studio directories for building
Signed-off-by: Ron Koenderink <rkoenderink@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-02-13 19:25:18 +01:00
Ron Koenderink
8447fc1cd2 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>
2021-02-13 19:25:18 +01:00
a164390d1f 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>
2021-02-13 19:25:18 +01:00
598669673e 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>
2021-02-13 19:25:18 +01:00
b19aa1c13f 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>
2021-02-13 19:25:18 +01:00
f69db5e413 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>
2021-02-06 16:55:37 +01:00
e23882161e 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>
2021-02-06 16:55:37 +01:00
4914daa587 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>
2021-02-06 16:55:37 +01:00
1f6b79dd10 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>
2021-02-06 16:55:37 +01:00
b770ac4ba8 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>
2021-02-06 16:55:37 +01:00
dc793ea0a1 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>
2021-02-06 16:55:37 +01:00
bfac52eb6d 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>
2021-02-06 16:55:37 +01:00
539c44a13a 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>
2021-02-06 16:55:37 +01:00
c6ec6a41c2 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>
2021-01-23 08:39:14 +01:00
a6c46316e9 info/Empire4.4: Update change log for 4.4.1
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:14 +01:00
a021a20e55 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>
2021-01-23 08:39:14 +01:00
1b677a4578 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>
2021-01-23 08:39:14 +01:00
e23e4cd738 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>
2021-01-23 08:39:14 +01:00
5f3c64c062 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>
2021-01-23 08:39:14 +01:00
223add6a92 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>
2021-01-23 08:39:14 +01:00
1d8451e87b 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>
2021-01-23 08:39:14 +01:00
8c9a383fa1 tests/version: Cover show product and show news
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:14 +01:00
992ab36b59 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>
2021-01-23 08:39:14 +01:00
9e9355da41 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>
2021-01-23 08:39:14 +01:00
5d23a13fef info/Products: Don't call sector p.e. "level p.e."
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:14 +01:00
c347db0551 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>
2021-01-23 08:39:14 +01:00
0b46e31d60 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>
2021-01-23 08:39:14 +01:00
61f0762eaa 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>
2021-01-23 08:39:14 +01:00
f8ccf1d918 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>
2021-01-23 08:39:13 +01:00
bdd2a7a764 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>
2021-01-23 08:39:13 +01:00
7b24e312e3 mission: Fix an error message pasto going back to Chainsaw 3
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:13 +01:00
da9d5c6404 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>
2021-01-23 08:39:13 +01:00
628e2e8e82 info/Plane-types: Document SAM, ABM and a-sat missile abilities
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:13 +01:00
df7e8b3d21 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>
2021-01-23 08:39:13 +01:00
125b5df9af 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>
2021-01-23 08:39:13 +01:00
52e540d62a lwp: Include signal.h instead of ucontext.h where possible
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:13 +01:00
cadb6e7f29 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>
2021-01-23 08:39:13 +01:00
e14c5326e3 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>
2021-01-23 08:39:13 +01:00
06487a46a3 Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:13 +01:00
87952c7f7c 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>
2021-01-23 08:39:13 +01:00
7714a8cb82 doc/coding: Improve section "Portability" a bit
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 08:39:13 +01:00
c48abacad2 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>
2021-01-23 08:39:13 +01:00
a0d1f63729 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>
2021-01-23 08:39:13 +01:00
ae421dafc2 configure: Move terminfo check next to readline check
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-23 07:08:21 +01:00
55ff9cce09 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>
2021-01-23 07:08:21 +01:00