Commit graph

50 commits

Author SHA1 Message Date
e6ce36df64 Spelling corrections
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-07 10:08:31 +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
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
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
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
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
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
827e2e4cc0 edit: Trim trailing tab in output
print_plane() ends its output with '\t' instead of '\n'.  Next is a
prompt, which supplies the missing newline (see pr_id()).

Ugly, clean up.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-08 13:36:57 +02:00
f3cb215e1f edit: Generalize edit to multiple objects
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>
2013-06-06 19:59:18 +02:00
f2bf352e66 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>
2013-06-06 19:55:02 +02:00
2975ea02ae edit: Add remaining missing nation change reporting
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>
2013-06-06 19:55:02 +02:00
d006791ed6 edit: Improve remaining existing nation change reporting
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>
2013-06-06 19:55:02 +02:00
93aa604b67 edit: Improve tech, research, edu, happiness change reporting
Print "Technology" instead of "Tech".  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 unit owner and report news on change.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
a03d804ffc edit: Add remaining missing unit change reporting
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>
2013-06-06 19:55:02 +02:00
4aa2f071ba edit: Report flags change properly
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>
2013-06-06 19:55:02 +02:00
ef2e2d08a2 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>
2013-06-06 19:55:02 +02:00
3dceefbbc9 edit: Refuse to move planes and land units on carriers
They really need to stay with their carrier.  Else, cargo gets
silently teleported to its carrier when the carrier moves.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
cbe9897bfa 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>
2013-06-06 19:55:02 +02:00
97b3aacaca edit: Report unit loss and gain properly for key 'U'
Send bulletin to owner and report news exactly like for key 'O' or
sector key 'L'.

Print a "duplicated" message, just for consistency with other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
1f950f6a70 edit: Report unit key 'U' failure more nicely, and avoid oops
Two failure modes:

* When the argument is negative, edit() attempts an invalid write,
  triggering an oops.  edit() detects the write failure, and returns
  RET_FAIL.

  Detect the negative argument instead, and return RET_SYN, like we do
  for other invalid edit arguments.

* When the argument requires the table to be extended, but the
  extension fails, edit() returns RET_FAIL.

  Additionally report the failure to the player.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:02 +02:00
ccd4368679 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>
2013-06-06 19:55:02 +02:00
b99a116dd6 edit: Report ship and land unit commodity change properly
Print a message describing the actual change.  Necessary to give the
deity a chance to catch unexpected changes, e.g. a player unloading
stuff right before the deity edits it, leaving fewer items than the
deity intends to take.  Watching out for such changes is especially
important with non-interactive edit.

Send bulletin to owner and report news exactly like the give command.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
004c4d0f23 edit &c: Report sector non-change differently
Print "unchanged" instead of "changed from X to X".  Affects edit,
setresource, setsector.  Suppress bulletin and news.  Affects only
edit sector key 'L'.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
82a59fbcc3 edit: Streamline wording of sector change reports slightly
Most places use "FOO of X,Y changed", some use "FOO in X,Y changed",
"FOO in X,Y was changed", "FOO of sector X,Y changed".  Normalize to
the former.

Most places do not end the message with a period, some do.  Normalize
to no period.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
eb60b38a26 swapsector: Notify affected sector owners
Send bulletins, like edit does.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
e109d981b8 setsector setresource: Switch to edit_sect()
One copy of the code suffices.

"Fertility content" becomes just "Fertility" in messages.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:01 +02:00
542a9ef83f edit &c: Add remaining missing sector change reporting
edit, setresource and setsector report change in three ways:

* Print a message.

* Send a bulletin to the changed object's owner.  This should be done
  if and only if the change is visible to the owner, e.g. in census or
  xdump.

* Report divine aid in news.  This should be done if and only if a
  bulletin was sent, except for changes that are neither negative nor
  positive, such as changing the distribution sector.

