fix(combat): keep the hero casualty when rams force a battle recalculation [#372] (#373)

When rams change the wall level, applyRamDamage() replays the whole battle
through calculateBattle(). That helper WRITES to the hero table, so the replay
applied the hero damage a second time: applyHeroBattleDamage() only looks up
heroes with dead = 0, so the hero who had just died on the first pass was no
longer found, the call returned null and casualties_attacker[11] was never set.

Consequences, all visible in the screenshots of the issue: the report showed the
hero alive and "gained XP" instead of "died", modifyAttack3() never decremented
t11, and returnunitsComplete() added the hero back to units.hero - a hero dead in
the hero table but still displayed in dorf1 and in the rally point. Defender
heroes were also charged their health damage twice.

calculateBattle() now takes an optional $previousHeroOutcome: when the caller
hands over the first pass result, the hero damage is not applied again and the
first verdict (attacker / defender / reinforcement heroes) is carried over.

Also:
- drop the temporary [TravianZ][EROU] error_log() debug traces;
- 37_revive.tpl: only render a revive row for a hero that is actually dead
  (the revive action itself was already gated on dead = 1).

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Catalin Novgorodschi <cata7007@gmail.com>
This commit is contained in:
Ferywir
2026-08-09 19:20:37 +02:00
committed by GitHub
parent 770fa9fd6b
commit 91a980fa3d
3 changed files with 26 additions and 7 deletions
+6 -1
View File
@@ -184,8 +184,13 @@ foreach ($heroes as $hero_datarow) {
</tr>
</table>
<?php
} elseif (!$reviving) {
} elseif (!$reviving && $hero_datarow['dead'] == 1) {
/**
* Only a DEAD hero gets a revive row: $heroes holds every hero row of
* the player, so without this guard a hero who is merely in training
* was offered for revival as well (the action below is already gated
* on dead == 1, so the button did nothing).
*
* BUG REPARAT: invierea cerea ca unitatea EROULUI sa fie cercetata in
* satul CURENT.
*