]> git.pond.sub.org Git - empserver/log
empserver
13 years agoDrop "xdump ver" deprecated in 4.3.12
Markus Armbruster [Sat, 9 Apr 2011 06:01:58 +0000 (08:01 +0200)]
Drop "xdump ver" deprecated in 4.3.12

13 years agoinfo xdump still has long gone pseudo-table ver, remove
Markus Armbruster [Sat, 9 Apr 2011 05:59:19 +0000 (07:59 +0200)]
info xdump still has long gone pseudo-table ver, remove

Missed in commit da8a1dae, v4.3.12

13 years agoMove xdmeta() back to commands/xdump.c, internal linkage
Markus Armbruster [Sat, 9 Apr 2011 05:39:58 +0000 (07:39 +0200)]
Move xdmeta() back to commands/xdump.c, internal linkage

Partially revert commit 4c746b5e.

13 years agoSimplify satmap() with snxtitem_use_condarg(), snxtsct_use_condarg()
Markus Armbruster [Fri, 8 Apr 2011 19:15:05 +0000 (21:15 +0200)]
Simplify satmap() with snxtitem_use_condarg(), snxtsct_use_condarg()

13 years agoFactor snxtsct_use_condarg() out of snxtsct()
Markus Armbruster [Fri, 8 Apr 2011 19:13:07 +0000 (21:13 +0200)]
Factor snxtsct_use_condarg() out of snxtsct()

13 years agoFactor snxtitem_use_condarg() out of snxtitem()
Markus Armbruster [Fri, 8 Apr 2011 19:11:34 +0000 (21:11 +0200)]
Factor snxtitem_use_condarg() out of snxtitem()

13 years agoFix satellite to fail on bad conditional
Markus Armbruster [Fri, 8 Apr 2011 19:06:56 +0000 (21:06 +0200)]
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.

13 years agoCollect nstr_item, nstr_sect function declarations in nsc.h
Markus Armbruster [Fri, 8 Apr 2011 18:42:16 +0000 (20:42 +0200)]
Collect nstr_item, nstr_sect function declarations in nsc.h

Moved from prototypes.h.

13 years agoMove xysize_range(), xydist_range() to xy.c and xy.h
Markus Armbruster [Fri, 8 Apr 2011 18:38:03 +0000 (20:38 +0200)]
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.

13 years agoFix journal.c boilerplate comment
Markus Armbruster [Mon, 4 Apr 2011 17:58:47 +0000 (19:58 +0200)]
Fix journal.c boilerplate comment

13 years agoNew journal event "output"
Markus Armbruster [Mon, 4 Apr 2011 06:09:25 +0000 (08:09 +0200)]
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.

13 years agoFix journal not to truncate long lines
Markus Armbruster [Mon, 4 Apr 2011 06:00:08 +0000 (08:00 +0200)]
Fix journal not to truncate long lines

Could happen only for input events.

13 years agoEscape '\\' in journal, but not '\t'
Markus Armbruster [Mon, 4 Apr 2011 05:59:25 +0000 (07:59 +0200)]
Escape '\\' in journal, but not '\t'

13 years agoJournal login phase input, too
Markus Armbruster [Mon, 4 Apr 2011 05:58:08 +0000 (07:58 +0200)]
Journal login phase input, too

13 years agoNew journal event "command"
Markus Armbruster [Sun, 3 Apr 2011 06:27:30 +0000 (08:27 +0200)]
New journal event "command"

Redundant information.  Allows making sense of input without context.
The redundancy could help making a journal replay tool more robust.

13 years agoClean up superfluous include of queue.h in land.h, ship.h
Markus Armbruster [Sun, 3 Apr 2011 09:20:06 +0000 (11:20 +0200)]
Clean up superfluous include of queue.h in land.h, ship.h

13 years agoClean up superfluous include of nsc.h in prototypes.h
Markus Armbruster [Sun, 3 Apr 2011 08:41:10 +0000 (10:41 +0200)]
Clean up superfluous include of nsc.h in prototypes.h

13 years agoClean up superfluous include of news.h in empobj.h
Markus Armbruster [Sun, 3 Apr 2011 08:36:46 +0000 (10:36 +0200)]
Clean up superfluous include of news.h in empobj.h

