Commit graph

4415 commits

Author SHA1 Message Date
b98a806d82 Fix pending anno count for annos squashed together
Adjacent announcements are squashed together when the sender is the
same and the timestamp is "close enough".  Except typed_wu()
increments natstr member nat_ann regardless.  Fix that to work exactly
like nat_tgms.
2011-12-29 11:47:07 +01:00
17223e8fe2 Fix read not to split production report when update is slow
Adjacent telegrams are squashed together if type and sender are the
same, and the timestamp is "close enough".  This is done in two
places: rea() and typed_wu().  They're inconsistent: typed_wu()
ignores the timestamp for production reports since Empire 2, but rea()
doesn't.

Record typed_wu()'s decision in new telstr member tel_cont.  Use it in
rea().
2011-12-29 11:47:06 +01:00
a0b82b8d46 Simplify how typed_wu() counts telegrams
typed_wu() counts telegrams to update nat_tgms and, since Empire 2,
send C_INFORM messages.  Adjacent telegrams are squashed together if
type and sender are the same, and the timestamp is within TEL_SECONDS.

typed_wu() increments nat_tgms when it sends a telegram that read
doesn't squash into the previous one.

Since Empire 2, it also sends a C_INFORM message then.  Inexplicably,
it fails to use the same condition: it tests just new_tele, not
new_tele || np->nat_tgms == 0.  C_INFORM messages got missed, until
4.0.18 made rea() call clear_telegram_is_new().  Convoluted.

