summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-04 18:41:41 +0000
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-04 18:41:41 +0000
commitc9fba69c164a4760d0db7737866bf7405ad448e9 (patch)
tree5510f3711474c5f79dc46ebabdf019678011d58e
parent452ebe4c4a0199fd07848a27f176723d3acf5704 (diff)
downloadmana-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)
-rw-r--r--src/actorspritemanager.cpp17
-rw-r--r--src/being.cpp7
-rw-r--r--src/being.h6
-rw-r--r--src/resources/beinginfo.h7
-rw-r--r--src/resources/monsterdb.cpp3
-rw-r--r--src/resources/npcdb.cpp3
6 files changed, 37 insertions, 6 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);
diff --git a/src/being.cpp b/src/being.cpp
index 985faa83..b9a24509 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -127,6 +127,11 @@ void Being::setSubtype(Uint16 subtype)
}
}
+bool Being::isTargetSelection() const
+{
+ return mInfo->isTargetSelection();
+}
+
ActorSprite::TargetCursorSize Being::getTargetCursorSize() const
{
return mInfo->getTargetCursorSize();
@@ -383,7 +388,7 @@ void Being::takeDamage(Being *attacker, int amount,
}
else if (attacker && attacker->getType() == MONSTER)
{
- const Attack &attack = attacker->getInfo()->getAttack(attackId);
+ const Attack &attack = attacker->getInfo().getAttack(attackId);
if (type != CRITICAL)
hitEffectId = attack.mHitEffectId;
diff --git a/src/being.h b/src/being.h
index a1908f94..0c1d54d6 100644
--- a/src/being.h
+++ b/src/being.h
@@ -293,8 +293,10 @@ class Being : public ActorSprite, public EventListener
*/
void setSubtype(uint16_t subtype);
- const BeingInfo *getInfo() const
- { return mInfo; }
+ const BeingInfo &getInfo() const
+ { return *mInfo; }
+
+ bool isTargetSelection() const;
TargetCursorSize getTargetCursorSize() const override;
diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h
index d65feb5e..10411848 100644
--- a/src/resources/beinginfo.h
+++ b/src/resources/beinginfo.h
@@ -113,6 +113,12 @@ class BeingInfo
Map::BlockType getBlockType() const
{ return mBlockType; }
+ void setTargetSelection(bool n)
+ { mTargetSelection = n; }
+
+ bool isTargetSelection() const
+ { return mTargetSelection; }
+
private:
SpriteDisplay mDisplay;
std::string mName;
@@ -122,6 +128,7 @@ class BeingInfo
std::map<int, Attack> mAttacks;
unsigned char mWalkMask;
Map::BlockType mBlockType = Map::BLOCKTYPE_CHARACTER;
+ bool mTargetSelection = true;
};
#endif // BEINGINFO_H
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index e28fe75e..fe2a3e97 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -81,6 +81,9 @@ void MonsterDB::readMonsterNode(xmlNodePtr node, const std::string &filename)
currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "attack"));
+ currentInfo->setTargetSelection(XML::getProperty(
+ node, "targetSelection", true));
+
SpriteDisplay display;
//iterate <sprite>s and <sound>s
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index ce1bf14c..853c229d 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -57,6 +57,9 @@ void NPCDB::readNPCNode(xmlNodePtr node, const std::string &filename)
currentInfo->setHoverCursor(XML::getProperty(node, "hoverCursor", "talk"));
+ currentInfo->setTargetSelection(XML::getProperty(
+ node, "targetSelection", true));
+
SpriteDisplay display;
for_each_xml_child_node(spriteNode, node)
{