Missed in commit 0ba61f17, v4.3.24.

13 years agoDisable BRIDGETOWERS by default
Markus Armbruster [Sat, 2 Apr 2011 12:41:09 +0000 (14:41 +0200)]
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.

13 years agoReduce bridge tower materials from 400 to 300 hcms.
Markus Armbruster [Sat, 2 Apr 2011 12:20:54 +0000 (14:20 +0200)]
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.

13 years agoFix stop orders to expire even when the country is broke
Markus Armbruster [Tue, 29 Mar 2011 18:09:56 +0000 (20:09 +0200)]
Fix stop orders to expire even when the country is broke

Broken in commit 8da88626, v4.3.8.

13 years agoFix march and navigate not to interpret coordinates as path
Markus Armbruster [Sun, 27 Mar 2011 15:55:35 +0000 (17:55 +0200)]
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.

13 years agoClean up path finding in perform_mission_bomb()
Markus Armbruster [Sun, 27 Mar 2011 08:08:16 +0000 (10:08 +0200)]
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.

13 years agoClean up path finding in nav_ship()
Markus Armbruster [Sun, 27 Mar 2011 08:02:36 +0000 (10:02 +0200)]
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.

13 years agoClean up path finding in getpath()
Markus Armbruster [Sun, 27 Mar 2011 06:44:30 +0000 (08:44 +0200)]
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.

13 years agoRemove p_mode, use MOB_FLY and MOB_SAIL instead
Markus Armbruster [Sun, 27 Mar 2011 06:29:50 +0000 (08:29 +0200)]
Remove p_mode, use MOB_FLY and MOB_SAIL instead

13 years agoClean up path finding in unit_sub()
Markus Armbruster [Sat, 26 Mar 2011 13:34:53 +0000 (14:34 +0100)]
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.

13 years agoClean up path finding in move_ground()
Markus Armbruster [Sat, 26 Mar 2011 12:15:05 +0000 (13:15 +0100)]
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.

13 years agoClean up path finding in path()
Markus Armbruster [Sat, 26 Mar 2011 07:15:08 +0000 (08:15 +0100)]
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.

13 years agoClean up path finding in best()
Markus Armbruster [Sat, 26 Mar 2011 07:10:30 +0000 (08:10 +0100)]
Clean up path finding in best()

Handle paths longer than 1023 characters sensibly: show them with
"..." appended.

13 years agoInline BestShipPath(), BestAirPath() glue
Markus Armbruster [Sat, 26 Mar 2011 07:03:19 +0000 (08:03 +0100)]
Inline BestShipPath(), BestAirPath() glue

Following commits will simplify the resulting code.

13 years agoInline BestLandPath(), BestDistPath() glue
Markus Armbruster [Sat, 26 Mar 2011 06:51:52 +0000 (07:51 +0100)]
Inline BestLandPath(), BestDistPath() glue

Following commits will simplify the resulting code.

13 years agoUse path_find() directly in sorde()
Markus Armbruster [Mon, 21 Mar 2011 19:45:04 +0000 (20:45 +0100)]
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.

13 years agoSimplify eta_calc(): drop pointer parameter, return value instead
Markus Armbruster [Mon, 21 Mar 2011 19:43:21 +0000 (20:43 +0100)]
Simplify eta_calc(): drop pointer parameter, return value instead

13 years agoSimplify eta_calc(): let caller compute path length
Markus Armbruster [Mon, 21 Mar 2011 19:42:37 +0000 (20:42 +0100)]
Simplify eta_calc(): let caller compute path length

13 years agoOptimize s_commod()'s harbor check for embarked land units
Markus Armbruster [Mon, 21 Mar 2011 19:39:47 +0000 (20:39 +0100)]
Optimize s_commod()'s harbor check for embarked land units

13 years agoUse path_find() directly where only cost is needed
Markus Armbruster [Mon, 21 Mar 2011 19:26:02 +0000 (20:26 +0100)]
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.

13 years agoUse the new path finder for sea & air, drop bestownedpath()
Markus Armbruster [Tue, 22 Feb 2011 06:18:41 +0000 (07:18 +0100)]
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.

13 years agoCompute distribution paths center by center
Markus Armbruster [Mon, 21 Feb 2011 22:13:07 +0000 (23:13 +0100)]
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.

