Commit graph

3119 commits

Author SHA1 Message Date
c7426e1b45 Swap zdone's deity arguments
This puts the additional deity argument last.

Deity syntax wasn't documented before.
2008-07-25 08:16:38 -04:00
8fa45735db Make zdone accept country names
Use natarg() so that country names work.  Simplify control flow.
2008-07-25 08:16:38 -04:00
9031b03b56 Fix validation of threshold's threshold argument
There were two checks meant to enforce positive numbers, both dating
back to the earliest known versions of the code, and both wrong.

The first one applied only to thresholds given with the command, not
ones prompted for, and it incorrectly rejected numbers starting with +
or prefixed by whitespace.  Remove it.

The second one failed to reject negative numbers when prefixed by
whitespace.  Fix.

Fortunately, the update doesn't conjure up stuff to satisfy negative
thresholds.
2008-07-25 08:16:29 -04:00
3c25ebd927 Simplify att_prompt() 2008-07-21 08:13:40 -04:00
0b0612ea04 Simplify getpath() 2008-07-21 08:13:40 -04:00
052d514bfe Simplify getele()
No need to check player->aborted(), checking value of uprmptrd()
suffices.
2008-07-21 08:13:40 -04:00
05364c0f68 Avoid cryptic message when survey's first argument is empty
Catch empty argument instead of letting nstr_comp_val() choke on it.
2008-07-21 08:13:40 -04:00
4646dfbf80 Fix origin and zdone for invalid country argument
Invalid country argument was interpreted as (natid)-1, which is
normally 255.  Harmless as long as this is less than MAXNOC (99).
Wrong anyway.
2008-07-21 08:13:40 -04:00
da59e02706 Validate explore's third argument earlier
The old code checked a bunch of other things first, which made it hard
to see that the value of onearg() was checked properly.
2008-07-21 08:13:40 -04:00
03937d6c58 Fix cede not prompt twice for its first argument 2008-07-21 08:13:40 -04:00
be41e70fa8 Fail commands properly when they get aborted
The old code didn't return RET_SYN when aborting at the following
prompts:

* designate second argument

* morale second argument

* route second argument

* set third argument

* tend fourth argument

* zdone last argument
2008-07-21 08:13:40 -04:00
a7cf69af50 Clean up how desi() handles bad designation arguments
Fail the command when the designation isn't allowed for mortals, or
when the player can't afford it.

Treat '=' and '@' like the other designations not allowed for mortals,
not like invalid designations.  Change failure for invalid designation
from RET_FAIL to RET_SYN.
2008-07-21 08:13:40 -04:00
d000bf9296 Fix bdes and designate to always write updated bmap to disk
bdes() failed to do that when the player aborted at the prompt for the
new designation.

desi() failed to do it when it failed the command because the new
designation was bad.
2008-07-21 08:13:31 -04:00
90a4864c17 Fix bdes not to gripe about empty desig input 2008-07-21 08:13:20 -04:00
e031a8a052 Fix bomb to fail on empty <pin|strat> argument
Before, the planes flew empty, and oopsed (since commit feaa2dd9,
v4.3.12) or complained (before) over the target instead of bombing it.
2008-07-21 07:52:35 -04:00
7bbd3fcd89 Fix distribute aborting at prompt for second argument
Before failing the command, the old code attempted to change the
current sector's distribution center to the last one used, which might
have been uninitialized coordinates.  If lucky, the coordinates were
invalid, and the attempt oopsed and did nothing.
2008-07-21 07:50:13 -04:00
2fa522588a Simplify pin_bomb() aborting at "Bomb what" prompt 2008-07-21 07:25:16 -04:00
9eda5f87b8 Fix command abortion after getting player input
The old code didn't honor command abortion at the following prompts:

* arm third argument

* deliver fourth argument (also simplify)

* fire third argument

* fly and recon prompt for carrier to land on: pln_onewaymission()
  treated abort like empty input, which made planes attempt landing in
  the sector.

* lmine second argument

* order d fourth argument

* power c nat(s) argument

* range second argument

* sail second argument

* shutdown both arguments (first one was broken in commit 84cfd670,
  v4.3.10, second one never worked).

* tend third argument
2008-07-21 07:19:18 -04:00
b3a7a8ee11 Fix treatment of EOF from player
Commit 79407e68 (v4.3.11) changed recvclient() to keep failing after
receiving EOF from player.  This was bad, because some places getting
input check player->aborted instead of recvclient() failure, and
player->aborted wasn't set on EOF.  Bugs caused by this:

* comm_bomb(), ship_bomb(), plane_bomb(), land_bomb() went into an
  infinite loop that eventually ate all memory.

* deli(), desi(), dist(), fly(), morale(), zdon(), att_prompt(),
  ask_move_in() interpreted EOF as empty input instead of no more
  input.

* cmd_sail_ship() dereferenced a null pointer.

