Commit graph

4770 commits

Author SHA1 Message Date
199388b084 nat: Deprecate selector hostname, fix value to ""
Its value has always been "", unless the deity recompiled with
RESOLVE_IPADDRESS defined, or imported another value with empdump.

I'm going to drop the RESOLVE_IPADDRESS code, including struct natstr
member nat_hostname.  To prepare for that, fix the selector's value to
"", so it doesn't need nat_hostname, and deprecate it.

This changes its "len" in xdump meta nat from 512 to 0.  Unlikely to
upset clients.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
a06cea24c1 xundump: Clean up lazy coding limiting string length to 65536
Can't just replace the literal 65536 by INT_MAX, because my system's
vfprintf() rejects that with EOVERFLOW.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
55857c7b20 xdump: Avoid undefined pointer arithmetic
s + n is defined only as long as it points into or just beyond the
same array as s.  Thus, our use of INT_MAX for "unlimited" relies on
undefined behavior.  Works fine in practice, but avoiding undefined
pointer arithmetic isn't hard here, so let's do it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
002a3a3f1e xundump: Refuse to undump strings too long for terminating null
We're dealing with three kinds of string storage: char * pointing to a
null-terminated string, char[] holding a null-terminated string, and
char holding a string of length 0 or 1.

Unfortunately, xdump meta data doesn't distinguish the latter two:
both are NSC_STRINGY.  Because of that, xundump happily fills char[]
to the limit, producing strings that aren't null-terminated, resulting
in read beyond buffer and possibly worse.

Affects struct shpstr members shp_path, shp_name, shp_rpath, struct
lndstr member lnd_rpath, and struct natstr members nat_cnam, nat_pnam,
nat_hostaddr, nat_hostname, nat_userid.  Since these are all in game
state, only the empdump utility program is affected, not the
configuration table reader.

We clearly need to require null-termination for char[] values.  Since
using char[1] for null-terminated strings makes no sense, we can still
make NSC_STRINGY with length 1 serve char values as before, by
permitting non-null-terminated strings only when length is 1.  Ugly
wart, but it fixes the bug without a possibly awkward change xdump
meta-data.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:58 +01:00
47ccc40e38 subs: Factor out lnd_mar_put_one()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:52:28 +01:00
268b05225f subs: Factor out shp_nav_put_one()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:51:39 +01:00
86c7249ca9 subs: Use lnd_put_one() in lnd_put(), lnd_mar_put()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-17 15:25:24 +01:00
56cadfe157 subs: Rename lnd_delete() to lnd_put_one()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-17 15:25:24 +01:00
7548337e73 subs: Rename shp_put() to shp_nav_put()
For consistency with lnd_mar_put().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-17 15:25:24 +01:00
18bf9e0b34 subs: Split lnd_mar_put() off lnd_put() and specialize
lnd_put() serves two masters: march, which wants it to report
"stopped" and write back struct ulist member mobility to
unit.land.lnd_mobil, and ground combat, which doesn't.

lnd_put() assumes march when actor is non-zero.  Correct (but see
commit 8c502d4).  Dates back to Empire 2.

Too ugly for my taste.  Specialize for each master instead:
lnd_mar_put() for march, and lnd_put() for ground combat.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-17 15:25:23 +01:00
b5ffc1ca49 subs: Split unit_put() into shp_put() and lnd_put() again
Commit d94d269 combined them into unit_put(), but that has turned out
not to be useful.  Split them again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-17 15:25:16 +01:00
62b9399cdf subs: Factor lnd_insque() out of lnd_sel(), ask_olist(), ...
... get_dlist(), att_reacting_units().

This loses malloc() error checking in ask_olist() and get_dlist().  No
great loss, because we don't check in so many other places, including
att_reacting_units().  We should use a wrapper that terminates on
error, though.  Left for another day.