13 years agoExploit fast "multiple paths from same source" in distribution
Markus Armbruster [Mon, 21 Feb 2011 21:22:54 +0000 (22:22 +0100)]
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.

13 years agoNew path_find_visualize(), to aid debugging
Markus Armbruster [Mon, 21 Feb 2011 21:49:44 +0000 (22:49 +0100)]
New path_find_visualize(), to aid debugging

13 years agoAdd performance statistics to path finder
Markus Armbruster [Mon, 21 Feb 2011 21:30:41 +0000 (22:30 +0100)]
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.

13 years agoOptimize Dijkstra's inner loop for hex maps
Markus Armbruster [Sat, 26 Feb 2011 16:40:13 +0000 (17:40 +0100)]
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.

13 years agoUse the new path finder for land paths, drop old A*
Markus Armbruster [Sat, 26 Feb 2011 15:06:09 +0000 (16:06 +0100)]
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.

13 years agoNew path finder
Markus Armbruster [Mon, 21 Feb 2011 19:38:09 +0000 (20:38 +0100)]
New path finder

We've been using Phil Lapsley's A* library to find land paths since
Chainsaw 3.  It's reasonably general, and uses relatively complex data
structures to conserve memory.  Unfortunately, it occasionally leaks a
bit of memory (see commit 86a187c0), and is unsafe for long paths (see
commit e30dc417).

To speed it up, v4.2.2 added two caches: the neighbor cache and the
path cache.

The neighbor cache attempts to speed up lookup of adjacent sectors.
It allocates 6 pointers per sector for that.  In my tests, this is
more, sometimes much more memory than the A* library uses.  See commit
7edcd3ea on branch old-astar for its (modest) performance impact.

The path cache attempts to speed up the update's computation of
distribution path costs.  There, A* runs many times.  Each run finds
many shortest paths, of which only the one asked for is returned.  The
path cache saves all of them, so that when one of them is needed
later, we can get it from the path cache instead of running A* again.
The cache is quite effective, but a bit of a memory hog (see commit
a02d3e9f on branch old-astar).

I'm pretty sure I could speed up the path cache even more by reducing
its excessive memory consumption --- why store paths when we're only
interested in cost?  But that's a bad idea, because the path cache
itself is a bad idea.

Finding many shortest paths from the same source has a well-known
efficient and simple solution: Dijkstra's algorithm[*].

A* is an extension of Dijkstra's algorithm.  It computes a *single*
path faster than Dijkstra's.  But it can't compute *many* shortest
paths from the same source as efficiently as Dijkstra's.

I could try to modify Phil's code to make it compute many shortest
paths from the same source efficiently: turn A* into its special case
Dijkstra's algorithm (at least for distribution path assembly), then
generalize it to the many paths problem.  Of course, I'd also have to
track down its memory allocation bugs, and make it safe for long
paths.

Instead, I'm replacing it.  This commit is the first step: a rather
unsophisticated implementation of Dijkstra's algorithm specialized to
hex maps.  It works with simple data structures: an array for the hex
map (16 bytes per sector), and a binary heap for the priority queue
(16 bytes per sector, most of it never touched).  This is more memory
than Phil's A* uses, but much less than Phil's A* with v4.2.2's
caches.

[*] To fully exploit Dijkstra's "many paths" capability, we need to
compute distribution paths in distribution center order.

13 years agoLicense upgrade to GPL version 3 or later
Markus Armbruster [Mon, 21 Feb 2011 18:37:40 +0000 (19:37 +0100)]
License upgrade to GPL version 3 or later

Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.

13 years agoDocument buffer overrun for long land paths
Markus Armbruster [Sun, 20 Mar 2011 09:06:33 +0000 (10:06 +0100)]
Document buffer overrun for long land paths

BestLandPath(), BestDistPath() and best_path() are unsafe by design:
they take a path[] argument without a size, and blindly assume there's
enough space.  When that's wrong, bp_path() overruns the caller's
buffer.

move_ground() and assemble_dist_paths() provide space for 512
characters.  best(), dist(), path(), att_reacting_units(), s_commod()
and do_unit_move() provide space for 1024 characters.

A malicious player can arrange paths longer than that, but it takes a
lot of land.

