1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

Fix ballista damage range display

- Adjusted the displayed damage range of ballista to reflect the changes in hero/es attack skill like in OH3.
- Added checks to ensure the battle interface and relevant heroes are valid before calculating damage.
This commit is contained in:
kodobi 2024-10-29 20:44:31 +01:00
parent 6dc6cc4cbf
commit b82444ba43

View File

@ -25,6 +25,7 @@
#include "../windows/InfoWindows.h"
#include "../gui/CGuiHandler.h"
#include "../gui/Shortcut.h"
#include "../battle/BattleInterface.h"
#include "../../CCallback.h"
#include "../../lib/ArtifactUtils.h"
@ -523,6 +524,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
CRClickPopup::createAndPush(parent->info->creature->getDescriptionTranslated());
});
if(parent->info->stackNode != nullptr && parent->info->commander == nullptr)
{
//normal stack, not a commander and not non-existing stack (e.g. recruitment dialog)
@ -531,14 +533,22 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
name = std::make_shared<CLabel>(215, 12, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, parent->info->getName());
const BattleInterface* battleInterface = LOCPLINT->battleInt.get();
const CStack* battleStack = parent->info->stack;
int dmgMultiply = 1;
if(parent->info->owner && parent->info->stackNode->hasBonusOfType(BonusType::SIEGE_WEAPON))
dmgMultiply += parent->info->owner->getPrimSkillLevel(PrimarySkill::ATTACK);
if (battleInterface && battleInterface->getBattle() != nullptr && battleStack->hasBonusOfType(BonusType::SIEGE_WEAPON))
{
// Determine the relevant hero based on the unit side
const auto hero = (battleStack->unitSide() == BattleSide::ATTACKER)
? battleInterface->attackingHeroInstance
: battleInterface->defendingHeroInstance;
dmgMultiply += hero->getPrimSkillLevel(PrimarySkill::ATTACK);
}
icons = std::make_shared<CPicture>(ImagePath::builtin("stackWindow/icons"), 117, 32);
const CStack * battleStack = parent->info->stack;
morale = std::make_shared<MoraleLuckBox>(true, Rect(Point(321, 110), Point(42, 42) ));
luck = std::make_shared<MoraleLuckBox>(false, Rect(Point(375, 110), Point(42, 42) ));
@ -566,7 +576,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
addStatLabel(EStat::ATTACK, parent->info->creature->getAttack(shooter), parent->info->stackNode->getAttack(shooter));
addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(shooter), parent->info->stackNode->getDefense(shooter));
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(shooter) * dmgMultiply, parent->info->stackNode->getMaxDamage(shooter) * dmgMultiply);
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(shooter), parent->info->stackNode->getMaxDamage(shooter));
addStatLabel(EStat::HEALTH, parent->info->creature->getMaxHealth(), parent->info->stackNode->getMaxHealth());
addStatLabel(EStat::SPEED, parent->info->creature->getMovementRange(), parent->info->stackNode->getMovementRange());