MAPWIDTH(3) used to be one too small, which made rout() clobber the
map row's terminating zero when the map spans the whole world in x.
Since Chainsaw 2, rout() copied rows into an additional buffer to add
a terminating zero. Remove that junk.
MAPWIDTH(x) was (x+2)/2 - 1 too small. Affected were path and route,
which use MAPWIDTH(3) to size their map buffer: they clobber map rows'
terminating zero when the map spans the whole world in x. rout() has
a cheesy work-around for that since Chainsaw 2. path() doesn't, and
duly breaks.
Sub-command 'm' calls display_region_map() to display a map. The map
is centered on the current sector by default. It extended one sector
farther to the right and down than to the left and up. Odd, and
inconsistent with the map size used by unit_map() for navigate and
march sub-command 'M'. Fix that.
Change struct range from exclusive to inclusive upper bounds, for
consistency with struct realmstr and the area syntax. Also fix many
bugs.
real()'s conversion from struct range's exclusive upper bounds to
struct realmstr's inclusive upper bounds could underflow and store -1
in the realms file. Harmless, because its users didn't mind:
list_realm() and nstr_exec_val() convert back to relative coordinates,
and sarg_getrange() is only used by sarg_area(), which happened to
undo the damage. The change to inclusive upper bounds gets rid of the
broken conversion.
xyinrange() incorrectly treated the upper bound as inclusive, unless
the bounds were equal. Impact:
* nxtitem() and nxtitemp() cases NS_AREA and NS_DIST attempted to hack
around xyinrange()'s lossage(!), but screwed up: sectors on the
lower bound of of a range spanning the the whole world were skipped.
This affected all command arguments that support area or distance
syntax for items. In sufficiently small worlds, it could also make
radar miss satellites and ships, sonar miss ships, satellite miss
ships and land units, nuclear detonations miss ships, planes, land
units and nukes, automatic supply miss ship and land unit supply
sources, ships and land units fail to return fire, ships fail to
fire support.
* draw_map() could draw units sitting just right or just below of the
mapped area. No effect, as these parts of the map weren't actually
shown.
xydist_range() produced an inclusive upper bound when it decided that
the range covers everything in that dimension (which it didn't get
quite right either). This could make snxtsct_dist() and
snxtitem_dist() initialize the iterator with an incorrect upper bound.
Similar impact as the xyinrange() / nxtitem() lossage.
border() could print the hundreds line unnecessarily.
snxtsct() and snxtsct_all() screwed up for odd WORLD_Y: they failed to
include (WORLD_Y - 1) / 2 in the y-range. This affected all command
arguments that support "*" syntax for sectors, plus add ... c, power
n, and break.
snxtsct_all() failed to normalize the bounds (presumed harmless).
There were a few correct, but somewhat unclean uses of struct range
with inclusive upper bounds:
* nat_reset() used one internally.
* pathrange() worked with inclusive upper bounds internally, but
corrected to exclusive upper bounds before passing the range out.
* sarg_getrange() worked with inclusive upper bounds. Its only caller
sarg_area() corrected that to exclusive upper bounds.
The change to inclusive upper bounds cleans this up.
unit_map() and xysize_range() had no issues (isn't that amazing?), but
need to be updated for the changed struct range semantics.
snxtsct_area() computed width and height, overwriting the values
passed in, even though all but two callers passed correct values. The
exceptions were snxtsct() in case NS_ALL, and snxtsct_all(). Change
them to pass correct values, and drop the recomputation from
snxtsct_area(). Simplifies the interface between snxtsct_area() and
its callers.
The correct method to compute indexes into a map buffer for a struct
range is deltx(), delty().
path() used deltax(), deltay() instead, which yield correct results
only for indexes up to half the world size. Pathes spanning larger
areas were screwed up.
sona(), radmap2(), satmap() also used deltax(), deltay(), but only
with arguments where those yield correct results.
draw_map() used xnorm(), ynorm() instead, which is correct, but less
clear and less efficient.
The following tests were added:
bridge building
spy
radar (ship, sector)
look
convert
In additon, prepartion for testing research and
hapiness production was added and improvements
for general economy for player 1 were added.
Set the ef_timestamp to 100 for the nightly build.
Set the DUMP LOST timestamp to 101 for the nightly build.
This will the suppress the timestamp differences
that occur when testing lost command and will facilitate
testing for dump and xdump commands.
The following tests were added:
ship list
ship navigation
assault
tech production
sector lost
commodity monitoring
tech monitoring
education monitoring
Failing a command with code RET_SYN prints help and doesn't charge
BTUs. Failing with code RET_FAIL doesn't print help and charges BTUs.
A couple of command failures were changed or added recently to fail
with RET_SYN, because they're due to invalid player input. Some of
them, however, can happen after the command already did something, so
BTUs must be charged, or else players can deliberately fail the
command to save BTUs:
* Commit 9eda5f87 adds RET_SYN failures when getting player input
fails for:
- arm third argument
- deliver fourth argument
- fire third argument
- lmine second argument
- order d fourth argument
- range second argument
- sail second argument
- tend third argument
* Commit be41e70f likewise for:
- designate second argument
- morale second argument
- set third argument
- tend fourth argument
* Commit d000bf92 likewise (with a bogus commit message) for bdes
second argument.
* Commit 9f4ce71a likewise for ltend third and fourth argument.
* Commit 9031b03b changes failure code from RET_FAIL when getting
player input fails for threshold third argument. It adds RET_SYN
failure when the argument is bad. Some bad arguments already failed
that way before.
* Commit a7cf69af changes it from RET_FAIL when designate second
argument is bad.
Change them all to fail with RET_FAIL.
Many other places have the same bug, but those are left for another
day.
Item production is limited to 999 units, level production is
unlimited.
Commit 0e721173 (v4.2.15) changed prod() from no limit to 999 units,
which fixed it for items, and broke it for levels. Undo the change
for levels.
The cheesy test for repeated messages broke down when working on more
than one sector. Reword the message so that repetition is fine, and
drop the test.
improve() attempted not to spend the last dollar, but screwed up when
improving more than one sector. This could bankrupt the player.
Replace the flawed code by the same simple method that is used
elsewhere: break the loop when there's not enough money left for the
current sector.
Complicated by the fact that conv() ran the conversion code twice,
first for adding up the cost for chkmoney(), then for actually
converting. chkmoney() asks the player to confirm when he's about to
spend more than half his cash. Get rid of that, not worth the
complexity. This merges do_conv() back into conv().
Complicated by the fact that demo() ran the demobilization code twice,
first for adding up the cost for chkmoney(), then for actually
demobilizing. chkmoney() asks the player to confirm when he's about
to spend more than half his cash. Get rid of that, not worth the
complexity. This merges do_demo() back into demo().
It also removes the command's virtually undocumented fourth argument.
Update player_coms[] accordingly. While there, make it require money;
it won't do anything useful without money anyway.
RET_SYS was used for commands failing due to internal or environmental
errors, but not really systematically. The difference to RET_FAIL is
how dispatch() treats them: RET_SYS got logged, and cost no BTUs.
More specific logging is possible at the point of failure than in
dispatch(). Make sure that's done for all failures that used to
return RET_SYS.
The change in BTU charging affects commands consider, offer, repay,
trade failing due to internal errors. It also affects deity commands
reload and turn (irrelevant because deities get unlimited BTUs), and
commands apropos, info and motd (irrelevant because they cost no
BTUs).
Behave like plane_bomb() and land_bomb(): deal with leading whitespace
and signs in the input, print a message when asked to bomb a ship that
is not there.
land_bomb() failed to reduce flak proportional to efficiency. Missed
in commit c7f68f2e, v4.3.6.
Also change it to round randomly instead of down, to match
ac_landflak().
Change planesatxy() not to list embarked planes, plane_bomb() not to
bomb them, and land_bomb() not to bomb embarked land units.
Curiously, embarked land units were not listed as targets before, but
could be bombed all the same.