1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Move isMeleeAttacker to Unit

This commit is contained in:
Andrej Dudenhefner
2025-11-07 12:13:16 +01:00
parent 31c093baae
commit 7c4b7aa3f0
4 changed files with 17 additions and 18 deletions

View File

@@ -545,22 +545,6 @@ bool CUnitState::isShooter() const
return shots.total() > 0;
}
bool CUnitState::isMeleeAttacker() const
{
//exclude non melee attackers
static const std::set<CreatureID> nonMeleeAttackers{
CreatureID::FIRST_AID_TENT,
CreatureID::CATAPULT,
CreatureID::BALLISTA,
CreatureID::AMMO_CART,
CreatureID::ARROW_TOWERS
};
if (vstd::contains(nonMeleeAttackers, creatureId()))
return false;
return true;
}
int32_t CUnitState::getKilled() const
{
int32_t res = unitBaseAmount() - health.getCount() + health.getResurrected();

View File

@@ -205,7 +205,6 @@ public:
bool canShootBlocked() const override;
bool canShoot() const override;
bool isShooter() const override;
bool isMeleeAttacker() const override;
int32_t getKilled() const override;
int32_t getCount() const override;

View File

@@ -38,6 +38,22 @@ bool Unit::isTurret() const
return creatureIndex() == CreatureID::ARROW_TOWERS;
}
bool Unit::isMeleeAttacker() const
{
//exclude non melee attackers
static const std::set<CreatureID> nonMeleeAttackers{
CreatureID::FIRST_AID_TENT,
CreatureID::CATAPULT,
CreatureID::BALLISTA,
CreatureID::AMMO_CART,
CreatureID::ARROW_TOWERS
};
if (vstd::contains(nonMeleeAttackers, creatureId()))
return false;
return true;
}
std::string Unit::getDescription() const
{
boost::format fmt("Unit %d of side %d");

View File

@@ -97,7 +97,7 @@ public:
virtual bool canShootBlocked() const = 0;
virtual bool canShoot() const = 0;
virtual bool isShooter() const = 0;
virtual bool isMeleeAttacker() const = 0;
bool isMeleeAttacker() const;
/// returns initial size of this unit
virtual int32_t getCount() const = 0;