ask_olist(), get_dlist() and att_reacting_units() zero the struct
ulist with memset().  lnd_insque() doesn't, so these functions need to
zero any members not otherwise initialized explicitly now.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-14 19:08:47 +01:00
e62af86066 subs: Set struct ulist member supplied properly for attackers
It's set to zero via memset().  Incorrect, but harmless, because it's
not actually used.  Correct it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-14 19:08:46 +01:00
5c9d6063a4 unit: Fix comments on struct ulist member use
Members x, y, eff, supplied are not "LAND only", they're used only by
ground combat.  They're not used by march.

In ground combat, member mobil is not how much the land unit has left,
it's how much it still needs to be charged.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-14 19:08:46 +01:00
fe42e6e8dd subs: Factor shp_insque() out of shp_sel(), shp_missdef(), ...
... nav_ship(), fltp_to_list().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-14 19:08:46 +01:00
da400d4fe7 Remove superfluous override directive in make check
Travis CI and OS X system make on 10.9.x at least don't have GNU make
>=3.82 which contains a parser enhancement that allows multiple
directives.

Signed-off-by: Gerd Flaig <gefla@pond.sub.org>

Here's why removing override is a good idea.  The variable assignment
should already override anything Make may find in its environment.
All "override" does is protect against unwise make arguments.

