1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

fix direction

This commit is contained in:
Laserlicht
2025-06-20 03:45:11 +02:00
parent 0cb74bc719
commit eef3e00f42
4 changed files with 11 additions and 9 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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

View File

@@ -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;