Commit graph

3394 commits

Author SHA1 Message Date
774b590f55 Fix standalone client build for Windows
Need to compile with -mthreads since commit f082ef9f, v4.3.11.
2008-09-20 11:57:59 -04:00
65410d16fd Disable incorrect autmatic supply in load and lload
load_land_ship() and load_land_land() automatically resupply the land
units they load.  This can draw supplies from the sector where the
land units are.  When load() and lload() later update the sector, they
wipe out the update made for drawing supplies, and we get a seqno
mismatch oops.  Highly abusable.  Disable for now.
2008-09-20 09:16:46 -04:00
e0f7751f6b Update change log for 4.3.17 2008-09-17 21:38:42 -04:00
b2f75427bd Update example to current output 2008-09-17 21:31:46 -04:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
a9653c475b Fix whitespace: space before tab 2008-09-17 19:29:42 -04:00
db4770426e Update known contributors comments 2008-09-17 18:54:15 -04:00
6589601e56 Make unit_give_away() immune to infinite recursion
Put the unit before recursing into its cargo.  This breaks cycles in
the "is loaded on" relations.  Such cycles exist only in a corrupt
game state.  Mildly inefficient, because callers typically put the
unit again.
2008-09-16 21:47:55 -04:00
5820e12504 Belatedly remove DEMANDUPDATE from info Options
Option gone since commit 6ca5e47f, v4.3.10.
2008-09-16 19:14:41 -04:00
3e15a8e226 Make trade show exactly what's on sale, remove option SHOW_PLANE
Planes and land units on ships are sold along with the ship, but trade
showed them only when SHOWPLANE was enabled.  Show them always.

Planes on land units are not sold along with the land unit, but trade
showed them when SHOWPLANE was enabled.  Don't.
2008-09-16 19:11:18 -04:00
4a44b51f8c Guard unit.h against multiple inclusion 2008-09-16 18:47:06 -04:00
60000b1a42 Use unit_wipe_orders() to simplify build.c
Simplify build_ship(), build_plane(), build_land() and build_nuke().
2008-09-15 19:40:44 -04:00
574e20f6f5 Stop ships, planes, land units and nukes on violent takeover
This is for consistency with sectors, and for the same reason: pause
before spending money on stuff taken in the heat of battle.
2008-09-15 19:40:44 -04:00
e7ce50405e Wipe orders when ship, plane, land unit or nuke changes owner
Use new unit_wipe_orders() for violent takeover (takeover_unit() on
behalf of assault, attack, board, lboard, paradrop and pboard), and
peaceful takeover (unit_give_away() on behalf of arm, disarm, load,
unload, lload, lunload, scrap, scuttle, tend, trade).

Before, takeover_unit() cleared only group, mission and ship retreat
orders, and unit_give_away() only group and mission.  Orders that
weren't cleared:

* Mission op area (visible in xdump)

* Ship autonav orders

* Ship sail path including ship to follow and mobility quota

* Plane range limit

* Land unit retreat orders and retreat percentage
2008-09-15 19:40:44 -04:00
5f6e27ff80 Refactor and fix takeover.c
Factor new takeover_unit() out of takeover_ship(), takeover_plane(),
takeover_land().  This fixes the following bugs in assault, attack,
board, lboard, paradrop and pboard:

* When the "land unit loaded on land unit" relation had a cycle,
  takeover_land() went into an infinite recursion.  Such cycles exist
  only in a corrupt game state.

* Nukes armed on planes weren't taken over along with their plane.
  Broken in commit 2e40a4bb, v4.3.3.

* Taking over land units with negative mobility increased mobility to
  zero.  Ditto planes embarked on ships or land units.

* Taking over planes embarked on ships or land units didn't clear
  their wing.

* Taking over planes and land units updated their MOB_ACCESS timestamp
  (pln_access, lnd_access), except for planes not embarked on
  anything.  This had no effect.
2008-09-15 19:40:44 -04:00
94a3108b23 Fix marking of unused trade slots
Trade code can't quite decide whether negative trd_unitid or zero
trd_owner marks unused slots.  The former is a bad idea, because blank
slots have a zero trd_unitid.

Make sure to zero trd_owner when setting trd_unitid to negative value
in trad() and check_trade().  This fixes recognition of unused slots
in set (broken in commit e16e38df, v4.2.18) and xdump (never worked).
2008-09-15 19:40:44 -04:00
69b74bb5dd Remove takeover_ship() and takeover_land() parameter hostile
All callers pass non-zero.  Simplify accordingly.
2008-09-15 19:40:44 -04:00
b8ab065a6e Fix and simplify check_trade()
Use unit_drop_cargo() to drop a sold land unit's cargo.

Use unit_give_away() to transfer ownership.  This fixes the following
bugs and misfeatures:

* Sold nuke wasn't taken off its plane.  Could not happen before
  commit 2e40a4bb, v4.3.3.

