mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-13 11:40:38 +02:00
Small micro-optimizations for code that gets called A LOT
This commit is contained in:
parent
b8a04c6356
commit
4f80ccd648
@ -48,12 +48,15 @@ template <class _ObjectID, class _ObjectBase, class _Object, class _ServiceBase>
|
||||
{
|
||||
const _Object * getObjectImpl(const int32_t index) const
|
||||
{
|
||||
if(index < 0 || index >= objects.size())
|
||||
try
|
||||
{
|
||||
return objects.at(index).get();
|
||||
}
|
||||
catch (const std::out_of_range&)
|
||||
{
|
||||
logMod->error("%s id %d is invalid", getTypeNames()[0], index);
|
||||
throw std::runtime_error("Attempt to access invalid index " + std::to_string(index) + " of type " + getTypeNames().front());
|
||||
}
|
||||
return objects[index].get();
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -711,6 +711,9 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
|
||||
if (attacker->creatureIndex() == CreatureID::CATAPULT) //catapult cannot attack creatures
|
||||
return false;
|
||||
|
||||
if (!attacker->canShoot())
|
||||
return false;
|
||||
|
||||
//forgetfulness
|
||||
TConstBonusListPtr forgetfulList = attacker->getBonuses(Selector::type()(BonusType::FORGETFULL));
|
||||
if(!forgetfulList->empty())
|
||||
@ -722,8 +725,7 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
|
||||
return false;
|
||||
}
|
||||
|
||||
return attacker->canShoot() && (!battleIsUnitBlocked(attacker)
|
||||
|| attacker->hasBonusOfType(BonusType::FREE_SHOOTING));
|
||||
return !battleIsUnitBlocked(attacker) || attacker->hasBonusOfType(BonusType::FREE_SHOOTING);
|
||||
}
|
||||
|
||||
bool CBattleInfoCallback::battleCanTargetEmptyHex(const battle::Unit * attacker) const
|
||||
|
@ -325,7 +325,7 @@ const Skill * SecondarySkill::toEntity(const Services * services) const
|
||||
|
||||
const CCreature * CreatureIDBase::toCreature() const
|
||||
{
|
||||
return dynamic_cast<const CCreature *>(toEntity(VLC));
|
||||
return (*VLC->creh)[num];
|
||||
}
|
||||
|
||||
const Creature * CreatureIDBase::toEntity(const Services * services) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user