Commit graph

3950 commits

Author SHA1 Message Date
4dfb84086a Remove disabled command cede
It misuses snxtsct() and snxtitem() to find out whether the first
argument looks like sectors or like ships, which doesn't work with a
bad conditional argument.

Not worth fixing now; it's been disabled since 4.0.1, and broken at
least since commit 2fc1e74a (v4.3.0) broke its sector/ship
disambiguation via third argument.
2011-04-14 20:21:22 +02:00
16daa4007c Fix do_map()'s misuse of snxtsct() for testing argument syntax
It assumes snxtsct() fails only when the argument can't be parsed.  It
can also fail when the condition argument has errors.  `map # ?xxx'
first complains about xxx, then maps around ship#0.  Broken since
Chainsaw 2 introduced smap, pmap and lmap.

Use sarg_type() to recognize sectors vs. unit argument.  `map # ?xxx'
now fails as it should.

Subtle side effect: do_map() no longer prompts for argument "",
because snxtsct() is now guarded by sarg_type().  Impact on callers:

* display_region_map() is not affected, because it never passes "".

* map() passes on "" arguments.  Change it to prompt in that case.
  Consistent with how other commands behave.  No functional change.

* do_unit_move() passes on "" arguments.  Keep it that way.  This
  changes navigate and march sub-commands 'M' and 'B' not to prompt
  for "" arguments, which is consistent with sub-command 'm' of move,
  test and transport.
2011-04-14 20:21:22 +02:00
baee0744ff Make map drawing commands fail on bad flags
Also affects mapping at movement prompts of navigate, march, move,
test, transport.
2011-04-14 20:21:22 +02:00
d78df0b48b Move function declarations for maps.c from prototypes.h to map.h 2011-04-14 20:21:22 +02:00
8dc69a9a84 Move map flags from map.h to maps.c, and reorder
Not useful elsewhere.  Since I'm touching them anyway, put them in the
usual ship, plane, land, nuke order.
2011-04-14 20:21:21 +02:00
0f0b5605e9 Remove misleading comment on MAP_PLANE & friends
ef_unit_list doesn't exist.  Order doesn't matter, priority is defined
by draw_map()'s ef_unit_map[].

This reverts commit 9e75e5e009.
2011-04-14 20:21:21 +02:00
78b3af20fe Drop "xdump ver" deprecated in 4.3.12 2011-04-14 20:21:21 +02:00
1ffea04a6d info xdump still has long gone pseudo-table ver, remove
Missed in commit da8a1dae, v4.3.12
2011-04-14 20:21:21 +02:00
af5e25aa16 Move xdmeta() back to commands/xdump.c, internal linkage
Partially revert commit 4c746b5e.
2011-04-14 20:21:21 +02:00
6db74cd282 Simplify satmap() with snxtitem_use_condarg(), snxtsct_use_condarg() 2011-04-14 20:21:21 +02:00
7de511fb66 Factor snxtsct_use_condarg() out of snxtsct() 2011-04-14 20:21:21 +02:00
84072cff5d Factor snxtitem_use_condarg() out of snxtitem() 2011-04-14 20:21:21 +02:00
74a69cf74c Fix satellite to fail on bad conditional
snxtsct() and snxtitem() fail when the condition argument is bad.
satmap() didn't check for failure.  Due to the way snxtsct() and
snxtitem() work, bad condition arguments were reported and otherwise
ignored.
2011-04-14 20:21:21 +02:00
d0a6dffa02 Collect nstr_item, nstr_sect function declarations in nsc.h
Moved from prototypes.h.
2011-04-14 20:21:21 +02:00
40b6032a5d Move xysize_range(), xydist_range() to xy.c and xy.h
Moved from snxtsct.c and prototypes.h next to the other struct range
functions.
2011-04-14 20:21:21 +02:00
e7d7cfdc10 Fix journal.c boilerplate comment 2011-04-14 20:21:21 +02:00
4785662587 New journal event "output"
Redundant information, but incredibly useful when you want to figure
out what happened without a (still nonexistent) journal replay tool.
The redundancy could help making a journal replay tool more robust.