BestAirPath() and BestShipPath() also take a path[] argument without a
size, but they're actually safe: bestownedpath() writes at most 100
(MAXROUTE) characters, perform_mission_bomb() provides space for 512,
sorde(), getpath(), do_unit_move() and nav_ship() for 1024.

13 years agoRemove pointless check for sea from finish_sects()
Markus Armbruster [Fri, 25 Feb 2011 18:45:46 +0000 (19:45 +0100)]
Remove pointless check for sea from finish_sects()

Checking "sea or unowned" is pointless, because sea is always unowned.

13 years agoOptimize assemble_dist_paths() for foreign distribution center
Markus Armbruster [Fri, 25 Feb 2011 18:40:08 +0000 (19:40 +0100)]
Optimize assemble_dist_paths() for foreign distribution center

You can't distribute to a foreign sector.  This case is relatively
rare.  However, unsuccessful path search is relatively expensive, and
the extra check doesn't really slow down the common case.

13 years agoOptimize dodistribute() for sectors with no distribution center
Markus Armbruster [Fri, 25 Feb 2011 07:08:05 +0000 (08:08 +0100)]
Optimize dodistribute() for sectors with no distribution center

import_cost is now -1 in that case, so checking that suffices.

13 years agoFix assemble_dist_paths()'s recovery from invalid dist center
Markus Armbruster [Fri, 25 Feb 2011 07:00:59 +0000 (08:00 +0100)]
Fix assemble_dist_paths()'s recovery from invalid dist center

The recovery avoided crashing here, but left the path costs undefined.
If they happend to be non-negative, dodistribute() still crashed.  Set
the costs to -1 to avoid that.

While there, oops on invalid distribution center.

13 years agoSpeed up export cost calculation in assemble_dist_paths()
Markus Armbruster [Sat, 19 Feb 2011 07:21:33 +0000 (08:21 +0100)]
Speed up export cost calculation in assemble_dist_paths()

Import and export paths enter the same sectors, except for the last
one.  Compute export cost from import cost instead of reverting the
import path.  Do it in dodistribute(), so that we need to store only
import costs.

13 years agoSupply charged mobility for backward path
Markus Armbruster [Fri, 18 Feb 2011 19:05:32 +0000 (20:05 +0100)]
Supply charged mobility for backward path

It used the path from supply recipient back to supply source.  Has
always been broken that way.

13 years agoDocument memory leak in as_search()
Markus Armbruster [Fri, 18 Feb 2011 18:10:28 +0000 (19:10 +0100)]
Document memory leak in as_search()

13 years agoMake bestpath work for deities in foreign land
Markus Armbruster [Fri, 18 Feb 2011 18:29:29 +0000 (19:29 +0100)]
Make bestpath work for deities in foreign land

Before, it only worked in land owned by the deity.

As always, paths can't cross international borders.

13 years agoMerge dodistribute() parameters dist_i_cost, dist_e_cost
Markus Armbruster [Fri, 18 Feb 2011 18:07:31 +0000 (19:07 +0100)]
Merge dodistribute() parameters dist_i_cost, dist_e_cost

Only one of them is used, depending on argument imex.  Replace them by
a single parameter path_cost.

13 years agoRemove dodistribute() parameter path
Markus Armbruster [Fri, 18 Feb 2011 18:01:25 +0000 (19:01 +0100)]
Remove dodistribute() parameter path

It was only used to see whether a path to the dist center exists.  Use
negative cost for that.

13 years agoSAVE_FINISH_PATHS hasn't been used since 4.2.2, remove it
Markus Armbruster [Fri, 18 Feb 2011 17:53:37 +0000 (18:53 +0100)]
SAVE_FINISH_PATHS hasn't been used since 4.2.2, remove it

Since 4.2.2, assemble_dist_paths() stores a dummy path instead of the
real path to the dist center.  That's possible because distribution
doesn't actually use the path, only whether it exists.

The code to store and free the real path is still around, under #ifdef
SAVE_FINISH_PATHS.  Remove it.

13 years agoPrint distribution costs when compiled with DISTRIBUTE_DEBUG
Markus Armbruster [Fri, 25 Feb 2011 05:13:23 +0000 (06:13 +0100)]
Print distribution costs when compiled with DISTRIBUTE_DEBUG

