Commit graph

3272 commits

Author SHA1 Message Date
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
Ron Koenderink
7581b50eb6 Use empty schedule file for the nightly build
This ensures that no unplanned updates occur
during the nightly build sequence.  Remove
unnecesary enables and disables from the script.
Remove unnecessary argument for force command.
2008-09-11 14:58:32 -06:00
Ron Koenderink
5edaccafa4 Change the thread name in play_cmd() to show country number
This makes the journal easier to read.  We can't use the country
number earlier, because it is not unique then.
2008-09-11 14:50:08 -06:00
Ron Koenderink
effc1b187a Use the thread name to identify threads in the journal
This makes the journal easier to read, and makes journals
from the nightly build easier to diff.

Since we use only the 10 first characters of the name,
abridge existing thread names to make them unique within
that many characters.
2008-09-11 14:49:28 -06:00
Ron Koenderink
2ddeda99d0 New empth_name() and empth_set_name() 2008-09-11 14:46:31 -06:00
2e5915dd09 Remove bogus comment from empthread.h
Became bogus in commit d500a707.
2008-09-11 07:51:09 -04:00
fe3fd39d8f Fix double free() in unit_onresize()
Introduced in commit 64a53c90.
2008-09-11 07:50:18 -04:00
9189e67ad7 Simplify tests for presence of load
Instead of counting the load with lnd_nland() / lnd_nxlight(), check
whether there's at least one loaded with lnd_first_on_land() /
pln_first_on_land().
2008-09-08 21:41:56 -04:00
3e370da58c Get rid of ship and land unit load counters
Load counters are redundant; they can be computed from the carrier
uids.  Keeping them up-to-date as the carriers change is a pain, and
we never got that quite complete.

Computing load counters straight from the carrier uids every time we
need them would be rather inefficient, but computing them from cargo
lists is not.  So do that.

Remove the load counters: struct shpstr members shp_nplane,
shp_nchoppers, shp_nxlight, shp_nland, and struct lndstr members
lnd_nxlight and lnd_nland.

Don't compute/update load counters in build_ship(), build_land(),
land(), ldump(), load_plane_ship(), load_land_ship(),
load_plane_land(), load_land_land(), lstat(), sdump(), shi(), sstat(),
tend_land(), check_trade(), put_combat(), pln_oneway_to_carrier_ok),
pln_newlanding(), fit_plane_on_ship(), fit_plane_on_land(),
unit_list().

Nothing left in fit_plane_off_ship(), fit_plane_off_land(), so remove
them.

load_land_ship(), load_land_land(), check_trade(), pln_newlanding(),
put_plane_on_ship(), take_plane_off_ship(), put_plane_on_land(),
take_plane_off_land() no longer change the carrier, so don't put it.

Remove functions to recompute the load counters from carrier uids:
count_units(), lnd_count_units(), count_planes(), count_land_planes(),
pln_fixup() and lnd_fixup(), along with the latter two's private
copies of fit_plane_on_ship() and fit_plane_on_land().

New cargo list functions to compute load counts: unit_cargo_count()
and unit_nplane(), with convenience wrappers shp_nplane(),
shp_nland(), lnd_nxlight(), lnd_nland().

Use them to make ship selectors nplane, nchoppers, nxlight, nland
virtual.  They now reflect what is loaded, not how the load uses the
available slots.  This makes a difference when x-light planes or
choppers use plane slots.

Use them to make land unit selectors nxlight and nland virtual.

Use them to get load counts in land(), ldump(), load_plane_ship(),
load_land_ship(), load_plane_land(), load_land_land(), sdump(), shi(),
tend_land(), fit_plane_on_land(), trade_desc(), unit_list().

Rewrite fit_plane_on_ship() and could_be_on_ship() to use
shp_nplane().  could_be_on_ship() now takes load count arguments, as
computed by shp_nplane(), so it can be used for checking against an
existing load as well.
2008-09-08 21:32:56 -04:00
8b1470e3a8 Get rid of struct plnstr member pln_nuktype
pln_nuktype is redundant; it can be computed from the nuke's
nuk_plane.

