Commit graph

4831 commits

Author SHA1 Message Date
51f101df21 info/fire info/torpedo: Purge references to option MULTIFIRE
MULTIFIRE became non-optional in Chainsaw 3, more than two decades
ago.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:53 +01:00
e60f0be73f emp_config: Don't monkey-patch WORLD_X to be even
emp_config() silently truncates WORLD_X to even.  Drop that.  We could
flag odd WORLD_X as error, but we don't validate the other
configuration values, so why this one?  Instead document it needs to
be even.  WORLD_Y, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
ab82a804a6 ef_verify: Polish product error message
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
a4a25df2f4 init ef_verify: Don't monkey-patch capability VTOL, require it
A plane with capability missile must have capability VTOL.  When it's
missing, global_init() silently adds it.

Drop that.  Check for it in ef_verify_config() instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
c0c58222bc init ef_verify: Don't monkey-patch capability miss, require it
A ship with non-zero nplanes must have capability plane or miss.  When
one doesn't, global_init() silently adds capability miss.

Drop that.  Check for it in ef_verify_config() instead.  Fix up
ship.config accordingly.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
c3a26dc899 ef_verify: Require ship glim != 0 with capability dchrg
Because the fire command doesn't work with zero glim (commit a109de9).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
0e24049ce4 torpedo: Suppress bulletin when player torpedoes his own ship
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
88bfa2e6a3 torpedo: Print "Starting our attack run" regardless of target
Instead of printing it only when the target owned by somebody else.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
33497e4242 torpedo: Let torpedo hit land only when target is in range
Telling the player his torpedo "slams into land" can give a clue on
the direction to the target.  No good when the target is out of range,
because we shouldn't tell the player more than that then.

Screwed up in 4.2.2.  Fix by checking range before line of sight.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
bb6c974ef2 info/torpedo: Fix misinformation on submarine identification
Claims the victim of a torpedo attack gets told the attacking ship's
number.  This hasn't been the case for submarines since Empire 2.3.
Recent commits again reveal the attacking submarine's number, but only
when it gets hit by return fire.  Update info accordingly.

Reported-by: Neeraj Jain <thisisfranz@gmail.com>
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
05671c69b4 info/torpedo: Cover return torpedoes, drop depth charge details
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
17abdbc5e0 torpedo fire: Reveal sub hit by return fire or depth charge
This partly reverts a change made in Empire 2.3 to tell a submarine's
opponent only that he's dealing with a "sub" instead of the
submarine's UID and type.  Hiding submarines is done by prsub().
Uses:

* Command torpedo: defender depth charges or torpedoes an attacking
  submarine

  If you can attack a submarine reactively, you should be able to
  attack it actively, too.  But that requires its UID.  Reveal it
  again, but keep the type hidden.

* Command fire: defender fires back at a submarine using its deck gun

  Submarines need to surface to fire deck guns, so they shouldn't be
  treated any different than surface ships.  Revert Empire 2.3's
  change entirely there, i.e. defender learns type as well as UID.

* Command torpedo: attacking submarine hits its target

  Keep the submarine hidden.

* Commands torpedo and fire: attacking ship hits a submarine

  The attacker passed the UID as command argument, so it doesn't
  matter whether we print it or not.  Printing it is simpler to code,
  so do that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
76214dbfbd torpedo: New variable sub_mcp to make code more concise
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
695352d9d3 tests/torpedo: New; exercises torpedo command
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
81710a935c tests/fire: Cover firing at unused / sunk ships
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
ebb36f8dc3 tests/fire: Cover firing with foreign assets
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
165fbed512 fire: Clean up damage sanity check and printing of range
Repeated for ship, sector and land unit firing.  The latter prints
range only when the sanity check succeeds.

Factor out, changing ship and sector to behave like land unit firing.

When the sanity check fails, print "Jammed!" instead of "Klick!",
because "Klick!" suggests no shells.  Used to be printed exactly then,
but the condition first became impossible (Chainsaw), then generalized
to "can't fire for whatever reason" (commit 22c6fd8, v4.3.12).

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
ee3b02c514 Revert "Permit ships that can drop depth charges, but not fire"
This reverts commit 9b0b0dc772.

The fire command drops depth charges when the target is a submarine in
range and firing ship has the capability.  Else, it blindly fires
guns.  It used to reject ships that can't use guns, even when they
could use depth charges, but commit 9b0b0dc (v4.3.31) lifted that
restruction.  No such ships exist in the stock game.

If the firing ship can't fire guns, shp_fire() returns -1, triggering
an oops.  Broken in commit 0757042.