Fix the places that don't get it right for sectors:

    cmd  key    sctstr member   before  after   notes
    -------------------------------------------------
    edit l O    sct_oldown      --      B-
    edit l F    sct_fallout     --      BN      1
    edit l M    sct_mines       --      BN      2 3
    edit l D    sct_dist_x,y    --      B-      1
    edit l s    sct_type        --      B-      1
    edit l S    sct_newtype     --      B-      1
    setse ow    sct_own         B-      BN
    setse ol    sct_oldown      --      B-
    setse e     sct_effic       --      BN      2
    setse mo    sct_mobil       --      BN      2
    setse a     sct_avail       --      BN      2
    setse w     sct_work        --      BN      2

The two characters in columns before, after show whether the command
sends a bulletin (B) or not (-), and whether it reports news (N) or
not (-).

Notes:

1. Printed message massaged slightly for consistency with other keys.

2. Printed message improved to show the old value, too.  Necessary to
   give the deity a chance to catch unexpected changes, e.g. a player
   laying mines right before the deity edits them.  Watching out for
   such changes is especially important with non-interactive edit.

3. Bulletin and news suppressed for occupied sectors.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
fec5ad692d edit: Report sector loss and gain properly for key 'L'
Send bulletin to owner and report news exactly like for key 'o'.

Also print a "sector duplicated" message, just for consistency with
other keys.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
a41c74967d edit: Limit resources to 100 instead of 127
Back in Empire 1, resources were limited consistently: fertility to
120, all others to 100.

When Chainsaw added setresource, consistency was lost: fertility got
limited to 100 there.

Chainsaw 3 changed edit to limit all resources to 127.

Commit 3fcee8dd and commit 8e430ae2 (both v4.3.11) changed fairland
and setsector to limit fertility to 100, matching setresource.

Now only edit remains different.  Change it to finally make things
consistent again.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
985ac03fbe setsector setresource: Print effect for unowned sectors, too
The "changed from" message has always been suppressed for unowned
sectors.  Makes no sense.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
c900ef8f1e setsector: Don't disclose number of landmines to occupier
When the deity sets the number of mines with setsector, the sector
owner (if any) is told the resulting number of mines.  Even for
occupied sectors, where mines belong to the old owner, and thus
shouldn't be disclosed.  Oops.

Fix setsector not to tell the sector owner anything then.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
bdf7cbce38 edit &c: Suppress news and bulletins on no-op acts of god
give already suppresses when the new value equals the old one, but
edit, setresource and setsector don't.  Make them.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
3072386d8d Send bulletins only from POGO
In the beginning, all bulletins came from POGO.  Chainsaw changed edit
and give to send them from the deity using the command.  Its new
command setresource sent from POGO regardless.  Its new command
setsector did both.

Go back to sending them only from POGO.

Some of the affected bulletins don't mention the acting deity.  Reword
them so they do.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:55:00 +02:00
c0f3a1e5e5 edit: Accept interactive empty key argument again
Empty key arguments work fine when passed as command arguments, but
not interactively.  For example, 'edit s 42 R ""' clears the retreat
path, but in an interactive 'edit s 43', 'R ""' sets it to "".

In Empire 1, omitting the argument made it empty.  Empire 2 turned
that into an error without providing an alternative.

Switch to the common command parser, so that quoting works, and "" is
parsed as empty argument.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:54:58 +02:00
33456b3371 edit: Treat blank interactive input like empty input
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:53:56 +02:00
4c1866285b give: Report number given when less than requested amount
Necessary to give the deity a chance to catch unexpected changes,
e.g. a player moving away stuff right before a give command, leaving
fewer items than the deity intends to take.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
9aaf609359 give: Fix integer overflows on silly third arguments
give() silently caps the resulting number of items to 0..ITEM_MAX.

However, its test for "< 0" suffers integer overflow on two's
complement machines (i.e. practically everywhere) when the amount
argument is INT_MIN.  give() proceeds as if the result was in range:
it sets the number of items to (short)(n + INT_MIN), telexes the owner
that INT_MIN items were stolen (obviously bogus), and tells the deity
that there are now n + INT_MIN items in X,Y.

On common machines, (short)(n + INT_MIN) == n, i.e. nothing is given.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

In both cases, output and telegram lie.