"info make" says:

    The `override' directive was not invented for escalation in the war
    between makefiles and command arguments.  It was invented so you can
    alter and add to values that the user specifies with command
    arguments.

Thus, override is ill-advised here.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-01-14 19:01:40 +01:00
990b246b86 tests/build: Clean up setup a bit
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
602e536524 tests/fire: Clean up setup a bit
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
862ad614c1 tests/actofgod: Switch setup from deprecated setsect to edit
Clean it up a bit while there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
47af370eaa attsub: Clean up take_casualty() a bit
Giving biggest the appropriate type saves a type cast.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
76ca2011c3 trade: Clean up type of trdswitchown()'s second parameter
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
c274d0820c Clean up casts from union empobj_storage * to struct empobj *
Take the address of member gen instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:27 +01:00
52a40481cb Clean up casts from struct FOO * to struct emp_qelem *
Take the address of the queue member instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
4d899f6e6d pathfind: Fix up comment for commit 92e64d7
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
5cbcdc0497 Clean up superfluous includes
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
3b6f3a5516 retreat: Move function declarations to retreat.h
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
8f5c600f71 retreat: Clean up interface between retreat_FOO(), retreat_FOO1()
Move clearing of retreat flags from retreat_ship(), retreat_land() to
retreat_ship1(), retreat_land1(), so it's where the retreat path is
shortened.

Move putship(), putland() from retreat_ship1(), retreat_land1() to
retreat_ship(), retreat_land(), so it's where the nxtitem() is, and
doesn't need a "if (!orig)" guard.  Requires making retreat_ship1()
and retreat_land() return non-zero when they modified their argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
ff826d2582 retreat: Don't consume a retreat direction that wasn't followed
When a retreating ship or land unit runs into a sector it can't enter,
it stops.  The direction character that led it there is consumed, even
though it could not be followed.  The next retreat will then attempt
to follow the rest of the path.  Don't do that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
40ec33b099 retreat: Reject invalid retreat paths
Undocumented misfeature: retreat and lretreat accept anything as
retreat path.  The paths' actual consumers retreat_ship1() and
retread_land1() silently ignore invalid direction characters.

The retreat paths are in xdump, and invalid ones could conceivably
confuse smart clients.

Change the commands to reject invalid paths, and the consumers to oops
on invalid direction characters.

Note that invalid paths get rejected even when they're not actually
used because the conditions argument contains a "c" for "cancel".
Requiring the user give a new path so he can cancel the old one is
comically bad design.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
1e3b7773d4 retreat: Fail without charging BTUs when given no conditions
Return RET_SYN instead of RET_FAIL then.  Also drop the error message;
the usage help printed for RET_SYN should do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
c699949326 retreat: Fix infinite loop when third argument contains '?'
Broken in commit bb5dfd8, v4.3.16.  Fix by recognizing '?' only when
getting the argument interactively.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
b3453efdfc retreat: Don't charge mobility for retreating in direction 'h'
Obscure feature: 'h' in a retreat path stops the current retreat.  The
code treats that as entering the current sector again, thus charges
mobility for staying put.  It also reports "could not retreat to" for
a ship or land unit that can retreat out of, but could not retreat
into its current sector, e.g. a ship in an unfriendly harbor.

Fix by cleaning up the tortuous control flow.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
98cb83302c retreat: Drop useless write back on failed retreat
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
d1c3529009 retreat: Don't retreat the current player's ships or land units
The retreat code happily retreats anything, without considering who
owns it.  It reports retreat to the owner by bulletin, even when the
owner is the current player.

Commands shouldn't report to the current player by bulletin, they
should print directly.  Fixable.  However, your ships and land units
retreating from your own actions makes little sense.  Suppress it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
df8a1ffc1b retreat: Don't report a destroyed ship/land unit couldn't retreat
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
c3a839934f retreat: Oops on retreating ghosts
Code never actually retreated them, but it could zap their mission and
retreat flags.  Harmless, but avoid it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:26 +01:00
c03db4c5ef shpsub: Make shp_check_nav() return more useful information
Some callers have to second-guess shp_check_nav() to figure out
whether CN_LANDLOCKED means "too big to fit into the canal" or "can't
go there at all".

Fix that by returning d_navigation.  CN_LANDLOCKED becomes either
NAV_CANAL or NAV_NONE, CN_CONSTRUCTION becomes either NAV_02 or
NAV_60, and CN_NAVIGABLE becomes NAVOK.

The CN_NAVIGABLE, ... codes are now unused.  Drop them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
1fee5028a2 Delete trivial instances of /*NOTREACHED*/
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
a0cdd157f1 shpsub: Move declarations to ship.h
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
b860123590 retreat: Retreat groups in a more sensible order
A group retreat is executed in increasing UID order.  The resulting
bulletin can be confusing.

Instead, retreat the ship that had its retreat conditions satisfied
first, and only then its group, if any.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
e7949e20f3 retreat: Clear mission only when ship or land unit moves
The mission gets cleared whenever a retreat is triggered, even for
ships and land units that are unable to retreat.

Clear it only when the ship or land unit actually retreats.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
2cc0664e3e retreat: Fix stack smash in land unit group retreat
retreat_land() reads ships instead of land units, overrunning local
variable land.  On lucky systems such as mine, this clobbers ni, and
triggers an oops.  On unlucky systems, it crashes.  On really unlucky
systems, it corrupts the land units file.

Broken since land unit retreat was added in Chainsaw 3.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
a963b4e703 tests/fire: Drop test of ship retreat
Now covered in tests/retreat.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
58cd269bed tests/retreat: New; exercising retreat
Does not cover land unit retreat after a failed morale check.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
c7af9bd955 edit: Keep missions centered on unit centered when teleporting
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
10f6322594 tests/actofgod: Show moving units with edit doesn't affect mission
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
c2683e5b58 tests: Save diff -u between expected and actual output
"diff -q" isn't blessed by POSIX anyway.  Neither is -u, but it should
be widely available.  -c is blessed, but I find its output hard to
read.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
b7bcf8fde2 tests/fire: Drop test of falling bridges
Now covered in tests/bridgefall.  Damage perturbed, because deleting
the bridges from the setup makes defend() roll fewer dice.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:25 +01:00
2da09bc4b0 tests/fire: Drop test of units tumbling down with bridges
Now covered in tests/bridgefall.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
57f53293e6 tests/fire: Protect against unintended shelling to deity
Sector 0,2 takes a lot of damage.  When it gets shot to deity, the
rest of the test can be upset.  Avoid by putting more civilians there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00