Avoiding dependence of depth charge on gun fire capability is
pleasing, but nevertheless a bad idea without test coverage.  Creating
the necessary tests isn't worth it, so put back the traditional
restriction instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:52 +01:00
ac15e5b961 fire: Print "Kaboom" even when the target is out of range
To make shell use more obvious.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
2f24a01c65 fire: Simplify logic to use depth charges rather than guns
Meaning of targ_sub changes from "target is a submarine" to "attacking
the target with depth charges".

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
634aa708f4 fire: Drop a sanity check that can't fail
Can't fail since commit 66165f3, v4.3.14.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
7b700e82c6 fire: Always clear mission when firing
Mission is cleared only when firing at a target that is out of range.
Screwed up when missions were added in Chainsaw.  Always clear it when
firing.  Matches torpedo.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
6d3106a582 tests/fire: Cover mission clearing
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
b8af67d32c tests/fire: Show all ships, planes, land units after the test
Instead of just the damaged ones.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
c88344dad4 fire: Fix artillery splashing the bridge span under itself
multifire() writes back the firing sector after applying damage.  When
an artillery unit on a bridge span commits suicide by shelling down
the supporting bridge heads, this writeback puts the bridge span right
back (less the land units and planes on it), triggering a seqno oops.
On the next update of the bridge head, the bridge span falls again.
Broken in commit fe5b266, v4.3.14.

The problematic write back is superfluous.  Remove it along with a few
equally superfluous ones.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
48d8533443 board: Fix mobility cost when defender's efficiency < 100%
The cost is meant to be proportional to efficiency / 100, but the code
truncates the fraction to zero.  Broken in Empire 2.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
39884aff59 convert: Drop broken code to charge security unit mobility
Conversion is easier when land units with capability security are
present.  Each such land unit is charged 10 mobility.  The mobility
charge is undocumented.

Land unit mobility is charged even when conversion turns out to be
impossible, say because the sector has no mobility.  I call this a
bug.  Has been that way since security land units were added in
Chainsaw 3.

Except the mobility charge doesn't actually work anymore: the changed
land unit is never written back.  Broken in commit 82c9166, v4.3.16.
Fix this bug would be trivial, but would bring back the bug described
above, and fixing that one is harder, and doesn't feel worthwhile.

Remove the broken charging of land unit mobility instead.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
2575ea8940 bomb: Fix damage to mobility when bombing planes
A bombed plane's mobility is multiplied by dam/100.0, i.e. the higher
the damage, the lower the mobility loss.  Has always been broken.  Fix
by computing the new mobility with damage(), like we do elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
f4d8d64bb3 commands: Always put ship or land unit before retreating it
boar() puts before retreating, the other callers afterwards.  Subtle
difference, because putting resets the owner of the dead to POGO.

Until the commit before previous, retreat didn't fully work after put.
Now it does.  The subtle difference between boar() and the other
callers still exists.  It's better to do it the same everywhere, as
subtle differences invite bugs.  Since changing boar() is not
practical, change the others.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
32b611eb8d sonar: Drop a redundant putship()
The old retreat_ship() took care not to put its ship argument (it
still put other ships in a group retreat).  Callers put it
unconditionally to make the change to the ship permanent.

The current retreat code puts all ships it changes, rendering sona()'s
putship() redundant.  Drop it.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
fff476ac4b retreat: Fix group retreat after failed board sinks ship
Group retreat still doesn't work, because when boar() passes a sunk
ship to retreat_ship(), its owner has been reset to POGO already.
This makes it impossible to find the group to retreat.  Instead, it
attempts to retreat ships that sank in the same sector with group
retreat orders and with the same fleet letter assigned.  If any exist,
shp_may_nav() oopses, and prevents actual retreat of these ghosts.

The other retreat conditions don't have this problem, because they
call putship(), which resets the owner, only after retreat_ship().

Making boar() work the same is not practical.  Instead, add an owner
parameter to retreat_ship(), and for symmetry also to retreat_land().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
7b3d541c0d Revert "retreat: Oops on retreating ghosts"
This reverts commit c3a839934f.

The commit message's claim that the code never actually retreats
ghosts is wrong: boar() does.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>

Conflicts:
	src/lib/subs/retreat.c
2015-03-02 08:20:51 +01:00
ebe4f05d87 board: Don't retreat ship#0 after failed board sinks ship
The root cause is in put_combat(): after it sinks the ship, it calls
att_get_combat(), which treats a combat object with a dead ship as an
error, tells the attacker "not in the same sector!", and "recovers" by
putting the combat object into an error state.  Too hard for me to fix
right now, so put in a FIXME comment.

The error state trips up retreat.  boar() uses the victim's ship
number in the combat object to find the ship it may have to retreat.
Putting the combat object into an error state sets this number to
zero.  If that ship exists, and isn't owned by the attacker, and has
RET_BOARDED set, it retreats.  Oops.  Broken when Empire 2 factored
out common combat code.