13 years agoCollect path-related stuff in path.h
Markus Armbruster [Sun, 11 Jul 2010 09:30:02 +0000 (11:30 +0200)]
Collect path-related stuff in path.h

13 years agoLog distribution path assembly's CPU use (user and system time)
Markus Armbruster [Wed, 16 Mar 2011 17:25:18 +0000 (18:25 +0100)]
Log distribution path assembly's CPU use (user and system time)

13 years agoLog update's CPU use (user and system time)
Markus Armbruster [Wed, 16 Mar 2011 17:24:58 +0000 (18:24 +0100)]
Log update's CPU use (user and system time)

13 years agoFleshed out getrusage() stub for Windows
Ron Koenderink [Sat, 19 Mar 2011 22:05:35 +0000 (16:05 -0600)]
Fleshed out getrusage() stub for Windows

13 years agoProvide a getrusage() stub for Windows
Markus Armbruster [Wed, 16 Mar 2011 06:16:21 +0000 (07:16 +0100)]
Provide a getrusage() stub for Windows

13 years agoMake savecore mind available disk space
Markus Armbruster [Sun, 13 Mar 2011 13:23:13 +0000 (14:23 +0100)]
Make savecore mind available disk space

13 years agoMake savecore check core file is accessible
Markus Armbruster [Sun, 13 Mar 2011 13:22:30 +0000 (14:22 +0100)]
Make savecore check core file is accessible

13 years agoFix bitmap overruns when WORLD_X * WORLD_Y not a multiple of 16
Markus Armbruster [Mon, 28 Feb 2011 05:58:51 +0000 (06:58 +0100)]
Fix bitmap overruns when WORLD_X * WORLD_Y not a multiple of 16

World-sized bitmaps were allocated with size WORLD_SZ() / 8, which
expands to (WORLD_X * WORLD_Y / 2) / 8.  The divisions truncate unless
WORLD_X * WORLD_Y is a multiple of 16.  The bitmaps were one byte too
small then.  Bitmap overruns happen when:

* A lookout looks at one of the last sectors of the sector file.
  Besides commands look and llook, this affects navigate and march
  sub-command 'l'.

* Command spy spies into one of the last sectors of the sector file.

* A map or nmap (but not a bmap) shows one of the last sectors of the
  sector file, or a sector that can see one of the last sectors
  (visual range is two sectors at 100% efficiency).  Besides commands
  lmap, map, nmap, pmap, smap, this affects move and transport
  sub-command 'm'.

Diagnosed with valgrind.

Already broken in BSD Empire 1.1 (bitmaps were on the stack then).

13 years agoFix pathrange()'s computation of the range's right limit
Markus Armbruster [Fri, 18 Feb 2011 18:36:55 +0000 (19:36 +0100)]
Fix pathrange()'s computation of the range's right limit

Because of the bug, the path command's maps weren't always fitted to
the path correctly.  Broken in commit 0f458d2c, v4.3.17

13 years agoLand units no longer hit allied mines
Markus Armbruster [Sun, 6 Feb 2011 15:28:12 +0000 (16:28 +0100)]
Land units no longer hit allied mines

13 years agoUse relations_with() in sendmessage()
Markus Armbruster [Sun, 6 Feb 2011 09:29:14 +0000 (10:29 +0100)]
Use relations_with() in sendmessage()

We know player != other.  Because we can have only one player in state
PS_PLAYING per country, and we know other->state == PS_PLAYING, it
follows that player->cnum != other->cnum.  Thus, no functional change.

Adds another call to getnatp() hidden in relations_with(), though.
Keeping that optimized isn't worth it.

13 years agoUse relations_with() for getrel(NP, THEM) where NP isn't THEM
Markus Armbruster [Sun, 6 Feb 2011 09:27:45 +0000 (10:27 +0100)]
Use relations_with() for getrel(NP, THEM) where NP isn't THEM

Replacing getrel(NP, THEM), where NP is known to be getnatp(US), by
relations_with(US, THEM) makes a difference only when US equals THEM.
Replace in places where it's obvious that they're not equal.

Adds a few calls to getnatp() hidden in relations_with().  Keeping
that optimized isn't worth it.

