Commit graph

89 commits

Author SHA1 Message Date
8b9ce7be43 subs: Maintain plane and land unit fortification invariant
Make lnd_prewrite() and pln_prewrite() ensure that land units and
missiles loaded on a land unit or ship are never fortified / hardened.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 10:40:34 +01:00
b2be5a227d tests/actofgod: Cover loading hardened missiles
Demonstrates that edit leaves a missile's hardening intact on load.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:25:18 +01:00
fd303fc6b3 edit: Implement editing of missile fortification
The edit command doesn't support editing plane fortification.  Has
always been that way.  Implement it as key 'F'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
4746d22c3e tests/actofgod: Test integer values more thoroughly
For integer values, we test lower bound - 1, lower bound, upper bound,
upper bound + 1.  Additionally test lower bound + 1, upper bound -1.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
5363ef85d4 tests/actofgod: Fix owner of plane 7/8
Planes 7/8 aren't visible in output, because the test neglects to set
their owner.  Messed up in commit commit efec441, v4.3.33.  Correct
that oversight.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
16e565ed5f edit: Implement editing bars on ships and land units
The edit command doesn't support editing bars on ships and land units.
Has always been that way.  The stock game's ships have always been
unable to load bars.  Not the case for land units.

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

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
647dc66a40 tests/actofgod: Test give and edit for each item type
The test covers only 'c' and 'l' with give, 'm' and 'g' with edit.
Cover the other item types, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
2902cc22c4 edit: Print ship and land unit items with field width 5
print_items() uses field widths between 3 and 5.  They go back all the
way to Empire 1, and are fine for the stock game.  Widen the narrower
ones to 5, because a consistent field width looks tidier, and can
avoid misaligned columns with customized ships and land units.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2021-01-05 07:23:45 +01:00
e6ce36df64 Spelling corrections
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +02:00
92693cba65 relations: Move relations state from struct natstr to relatstr
Relations state is relatively bulky: it's a big chunk of struct
natstr, and adds 200 bytes per country to xdump nat.

Relations change rarely.  Rewriting it to disk on every nation update
and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move relations state to its own struct relatstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:22 +02:00
de24545963 relations: Create EF_RELAT table of struct relatstr
New struct relatstr is basically empty so far.  The next commit will
move relations state from struct natstr to struct relatstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
eaa678c903 reject: Move reject state from struct natstr to rejectstr
Reject state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat.

Reject state changes rarely.  Rewriting it to disk on every nation
update and retransmitting it in every xdump nat is wasteful.

To avoid this waste, move reject state to its own struct rejectstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
f35f16c0a2 reject: Create EF_REJECT table of struct rejectstr
New struct rejectstr is basically empty so far.  The next commit will
move reject state from struct natstr to struct rejectstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:21 +02:00
c8e7548f24 contact: Move contact state from struct natstr to contactstr
Contact state is relatively bulky: it's a big chunk of struct natstr,
and adds almost 200 bytes per country to xdump nat for deities.

Contact changes rarely.  Since we avoid unnecessary updates, it
doesn't change at all unless option HIDDEN is enabled.  Rewriting it
to disk on every nation update and retransmitting it in every deity
xdump nat is wasteful.

To avoid this waste, move contact state to its own struct contactstr.

This is of course an xdump compatibility break.  We're not maintaining
xdump compatibility in this release.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
4b4df53485 contact: Create EF_CONTACT table of struct contactstr
New struct contactstr is basically empty so far.  The next commit will
move contact state from struct natstr to struct contactstr.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
cf4e9bc89d contact: Initialize contact state properly
A country must always be in contact of itself when option HIDDEN is
enabled.  The code ensures this by establishing contact whenever a
player logs in, in init_nats().  This is not the proper place.  Game
state should be initialized in empfile's oninit() callback, in this
case nat_oninit().  Do that, and drop the putcontact() from
init_nats().

Note that option LOSE_CONTACT only affects contact to other countries:
agecontact() doesn't age the country's contact to itself.

Use the opportunity to initialize contact so that getcontact() works
even when HIDDEN is disabled.  Just cleanup, it isn't actually called
then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:20 +02:00
2402f3f2a2 lost: Fix to track more than one lost sector per owner
makelost() overwrites an existing entry for the same thing, else
creates a new one.  It calls findlost() to find existing entries.
findlost() means to look up by coordinates if it's looking for a
sector entry, and by ID if it's looking for a ship, plane, land unit
or nuke entry.  It actually does both for sectors.  Since callers pass
zero ID for sectors, sector entries always match, so at most one gets
created, and additional ones overwrite it.

Broken since the lost table was introduced in 4.0.7.  Fix the flawed
comparison in findlost().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:18 +02:00
7b5bd13767 nsc: Drop deprecated nat and country selector hostname
Deprecated since commit 199388b, v4.3.33.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:09:17 +02:00
0bdcb5ee19 sect: Keep work percentage without civilians at 100%
We maintain a few sector invariants in sct_prewrite().  Since the
update bypasses sct_prewrite(), it needs to maintain them itself.  The
two should be consistent.