Fix by setting player->aborted on EOF, too.
2008-07-15 06:35:56 -04:00
9c5854c8c9 Simplify breaking of command loop
Change status() to check player->eof instead of io_error() and
io_eof().  Ignore value of command().
2008-07-15 06:25:29 -04:00
b7153d095c Change recvclient() to treat io_error() like io_eof()
This is for consistency with status() and player_login().
2008-07-15 06:25:18 -04:00
49c24d7b78 Oops when player thread keeps reading input unsuccessfully
Reading input fails after EOF and while the current command is
aborted.  Commands should detect that and fail.  If a command neglects
to do that in a loop, the loop can become infinite.  This is
especially bad after EOF, because then the client might not read
output anymore.  Output gets buffered until memory runs out.

Mitigate such bugs by counting how many calls have failed in a row,
oopsing on the 256th, and sleeping one minute from the 256th on.
2008-07-13 07:50:20 -04:00
f2294d67a4 Change pln_mine() parameters to match pln_dropoff()
This moves getting the target sector from caller into pln_mine().
Makes sense, because that's where it's put.
2008-07-12 14:53:46 -04:00
27edba1f1b Change pln_dropoff() parameters to match pln_newlanding()
This moves getting the target sector or ship from caller into
pln_dropoff().  Makes sense, because that's where it's put.
2008-07-12 14:53:28 -04:00
42d9475d89 Fix seqno mismatch in fly()
fly() reads the carrier, then passes it to pln_dropoff(), which writes
it back.  fly() also calls pln_oneway_to_carrier_ok(), which updates
the carrier when its plane summary information is incorrect.

The old code called it between reading the carrier and passing it to
pln_dropoff().  This made pln_dropoff() wipe out the plane summary
update, and triggered a seqno mismatch oops.  Broken by introduction
of pln_oneway_to_carrier_ok() in commit 1127762c, v4.2.17.

Fix by reading the carrier right before passing it to pln_dropoff().
2008-07-12 14:51:18 -04:00
89d168cd65 Make selector terr do the right thing for deities
Commit db1ac2ed (v4.3.6) introduced a separate territory for deities,
and made the territory command use it by default for deities.  Deities
can still access the old default territory as territory number 0.

Selectors terr, terr0 (alias for terr), terr1, terr2, terr3 remained
unchanged, and a new selector dterr was created to let deities access
the deity territory.

Make selector terr virtual, so that it can do "the right thing", just
like the territory command: select territory 0 for mortals, and the
deity territory for deities.

Unfortunately, this requires us to switch xdump to use terr0 instead
of terr, because otherwise the deity xdump would contain the deity
territory twice, and territory 0 not at all.
2008-07-12 10:43:03 -04:00
7a06a58bec Don't fix up dead planes stuck in the air
Missile interdiction leaves behind used up missiles with the
PLN_LAUNCHED flag set.  This can lead to a bogus warning from
pln_zap_transient_flags() on server restart.

Change pln_zap_transient_flags() to ignore dead planes.
2008-07-12 10:43:03 -04:00
23d52a4147 Fix bomb not to let you p-bomb dead ships and land units
ASW planes bombing ships were not affected, because asw_shipsatxy()
excludes dead ships correctly.
2008-07-12 10:43:03 -04:00
dc41544a8f Document retreat condition help in info retreat
While there, layout the table more nicely.
2008-07-12 10:43:03 -04:00
bb5dfd803b Clean up and improve retreat condition handling
Change retreat condition prompt to point to help.  Before, it listed
conditions rather cryptically, without mentioning how to get help.

Don't provide help when encountering a bad retreat condition
character.

Fail the command when encountering a bad retreat condition character.
Before, they were dropped.

Don't fail the command when the player asks for help at the condition
code prompt.

Retreat condition help failed to explain 'c'.
2008-07-12 10:41:44 -04:00
700089dd42 Clean up unified unit loop in retreat()
Factor common code out of the type conditional.  Widens the "as flt?"
column to match the "as army?" column.
2008-07-11 07:19:29 -04:00
6b311f39da Unify retreat and lretreat code
New retreat(), call from retr() and lretr().  No functional changes.
Needs cleanup.
2008-07-11 07:19:29 -04:00
44e2ef468f Make retr() and lretr() simpler and more robust
The old code recognized group retreat only when the first argument was
on the command line.  Didn't make a difference, because it was only
used when there were at least two arguments on the command line.

The old code relied on rflags being represented as two's complement.

When given an empty retreat path, the old code deleted the retreat
path and set the retreat flags normally.  The new code deletes both.
Neither is nice; it should perhaps keep the retreat path and only set
the flags.
2008-07-11 07:18:59 -04:00
67a9a8d96a Fix mapper to work with current code
4.2.0 broke over.awk.
2008-07-04 17:31:33 -04:00
801780043f Fix flying commands not to let planes do double duty as escorts
Commit 7ca4f412 (v4.3.12) marked planes flying a sortie with
PLN_LAUNCHED, and made pln_arm() reject planes with that flag set.
This was designed to reject escorts that were already flying as
bombers.  It didn't work, because the test for PLN_LAUNCHED used a
stale copy of the plane created by pln_sel().  Fix by getting a fresh
copy.

