From 2acfe2297538e674f9889d77a4b0d72f46f699b3 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Sun, 8 Aug 2010 14:28:35 +0200
Subject: [PATCH] added test for actor ID

---
 apps/openmw/mwclass/creature.cpp           | 8 ++++++++
 apps/openmw/mwclass/creature.hpp           | 3 +++
 apps/openmw/mwclass/npc.cpp                | 8 ++++++++
 apps/openmw/mwclass/npc.hpp                | 3 +++
 apps/openmw/mwdialogue/dialoguemanager.cpp | 7 +++++--
 apps/openmw/mwworld/class.cpp              | 5 +++++
 apps/openmw/mwworld/class.hpp              | 4 ++++
 7 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp
index 4529094ec..1cdada64c 100644
--- a/apps/openmw/mwclass/creature.cpp
+++ b/apps/openmw/mwclass/creature.cpp
@@ -10,6 +10,14 @@
 
 namespace MWClass
 {
+    std::string Creature::getId (const MWWorld::Ptr& ptr) const
+    {
+        ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
+            ptr.get<ESM::Creature>();
+
+        return ref->base->mId;
+    }
+
     std::string Creature::getName (const MWWorld::Ptr& ptr) const
     {
         ESMS::LiveCellRef<ESM::Creature, MWWorld::RefData> *ref =
diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp
index e964a7708..85a89a919 100644
--- a/apps/openmw/mwclass/creature.hpp
+++ b/apps/openmw/mwclass/creature.hpp
@@ -9,6 +9,9 @@ namespace MWClass
     {
         public:
 
+            virtual std::string getId (const MWWorld::Ptr& ptr) const;
+            ///< Return ID of \a ptr
+
             virtual std::string getName (const MWWorld::Ptr& ptr) const;
             ///< \return name (the one that is to be presented to the user; not the internal one);
             /// can return an empty string.
diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp
index ae647c802..b6a4bbc05 100644
--- a/apps/openmw/mwclass/npc.cpp
+++ b/apps/openmw/mwclass/npc.cpp
@@ -10,6 +10,14 @@
 
 namespace MWClass
 {
+    std::string Npc::getId (const MWWorld::Ptr& ptr) const
+    {
+        ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
+            ptr.get<ESM::NPC>();
+
+        return ref->base->mId;
+    }
+
     std::string Npc::getName (const MWWorld::Ptr& ptr) const
     {
         ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> *ref =
diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp
index 2ef37193a..a6f4a2965 100644
--- a/apps/openmw/mwclass/npc.hpp
+++ b/apps/openmw/mwclass/npc.hpp
@@ -9,6 +9,9 @@ namespace MWClass
     {
         public:
 
+            virtual std::string getId (const MWWorld::Ptr& ptr) const;
+            ///< Return ID of \a ptr
+
             virtual std::string getName (const MWWorld::Ptr& ptr) const;
             ///< \return name (the one that is to be presented to the user; not the internal one);
             /// can return an empty string.
diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp
index 4f9cf602f..3c3a60180 100644
--- a/apps/openmw/mwdialogue/dialoguemanager.cpp
+++ b/apps/openmw/mwdialogue/dialoguemanager.cpp
@@ -114,7 +114,11 @@ namespace MWDialogue
 
     bool DialogueManager::isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const
     {
-        // TODO check actor id
+        // actor id
+        if (!info.actor.empty())
+            if (info.actor!=MWWorld::Class::get (actor).getId (actor))
+                return false;
+
         // TODO check actor race
         // TODO check actor class
         // TODO check actor faction
@@ -134,7 +138,6 @@ namespace MWDialogue
 
         std::cout
             << "unchecked entries:" << std::endl
-            << "    actor id: " << info.actor << std::endl
             << "    actor race: " << info.race << std::endl
             << "    actor class: " << info.clas << std::endl
             << "    actor faction: " << info.npcFaction << std::endl
diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp
index 85e5140ea..62e0ee8c9 100644
--- a/apps/openmw/mwworld/class.cpp
+++ b/apps/openmw/mwworld/class.cpp
@@ -14,6 +14,11 @@ namespace MWWorld
 
     Class::~Class() {}
 
+    std::string Class::getId (const Ptr& ptr) const
+    {
+        throw std::runtime_error ("class does not support ID retrieval");
+    }
+
     MWMechanics::CreatureStats& Class::getCreatureStats (const Ptr& ptr) const
     {
         throw std::runtime_error ("class does not have creature stats");
diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp
index 28d96d69f..d456cc06b 100644
--- a/apps/openmw/mwworld/class.hpp
+++ b/apps/openmw/mwworld/class.hpp
@@ -36,6 +36,10 @@ namespace MWWorld
 
             virtual ~Class();
 
+            virtual std::string getId (const Ptr& ptr) const;
+            ///< Return ID of \a ptr or throw an exception, if class does not support ID retrieval
+            /// (default implementation: throw an exception)
+
             virtual std::string getName (const Ptr& ptr) const = 0;
             ///< \return name (the one that is to be presented to the user; not the internal one);
             /// can return an empty string.