sct_prewrite() resets work percentage of owned sectors to 100% when
there are no civilians.  The update's populace() resets it for unowned
sectors as well, if they have military.

Change sct_prewrite() to reset sct_work = 100 regardless of owner.
Also change sct_oninit() to initialize sct_work = 100, so it doesn't
change on first write.  Update tests/smoke/fairland.xdump for the same
reason.

The massive test output differences are all due to sct_work.

Inconsistencies with the update remain.  They will be fixed next.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:57 +02:00
d5d92caf94 retreat lretreat edit xdump: Change "torped" to "torpedoed"
"torped" comes from symbol table retreat_flags.  Visible in output of
edit, retreat, lretreat and xdump.  Tolerable in edit, but player
commands like retreat should really use proper words.

Fixing it in retreat_flags changes xdump output, thus risks breaking
clients.  Do it anyway, since no known client recognizes this
particular symbol value.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
0a012a3ed5 edit: Fix tech and range adjustment for edit p key 'T'
It sets the new type, then falls through to setting tech if the new
type requires more than the plane currently has.  Two problems with
that:

* If we fall through, the plane is invalid: it has less tech than
  required.  Its only use before it gets overwritten is pln_set_tech()
  calling pln_range_max() to find out whether the range is limited.
  Passes a negative number to log().  Not fatal, but pln_set_tech()'s
  range adjustment is unlikely to work.

