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
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).
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.
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.
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.
RET_SYS was used for commands failing due to internal or environmental
errors, but not really systematically. The difference to RET_FAIL is
how dispatch() treats them: RET_SYS got logged, and cost no BTUs.
More specific logging is possible at the point of failure than in
dispatch(). Make sure that's done for all failures that used to
return RET_SYS.
The change in BTU charging affects commands consider, offer, repay,
trade failing due to internal errors. It also affects deity commands
reload and turn (irrelevant because deities get unlimited BTUs), and
commands apropos, info and motd (irrelevant because they cost no
BTUs).
Use new pln_is_in_orbit() when we want to test for orbit specifically,
and test PLN_LAUNCHED when we want to test whether the plane not
sitting in the sector (because it is flying). This distinction is
pointless at this time, because the only way PLN_LAUNCHED gets set is
when a satellite goes into orbit. It will become useful in a later
commit, which will use PLN_LAUNCHED to mark flying planes.
Trade teleports planes to a destination chosen by the buyer, except
for satellites in orbit. trad() failed to enforce the usual rules on
destinations for satellites (not in orbit) and asat missiles: they
could be teleported anywhere. Abusable, because abms intercept from
anywhere, and satellites can be launched from unowned sectors, even
sea. Broken since BSD Empire 1.1.
(lndstr, plnstr, sctstr, shpstr): Change timestamp members lnd_access,
pln_access, sct_access, shp_access from real time (time_t) to ETUs
within a turn (short).
(land_ca, plane_ca, sect_ca, ship_ca): Update accordingly.
(build_ship, build_land, build_bridge, build_plane, build_tower)
(explore, check_trade, bsanct, takeover, takeover_ship)
(takeover_land): Use game_tick_to_now() instead of time() to update
the timestamp. Change check_trade(), takeover_ship(), takeover_land()
to do that only when MOB_ACCESS is enabled, for consistency.
(lupgr, supgr, pupgr, takeover_ship): Don't touch the timestamp where
mobility isn't touched either.
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob): Use
game_tick_to_now() instead of increase_mob() to compute ETUs since
the timestamp and update the timestamp. Closes#1012699.
(increase_mob): Remove.
(mob_sect, mob_ship, mob_land, mob_plane): sct_do_upd_mob() & friends
no longer do the right thing at the update. Use game_reset_tick() and
pass its result directly to do_mob_sect() & friends. This is only
correct when argument is etu_per_update, which it always is. Remove
parameter. Callers changed.
(do_mob_sect, do_mob_ship, do_mob_land, do_mob_plane): Oops on
negative argument.
(mob_acc_globals, timestampfil, mobupdate, updating_mob)
(update_all_mob, timestamp_fixing, update_timestamps, mobility_check):
The mobupdate command was important to let deities manually
synchronize mobility updating with updates. That's no longer needed.
The code behind it is somewhat hairy and ugly, and updating it to work
with the Empire clock is just not worth it. Remove. Users changed.
(player_coms): Update accordingly.
(upda): Remove display of mobility updating state.
(mobility_init): No need to fix up mobility on startup, as the Empire
clock runs normally even when the server is down. Remove. Caller
changed.
other. Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special). New header types.h to
help avoid inclusion cycles. Sort include directives. Remove some
superflous includes.
oprange, show_mission, nameofitem, build_mission_list_type,
unit_map, xdvisible, trdswitchown, ontradingblock, trad, check_trade,
unit_type_name, start_stop_unit, scut, scra, mission, multifire,
perform_mission, fuel, NSC_GENITEM): Replace struct genitem with
struct empobj. Remove genitem.h and create a new file empobj.h.
Replace multiple instances of unions of ef_type structures with
one standard union empobj_storage which is a superset of the individual
instances.
undocumented feature: When a buyer didn't have enough money at the
time of the trade, the seller *automatically* granted a high-interest,
medium term loan for up to 90% of the price. This is just a silly
trap for unwary sellers and buyers alike.
(N_FIN_TROUBLE, N_CREDIT_JUNK): Unused, remove.
(rpt): Update accordingly.
freshly extended trade file makes sense. When set() removes a lot,
simply zero the slot.
(set): Initialize trd_uid.
(trade_check_ok): Use check_land_ok() & friends instead of doing it by
hand, but wrong. This fixes bying planes and land units loaded on
ships that moved after loading.
(check_trade_ok): New.
(trade_check_ok): Use it. Remove unused argument lot. Callers
changed.
them. From Marc Olzheim.
Type modifier 'l' was missing in many places, probably rendering the
server useless on 64-bit hosts.
(ef_flush, ef_write, ef_extend, lwpCreate, lwpDestroy): Use conversion
specifier 'p' to print pointers.
(check_market): Fix display of loan amount.
(doland): Fix unescaped '%' (undefined behavior).
(ldump, ndump, pdump, sdump): Don't use flag '0' with conversion
specifier 's' (undefined behavior).
(dump, ldump, lost, ndump, pdump, sdump, empth_create, update_sched):
Cast time_t and pthread_t to long for printing.
(lwpStackCheck, lwpStackCheckUsed, finish_sects): Insert cast to fix
argument type on all platforms.
(prod): Remove extra argument.
(perform_mission, airdamage, retreat_land1, lwpReschedule): Format
string missed arguments.
(genitem_ca, ship_ca, plane_ca, land_ca): Remove selector "sell".
(comstr, trdstr): Members trd_price, com_price have no effect. Use
them instead of trd_maxprice, com_maxprice and remove the latter.
(commodity_ca, trade_ca): Remove selector "maxprice".
instead of declaring them all over the place. This uncovered type
errors:
(s_p_etu, adj_update): Defined long, sometimes declared int. Kills
big endian machines where sizeof(long) != sizeof(int). Change to
int.
(set_option, delete_option, optstrset, intset, floatset, doubleset,
longset, optionset, optiondel, worldxset): Change linkage to static.