To enable, set econfig key keep_journal to at least 2.  Output events
are *not* flushed to disk immediately.
2011-04-14 20:21:21 +02:00
f04d1ae032 Fix journal not to truncate long lines
Could happen only for input events.
2011-04-14 20:21:21 +02:00
27212dc46b Escape '\\' in journal, but not '\t' 2011-04-14 20:15:19 +02:00
a7be765ed4 Journal login phase input, too 2011-04-14 19:58:49 +02:00
72d051310c New journal event "command"
Redundant information.  Allows making sense of input without context.
The redundancy could help making a journal replay tool more robust.
2011-04-14 19:46:05 +02:00
9be4f57ad5 Clean up superfluous include of queue.h in land.h, ship.h 2011-04-14 19:46:05 +02:00
157ae8ec21 Clean up superfluous include of nsc.h in prototypes.h 2011-04-14 19:46:05 +02:00
a2386edc01 Clean up superfluous include of news.h in empobj.h
Missed in commit 0ba61f17, v4.3.24.
2011-04-14 19:46:05 +02:00
44db545344 Disable BRIDGETOWERS by default
A deity can easily break BRIDGETOWERS by reducing etu_per_update
without compensating customization of buil_tower_bh,
rollover_avail_max or bridge span maxpop.

Document the issue in output of pconfig (which is installed as
$prefix/etc/empire/econfig).

To increase the chance deities actually read the documentation,
disable BRIDGETOWERS.
2011-04-12 21:51:32 +02:00
11ab95411e Reduce bridge tower materials from 400 to 300 hcms.
Bridge spans have been unable to produce enough avail for a tower with
default game configuration since we reduced their maximum population
in commit 6bbd7ffd, v4.3.6.  This commit reduces required avail from
160 to 120, fixing the stock game: 100 civilians and 100 uws can make
that much in a 60 ETU update.
2011-04-12 21:51:32 +02:00
a12a315cd9 Fix stop orders to expire even when the country is broke
Broken in commit 8da88626, v4.3.8.
2011-04-12 21:51:32 +02:00
d6cf175b0b Fix march and navigate not to interpret coordinates as path
Destination arguments can be a path or sector coordinates.
do_unit_move() passes the argument buffer to unit_path() to convert
coordinates to a path.  If unit_path() fails, do_unit_move() still
interprets the argument as path.

This is correct when unit_path() fails because the argument is not
coordinates.  But it can also fail when it is coordinates, namely when
the destination isn't reachable, when the path to it is too long, or
when the ships or land units aren't together.  Then do_unit_move()
interprets coordinates as path, and rejects them with "Legal
directions are:".

Except when a land unit's destination read from a march prompt isn't
reachable, because then unit_path() empties the argument buffer that
do_unit_move() uses.

Change unit_path() to succeed when the argument is not coordinates.
Make do_unit_move() discard the argument when unit_path() fails,
i.e. when it is bad coordinates.  unit_path() emptying the argument no
longer has an effect, drop it.
2011-04-12 21:51:32 +02:00
74b08563af Clean up path finding in perform_mission_bomb()
Support missions up to 1023 sectors away from the airfield, up from
99.

Don't bother to call mapdist() for distance to target, just use the
path length.
2011-04-12 21:51:32 +02:00
8d23975299 Clean up path finding in nav_ship()
Destinations are no longer treated as unreachable when the best path
is longer than 99 characters.  Instead, consider up to 1023 characters
of the best path.
2011-04-12 21:51:32 +02:00
404a76f79e Clean up path finding in getpath()
Don't claim the destination sector is unreachable when the best path
is longer than 99 characters or the complete path is longer than 1023
characters.  Instead, report that the path is too long when the total
path is longer than 1023 characters.
2011-04-12 21:51:32 +02:00
182d62deed Remove p_mode, use MOB_FLY and MOB_SAIL instead 2011-04-12 21:51:32 +02:00
8f008bf849 Clean up path finding in unit_sub()
Don't claim the destination sector is unreachable when the best path
is longer than 1023 characters for land units or 99 characters for
ships.  Instead, report that the path is too long.  Up the limit for
ships to 1023 characters.
2011-04-12 21:51:32 +02:00
dac2c95dd5 Clean up path finding in move_ground()
Don't claim the destination sector is unreachable when the best path
is longer than 1023 characters.  Instead, report that the path is too
long.
2011-04-12 21:51:32 +02:00
b73a3f52e5 Clean up path finding in path()
Don't claim the destination sector is unreachable when the best path
is longer than 1023 characters.  Instead, report that the path is too
long.
2011-04-12 21:51:32 +02:00
a34517a3f5 Clean up path finding in best()
Handle paths longer than 1023 characters sensibly: show them with
"..." appended.
2011-04-12 21:51:32 +02:00
e450c31ddb Inline BestShipPath(), BestAirPath() glue
Following commits will simplify the resulting code.
2011-04-12 21:51:32 +02:00
92e64d7638 Inline BestLandPath(), BestDistPath() glue
Following commits will simplify the resulting code.
2011-04-12 21:51:32 +02:00
957a6a74df Use path_find() directly in sorde()
Don't compute the distance from the path, use the path cost.  The
actual path is no longer needed, and we can use path_find() instead of
BestShipPath().

