fire: Check land unit guns earlier, drop useless checks
We check all necessary conditions for being able to fire before
prompting for a target. Except for land unit guns. Clean that up.
fort_fire(), shp_fire() or lnd_fire() fail only when the fort, ship or
land unit can't fire. If that happens, our checking is incomplete.
Oops then.
We recheck some of the necessary conditions after getting the target.
However, because the command fails when the firing sector, ship or
land unit has changed since the first check, these rechecks can't
fail. Drop them.
Note that the rechecks were just as useless before commit 66165f3
fixed fire to fail on change, because they rechecked the unchanged
cached copy instead of the possibly changed original.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Adding or removing a command to/from a test has unfortunate effects:
* Before the previous commit: if the command consumes pseudorandom
numbers, all subsequent users of pseudorandom numbers get different
ones. This has always been a major headache.
* Since the previous commit: all subsequent users of pseudorandom
numbers get different ones whether the command consumes any or not.
That's even worse.
* If the command uses BTUs, subsequent prompts are changed. Not
nearly as bad as the above, but still annoying.
Create a new command __cmd to allow compensating for adding/removing
commands for tests. Throw in the ability to compensate treasury
changes for good measure. Three arguments: command count, BTU use,
money use.
Usage example: say you add a convert command to a test, and it uses 3
BTUs and $15. Then you compensate by adding "__cmd added 1 3 15"
right after it.
The command must not be available unless running_test_suite is on, of
course. Make it require the new player command capability TESTING,
and give that to all players when running_test_suite is on.
The command is intentionally not documented in info. Switch
running_test_suite off for info-test, to hide it (and any future
TESTING commands) from info-test.
Suppress the command counter increment for TESTING commands, so they
can be used without upsetting pseudorandom numbers
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Tests need repeatable pseudorandom numbers to yield repeatable
results. We seed the pseudorandom number generator with a fixed value
(emp_server -R) to make it produce the same sequence of numbers every
time. But whenever code exercised by a test is changed to consume
fewer or more of them, all subsequent users get different numbers
regardless. The ensuing test result changes are extremely tedious to
review.
To address this problem, reseed the PRNG with the count of commands
right before executing a command when running_test_suite is on. This
way, the effect of perturbing the PRN sequence lasts only until the
next command.
Note that the next command could be another player's. Doesn't matter.
Adding or removing commands now upsets the PRN sequence even for
commands that don't consume PRNs. The next commit will take care of
that.
Perturbs test results across the board. Hopefully, that'll happen
much less frequently now.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
tests: Fix normalization of nat_timeused in prompt in journal
Command prompts show nat_timeused rounded down to minutes. They need
to be normalized, or else tests can fail when they take too long, or
cross midnight. Formatted prompts are normalized correctly (not
actually used since commit 9ca3fa9), but the journal contains raw
prompts. Normalize them, too.
Smoke test's journal.log is affected, because the server charges at
least 15s per login, which adds up into minutes in this test.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
tests: Normalize trailing white space in test output completely
Commit 37ff377 stripped trailing white space in test output, except
for journal.log, where it stripped it only from player output. This
misses the space preceeding player empty output, and doesn't cover
equally annoying trailing white space elsewhere, such as the space
preceeding empty input and trailing white space in prompts. Testing
the latter could be marginally useful, but let's keep things simple,
and strip all trailing white space for now.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Obviously attempts to provide space for a known configuration-
dependent stack hog. The hog went away when finish_sects()'s arrays
became dynamically allocated in 4.2.0.
Adjusting for that by dropping the extra term might well do (I observe
only a few KiB of stack used on my system). But let's set it to 512
KiB instead to be on the safe side.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Obviously attempts to provide space for known configuration-dependent
stack hogs.
The first hog is allegedly budget. Bogus since day one: its large
arrays were static in Empire 2, and became dynamically allocated in
Empire 3.
The second one makes some sense: powe() has a struct powstr[MAXNOC].
It also has an int[MAXNOC], which isn't accounted for.
Except for ridiculously small worlds, the second term is smaller, and
only the (bogus) first term matters.
Two hogs are missing: head() has a struct histstr[MAXNOC][MAXNOC], and
news() has a short[MAXNOC][MAXNOC]. It also calls head().
I looked for more hogs with "gcc -fstack-usage", and found none.
On my x86_64 system, a news command needs almost 107KiB of stack.
Only slightly less when compiled for 32 bit. Stack overrun for worlds
with fewer than some 320 sectors, thus unlikely to bite in real games.
Increase player stack size to 1 MiB. Using MAXNOC to size the stack
isn't worth the trouble.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Normally, git's pre-commit hook protects us from them. However, when
expected test output contains trailing white space, we have to bypass
commit hooks. Unwanted space can then slip in if you don't pay
attention. I obviously didn't; clean up.
The previous commit should reduce the need for such hook suppression.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
tests: New helper function feed_input, for comment support
feed_input drops lines starting with a bar character '|', so they can
serve as comments. Syntax chosen because such lines shouldn't be
needed in tests. In particular, the server already ignores such lines
when it reads commands, because they get parsed as empty command with
a pipeline, and empty commands get ignored, regardless of
redirections.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Units owned by POGO are not in use. Giving a unit to POGO destroys
it. The opposite doesn't work, however: the unit prewrite hooks give
it right back to POGO, because efficiency is below the minimum. Make
it work by also increasing efficiency to minimum.
Note that you can't use this to create a unit that doesn't already
exist in the respective file. That's because edit's second argument
selects from existing objects only.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Blow away $(einfodir) and $(ehtmldir). Without this, formatted pages
can linger after page removal. Matters, because info.c searches
$(einfodir) rather than the index $(einfodir)/all. Same for web
servers and $(ehtmldir).
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
SO_KEEPALIVE isn't useless with long idle timeouts. Before v4.3.30's
idle timeout changes, such long timeouts had serious drawbacks (easy
denial of service), but they're just fine since then.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
supply: Fix harmless bug in supply from ship in same sector
Bug bites when a ship supplies the sector it's in. First the sector
is charged zero mob for moving the stuff, and is written back. Next,
the sector receives the stuff, and is written back, clobbering the
first write (no effect), and triggering a seqno oops.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
tests/actofgod: Disable in "make check" unless LWP
Expected to work only with thread package LWP, just like the smoke
test. Commit 7a91041 carelessly enabled it for all thread packages.
Revert, except with LWP.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Breaking sanctuary turns 100% sanctuaries into capitals, all others
into highways. Before Empire 3, sanctuaries always became capitals.
Give deities more control over initial state of countries than
choosing between 100% capital and <100% highway sectors: turn
sanctuaries into their new designation on break. Except make a
capital when the new designation is sanctuary (which it normally is).
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
"info setsector" claims you "can change anything that appears in dump
or peek (I think)", which has always been wrong.
edit is much more complete. However, edit used to be more limited in
that it could change only one sector. For mass-changes, you had to
use setsector and setresource. Since that limitation is gone, there's
no real use left for setsector and setresource.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Accept general <SECTS|SHIPS|PLANES|LANDS|NATS> argument instead of
just <SECT|SHIP|PLANE|LAND|NAT>.
edit with <KEY> <VALUE>... arguments applies the arguments to all
selected objects. Without such arguments, edit lets you edit the
selected objects interactively one after the other.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
edit: Detect concurrent updates during interactive nation edit
Unlike other edits, editing a country modifies the object in-place.
It has to, because editing may send bulletins, which updates nat_tgms,
and writing back a copy would clobber these updates, triggering a
seqno mismatch oops.
However, the in-place editing neglects to detect concurrent updates.
Fix that.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
edit: Don't reprint edited object when done with it
Interactive edit prints the edited object, then reads player input.
If it gets key and value, it applies them to the object, and repeats.
If it gets nothing, it prints the edited object again, and stops.
Remove this last print, because it's not really useful. The object is
commonly the same after reading input as before. Except when a nation
gets updated while "edit c" is waiting for input: then the second
print actually reflects the updates. Has always been that way.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Print a message describing the actual change for keys 't' (nat_tgms)
and 's' (nat_status). The message is necessary to give the deity a
chance to catch unexpected changes, e.g. a player reading telegrams
just before the deity edits nat_tgms.
Send a bulletin to the country for key 's'.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Print "FOO of CNAME (#CNUM)" instead of just "FOO". Print "unchanged"
instead of "changed from X to X" on no-op.
Send a bulletin to the country and report news when appropriate.
Affected keys:
key struct member before after notes
-------------------------------------------
n nat_cnam -- BN 1
r nat_pnam -- B- 2
b nat_btu -- BN 3
m nat_reserve BN BN
c nat_xcap,ycap -- B-
o nat_xorg,yorg -- B-
u nat_timeused -- BN
M nat_money B- BN
Notes:
1. Reports N_NAME_CHNG rather than N_AIDS/N_HURTS.
2. Message improved to accurately reflect string truncation.
3. Greengrocers' apostrophe in message fixed.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Print a message (always), send a bulletin to the unit owner and report
news (sometimes).
The message is necessary to give the deity a chance to catch
unexpected changes, e.g. a player spending mobility right before the
deity edits it. Watching out for such changes is especially important
with non-interactive edit.
Affected keys:
cmd key struct member action
----------------------------------
edit s L shp_x,y B-
E shp_effic BN
M shp_mobil BN
F shp_fleet B-
T shp_tech BN
a shp_pstage --
b shp_ptime --
R shp_rpath B-
edit p l pln_x,y B-
e pln_effic BN
m pln_mobil BN
w pln_wing B-
t pln_tech BN
r pln_range B-
edit u L lnd_x,y B-
e lnd_effic BN
M lnd_mobil BN
a lnd_army B-
t lnd_tech BN
F lnd_harden BN
Z lnd_retreat B-
R lnd_rpath B-
The two characters in column action show whether the command sends a
bulletin (B) or not (-), and whether it reports news (N) or not (-).
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
Print a message, send bulletin to owner. Affects ship key 'W', land
unit key 'W', and plane key 'f'. The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player modifying
retreat conditions right before the deity edits them. Watching out
for such changes is especially important with non-interactive edit.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
edit: Teleport planes and land units to carrier on load
Edit lets deities load units onto remote carriers, resulting in a
carriers having cargo in another sector. Not good. Cargo gets
teleported to its carrier belatedly when the carrier moves.
Better let edit take care of the teleport.
Also tell the deity that he just caused a teleport. Necessary to give
the deity a chance to catch unexpected changes, e.g. a player moving a
plane right before the deity edits it. Watching out for such changes
is especially important with non-interactive edit.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
edit: Report loading/unloading of planes & land units properly
Print a message, send bulletin to owner. Affects plane keys 's', 'y',
and land unit keys 'S', 'Y'. The message is necessary to give the
deity a chance to catch unexpected changes, e.g. a player loading a
plane right before the deity edits it. Watching out for such changes
is especially important with non-interactive edit.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
edit: Report unit loss and gain properly for unit key 'O'
Print a message describing the actual change. Necessary to give the
deity a chance to catch unexpected changes, e.g. a player boarding a
ship right before the deity edits it. Watching out for such changes
is especially important with non-interactive edit.
Code already sends bulletins. Also report news.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>