diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-08-04 18:41:41 +0000 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-08-04 18:41:41 +0000 |
commit | c9fba69c164a4760d0db7737866bf7405ad448e9 (patch) | |
tree | 5510f3711474c5f79dc46ebabdf019678011d58e /src/actorspritemanager.cpp | |
parent | 452ebe4c4a0199fd07848a27f176723d3acf5704 (diff) | |
download | mana-c9fba69c164a4760d0db7737866bf7405ad448e9.tar.gz mana-c9fba69c164a4760d0db7737866bf7405ad448e9.tar.bz2 mana-c9fba69c164a4760d0db7737866bf7405ad448e9.tar.xz mana-c9fba69c164a4760d0db7737866bf7405ad448e9.zip |
Add to npc option targetSelection to allow/disallow npc selection.
The targetSelection attribute is supported on monsters and NPCs.
Also changed return value of Being::getInfo to indicate it can't return
nullptr.
(cherry picked from M+ commit dbc3b324a0c5dcb1a0ee29b289e71423a06e85fd)
Diffstat (limited to 'src/actorspritemanager.cpp')
-rw-r--r-- | src/actorspritemanager.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 5308b3ad..a5f1a4b9 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -144,13 +144,17 @@ Being *ActorSpriteManager::findBeing(int x, int y, ActorSprite::Type type) const if (type != ActorSprite::UNKNOWN && actorType != type) return false; - auto *b = static_cast<Being*>(actor); + auto *being = static_cast<Being*>(actor); + + if (!being->isTargetSelection()) + return false; + uint16_t other_y = y + (actorType == ActorSprite::NPC ? 1 : 0); - const Vector &pos = b->getPosition(); + const Vector &pos = being->getPosition(); return ((int) pos.x / tileWidth == x && ((int) pos.y / tileHeight == y || (int) pos.y / tileHeight == other_y) && - b->isAlive()); + being->isAlive()); }); return it == mActors.end() ? nullptr : static_cast<Being*>(*it); @@ -174,6 +178,9 @@ Being *ActorSpriteManager::findBeingByPixel(int x, int y) const auto *being = static_cast<Being *>(actor); + if (!being->isTargetSelection()) + continue; + const int halfWidth = std::max(16, being->getWidth() / 2); const int height = std::max(32, being->getHeight()); const int halfHeight = height / 2; @@ -296,6 +303,10 @@ Being *ActorSpriteManager::findNearestLivingBeing(int x, int y, continue; auto *being = static_cast<Being *>(actor); + + if (!being->isTargetSelection()) + continue; + const Vector &pos = being->getPosition(); int d = abs(((int)pos.x) - x) + abs(((int)pos.y) - y); |