mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
fix direction
This commit is contained in:
@@ -56,8 +56,8 @@ public:
|
||||
/// returns true if specified object is the currently active hero
|
||||
virtual bool isActiveHero(const CGObjectInstance* obj) const = 0;
|
||||
|
||||
/// returns pos of attacker if specified object is a monster and currently attacked
|
||||
virtual std::optional<int3> monsterAttacked(const CGObjectInstance * obj) const = 0;
|
||||
/// returns direction of attacker if specified object is a monster and currently attacked
|
||||
virtual int monsterAttacked(const CGObjectInstance * obj) const = 0;
|
||||
|
||||
virtual size_t objectGroupIndex(ObjectInstanceID objectID) const = 0;
|
||||
virtual Point objectImageOffset(ObjectInstanceID objectID, const int3 & coordinates) const = 0;
|
||||
|
||||
@@ -466,10 +466,12 @@ std::shared_ptr<IImage> MapRendererObjects::getImage(IMapRendererContext & conte
|
||||
if(animation->size(groupIndex) == 0)
|
||||
return nullptr;
|
||||
|
||||
if(auto attackerPos = context.monsterAttacked(obj))
|
||||
auto attackerPos = context.monsterAttacked(obj);
|
||||
if(attackerPos != -1)
|
||||
{
|
||||
const auto * creature = dynamic_cast<const CArmedInstance *>(obj);
|
||||
ImagePath imgPath = (*attackerPos).x < obj->pos.x ? (*creature->getCreatureMap().begin()).first->mapAttackFromLeft : (*creature->getCreatureMap().begin()).first->mapAttackFromRight;
|
||||
auto dir = std::vector<int>({1, 2, 7, 8});
|
||||
ImagePath imgPath = std::count(dir.begin(), dir.end(), attackerPos) ? (*creature->getCreatureMap().begin()).first->mapAttackFromRight : (*creature->getCreatureMap().begin()).first->mapAttackFromLeft;
|
||||
if(!imgPath.empty())
|
||||
{
|
||||
auto img = ENGINE->renderHandler().loadImage(imgPath, EImageBlitMode::SIMPLE);
|
||||
|
||||
@@ -87,16 +87,16 @@ bool MapRendererBaseContext::isActiveHero(const CGObjectInstance * obj) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<int3> MapRendererBaseContext::monsterAttacked(const CGObjectInstance * obj) const
|
||||
int MapRendererBaseContext::monsterAttacked(const CGObjectInstance * obj) const
|
||||
{
|
||||
if(obj->ID != Obj::MONSTER)
|
||||
return std::nullopt;
|
||||
return -1;
|
||||
|
||||
for(auto & battle : GAME->interface()->cb->getActiveBattles())
|
||||
if(obj->pos == battle.second->getBattle()->getLocation())
|
||||
return battle.second->getBattle()->getSideHero(BattleSide::ATTACKER)->pos;
|
||||
return battle.second->getBattle()->getSideHero(BattleSide::ATTACKER)->moveDir;
|
||||
|
||||
return std::nullopt;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool MapRendererBaseContext::tileAnimated(const int3 & coordinates) const
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
bool tileAnimated(const int3 & coordinates) const override;
|
||||
|
||||
bool isActiveHero(const CGObjectInstance* obj) const override;
|
||||
std::optional<int3> monsterAttacked(const CGObjectInstance * obj) const override;
|
||||
int monsterAttacked(const CGObjectInstance * obj) const override;
|
||||
|
||||
const TerrainTile & getMapTile(const int3 & coordinates) const override;
|
||||
const MapObjectsList & getObjects(const int3 & coordinates) const override;
|
||||
|
||||
Reference in New Issue
Block a user