From df126d9045745251f1e6e12810b966253bdbf5a7 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Wed, 10 Feb 2021 21:18:40 +0000 Subject: [PATCH] Entity::Attachment now provides joint information Pass the already-parsed joint value from AttachmentData to the Entity::Attachment functor parameter, and confirm this in the unit test of the builder_guard AI. --- include/ientity.h | 3 +++ radiantcore/entity/AttachmentData.h | 9 ++++++++- test/Entity.cpp | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/ientity.h b/include/ientity.h index a37e55159c..1199affde7 100644 --- a/include/ientity.h +++ b/include/ientity.h @@ -245,6 +245,9 @@ class Entity /// Vector offset where the attached entity should appear Vector3 offset; + + /// Optional model joint to use as origin + std::string joint; }; /// A functor which can receive Attachment objects diff --git a/radiantcore/entity/AttachmentData.h b/radiantcore/entity/AttachmentData.h index c737402a98..39e79166e0 100644 --- a/radiantcore/entity/AttachmentData.h +++ b/radiantcore/entity/AttachmentData.h @@ -107,9 +107,16 @@ class AttachmentData { for (auto i = _objects.begin(); i != _objects.end(); ++i) { + // Locate attachment position + const AttachPos& pos = _positions.at(i->second.posName); + + // Construct the functor argument Entity::Attachment a; a.eclass = i->second.className; - a.offset = _positions.at(i->second.posName).origin; + a.offset = pos.origin; + a.joint = pos.joint; + + // Invoke the functor func(a); } } diff --git a/test/Entity.cpp b/test/Entity.cpp index 264b0a5ebc..0eceabd51f 100644 --- a/test/Entity.cpp +++ b/test/Entity.cpp @@ -680,6 +680,9 @@ TEST_F(EntityTest, CreateAIEntity) // Guard should have a hammer attachment auto attachments = getAttachments(guard); EXPECT_EQ(attachments.size(), 1); + EXPECT_EQ(attachments.front().eclass, "atdm:moveable_warhammer"); + EXPECT_EQ(attachments.front().offset, Vector3(14, -6, -6)); + EXPECT_EQ(attachments.front().joint, "Spine2"); } } \ No newline at end of file