From b6e87313298aa8b9fb07b3a8818c97c3a765d633 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 8 Jul 2025 10:33:01 +0200 Subject: [PATCH] code review --- include/vcmi/spells/Caster.h | 1 - lib/battle/CUnitState.cpp | 5 ----- lib/battle/CUnitState.h | 1 - lib/mapObjects/CGHeroInstance.cpp | 5 ----- lib/mapObjects/CGHeroInstance.h | 1 - lib/spells/BattleSpellMechanics.cpp | 5 +++-- lib/spells/ProxyCaster.cpp | 8 -------- lib/spells/ProxyCaster.h | 1 - test/mock/mock_battle_Unit.h | 1 - 9 files changed, 3 insertions(+), 25 deletions(-) diff --git a/include/vcmi/spells/Caster.h b/include/vcmi/spells/Caster.h index 03d1c9dcc..de51c5e71 100644 --- a/include/vcmi/spells/Caster.h +++ b/include/vcmi/spells/Caster.h @@ -38,7 +38,6 @@ public: virtual ~Caster() = default; virtual int32_t getCasterUnitId() const = 0; - virtual BattleHex getCasterPosition() const = 0; /// returns level on which given spell would be cast by this(0 - none, 1 - basic etc); /// caster may not know this spell at all diff --git a/lib/battle/CUnitState.cpp b/lib/battle/CUnitState.cpp index f744c2b18..a6b64a472 100644 --- a/lib/battle/CUnitState.cpp +++ b/lib/battle/CUnitState.cpp @@ -407,11 +407,6 @@ int32_t CUnitState::getCasterUnitId() const return static_cast(unitId()); } -BattleHex CUnitState::getCasterPosition() const -{ - return getPosition(); -} - const CGHeroInstance * CUnitState::getHeroCaster() const { return nullptr; diff --git a/lib/battle/CUnitState.h b/lib/battle/CUnitState.h index 1f23c0d19..b1ec4a6d4 100644 --- a/lib/battle/CUnitState.h +++ b/lib/battle/CUnitState.h @@ -170,7 +170,6 @@ public: int32_t creatureIconIndex() const override; int32_t getCasterUnitId() const override; - BattleHex getCasterPosition() const override; int32_t getSpellSchoolLevel(const spells::Spell * spell, SpellSchool * outSelectedSchool = nullptr) const override; int32_t getEffectLevel(const spells::Spell * spell) const override; diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index ed5033f00..88cc6321e 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -782,11 +782,6 @@ int32_t CGHeroInstance::getCasterUnitId() const return id.getNum(); } -BattleHex CGHeroInstance::getCasterPosition() const -{ - return BattleHex::INVALID; -} - int32_t CGHeroInstance::getSpellSchoolLevel(const spells::Spell * spell, SpellSchool * outSelectedSchool) const { int32_t skill = -1; //skill level diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index 2bb61c92e..eb5abf561 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -279,7 +279,6 @@ public: ///spells::Caster int32_t getCasterUnitId() const override; - BattleHex getCasterPosition() const override; int32_t getSpellSchoolLevel(const spells::Spell * spell, SpellSchool * outSelectedSchool = nullptr) const override; int64_t getSpellBonus(const spells::Spell * spell, int64_t base, const battle::Unit * affectedStack) const override; int64_t getSpecificSpellBonus(const spells::Spell * spell, int64_t base) const override; diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index 242db888e..beb186eae 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -223,8 +223,9 @@ bool BattleSpellMechanics::canCastAtTarget(const battle::Unit * target) const if(range <= 0) return true; - std::vector casterPos = { caster->getCasterPosition() }; - BattleHex casterWidePos = battle()->battleGetStackByID(caster->getCasterUnitId(), false)->occupiedHex(); + auto casterStack = battle()->battleGetStackByID(caster->getCasterUnitId(), false); + std::vector casterPos = { casterStack->getPosition() }; + BattleHex casterWidePos = casterStack->occupiedHex(); if(casterWidePos != BattleHex::INVALID) casterPos.push_back(casterWidePos); diff --git a/lib/spells/ProxyCaster.cpp b/lib/spells/ProxyCaster.cpp index b4033e662..dd1d8174f 100644 --- a/lib/spells/ProxyCaster.cpp +++ b/lib/spells/ProxyCaster.cpp @@ -36,14 +36,6 @@ int32_t ProxyCaster::getCasterUnitId() const return -1; } -BattleHex ProxyCaster::getCasterPosition() const -{ - if(actualCaster) - return actualCaster->getCasterPosition(); - - return BattleHex::INVALID; -} - int32_t ProxyCaster::getSpellSchoolLevel(const Spell * spell, SpellSchool * outSelectedSchool) const { if(actualCaster) diff --git a/lib/spells/ProxyCaster.h b/lib/spells/ProxyCaster.h index 67e0a7d32..a4129c8cc 100644 --- a/lib/spells/ProxyCaster.h +++ b/lib/spells/ProxyCaster.h @@ -24,7 +24,6 @@ public: virtual ~ProxyCaster(); int32_t getCasterUnitId() const override; - BattleHex getCasterPosition() const override; int32_t getSpellSchoolLevel(const Spell * spell, SpellSchool * outSelectedSchool = nullptr) const override; int32_t getEffectLevel(const Spell * spell) const override; int64_t getSpellBonus(const Spell * spell, int64_t base, const battle::Unit * affectedStack) const override; diff --git a/test/mock/mock_battle_Unit.h b/test/mock/mock_battle_Unit.h index 5d374c347..eb9e0e933 100644 --- a/test/mock/mock_battle_Unit.h +++ b/test/mock/mock_battle_Unit.h @@ -19,7 +19,6 @@ public: MOCK_CONST_METHOD0(getTreeVersion, int32_t()); MOCK_CONST_METHOD0(getCasterUnitId, int32_t()); - MOCK_CONST_METHOD0(getCasterPosition, BattleHex()); MOCK_CONST_METHOD2(getSpellSchoolLevel, int32_t(const spells::Spell *, SpellSchool *)); MOCK_CONST_METHOD1(getEffectLevel, int32_t(const spells::Spell *)); MOCK_CONST_METHOD3(getSpellBonus, int64_t(const spells::Spell *, int64_t, const battle::Unit *));