Commit graph

3881 commits

Author SHA1 Message Date
8ab0bca0c6 Provide a getrusage() stub for Windows 2011-04-11 22:29:12 +02:00
64e58e3417 Make savecore mind available disk space 2011-04-11 22:29:12 +02:00
30f12acf73 Make savecore check core file is accessible 2011-04-11 22:29:12 +02:00
88983a1a2e 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).
2011-04-11 22:29:12 +02:00
6c9363cc4f 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
2011-03-28 20:28:36 +02:00
fe372539b2 Land units no longer hit allied mines 2011-02-18 18:46:05 +01:00
67b9135e96 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.
2011-02-18 18:46:05 +01:00
6852ec6bc5 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.
2011-02-18 18:46:05 +01:00
bdf63bc5fa 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.
2011-02-18 18:46:05 +01:00
928e9a4cc3 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
2011-02-18 18:46:04 +01:00
9100af0b82 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.
2011-02-18 18:44:49 +01:00
5245cde582 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.
2011-02-16 07:57:43 +01:00
58cc82589e 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.
2011-02-16 07:55:24 +01:00
983dae641c 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.
2011-02-16 07:55:24 +01:00
6c893f5cc3 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.
2011-02-16 07:52:25 +01:00
97543baadb Use relations_with() in player_relstr()
No functional change, because argument is never player->cnum.
2011-02-16 07:52:25 +01:00
8cb7b75557 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().
2011-02-16 07:52:25 +01:00
6807cd91b5 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.
2011-02-16 07:52:25 +01:00
Markus Armbruster
8e75b22e0d 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)...".
2011-02-16 07:51:39 +01:00
ef7b9cedc3 Rearrange uses of getrel() slightly
Just to make the next few commits easier to review.
2011-02-16 07:50:26 +01:00
7ebbe7da4c Eliminate a few pointless relations variables
Just to make the next few commits easier to review.
2011-02-16 07:48:30 +01:00
bb5cd07ce5 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.
2011-02-13 17:48:58 +01:00
0c60e574a9 Permit sharebmap with yourself
Does nothing.  Before, it failed with a mildly bogus "does not have
friendly relations towards you" message.
2011-02-13 16:41:35 +01:00
58cbd4cc2e 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".
2011-02-13 16:41:35 +01:00
de7657dd99 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.
2011-02-13 16:39:20 +01:00
0d4566847f Drop redundant chat(), sendmessage() parameter us
It can't be anything but the current player.
2011-02-13 16:39:20 +01:00
5eeac45b8d 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.
2011-02-13 16:32:37 +01:00
e21f5035cb 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.
2011-02-13 16:06:23 +01:00
fc633a4f1f 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.
2011-02-13 16:06:23 +01:00
53a4fc6e26 Change flash not to print "Flash sent" for deities
It's annoying.  It never did that for mortals.
2011-02-13 16:06:23 +01:00
2b3e11d35d Remove pointless variables from setrel() 2011-02-13 16:06:22 +01:00
985ec19f8b Make setrel() refuse to change relations to self
No current caller actually attempts that, but let's make it obvious.
2011-02-13 16:06:22 +01:00
d4f0cb3576 Change setrel(), setcont(), setrej() to return void
Nobody cares for their value anyway.
2011-02-13 16:06:22 +01:00
a302bde1fb Oops on invalid arguments in setrel(), setcont(), setrej()
Before, they recovered silently.
2011-02-13 16:06:22 +01:00
89bc9c4d5b 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.
2011-02-13 16:06:22 +01:00
c095ad285b Factor feels_like_helping() out of quiet_bigdef(), sd(), dd() 2011-02-13 16:06:22 +01:00
7374002fd7 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().
2011-02-13 16:06:22 +01:00
6a35432346 Move code from def_support(), off_support() to dosupport() 2011-02-13 16:06:22 +01:00
723cc96d9c Eliminate nav_loadship() variables landown, shipown
Code is clearer without them.  Works because load_it() never changes
ship or sector owner.
2011-02-13 16:03:34 +01:00
4a142dd102 Drop redundant nav_loadship() parameter cnum 2011-02-13 16:03:34 +01:00
6d014e8069 Eliminate nav_ship() variable cnum
Code is clearer without it.
2011-02-13 16:03:34 +01:00
05b3e1b8d8 Oops on invalid actor and victim arguments in nreport()
Replaces the existing, silent recovery from invalid victim argument.
2011-02-13 16:03:34 +01:00
38e59474b1 Clean up use of current player in march code
lnd_mar() and lnd_mar_one_sector() take an actor argument.
Nevertheless, they sometimes used player->cnum.  Fortunately, they are
the same: all callers pass current player for actor.  Normalize to
actor for consistency.
2011-02-13 16:03:34 +01:00
98c5a92baa Fix land unit attack mobility cost out of allied sectors
Land units pay a mobility penalty when marching into a non-old-owned
sector without sector mobility, to slow them down in newly taken
sectors.  Attacking land units pay this penalty regardless of sector
mobility.

When attacking out of an allied sector, the penalty was computed as if
the land unit was owned by that ally.  Attacking sectors old-owned by
that ally was too cheap, and taking back one's own was too expensive.

Broken since attacking land units pay the "newly taken" mobility
penalty: commit 2e693275, v4.3.6.
2011-02-13 16:03:34 +01:00
13d9057bd8 Fix attack when attacking sector gets taken by ally
When an attacking sector got lost while the player was at a prompt,
and the new owner was allied to the player, the server got confused:

1. If the sector attacked with mil, the server let the ghost mil
attack, but not occupy.

2. If the sector was allied, the server reported the sector loss and
land units dropping out of the attack, but claimed the lost sector was
yours.

Fix 1. by dropping sectors from attack when they change owner away
from the player, regardless of relations.  Side effect: also drops any
surviving land units there.  Before, they dropped out only if the new
owner wasn't allied to the player.  That change's okay.

Fix 2. the obvious way: change the messages.

Broken in 4.0.0.
2011-02-13 16:03:34 +01:00
16c68eb403 Fix trade ships to pay off in own harbor
Broken in commit 3318e4e4, v4.3.17.
2011-02-13 16:03:34 +01:00
439f111f98 Remove option SLOW_WAR
SLOW_WAR has issues:

* The check whether the attacker old-owns the attacked sector is
  broken, because att_abort() uses sect.sct_oldown uninitialized.

  Spotted by the Clang Static Analyzer.

* Its implementation in setrel() is somewhat scary.  It's actually
  okay, because that part of setrel() only runs within decl().  Other
  callers don't reach it: update_main() because player->god != 0
  there, and the rest because they never pass a rel < HOSTILE.

* Documentation is a bit vague.

SLOW_WAR hasn't been used in a public game in years.  Fixing it is not
worth it, so remove it instead.
2011-02-13 15:59:49 +01:00
a94ae5f8c1 Fix nightly's sandbox cleanup not to hang when stdin is a tty
"rm -r" prompts for read-only files when stdin is a tty.  Probably
broken since we install builtin configuration read-only, in commit
b4161cd7, v4.3.0.

Move "done" message to the right place.  Broken in commit 70c03561,
v4.3.12.
2011-01-15 14:40:06 +01:00
c7d9d4fcf4 Fix nightly's check for existing sandbox
Broken in commit 70c03561, v4.3.12.
2011-01-15 14:40:06 +01:00
c77db95fad Clean up a useless use of cat 2011-01-15 14:40:06 +01:00