13 years agoUse relations_with() for US==THEM || getrel(NP, THEM)
Markus Armbruster [Sun, 6 Feb 2011 09:06:38 +0000 (10:06 +0100)]
Use relations_with() for US==THEM || getrel(NP, THEM)

Replace patterns like "US == THEM || getrel(NP, THEM)...", where NP is
known to be getnatp(US), by "relations_with(US, THEM)...".  No
functional change.

Adds a few calls to getnatp() hidden in relations_with(), though.
Keeping that optimized isn't worth it.

13 years agoUse relations_with() in unit_interdict()
Markus Armbruster [Tue, 1 Feb 2011 06:49:32 +0000 (07:49 +0100)]
Use relations_with() in unit_interdict()

No functional change, because the value of rel only matters when cn !=
victim, and then it's the same as before.

The new value of rel permits simplifying cn != victim && rel <=
NEUTRAL to just rel <= NEUTRAL

13 years agoUse relations_with() in owned_and_navigable()
Markus Armbruster [Sun, 30 Jan 2011 17:32:19 +0000 (18:32 +0100)]
Use relations_with() in owned_and_navigable()

This removes a special case for POGO (#0).  Before, unoccupied sectors
were treated as "own or allied" for POGO, but not for other deities.

Impact on callers:

* BestAirPath() is not affected, because the change is only reachable
  with a non-null bigmap argument.

* sorde() and nav_ship() pass a non-zero ship owner.  sorde() ensures
  that itself, and prod_ship() does it for nav_ship().

* unit_path() passes the player number when called with a ship
  argument, i.e. in the navigate command.  Player number is zero for
  POGO.  Since deities can't navigate foreign ships, this can happen
  only when POGO navigates dead ships.  Yes, that's possible, needs
  fixing.

* getpath() passes the player number (zero for POGO) when called with
  argument P_SAILING, i.e. by the sail command.

Thus, the change makes navigate's and sail's path finding work for
POGO exactly like it does for other deities.  That's fine.

13 years agoUse relations_with() in getilists()
Markus Armbruster [Sun, 30 Jan 2011 16:37:36 +0000 (17:37 +0100)]
Use relations_with() in getilists()

No functional change, even though this changes rel[intruder] from
NEUTRAL to ALLIED.  Uses of rel[]:

* getilists() and ac_encounter() compare rel[cn] to HOSTILE.  No
  change, because NEUTRAL and ALLIED are both greater than HOSTILE.

* ac_encounter() compares rel[cn] to ALLIED, but only when cn !=
  plane_owner.  Because it passes plane_owner as argument for
  getilists() parameter intruder, rel[cn] can't refer to the changed
  element of rel[] here.

The new value of rel[plane_owner] permits simplifying cn ==
plane_owner || rel[cn] == ALLIED to just rel[cn] == ALLIED.

13 years agoUse relations_with() in nav_loadship()
Markus Armbruster [Sun, 30 Jan 2011 16:10:43 +0000 (17:10 +0100)]
Use relations_with() in nav_loadship()

No functional change, because the value of rel only matters when
sectp->sct_own != sp->shp_own, and then it's the same as before.

The new value of rel permits simplifying sectp->sct_own == sp->shp_own
|| rel >= FRIENDLY to just rel >= FRIENDLY.

13 years agoUse relations_with() in shp_fort_interdiction()
Markus Armbruster [Sun, 30 Jan 2011 15:39:38 +0000 (16:39 +0100)]
Use relations_with() in shp_fort_interdiction()

No functional change, because the change affects only
notified[victim], which isn't used in the loop around
notify_coastguard(), and gets overwritten before the interdiction fire
loop.

13 years agoUse relations_with() in lnd_mar_one_sector()
Markus Armbruster [Sun, 30 Jan 2011 15:31:02 +0000 (16:31 +0100)]
Use relations_with() in lnd_mar_one_sector()

No functional change, because the value of rel only matters when
sect.sct_own != actor, and then it's the same as before.

The new value of rel permits simplifying sect.sct_own != actor && rel
!= ALLIED to just rel != ALLIED.

13 years agoUse relations_with() in player_relstr()
Markus Armbruster [Sun, 30 Jan 2011 15:26:22 +0000 (16:26 +0100)]
Use relations_with() in player_relstr()

No functional change, because argument is never player->cnum.

13 years agoUse relations_with() for getrel(getnatp(US), THEM) where US!=THEM
Markus Armbruster [Sat, 29 Jan 2011 13:34:40 +0000 (14:34 +0100)]
Use relations_with() for getrel(getnatp(US), THEM) where US!=THEM

Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.  Replace in places where it's
obvious that they're not equal.

Note: getsect() sets player->owner to "player is god or owns this
sector".  Thus, after getsect(..., &sect), sect.sct_own ==
player->cnum implies player->owner.  Conversely, !player->owner
implies sect.sct_own != player->cnum.  Similarly for getship(),
getplane() and nxtitem().

13 years agoUse relations_with() where its different value doesn't matter
Markus Armbruster [Sun, 30 Jan 2011 10:46:17 +0000 (11:46 +0100)]
Use relations_with() where its different value doesn't matter

Switching from getrel() to relations_with() can change the value from
NEUTRAL to ALLIED.  The change doesn't matter when the value's only
compared to HOSTILE, as both old and new value are greater than
HOSTILE.  Likewise for >= NEUTRAL.

13 years agoUse relations_with() for US==THEM || getrel(getnatp(US), THEM)
Markus Armbruster [Wed, 26 Jan 2011 18:41:28 +0000 (19:41 +0100)]
Use relations_with() for US==THEM || getrel(getnatp(US), THEM)

Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.

Replace patterns like "us == them || getrel(getnatp(us), them)..." by
"relations_with(us, them)...".

13 years agoRearrange uses of getrel() slightly
Markus Armbruster [Sat, 29 Jan 2011 08:57:21 +0000 (09:57 +0100)]
Rearrange uses of getrel() slightly

Just to make the next few commits easier to review.

13 years agoEliminate a few pointless relations variables
Markus Armbruster [Sat, 29 Jan 2011 12:09:26 +0000 (13:09 +0100)]
Eliminate a few pointless relations variables

Just to make the next few commits easier to review.

13 years agoNew relations_with()
Markus Armbruster [Tue, 25 Jan 2011 19:13:41 +0000 (20:13 +0100)]
New relations_with()

Relations checking with getrel() often needs a special case for "is
same country".  If you forget, you get behavior appropriate for a
neutral foreign country, which is usually very wrong (see commit
16c68eb4 for an example).

Unlike getrel(), relations_with() considers countries allied to
themselves.  Less dangerous.  In fact, allied behavior is typically
just right, so the special case isn't even needed.

13 years agoPermit sharebmap with yourself
Markus Armbruster [Sun, 30 Jan 2011 17:37:02 +0000 (18:37 +0100)]
Permit sharebmap with yourself

Does nothing.  Before, it failed with a mildly bogus "does not have
friendly relations towards you" message.

13 years agoMake share_bmap() do nothing for sharing with oneself
Markus Armbruster [Wed, 19 Jan 2011 20:05:44 +0000 (21:05 +0100)]
Make share_bmap() do nothing for sharing with oneself

Before, it overwrote '?', '.', ' ' in the bmap with the capitalized
country letter, but only for sectors the player owns.  Pretty
harmless, just weird.  It can't happen currently, because sharebmap
with self fails with "does not have friendly relations towards you".

13 years agoPermit flash to yourself
Markus Armbruster [Sat, 5 Feb 2011 11:50:50 +0000 (12:50 +0100)]
Permit flash to yourself

Flashing yourself failed with a bogus "not logged on" message for
deities, and a mildly bogus "not a deity or friendly with us" message
for mortals.

Fix by simply permitting it.  Not terribly useful, except perhaps for
empire-hub users, but why not.

13 years agoDrop redundant chat(), sendmessage() parameter us
Markus Armbruster [Sat, 5 Feb 2011 11:48:10 +0000 (12:48 +0100)]
Drop redundant chat(), sendmessage() parameter us

It can't be anything but the current player.

13 years agoClean up confusing control flow in sendmessage()
Markus Armbruster [Sat, 5 Feb 2011 10:30:32 +0000 (11:30 +0100)]
Clean up confusing control flow in sendmessage()

The second patch hunk fixes a latent bug.  Before, rejected deity
flashes led to a bogus "not logged on" message, now they lead to a
"not accepting" message.  But deity flashes can't be rejected, so this
doesn't matter.

13 years agoOptimize sendmessage() use of getnatp()
Markus Armbruster [Sat, 5 Feb 2011 10:17:40 +0000 (11:17 +0100)]
Optimize sendmessage() use of getnatp()

Don't call it when its value must be TO anyway.

While there, oops when it fails instead of recovering silently.

13 years agoFix racy detection of ally rejecting flashes
Markus Armbruster [Sat, 5 Feb 2011 10:09:37 +0000 (11:09 +0100)]
Fix racy detection of ally rejecting flashes

sendmessage() checked NF_FLASH on two places: when deciding whether to
send the message, and later when telling the player why it didn't send
a flash.  This can race with the toggle command as follows: if a flash
could not be sent because the recipient's NF_FLASH was off, and the
recipient toggled it on before the flag was checked again, the flash
command claimed the sender wasn't logged on.

13 years agoChange flash not to print "Flash sent" for deities
Markus Armbruster [Sat, 5 Feb 2011 09:42:58 +0000 (10:42 +0100)]
Change flash not to print "Flash sent" for deities

It's annoying.  It never did that for mortals.

13 years agoRemove pointless variables from setrel()
Markus Armbruster [Sat, 5 Feb 2011 09:18:30 +0000 (10:18 +0100)]
Remove pointless variables from setrel()

13 years agoMake setrel() refuse to change relations to self
Markus Armbruster [Sat, 5 Feb 2011 08:31:44 +0000 (09:31 +0100)]
Make setrel() refuse to change relations to self

No current caller actually attempts that, but let's make it obvious.

13 years agoChange setrel(), setcont(), setrej() to return void
Markus Armbruster [Sat, 5 Feb 2011 08:30:12 +0000 (09:30 +0100)]
Change setrel(), setcont(), setrej() to return void

Nobody cares for their value anyway.

13 years agoOops on invalid arguments in setrel(), setcont(), setrej()
Markus Armbruster [Sat, 5 Feb 2011 08:28:05 +0000 (09:28 +0100)]
Oops on invalid arguments in setrel(), setcont(), setrej()

Before, they recovered silently.

13 years agoUse feels_like_helping() in dosupport(), lnd_support()
Markus Armbruster [Mon, 31 Jan 2011 19:53:44 +0000 (20:53 +0100)]
Use feels_like_helping() in dosupport(), lnd_support()

feels_like_helping() case cn == foe is missing in the code it
replaces.  No difference in behavior, because:

* cn == foe && cn == friend can't happen.  Because you can't get into
  ground combat against yourself (assault, attack and paradrop don't
  let you), friend != foe for support.

* cn == foe && cn != friend behaves the same: no support.
  feels_like_helping() returns 0 because of the explicit case.  The
  replaced code doesn't support because cn can't be at war with
  itself.

13 years agoFactor feels_like_helping() out of quiet_bigdef(), sd(), dd()
Markus Armbruster [Mon, 31 Jan 2011 19:46:53 +0000 (20:46 +0100)]
Factor feels_like_helping() out of quiet_bigdef(), sd(), dd()

13 years agoPlug memory leaks in mission execution code
Markus Armbruster [Mon, 31 Jan 2011 06:56:44 +0000 (07:56 +0100)]
Plug memory leaks in mission execution code

Mission execution first builds lists of eligible units, one list per
country.  These lists are passed to perform_mission() one by one,
where they get freed.

Bugs:

* unit_interdict() didn't pass the list for the submarine's owner, but
  build_mission_list_type() built one.  Any submarine movement within
  own submarine interdiction mission op areas leaked memory.

* dosupport() passed only lists for countries that actually support
  (ally at war with victim), but build_mission_list_type() built lists
  for all countries hostile to the victim.  Ground combat within
  support mission op areas countries that are hostile to one of the
  party without actually supporting the other leaked memory.

* perform_mission() failed to free missiles targeting units.

Fixing the latter is straightforward.

Fix the first two by deciding whether a country acts on a mission
trigger before building any lists, in ground_interdict(),
unit_interdict(), dosupport().  Remove the code dealing with that from
build_mission_list_type() and the loops around perform_mission().