* Nuke on a plane wasn't sold along with the plane.  Broken in commit
  2e40a4bb, v4.3.3.

* Planes and land units on sold ships got their mobility zeroed.

* Planes on sold ships didn't get their wing reset.
2008-09-15 19:40:43 -04:00
8cf32c4854 Fix cargo giveaway in load, lload, unload, lunload and tend
Use unit_give_away() in gift().  This fixes a number of bugs:

* Nukes on planes weren't given away along with the plane.

* Likewise for land units on land units (can't happen in the stock
  game).

* Mission was not cleared by unload land/plane, lunload land/plane,
  and lload plane, except for planes on land units.

* Wing and army were never cleared.

It also happens to suppress information on planes given away along
with their land unit carriers.  Shrug.
2008-09-15 19:40:43 -04:00
d2b1bef0f5 Fix cargo giveaway in scrap and scuttle
When giving away cargo by scrapping or scuttling its carrier, the
cargo's cargo wasn't given away.  Happened for instance when a ship
carrying a land unit carrying a SAM got scrapped.

Also, wing, army and mission weren't cleared.

To fix, create unit_give_away() and use it in unit_drop_cargo().
2008-09-15 19:40:43 -04:00
f3651f17e5 Refactor and fix scuttle and scrap code
Factor unit_drop_cargo() out of scra(), scuttle_ship(),
scuttle_land(), fix it up:

* Some messages were sent as bulletins instead of printing them.

* Nukes were always destroyed.  They're now treated exactly like other
  cargo.

* scuttle destroyed some cargo silently, and listed other cargo as
  "scuttled".  It now simply lets unit_update_cargo() running from
  carrier prewrite callbacks list all cargo "lost".

Simplify its callers.  scuttle_ship() and scuttle_land() are now
trivial, inline and remove.
2008-09-15 19:40:13 -04:00
3318e4e4e5 Require friendly relations for trade ship to pay off 2008-09-15 19:04:17 -04:00
faca0eeac5 Refuse to auto-scuttle where it doesn't pay
When called from the scuttle command, scuttle_tradeship() asks for
confirmation when scuttling doesn't pay.  When called from the autonav
code, it can't ask.  Change it to fail then, and use that in
nav_ship() to avoid scuttle where it doesn't pay.  Also simplify some.
2008-09-15 18:59:26 -04:00
693c1a64c3 Fix when scuttle_tradeship() asks for confirmation
Fix scuttle to ask for confirmation when scuttling a tradeship in an
unsuitable sector even when the tradeship is pirated.  Broken when
commit a99bc3be (v4.2.13) suppressed that for pirated tradeships
wholesale because it let pirates ferret out where the ship was built.
2008-09-15 18:48:33 -04:00
96796dc756 Fix scuttle_tradeship() to require 2% efficiency 2008-09-15 07:49:24 -04:00
221324cc10 Clean up rules on where you can scrap stuff
You can now scrap ships in own or friendly, efficient harbors, planes
in own or allied, efficient airfields, and land units in any own or
allied sector.

When something can't be scrapped because of these rules, print a
suitable message.

Before, you could scrap ships regardless of relations to sector owner
(info claimed friendly was required), land units regardless of
relations, but not while on ships, and planes even in friendly
airfields (info claimed allied was required).

When scrapping in a deity sector, scrap claimed it gave the cargo to
POGO, which is somewhat bogus, as POGO can't own such stuff.
2008-09-15 07:49:24 -04:00
06dd3d80ac Fix scrap and scuttle output when there's output about cargo
scra() and scut() printed their "scrapped in" / "scuttled in" message
in two parts.  Messages for scrapped / scuttled cargo were printed
between the parts.  Fix by printing in one go, after the cargo
messages.
2008-09-15 07:49:24 -04:00
0103372471 Fix missing include in cargo.c 2008-09-15 07:48:33 -04:00
b024d57b38 Remove take_plane_off_ship(), take_plane_off_land()
Commit 3e370da5 left them pretty trivial.  Inline, simplify, remove.
2008-09-14 10:21:27 -04:00
4478df7da6 No need to take dead planes off carrier anymore
Until commit 3e370da5, dead planes had to be explicitely taken off
their carrier to update load counters.  This is no longer necessary;
simplify pln_put1() and scut().  scut() got it wrong, by the way: it
failed to take planes off land units.
2008-09-14 10:21:27 -04:00
87c3ca9cca Indentation fix 2008-09-14 10:21:26 -04:00
c34daec8c6 Fix cargo list shutdown oops
EF_PLANE is closed before EF_LAND: if a land unit carries a plane, the
plane goes away before its carrier, and unit_onresize() oopses.  Fix
by not checking cargo list consistency there when the file is already
gone.