Make plane selector nuketype virtual and NSC_EXTRA.  It should have
been NSC_EXTRA all along.  This changes xdump plane.

Don't set it in arm(), disarm(), build_plane(), pln_damage() and
nuk_fixup().  The latter no longer does anything, remove it.

Deprecate edit key 'n' in doplane(), and don't show it in pr_plane().
The key never made much sense.

eff_bomb(), comm_bomb(), ship_bomb(), plane_bomb(), land_bomb(),
strat_bomb(), mission_pln_equip(), air_damage(), msl_hit(),
pln_equip() tested pln_nuketype to check whether a plane carries a
nuke.  Test nuk_on_plane() instead.

pdump(), plan(), trade_desc() print whether and what kind of nuke a
plane carries.  Adapt that to use nuk_on_plane().
2008-09-08 21:32:53 -04:00
4086c25a15 Enable the new nuk_on_plane(), replacing the old one
Callers changed, as the new one isn't a drop-in replacements.
2008-09-08 21:32:52 -04:00
64a53c90f0 Cargo lists storing lists of cargo for each carrier
Persistent game state encodes "who carries what" by storing the
carrier uid in the cargo.  Cargo lists augment that: they store lists
of cargo for each carrier.  They are not persistent.

New unit_cargo_init() to compute the cargo lists from game state.
Call it in ef_init_srv() and at the end of update_main().

New unit_onresize() to resize the cargo list data structure.
Installed as units' struct empfile callback onresize to make them
resize automatically with the unit files.

New unit_carrier_change() to update cargo lists when carriers change
in game state.  Convenience wrappers pln_carrier_change(),
lnd_carrier_change() and nuk_carrier_change().  Call them from
prewrite callbacks to keep cargo lists in sync with game state.

To make that work, unused units must not point to a carrier.  Add new
pln_oninit(), lnd_oninit() and nuk_oninit() take care of newly created
units.  Change lnd_prewrite() and nuk_prewrite() to take dead land
units and nukes off their carrier.  pln_prewrite() did that already.

New unit_cargo_first(), unit_cargo_next() to traverse cargo lists.
Convenience wrappers lnd_first_on_ship(), lnd_first_on_land(),
lnd_next_on_unit(), pln_first_on_ship(), pln_first_on_land(),
pln_next_on_unit() and nuk_on_plane().  The latter is disabled for now
because it clashes with an existing function.
2008-09-08 21:30:39 -04:00
f21cb48f69 New struct empfile callback onresize 2008-09-08 21:30:37 -04:00
a1f20efd02 Revive struct empfile callback init as oninit
Commit a71f0158 removed unused callback init.  Bring it back renamed
to oninit, and without the redundant first argument.
2008-09-08 21:30:37 -04:00
b22520d180 Fix up filetable.c's file comment after rename. 2008-09-08 21:30:36 -04:00
011274515c Move selector code from src/lib/global to src/lib/common
Future virtual selectors will need to access game state.  This depends
on common/file.c, which can't be used from global without creating a
cyclic dependency between libglobal.a and libcommon.a.

Move nsc.c to src/lib/common.  file.c depends on it, so move it as
well, renamed to filetable.c so it doesn't clash with the existing
file.c.
2008-09-08 21:30:36 -04:00
136132773b New lost_and_found() to record ownership changes.
Factors out the common makelost()/makenotlost() pattern.
2008-09-08 21:28:29 -04:00
0d139ee1d1 Update lost file from prewrite callbacks
Losses of sectors, ships, planes, land units and nukes are tracked in
the lost file.  To keep it current, makelost() and makenotlost() were
called whenever one of these changed owners.  Cumbersome and
error-prone.  In fact, the lost file was never perfectly accurate.

Detect the ownership change in the prewrite callback and call
makelost() / makenotlost() from there.  Remove lost file updates from
where they're no longer needed: right before a put.  takeover() is a
bit more involved: it doesn't put the sectors, but all callers do,
except for guerrilla().  So remove the lost file update from
takeover(), but add it to guerrilla().