Likewise, its test for "> ITEM_MAX" suffers integer overflow for
sufficiently big amount arguments.  Again, give() proceeds as if the
result was in range: it sets the number of items to (short)(n + amt),
telexes the owner that -amt items were stolen (obviously bogus), and
tells the deity that there are now close to INT_MIN items in X,Y.

On common machines, (short)(n + amt) = n + INT_MAX - amt - 1,
i.e. some items are stolen.

On an oddball machine with short as wide as int, the cast to short
does nothing, item_prewrite() oopses, and corrects the number of items
to zero.

Again, output and telegram lie.

Aside: setsector can suffer similar overflows, but it reports the
resulting change correctly.  Good enough.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
2b80ce93da edit: Fix integer argument range checking
Upper bounds corrected:

    cmd  key  struct member   wrong   correct   notes
    -------------------------------------------------
    edit l m  sct_mobil         255       127      1
           t  sct_ptime         255     32767
    edit c b  nat_btu          1024  max_btus
    edit p m  pln_mobil         255       127      1
    edit u F  lnd_harden        255       127	   1

Missing bounds supplied, arguments out of bounds are silently clipped
unless noted otherwise:

    cmd  key     struct member   bounds           notes
    ---------------------------------------------------
    edit c t     nat_tgms        0   USHRT_MAX       2
           m     nat_reserve     0   INT_MAX
           T...  nat_level[]     0   infinity
    edit s a     shp_pstage      0   PLG_EXPOSED     3
           b     shp_ptime       0   32767
           M     shp_mobil    -127   127
           c...  shp_item[]      0   load limit      4
    edit u Y     lnd_land       -1   size of table   5
           M     lnd_mobil    -127   127
           S     lnd_ship       -1   size of table   5
           Z     lnd_retreat     0   100
           c...  lnd_item[]      0   load limit      4
    edit p r     pln_range       0   max range
           s     pln_ship       -1   size of table   5
           y     pln_land       -1   size of table   5

Notes:

1. Values between SCHAR_MAX and 255 were cast to signed char, changing
the sign.

2. The real upper bound is the number of telegrams in the mailbox, but
counting them isn't worth it.

3. This check is particularly important, because values out of bounds
make the server refuse to start without -F, and empdump -x warn
"export has errors, not importable as is".

4. Values outside 0..ITEM_MAX got caught and clipped by
item_prewrite().  This check avoids the oops, and tightens the upper
bound for units.

5. Argument out-of-bounds are rejected.  This check is particularly
important, because unit numbers beyond the size of the table trigger
oopses.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
29c7ae3d80 edit: Suppress "sunk!" after "taken from you by deity"
The fact that the ship wasn't given to anyone is none of the
ex-owner's business.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
381c479ff8 edit: Fix and unify handling of invalid country numbers
Negative numbers and numbers greater or equal than MAXNOC are invalid.
edit handles such arguments inconsistently:

    cmd  key  struct member   arg < 0     arg >= MAXNOC
    ---------------------------------------------------
    edit l o  sct_own         reject      MAXNOC - 1
           O  sct_oldown      reject      MAXNOC - 1
           X  sct_che_target  0           MAXNOC - 1
    edit s O  shp_own         cast        skip
    edit u O  lnd_own         cast        skip
    edit p O  pln_own         cast        skip

Legend:

    0           replace arg by 0
    MAXNOC - 1  replace arg by MAXNOC - 1
    reject      command fails
    cast        replace arg by (natid)arg
                bug: can be >= MAXNOC!
    skip        ignore this key and arg
                bug: telexes the owner he lost the unit, which is a lie

Unify to reject.  Matches setsector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
aa07f3393a edit: Don't show loyalty, plague stage and time as percentages
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
53d0edc838 edit: Show edited planes and land units just like ships
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:26 +02:00
aa870f5d91 tests/actofgod: New, disabled for now because it oopses
This is a fairly comprehensive test of the deity commands to edit game
state: edit, setresource, setsector, give, swapsector.

The test makes edit screw up game state, triggering oopses.  The
server refuses to start without -F then, and empdump -x warns "export
has errors, not importable as is".  Until these bugs are fixed, skip
this test in "make check".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2013-06-06 19:52:20 +02:00