unit_cargo_init() has a similar issue, at least theoretically: it
rebuilds cargo lists one after the other.  Zap them all first.
2008-09-14 10:21:26 -04:00
1876932cd9 Fix commit 738fb28f's screwy line endings 2008-09-14 10:19:33 -04:00
Ron Koenderink
738fb28f73 Do not update player's bank balance when the change is zero
Hackish work around for a race condition in the nightly build's
regression tests: sometimes the update starts right after the
force command yields, sometimes a bit later.  If it is late, we
use one random number here, for the bye, and throwing off the
random sequence.
2008-09-13 17:33:24 -06:00
861a66625c Make prewrite callbacks more robust
Treat zero owner just like efficiency below minimum.  Before, cargo
was taken off carriers only when efficiency fell below minimum, not
when owner changed to zero.

Run item_prewrite() unconditionally, for simplicity.
2008-09-13 19:15:58 -04:00
fc42f66b4a Rename llp to lp in lnd_postread() and lnd_prewrite() 2008-09-13 19:15:40 -04:00
Ron Koenderink
74b655f9fa Allow any length RW lock names for WIN32
Dynamically allocate the string space for RW
lock names for WIN32 (ntthread.c).  This
makes the WIN32 more consistent with the other
environments.
2008-09-13 16:39:45 -06:00
Ron Koenderink
838a1010c2 Allow any length thread names for WIN32
Dynamically allocate the string space for thread
name in WIN32 (ntthread.c) thread space.  This
makes the WIN32 more consistent with the other
environments.  It also addresses WIN32 issue of
the print width of 17 being used and only having
space for 16 characters in the fixed allocation.
2008-09-13 15:29:42 -06:00
2a9b89693e Use new snxtitem_cargo() to simplify a couple of loops
Change snxtitem_all() loops that skip everything but a carrier's cargo
to use snxtitem_cargo() in scra(), scuttle_ship(), scuttle_land(),
takeover_ship(), takeover_land(), trade_desc(), feed_ship().
2008-09-12 21:35:36 -04:00
3cf29456fe Rewrite the broken code to move cargo with its carrier
The old code did not move a carrier's cargo (planes, land units,
nukes) when the carrier moved.  Instead, it fixed up the location in
the postread callback.  Anything not going through ef_read(), in
particular the update, saw it in its old, incorrect location, until a
fixed up copy got written back.

Moreover, the timestamp did not change when cargo moved, so
incremental dumps did not pick up the movement.

The new code moves the cargo along with the carrier.

New unit_update_cargo() moves or destroys a carrier's cargo (planes,
land units, nukes) along with the carrier.  Call it from
shp_prewrite(), pln_prewrite() and lnd_prewrite() when the carrier
moves or gets destroyed.

Remove the code to destroy cargo from shp_prewrite(), pln_prewrite(),
lnd_prewrite().

Remove the code to fix up cargo location from pln_postread(),
lnd_postread(), nuk_postread().

This changes the message for ship and land unit cargo getting
destroyed from "sunk" and "MIA" to "lost".
2008-09-12 21:34:07 -04:00
e7f5b517a0 Make the item iterator capable of iterating over a cargo list
New snxtitem_cargo() initializes an iterator for a cargo list, with
new enum ns_seltype member NS_GROUP and new struct nstr_item member
next.  Extend nxtitem() and nxtitemp() to step through the list.
2008-09-12 18:46:54 -04:00
7a4b7f75a0 Clean up struct nstr_sect and struct nstr_item a bit
Members read were always set to ef_read, remove and call directly.

Member flag was only assigned to, never used, remove.

Change member group to char to match struct empobj.
2008-09-12 18:41:55 -04:00
b10ebe6992 Zap next uid in clink_rem(), check it in clink_add()
The former ensures that next links are valid even for uids not on any
list.  The latter oopses on adding an uid to a list when it is already
on a list, unless it is at the tail.
2008-09-12 18:34:11 -04:00
7441e2499f Expire lost items at the update instead of continuously
Replace thread DeleteItems running delete_lostitems() by simple
function delete_old_lostitems(), and call it from update_main().
2008-09-12 18:05:58 -04:00
b72fd20674 Replace econfig key lost_items_timeout by lost_keep_hours 2008-09-12 18:05:58 -04:00
0900cca4f5 Fix commit d46b0b72 (didn't even compile with pthreads) 2008-09-12 18:05:58 -04:00
19614ab6dc Fix journal_entry() to separate thread and event by space
Broken in commit effc1b18.
2008-09-12 17:57:29 -04:00
Ron Koenderink
4d7d7bb77e Add missing error check for thread creation for WIN32
_beginthread() call in empth_create() has two error
return values 0L and 1L.  Add the missing check for 0L.
2008-09-12 07:22:28 -06:00
Ron Koenderink
af2a87e490 Ensure the empth_sleep() always yields for WIN32
The WIN32 version did not block when the sleep was
already reached by the time empth_sleep() did the
time remaining calculation.  The other versions
of empth_sleep() do always yield.
2008-09-12 07:22:28 -06:00
d46b0b727d Make empth_name() and empth_set_name() take a thread argument 2008-09-11 19:25:34 -04:00