Send C_INFORM exactly when incrementing nat_tgms, and back out
4.0.18's fix.
2011-12-29 11:47:06 +01:00
a5bcb63b85 Fix clear_telegram_is_new() for TEL_NORM from POGO at the epoch
Purely theoretical, of course.
2011-12-29 11:47:06 +01:00
35e897f70b Clean up how telegram_is_new() detects production report
Test for TEL_UPDATE, not update_running.
2011-12-29 11:47:06 +01:00
ac5dac0690 Move clear_telegram_is_new() call to beginning of update
The call was added in 4.2.5 "so that the next telegram is flagged as
new and not part of the update".  Since the update sends only
TEL_UPDATE telegrams (the previous commit restored that property), and
nothing else does, the next telegram is flagged as new automatically,
except when it's from the next update.  Document that, and move the
call to a more natural place.
2011-12-29 11:47:06 +01:00
d46b168663 Ensure the update's production report isn't split by bulletins
During the update, wu() sends TEL_UPDATE telegrams ("Production
Report") instead of TEL_BULLETIN telegrams, but typed_wu() has no such
logic.  It's used by tele(), which doesn't run during the update, and
mpr(), which may, e.g. called from ship or mission code used by
autonav or sail.  This inserts bulletins in the middle of the
production report, splitting it apart.

Happens since mpr() was added in Empire 2.  Before, only tele() used
typed_wu() directly, and everything else wu().

Change mpr() to use wu().
2011-12-29 11:47:06 +01:00
9f9cbfb20c Saner error handling in typed_wu()
Leave nat_ann, nat_tgm alone and return -1 on all errors.  Before,
only failed open was handled that way.  Failed write and close were
logged and ignored.  While there, improve the log messages a bit.

Note: the return value fix has little effect.  It makes tele() log the
failure, which is redundant.  Everything else goes through wu() and
ignores the value.
2011-12-29 11:47:06 +01:00
0b2b51bbcb Drop superfluous fseek() from rea() 2011-12-29 11:47:06 +01:00
6d98cd3134 Make add require confirmation for unadvisable actions
Deleting a country in state STAT_SANCT, STAT_ACTIVE or STAT_GOD is
risky, because any references to this country become dangling, which
makes ef_verify() unhappy.  For a reason: we may well have code that
isn't prepared for dangling references, and breaks.

Replacing a country that is being used is risky, because it can get us
into weird states.  For instance, replacing a player by a visitor can
result in a visitor that owns stuff.
2011-12-29 11:47:06 +01:00
d2057af7a2 Make add refuse to touch a country while it's being played
I suspect player code could get terminally confused by country state
changing unexpectedly.  Not worth the risk.
2011-12-29 11:47:06 +01:00
881b6fbd2b Fix add not to crash on negative country number 2011-12-29 11:47:06 +01:00
b36727e7fb Don't bother giving POGO BTUs in files
Deity's BTUs get reset to maximum on login anyway.
2011-12-29 11:47:06 +01:00
37e9b6aa9c Create all deities with $123456789, not just POGO 2011-12-29 11:47:06 +01:00
ad308c5de8 Move setting nat_cnam, nat_pnam into nat_reset() 2011-12-29 11:47:06 +01:00
bb442abdcd Use nat_reset() for POGO in files.c
Requires moving it from subs/natsub.c to common/nat.c.
2011-12-29 11:47:06 +01:00
5fd595a59a Make files set the usual nation flags for POGO
The add command sets nation flags NF_FLASH, NF_BEEP, NF_COASTWATCH,
NF_SONAR, and since 4.2.6 NF_TECHLISTS.  POGO is created by the files
utility, which sets only NF_FLASH (since 4.2.2).  Change files to
match add.
2011-12-29 11:47:05 +01:00
5232add0f5 nat_reset() is no longer used with STAT_SANCT, simplify 2011-12-29 11:47:05 +01:00
7739830594 Change newcap back to not wiping the country
Just create sanctuaries, put country into STAT_SANCT, grant BTUs and
money, set origin and initial realms.

This reverts commit e1a68c72 (v4.3.12) as far as newcap is concerned.
Except we still set nat_access, because that needs to be set along
with nat_btu.

Additionally, leave levels and telegrams alone.

Should have no effect in practice, because newcap works only in
STAT_NEW, and we get there with the add command, which wipes the
country.
2011-12-29 11:47:05 +01:00
6984f9d982 Make add always reset the country
Before, add reset the country only when adding a player or a visitor.
When adding a deity or deleting a country, it set just nat_cnam,
nat_pnam and nat_state.  Has always been that way.

Because of that, a newly minted deity country could inherit all kinds
of crap from a previous user of its country number: origin, realms,
relations, telegrams, ...  Harmless if the country number has never
been used before, which is how add is generally used.

When adding a deity country, initial levels (start_education, ...) now
apply, relations start NEUTRAL instead of AT_WAR, and the usual
initial nation flags are set.

Reset on delete as well, just to get rid of the special case.
2011-12-29 11:47:05 +01:00
373f20a8b5 Rename add argument "new" to "player"
This makes the correct choice for player countries obvious.  Keep
recognizing "new" for now, but deprecate it.
2011-12-29 11:47:05 +01:00
3fb00c79d9 Drop add argument "active"
Argument "active" is obscure.  It creates a country in STAT_ACTIVE
that doesn't have a capital, and has its origin at the true origin.
If you really want such a country, create it in STAT_NEW normally,
then use edit to go to STAT_ACTIVE.
2011-12-29 11:47:05 +01:00
62f0da239f Drop add's obscure sector check and wipe functionality
If you really need to wipe out a country, there's much more to wipe
than just sectors.
2011-12-29 11:47:05 +01:00
a9e485b13e Drop add's undocumented land unit destruction feature
It doesn't destroy ships, planes or nukes, either.
2011-12-29 11:47:05 +01:00
062c660e28 Permit no-op country name change again
Commit aa5861d1 (v4.3.20) made add, edit and change reject a country
name that is already in use.  Even if it's used by the same country.
Relax that.
2011-12-29 11:47:05 +01:00
9b2e906ea1 Improve newcap's origin error message 2011-12-29 11:47:05 +01:00
c9b380eee4 Streamline a few files error messages
Write one nice line to stderr instead of a cryptic one to stderr, and
an uninformative one to stdout.
2011-12-29 11:47:05 +01:00
73129c15cc Fix files and fairland to report ef_open() failure just once
ef_open() already reports failure since commit 7eb2fe57, v4.2.20.
Drop the second report from its callers.
2011-12-29 11:47:05 +01:00
f006e373f9 Replace exit(-1) by exit(1)
exit() uses only the least significant byte of its argument.
2011-12-29 11:47:05 +01:00
06753c7e2b Make allocate_memory() return void
It can't fail since commit ba1a320c, v4.3.15.
2011-12-29 11:47:05 +01:00
9be42299b5 Guard against unusable fd in pthreads' empth_select()
0 <= fd < FD_SETSIZE must hold, or else undefined behavior in
FD_SET().
2011-12-29 11:47:05 +01:00
55e689fb31 Fix lwpSleepFd()'s guard against unusable fd
0 <= fd < FD_SETSIZE must hold, or else undefined behavior in FD_SET()
and buffer overrun in LwpFdwait[fd].  Check of upper bound off by one,
check of lower bound missing.
2011-12-29 11:47:05 +01:00
0b66d8e281 Plug FILE leak on show_first_tel() error paths
Leak introduced in commit 4238323d, v4.3.20.  Unlikely to bite in
practice, as only corrupt mailbox files can cause these errors.
2011-12-29 11:47:05 +01:00
8e391f29a1 Plug memory leak in set_paths() error path
Leak appeared in commit 91eefc3f, v4.3.12.  Harmless in practice,
since the error is ultimately fatal.
2011-12-29 11:47:05 +01:00
5a77a8186e Fix read_schedule() not to fclose(stdin)
Did that since the initial commit 71320ed6, v4.3.10.
2011-12-29 11:47:04 +01:00
881dd41626 Plug FILE leak on read_schedule() parse error path
Leak introduced in initial commit 71320ed6, v4.3.10.
2011-12-29 11:47:04 +01:00
6104d534e9 Plug memory leak in verify_row()
Leak introduced in commit b30c83cd, v4.3.28.
2011-12-29 11:47:04 +01:00
354664eef2 Make play show no last command when there hasn't been one
Before, it printed NULL, which isn't helpful.
2011-12-29 11:47:04 +01:00
11d6e8ce80 Remove unreachable code in sell()
sell used to search multiple sectors for sellable commodities, keeping
tally in totalcom.  It failed with message "No eligible" when none
could be found.

sell's second argument got changed to a single sector in Empire 3.  If
the sector can't sell, we return early.  Else, totalcom is positive.
Thus, the "No eligible" code is unreachable.  Remove it.
2011-12-29 11:47:04 +01:00
845fc9eb56 Fix info sell on second argument
Empire 3 changed it to a single sector, but neglected to update info.
2011-12-29 11:47:04 +01:00
1086387f8b Make scripts/savecore create the core directory 2011-12-29 11:47:04 +01:00
5e9fb6b607 Rename tgz to arc in scripts/backup
tgz looks silly when you hack the script to use something other than
tar+gzip.
2011-12-29 11:47:04 +01:00
44235c0092 Fix empire(6) synopsis for argument of -s
Commit 464094a6 (v4.3.26) changed it in section description, but
missed section synopsis.
2011-12-29 11:47:04 +01:00
14af9e5b96 Fix use-after-free when plane is downed or aborted in dogfight
ac_dog() passed ap and dp to ac_dog_report() after ac_planedamage()
freed it.  Broken in commit 73260a8a, v4.3.27.  Diagnosed with
valgrind.
2011-12-29 11:44:16 +01:00
a990d90b84 Bump version to 4.3.29 2011-08-03 20:36:28 +02:00
513352f50c Clean up omit_ids() not to set an extra element in idgap[] 2011-07-16 15:30:10 +02:00
b7594e6570 Update change log for 4.3.28 2011-07-16 13:47:48 +02:00
617cb41f66 Don't let POGO (#0) navigate and march ghosts
POGO can navigate dead ships, and march dead land units.  The ghosts
even get sighted and interdicted, and can hit mines (landmines only
until commit fe372539, v4.3.27).  Noted for ships in commit 9100af0b.
Has always been broken.  Fix by making shp_sel() and lnd_sel()
explicitly reject ghosts.

Same code pattern also exists in pln_sel, but dead plains fail the
efficiency test, so it's harmless there.  Apply the same fix anyway.
2011-07-16 13:47:48 +02:00
45d090b8c3 Make llook ignore land units and planes loaded on land units
Probably overlooked when trains were added in 4.0.0.
2011-07-16 13:47:48 +02:00
0a693c1fa2 Fix "sector can board" test to ignore land units on land units
boar() lets a sector board if it has mobility or usable land units.
Embarked land units are not usable.  But it tests only "on ship", not
"on land unit".  Broken in 4.0.17.
2011-07-16 13:47:36 +02:00