* If we don't fall through, the range may still need adjustment,
  either up (to keep it unlimited if the new type has more range), or
  down (to keep it within the new type's shorter range).

Screwed up when the key was added in commit 6b0b6f17.  Fix by
adjusting tech first, then setting the type, then adjusting the range.
The latter relies on pln_set_tech() coping with ranges exceeding the
type's maximum, which it does.

Change the other type edits similarly for consistency.

When a type edit triggers a tech change, the tech change is now
silent.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:47 +01:00
efec4417d3 tests/actofgod: Test plane type change's effect on range
Demonstrate bugs: doesn't always preserve unlimited range, and doesn't
always cut range back to maximum.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:47 +01:00
dc73207a99 sail: Remove option SAIL
SAIL has issues:

* Sail orders are executed at the update.  Crafty players can use them
  to get around the update window.

* The route is fixed at command time.  You can't let the update find
  the best route, like it does for distribution.

* The info pages documenting it amount to almost 100 non-blank lines
  formatted.  They claim you can follow friendly ships.  This is
  wrong.  They also show incorrect follow syntax.  Unlikely to be the
  only errors.

* Few players use it.  Makes it a nice hidey-hole for bugs.  Here are
  two nice ones:

  - If follow's second argument is negative, the code attempts to
    follow an uninitialized ship.  Could well be a remote hole.

  - If ship #1 follows #2 follows #3 follows #2, the update goes into
    an infinite loop.

* It's more than 500 lines of rather crufty code nobody wants to
  touch.  Thanks to a big effort in Empire 2, it shares some code with
  the navigation command.  It still duplicates other navigation code.
  The sharing complicates fixing the bugs demonstrated by
  navi-march-test.

Reviewing, fixing and testing this mess isn't worth the opportunity
cost.  Remove it instead.  Drop commands follow, mquota, sail and
unsail.  Drop ship selectors mquota, path, follow.

struct shpstr shrinks some more, on my system from 160 to 120 bytes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:11:28 +01:00
48e656c057 autonav: Remove the feature
The autonavigation feature has issues:

* Autonavigation orders are executed at the update.  Crafty players
  can use them to get around the update window.

* Usability is poor:

  - The order command is overly complex, not least because it can do
    five different things: clear, suspend, resume, declare route, set
    cargo levels.

  - Unlike every other command involving movement, order does not let
    you specify routes, only destination sectors.

  - Setting cargo levels can silently swap start and end point of a
    circular route, because "this keeps the load_it() procedure
    happy".  Maybe it does, but it surely keeps players confused.

  - Setting "start" cargo levels actually sets the "end" levels, and
    vice versa.  Has always been broken that way.

  - Predicting what exactly autonavigation will do at the update isn't
    easy.

* The info pages documenting it amount to almost 400 non-blank lines
  formatted.  They claim only merchant ships can be given orders.
  This is wrong.  Unlikely to be the only error.

* Few players use it, and its workings at the update a fairly opaque.
  Makes it a nice hidey-hole for bugs.  Here are two:

  - Unlike the scuttle command, autonavigation happily scuttles trade
    ships while they're on the trading block.

  - Unlike the load command, autonavigation can load in friendly and
    allied sectors.

* It's more than 700 lines of rather crufty code nobody wants to
  touch.  Thanks to a big effort in Empire 2, it shares code with the
  navigation command.  It still duplicates load code.  The sharing
  complicates fixing the bugs demonstrated by navi-march-test.

Reviewing, fixing and testing this mess isn't worth the opportunity
cost.  Remove it instead.  Drop commands order, qorder and sorder.
Drop ship selectors xstart, xend, ystart, yend, cargostart, cargoend,
amtstart, amtend, autonav.

xdump ship sheds almost half its columns.  struct shpstr shrinks, on
my system from 200 to 160 bytes.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:10:22 +01:00
f4f048234c empdump: Omit redundant data from export, new -c includes it
Cuts size of export files in test suite by a factor of four.  Not a
big deal for disk usage, as export files compress very well, and disk
space is cheap anyway.  Export files are simply easier to work with
when they aren't full of redundant crap.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-01 16:53:00 +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
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
ae595ec430 edit: Fix edit s key 'U' to preserve "does not follow"
Copying the ship copies the ship to follow.  When the source ship
doesn't follow a ship, the target ship is made to follow the source.
Screwed up since Chainsaw added the means to copy a ship.  Fix it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
e604c6e737 edit: Make edit l key 'L' preserve "no dist center"
Copying the sector copies its distribution center.  When the source
sector has none, the target sector is made to distribute to the
source.  Unexpected.  Zap the distribution center then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
3c7d9da3ab edit: Fix edit l key 'L' not to mess up coastal flag
Screwed up since Chainsaw added the means to copy a sector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
321f6161c9 tests/actofgod: Show edit l key 'L' mess up coastal flag
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 13:19:24 +01:00
893f9f3eb8 tests/actofgod: Use build command for setup
final.xdump changes, because setup no longer copies 3,-1 to 1,-1,
messing up its distribution center.  Harmless.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:31 +01:00
05f1844ca1 build: Deities build ex nihilo
Let deities build in any sector.  If the deity's tech level is too
low, use the required tech level instead.  Don't require or use
materials, work or money.  Bridge spans still require support.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 12:00:19 +01:00
964f55794c edit: Fix reporting of no-op unit location change
Report "unchanged" instead of "changed from X,Y to X,Y".  Screwed up
in v4.3.32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
caf239b3ed tests: Zap setup's news and lost items, like telegrams
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:51:50 +01:00
370b9d1c07 tests: Don't leak telegram counters from setup into test
Moving the telegram files away isn't enough, we also have to reset
nat_tgms.  actofgod/setup-POGO does it already, but fire/setup-POGO
doesn't.  Do it in begin_test instead, right where the telegram files
are moved away.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:42 +01:00
a109de948b Remove option TREATIES
TREATIES has issues:

* Treaties can cover attack, assault, paradrop, board, lboard, fire,
  build (s|p|l|n) and enlist, but not bomb, launch, torpedo and
  enlistment centers.

* Usability is very poor.  While a treaty is in effect, every player
  action that violates a treaty condition triggers a prompt like this:

    This action is in contravention of  treaty #0 (with Curmudgeon)
    Do you wish to go ahead anyway? [yn]

  If you decline, the action is not executed.  If you accept, it is.
  In both cases, your decision is reported in the news.

  You cannot get rid of these prompts until the treaty expires.

* Virtually nobody uses them.

* Virtually unused code is buggy code.  There is at least one race
  condition: multifire() reads the firing sector, ship or land unit
  before the treaty prompt, and writes it back after, triggering a
  generation oops.  Any updates made by other threads while trechk()
  waits for input are wiped out, triggering a seqno mismatch oops.

* The treaty prompts could confuse smart clients that aren't prepared
  for them.  WinACE isn't, but is reported to work anyway at least
  common usage.  Ron Koenderink (the WinACE maintainer) suspects there
  could be a few situations where it will fail.

This feature is not earning its keep.  Remove it.  Drop command
treaty, consider treaty, offer treaty, xdump treaty, reject treaties.
Output of accept changed, obviously.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-02-16 11:44:14 +01:00
6c0a1fcb1e tests: Enable running_test_suite by default
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:09:17 +01:00
cf942fbf1b tests: Use feed_files for setup scripts
To make setup scripting more similar to test scripting.  Also permits
use of countries other than POGO there, but that isn't necessary right
now.

Setup scripts renamed from init_script to setup-POGO.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:09:16 +01:00
ab913d73f9 tests: Rename final xdump files to final.xdump
The other test output files have fixed names, and having just one with
a name that varies with the test name complicates things with no gain.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-19 10:09:16 +01:00
3697a0a20b 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>
2014-01-19 08:14:33 +01:00
37ff3774ec tests: Normalize trailing white space away in test output
We don't really care for it there, and git's pre-commit hook flags it,
which is annoying.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-06 20:49:59 +01:00
c83cfbe33c edit: Trim unwanted trailing space from output
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-06 20:49:59 +01:00
216470a8d5 edit: Implement edit nuke
Has been "not implemented yet" since the dawn of time.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
b68b3c4589 edit: Suppress bulletin on no-op unit location change
Screwed up in commit a03d804f, v4.3.32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
329da055dd nukes: New selector stockpile
Not interesting without way to make stockpiles.  Coming soon.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:47 +01:00
6b0b6f174b edit: Add editing of ship, plane and land unit type
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:47 +01:00
2936e07f41 edit: Make unit owner change away from POGO work
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>
2014-01-02 14:07:22 +01:00
5de1e5ec5f tests: Drop smoke.out, actofgod.out
Uninteresting since commit 9ca3fa9, v4.3.32.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:07:22 +01:00