Fix by saving the ship number while it's still valid.

This uncovers the next bug: we now pass a dead ship to retreat_ship().
Oopses since commit f743f37.  Its commit message says "Harmless, but
avoid it anyway."  Going to revert.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:51 +01:00
0447bf3f58 tests/retreat: Cover retreat after failed board sinks victim
Should trigger group retreat, but doesn't; marked "BUG:" in the test
input.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
8348ce421c torpedo: Fix news on owner of ships sunk by return torpedoes
fire_torp() reads targ->shp_own after putship().  If targ sank, its
owner is POGO by then.  Screwed up when return torpedoes were added in
Chainsaw.  Fix by reporting news before putship().

torp() is correct, because it gets the owner from a local variable.
Change it like fire_torp() anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
7b8700fe00 torpedo: Don't disclose uid, type, owner of torpedoed subs
torp() reports target uid and type to the player.  Hide for submarine
targets, just like we hide attacking submarine details in bulletins to
the target's owner.

torp() and fire_torp() leak submarine owners through the news.
Suppress news for submarine targets.  This is consistent with fire:
mfir() doesn't report depth-charging, and quiet_bigdef() doesn't
report return torpedoes.

Historical note: the code has always hidden submarine uid, type and
owner in places, and leaked them in others.  When capability sub-torp
was added in Chainsaw, no attention was paid to hiding.  When Empire 2
hid attacking submarines, it did nothing for submarine targets.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
2bfc574943 bomb: Drop empty line after a ship's "blam-blam"
It's only printed for ships.  Looks misplaced when it's followed by
"sunk" or other damage reports.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
ce7f44a887 bomb: Include position when reporting bombed land unit
Use the exact same format as for ships.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
a2beecf26c bomb: Suppress bulletin when player bombs his own assets
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
df6b13ce89 bomb: Fix to report bombing of plane to owner once, not twice
Has always been broken that way.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
3aa088bb1c subs: Make correctness of some wu() uses more obvious
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
7be7ad98aa assault attack paradrop: Fix inconsistent support formatting
With offensive support but no defensive support, there's no empty line
separating the support table from the text that follows.  Fix that.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
c8e5b4fc50 subs: De-duplicate formatting in intelligence_report()
Every piece is formatted either with pr(), or with sprintf() for later
sending with wu().  The output is actually identical.  Format with
sprintf() always, and then either pr() or wu() the results.

While there, change the first parameter's type from int to natid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
61fc526b5d subs: Oops when a telegram doesn't end with a newline
Telegrams should always end with a newline.  The common cause for a
missing newline is misuse of wu() to print partial lines.  Almost
always works, as the read command merges telegrams arriving in quick
succession.  But if the telegrams are more than five seconds apart
(clock jumped somehow), we get a telegram header in the middle of a
line.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
4401cca0af subs: Clean up misuse of wu() around mission bomb damage
Don't use multiple calls of wu() to print a single line, because that
creates a separate bulletin for each part.  The read command normally
merges the bulletins, but if the bulletins are more than five seconds
apart (clock jumped somehow), we get a bulletin header in the middle
of a line.  Unlikely to happen, but it also messes up pln_damage()'s
line wrapping (see commit e002bf2).  Clean it up.

The wu() misuse was introduced in Empire 2.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
820d755e59 subs: Change pln_damage()'s parameter noisy to string prefix
No functional change for now.  The next commit will put it to use.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
9e643dad00 update: Clean up misuse of wu() in prod_nat()
Don't use multiple calls of wu() to print a single line, because that
creates a separate telegram for each part.  The read command normally
merges the telegrams, but if they are more than five seconds apart
(clock jumped somehow), we get a telegram header in the middle of a
line.  Unlikely to happen, but clean it up anyway.

The misuse has always been there.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
9a4f1ce9ef bomb: Fix to reject attempts to bomb unused planes
Report "not spotted", like we do for unused ships and land units.
Missed in commit 23d52a4, v4.3,16.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
e2b264f02c retreat lretreat: Be less loquacious when changing orders
Instead of listing all the ships or land units ordered, just print how
many got ordered, and describe the order, like this:

    [0:640] Command : retr 2/3 bg itb
    2 ships ordered to retreat along path bg when injured, torpedoed, bombed
    [0:640] Command : retr 2 h
    1 ship ordered not to retreat

fleetadd doesn't list the ships it reassigns, either.  On the other
hand, stop lists the sectors it stops.  Perhaps it should be gagged,
too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00
c702dc9e94 tests: Wean off deprecated retreat syntax
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:49 +01:00