This takes care of lost file update for all ownership changes that go
through ef_write().  It can't take care of any missing updates for
changes that don't go through it.
2008-09-08 21:26:42 -04:00
c5482e4bfb Pass old element to empfile callback prewrite()
Change sct_prewrite(), shp_prewrite(), pln_prewrite(), lnd_prewrite(),
nuk_prewrite() accordingly.  New argument isn't used for anything,
yet.
2008-09-08 21:26:40 -04:00
0bcd0a8422 Fix comments added in commit bf436a44. 2008-09-08 21:26:40 -04:00
e31ba545af Remove bogus correction of sct_mobil from sct_prewrite()
It used literal 127 instead of sect_mob_max, it didn't check the lower
bound, and it didn't report the corruption.  From Chainsaw 3.

Having *working* sanity checks there would be nice.  Left for another
day.
2008-09-08 21:26:40 -04:00
85eb288f97 Don't execute pre-write checks from sct_postread()
Chainsaw 3 factored out most checks from sct_prewrite() into
checksect(), and called that from sct_postread() as well.  Revert
this, because it was a bad idea: whenever checksect() called from
ef_read() found something to change, it was actually a bug, and
changing it just hid the bug from whatever called ef_read().  But it
couldn't hide it from code going through ef_ptr().  So, instead of
having bugs visible everywhere, including census and such, they were
hidden in hard to observe places.  For instance, the previous commit
fixed one that was visible to the path finder, but not the actual path
user, which led to the path user choking on an incorrect path in a
rather obscure manner.

Things no longer "corrected" on read: excessive mobility, low work
despite no civilians present, sector owned despite neither civilians,
military nor land units.  The latter had a scary-looking caploss(),
but NF_SACKED should have rendered that harmless.
2008-09-08 21:25:12 -04:00
f84d25378b Don't revert sectors without military to old owner
Change checksect() not to abandon occupied sectors to the old owner
when there is no military and no land units.  This effectively
restores pre-Chainsaw 3 behavior.  Matching change to would_abandon().

Rationale.  Traditional ways to change sector owner:

(1) Attack, assault, paradrop can transfer a sector to the attacker,
    in take_def().

(2) Guerrilla warfare at the update can transfer a sector to the old
    owner, in guerilla().  This happens when che kill all military and
    the sector is sufficiently disloyal to the owner.

(3) Whenever all civilians, military and land units are removed from a
    sector, no matter how, it silently reverts to the deity, in
    checksect().

Chainsaw 3 added:

(4) Whenever all military and land units are removed from an occupied
    sector, no matter how, it silently reverts to the old owner, in
    checksect().

This addition isn't seamless.  Funnies include:

* When che kill all military and land units, but the sector is loyal,
  (3) doesn't transfer to the old owner.  But since there's no
  military and land units left, (4) transfers it anyway, only without
  telling the lucky old owner.  The latter transfer is buggy:
  checksect() runs only on ef_read() and ef_write(), not the update
  (bug#1010856), so the silent transfer is delayed until the next
  ef_write().  But code using ef_read() sees it right away.  For
  instance, the path finder, which doesn't use ef_read(), can route a
  path through a sector lost that way.  The actual move, which does
  use ef_read(), then chokes on that path.

* When you attack a sector, and get defeated with the help of reacting
  land units, but succeed in killing the *local* defenders, (4) makes
  the sector silently revert to the old owner.  Which might be
  somebody who wasn't involved in the fight, and gets no notification
  whatsoever of his windfall.

* You can abandon a sector to the old-owner by removing all military
  and land units from it, in a myriad of ways.  Some ways ask you for
  confirmation (move, march, load), many don't (navigate, plane
  construction, delivery; arguably bugs), and others simply don't let
  you (paradrop, fly, distribution).

  This problem also exists for abandoning to deity, i.e. through (3)
  instead of (4).  Some ways to move out civilians don't let you do
  that (distribute), but most do.  However, accidentally abandoning an
  empty sector to deity is less serious than a populated one to
  another player.

In my opinion, (4) doesn't add much to the game, and fixing the
funnies isn't worth the effort.
2008-09-05 07:39:02 -04:00