The do_upd_checking recursion guard is superfluous: do_mob_sect()
doesn't call anything. Has been that way since MOB_ACCESS was added
in Empire 3.
Inline the remaining code of sct_do_upd_mob(), shp_do_upd_mob(),
pln_do_upd_mob(), lnd_do_upd_mob() in their only callers
sct_postread(), shp_postread(), pln_postread(), lnd_postread().
Rename do_mob_sect(), do_mob_ship(), do_mob_plane(), do_mob_land() to
mob_sect, mob_ship(), mob_plane(), mob_land() and give them external
linkage.
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
When updating in-place (old==new), we must not write through new
before we're done reading the same memory through old.
Bug: we write the carrier uids too early. Cargo lists aren't updated
when a carrier dies in an in-place update. No such updates are known.
Broken in commit 64a53c90, v4.3.17.
When units somehow get stuck on a dead carrier, a new build reusing
the dead carrier's UID picks up its cargo. The cargo gets teleported
to its new carrier when the carrier moves.
Oops when a ship, plane or land unit is created with cargo. To
recover, destroy the cargo.
They set up invariants, and thus should be always active, not just in
the server. Since ef_blank() isn't used for these files outside the
server right now, this isn't a bug fix, just cleanup.
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.
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.
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".
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.
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.
Empire3's C_SYNC code added these to sct_prewrite(), shp_prewrite(),
pln_prewrite(), lnd_prewrite() and nuk_prewrite(). They weren't
removed when C_SYNC was ripped out in 4.0.0.
New struct emptypedstr to avoid depending on empobj.h there.
Remove now superfluous manual initializations elsewhere.
This doesn't fix any missing initializations.
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.
effect. Replace calls by struct assignment where possible. Replace
clear buffer, copy string to buffer by strncpy(). Use assignment to
clear when that's clearer. Replace overlapping copy through bounce
buffer by memmove(). Replace rest by standard memset() and memcpy().
Also use sizeof() instead of literal array sizes for robustness, and
instead of symbolic array sizes for clarity.