diff --git a/dGame/dComponents/Character/MountControlComponent.cpp b/dGame/dComponents/Character/MountControlComponent.cpp index 2360433e6..e079e1284 100644 --- a/dGame/dComponents/Character/MountControlComponent.cpp +++ b/dGame/dComponents/Character/MountControlComponent.cpp @@ -1,7 +1,5 @@ #include "MountControlComponent.h" -#include "Entity.h" -#include "PossessorComponent.h" #include "tinyxml2.h" @@ -18,6 +16,6 @@ void MountControlComponent::WriteSaveData(tinyxml2::XMLDocument& doc) { auto* mount = obj->FirstChildElement("mnt"); if (!mount) mount = obj->InsertNewChildElement("mnt"); - const auto* const possessor = m_Parent->GetComponent(); - mount->SetAttribute("a", possessor ? possessor->GetMountItemID() : LWOOBJID_EMPTY); + // 0 in every live save looked at (450), so 0 is written, riding or not + mount->SetAttribute("a", 0); } diff --git a/dGame/dComponents/Character/MountControlComponent.h b/dGame/dComponents/Character/MountControlComponent.h index 02494f7cf..847cf6de7 100644 --- a/dGame/dComponents/Character/MountControlComponent.h +++ b/dGame/dComponents/Character/MountControlComponent.h @@ -7,8 +7,8 @@ /** * Mount control (111): the character's riding of mounts, as the client's LWOMountControlComponent: the client makes it (componentID -1) with every character - * (LWOCharacterComponent::Factory). It keeps the mount item in the character's save, as live did (, - * 0 when not riding: all 450 live saves looked at were 0). + * (LWOCharacterComponent::Factory). It writes the mount element of the character's save as live did: in + * all 450 live saves looked at, so always 0. */ class MountControlComponent final : public Component { public: @@ -19,10 +19,10 @@ public: // LWOMountControlComponent::LoadFromSaveData (0x00bf99c0): , the mount item of the save void LoadFromSaveData(const tinyxml2::XMLDocument& doc) override; - // Writes : the item of the mount being ridden (PossessorComponent's), 0 when on foot + // Writes , as live did, also while a mount is ridden void WriteSaveData(tinyxml2::XMLDocument& doc) override; - // The mount item the save named. Riding does not go on over a world change, so nothing is mounted from it. + // The mount item the save named (a save may hold one that is not 0). Nothing is mounted from it. LWOOBJID GetSavedMountItemID() const { return m_SavedMountItemID; } private: diff --git a/tests/dGameTests/dComponentsTests/MountControlComponentTests.cpp b/tests/dGameTests/dComponentsTests/MountControlComponentTests.cpp index cf930a084..6f22c2f5b 100644 --- a/tests/dGameTests/dComponentsTests/MountControlComponentTests.cpp +++ b/tests/dGameTests/dComponentsTests/MountControlComponentTests.cpp @@ -1,5 +1,5 @@ -// The mount item in a character's save: LWOMountControlComponent::LoadFromSaveData (0x00bf99c0) reads , and -// every live save had the element ( on the 450 looked at). +// The mount element of a character's save: LWOMountControlComponent::LoadFromSaveData (0x00bf99c0) reads , and +// every live save had the element, always as (450 looked at). #include "GameDependencies.h" #include "Entity.h" @@ -38,8 +38,9 @@ TEST_F(MountControlComponentTests, OldSaveGainsTheElement) { EXPECT_EQ(Print(doc), R"()"); } -// The item of the mount being ridden is saved, in the element's own place; on foot it is 0 again -TEST_F(MountControlComponentTests, TheRiddenMountIsSaved) { +// Live wrote 0 in every save, so 0 is written while a mount is ridden as well. A save that holds another value is +// read without failing and gets 0 at the next save. +TEST_F(MountControlComponentTests, ZeroIsWrittenAlsoWhileRiding) { tinyxml2::XMLDocument doc; ASSERT_EQ(doc.Parse(R"()"), tinyxml2::XML_SUCCESS); Entity player(71, info); @@ -48,15 +49,22 @@ TEST_F(MountControlComponentTests, TheRiddenMountIsSaved) { mountControl->LoadFromSaveData(doc); EXPECT_EQ(mountControl->GetSavedMountItemID(), 1152921510436607007LL); - // Nothing is ridden after a load mountControl->WriteSaveData(doc); EXPECT_EQ(Print(doc), R"()"); possessor->SetMountItemID(1152921510436607123LL); mountControl->WriteSaveData(doc); - EXPECT_EQ(Print(doc), R"()"); - - possessor->SetMountItemID(LWOOBJID_EMPTY); - mountControl->WriteSaveData(doc); EXPECT_EQ(Print(doc), R"()"); } + +// An a that is not a number is not an error: nothing is read and 0 is written +TEST_F(MountControlComponentTests, AnUnreadableValueDoesNotFail) { + tinyxml2::XMLDocument doc; + ASSERT_EQ(doc.Parse(R"()"), tinyxml2::XML_SUCCESS); + Entity player(72, info); + auto* const mountControl = player.AddComponent(-1); + mountControl->LoadFromSaveData(doc); + EXPECT_EQ(mountControl->GetSavedMountItemID(), LWOOBJID_EMPTY); + mountControl->WriteSaveData(doc); + EXPECT_EQ(Print(doc), R"()"); +}