Destinations are no longer treated as unreachable when the best path
is longer than 1023 characters.
2011-04-12 21:51:32 +02:00
ec1d91a34f Simplify eta_calc(): drop pointer parameter, return value instead 2011-04-12 21:51:32 +02:00
cdff437772 Simplify eta_calc(): let caller compute path length 2011-04-12 21:51:32 +02:00
37d3846009 Optimize s_commod()'s harbor check for embarked land units 2011-04-12 21:51:31 +02:00
aef27e3521 Use path_find() directly where only cost is needed
dist(), att_reacting_units() and s_commod() are only interested in
cost, not the actual path.  BestLandPath() and BestDistPath() compute
both cost and path.  Use path_find() directly instead.

Destinations are no longer treated as unreachable when the best path
is longer than 1023 characters.
2011-04-12 21:51:31 +02:00
04363a92db Use the new path finder for sea & air, drop bestownedpath()
bestownedpath() is a rather simple-minded breadth-first search.  It's
slower than the new path finder, and maintaining it in addition to the
new path finder makes no sense.
2011-04-12 21:51:31 +02:00
bbd6e9182f Compute distribution paths center by center
This way, we compute all distribution paths from the same center in
one go, and thus fully exploit the fast multiple paths from same
source capability of Dijkstra's algorithm.

Sorting by dist center increases the average length of runs from 4.5
to 73 for my continental test case, and from 3 to 10 for my island
test case.

Compared to the commit before the previous one, distribution path
assembly runs more than 40 times faster for my continental test case,
and more than 5 times faster for my island test case.

The new path finder now runs my continental test case more than 30
times faster than the old A*, and the island test case more than 6
times, in a fraction of the memory.  This makes the continental
updates run 3.5 times faster, and the island updates 6% faster.
Distribution path assembly no longer dominates the continental
update's run time: it takes less than 10% instead of more than 70%.

In a sense, this is the path cache done right.
2011-04-12 21:51:31 +02:00
bf97fa9c9c Exploit fast "multiple paths from same source" in distribution
Dijkstra's algorithm can find multiple paths from the same source.
This is much faster than starting from scratch for every path.

Make distribution path assembly work that way.  This speeds up runs of
distributions to the same center.  The next commit will reorder path
searches to maximize the length of these runs.  It also has benchmark
results.

Allocates four bytes per sector, actually uses only the first 4*n
bytes, where n is the number of distributing sectors.
2011-04-12 21:51:31 +02:00
2fc9dfc526 New path_find_visualize(), to aid debugging 2011-04-12 21:51:31 +02:00
18dd516076 Add performance statistics to path finder
New function path_find_print_stats() prints a few numbers of interest
when compiled with PATH_FIND_STATS defined.
2011-04-12 21:51:31 +02:00
d7dccef3b1 Optimize Dijkstra's inner loop for hex maps
Because the cost to enter a sector is independent of the direction of
entry, we visit sectors at most once.  Exploit that.

Beware: this is not the case for A*.  Pitfall for any future
generalization to A*.

Speeds up distribution path assembly by 35-40% in my tests.
2011-04-12 21:51:31 +02:00
ffbbfcb25f Use the new path finder for land paths, drop old A*
This gets rid of the memory leak mentioned in the previous commit.

To get rid of the buffer overruns for long paths mentioned in the
previous commit, make BestLandPath() fail when path length exceeds
1023 characters.

assemble_dist_paths() and move_ground() pass buffers with a different
size.  Eliminate assemble_dist_paths()'s buffer.  Update now works
regardless of distribution distance (the distribute command still
limits to 1023, to be fixed in a later commit).  Enlarge
move_ground()'s buffers.  Doubles the length of paths accepted by
explore, move, and transport.

I use two test cases to benchmark the path finders: "continental" (Hvy
Metal 2 updates) and "island" (Hvy Plastic 2 updates).

The new path finder runs my tests around 3-4 times faster than the old
A* without its caches.  That's enough to meet its cached performance
for "island", but it's only half as fast for "continental".  Not for
long; big speedups are coming.
2011-04-12 21:48:58 +02:00