The bug always existed, but the botched fix in commit 7ca4f412 made it
worse.  Before, ac_encounter() dropped escorts that were also bombers,
so the bug merely wasted plane fuel.  After, such planes were
effectively duplicated, and damage to one of them, usually the bomber,
was wiped out.  Abusable.
2008-06-28 11:24:43 -04:00
b0644e822c Fix seqno mismatch and use-after-free in shp_sweep()
The code wrote the swept sector after calling shp_check_one_mines().
This failed to use up the mine that hit the minesweeper, and triggered
a seqno mismatch oops.

The code wrote the minesweeper after calling shp_check_one_mines().
This used freed memory when the minesweeper got sunk there.

Broken in 4.0.17.  Fix by moving both calls before
shp_check_one_mines().
2008-06-28 09:24:32 -04:00
6d38a04930 Don't let non-light units board ships that can't carry them
ask_olist() let non-light land units board ships that can carry only
light units.  If the board succeeds, the non-light unit move onto the
ship and then are stuck there.
2008-06-17 20:17:15 +02:00
85bb88c26c Limit BTU production to 1000 civilians instead of 999
This makes the limit again equal maximum population of a capital
sector, which changed in commit 6bbd7ffd, v4.3.6.
2008-06-15 08:49:26 +02:00
4a67080656 Update info BTU on Empire clock and work percentage
Work percentage should have been documented in commit 233fce87,
v4.3.0.

Empire clock should have been documented in commit d3e0597f, v4.3.10.
2008-06-15 08:49:26 +02:00
860369ec7e Update info Citizens on census showing old owner
This was forgotten in commit 6b434ee3, v4.3.0.
2008-06-15 08:49:25 +02:00
3735f04b73 Make spy command require sector military
Spies shot were only deduced from sector military; land units were
immune to losses; in fact they needn't have any military to spy.

Fix by requiring and using only sector military.  Closes #758483.
2008-06-15 08:49:25 +02:00
ab2b930b5b Let spy report on unoccupied sectors
Make spy() not skip sectors without civilians, military and land
units.  There could be other interesting things to report there:
efficiency, gold bars, planes...
2008-06-15 08:49:21 +02:00
a233ecfea9 Remove columns lnd, pln from spy report to fix spy unit leak
The values in these columns were computed by count_sect_units() and
count_sect_planes(), which included land units and planes in the count
that aren't shown by prunits() and prplanes(), namely own and embarked
units.  Confusing.  Moreover, count_sect_planes() and prunits() rolled
dice separately for spy units.  This could leak the presence of spies
even when prunits() didn't show them.

All fixable, but not worth the trouble; just remove the counts.
2008-06-14 18:55:29 +02:00
c658d1e08d Simplify prunits() and prplanes()
Drop redundant conditional.  No functional change.
2008-06-14 18:28:44 +02:00
dbd886ae2e New player_relstr(), factored out out of prunits() and prplanes()
No functional change.
2008-06-14 18:20:48 +02:00
4025c242ff Have the complete spy report code in one place
Move prunits() and prplanes() from spyline()'s caller into spyline().
Rename spyline() to spy_report().  No functional change.
2008-06-14 18:07:01 +02:00
89e33f6218 Simplify control flow in spy()
Rearrange so that we make contact (each way) and print the spy report
in just one place.  No functional change.
2008-06-14 17:51:26 +02:00
ee6927122c Fix spy to make contact when spy succeeds due to recon unit
If you have a recon unit, you get a spy report whether the spy is
caught or not.  But you made contact only when he wasn't caught.  Fix
that.
2008-06-14 17:40:57 +02:00
3e251b474f Fix ship interdiction targeting ships not at sea
perform_mission() needs to know whether it is targeting ships or
something else, because the rules differ: submarines interdict only
ships, land units get their damage reduced when interdicting ships,
and different news are generated.

The old code assumed it was targeting ships when the target sector was
sea.  Wrong when interdicting ships in harbors, bridges and such.
This has always been broken.  Except when checking a submarine's
target: there it tested argument s, which is gross, but at least it
works.  That code was added in v4.0.8.

Replace the broken test by the gross hack everywhere.  This fixes news
and damage from land units when ships get interdicted in non-sea
sectors.
2008-06-08 11:35:04 +02:00
e1d7f9bf8e Fix land unit return fire damage to ships inconsistency
Land units firing at ships have their damage reduced based on their
accuracy.  This wasn't done when returning fire in quiet_bigdef().
Fix that.
2008-06-08 11:06:40 +02:00