Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Mission Prerequisites and document variables better #1012

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dGame/dMission/Mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@
#include "eMissionTaskType.h"
#include "eMissionLockState.h"
#include "eReplicaComponentType.h"

#include "CDMissionEmailTable.h"

Mission::Mission() {
m_MissionComponent = nullptr;
m_Completions = 0;
m_Timestamp = 0;
m_Reward = 0;
m_UniqueMissionID = 0;
m_State = eMissionState::UNKNOWN;
info = nullptr;

Check failure on line 36 in dGame/dMission/Mission.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-20.04)

no match for ‘operator=’ (operand types are ‘CDMissions’ and ‘std::nullptr_t’)

Check failure on line 36 in dGame/dMission/Mission.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (macos-11)

no viable overloaded '='
}

Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
m_MissionComponent = missionComponent;

Expand Down Expand Up @@ -205,7 +214,7 @@
}

Entity* Mission::GetAssociate() const {
return m_MissionComponent->GetParent();
return m_MissionComponent != nullptr? m_MissionComponent->GetParent() : nullptr;
}

User* Mission::GetUser() const {
Expand Down
1 change: 1 addition & 0 deletions dGame/dMission/Mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MissionComponent;
class Mission final
{
public:
Mission();
Mission(MissionComponent* missionComponent, uint32_t missionId);
~Mission();

Expand Down
4 changes: 1 addition & 3 deletions dGame/dMission/MissionPrerequisites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ bool PrerequisiteExpression::Execute(const std::unordered_map<uint32_t, Mission*

if (this->sub != 0) {
// Special case for one Wisp Lee repeatable mission.
a = mission->GetClientInfo().id == 1883 ?
mission->GetMissionState() == static_cast<eMissionState>(this->sub) :
mission->GetMissionState() >= static_cast<eMissionState>(this->sub);
a = mission->GetMissionState() == static_cast<eMissionState>(this->sub);
} else if (mission->IsComplete()) {
a = true;
}
Expand Down
1 change: 1 addition & 0 deletions dGame/dMission/MissionPrerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class PrerequisiteExpression final
{
public:
bool m_or;
uint32_t a;
uint32_t sub;
Expand Down
1 change: 1 addition & 0 deletions tests/dGameTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(DGAMETEST_SOURCES
"GameDependencies.cpp"
"MissionPrerequisiteTest.cpp"
)

add_subdirectory(dComponentsTests)
Expand Down
213 changes: 213 additions & 0 deletions tests/dGameTests/MissionPrerequisiteTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#include "GameDependencies.h"
#include <gtest/gtest.h>

#include "MissionPrerequisites.h"
#include "eMissionState.h"

class MissionPrerequisiteTest : public GameDependenciesTest {
protected:
std::unordered_map<uint32_t, Mission*> missionMap;
void SetUp() override {
SetUpDependencies();
}

void TearDown() override {
TearDownDependencies();
for (auto mission : missionMap) {
if (mission.second) delete mission.second;
}
}
};

/**
* Test that the structure of a single prerequisite mission is created correctly.
*/
TEST_F(MissionPrerequisiteTest, OneMissionPrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("1964");
ASSERT_EQ(preReq->a, 1964);
missionMap[1964] = new Mission();
missionMap[1] = new Mission();
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[1964]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
delete preReq;
};

/**
* Test that the structure of a multi mission prerequisite is created correctly.
*/
TEST_F(MissionPrerequisiteTest, MultiMissionPrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("1806,1868");
missionMap[1806] = new Mission();
missionMap[1868] = new Mission();
ASSERT_EQ(preReq->a, 1806);
ASSERT_FALSE(preReq->m_or);
ASSERT_EQ(preReq->b->a, 1868);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[1806]->SetMissionState(eMissionState::COMPLETE);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[1806]->SetMissionState(eMissionState::ACTIVE);
missionMap[1868]->SetMissionState(eMissionState::COMPLETE);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[1806]->SetMissionState(eMissionState::COMPLETE);
missionMap[1868]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
delete preReq;
};

/**
* Test that the structure of an or prerequisite for missions is created properly
*/
TEST_F(MissionPrerequisiteTest, OrMissionPrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("2061|891");
missionMap[2061] = new Mission();
missionMap[891] = new Mission();
ASSERT_TRUE(preReq->m_or);
ASSERT_EQ(preReq->a, 2061);
ASSERT_EQ(preReq->b->a, 891);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::ACTIVE);
missionMap[891]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::COMPLETE);
missionMap[891]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
delete preReq;
};

/**
* Test that the structure of an or prerequisite for multiple missions is created properly
*/
TEST_F(MissionPrerequisiteTest, MultiOrMissionPrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("815|812|813|814");
missionMap[815] = new Mission();
missionMap[812] = new Mission();
missionMap[813] = new Mission();
missionMap[814] = new Mission();
ASSERT_TRUE(preReq->m_or);
ASSERT_EQ(preReq->a, 815);
ASSERT_EQ(preReq->b->a, 812);
ASSERT_TRUE(preReq->b->m_or);
ASSERT_EQ(preReq->b->b->a, 813);
ASSERT_TRUE(preReq->b->b->m_or);
ASSERT_EQ(preReq->b->b->b->a, 814);
ASSERT_FALSE(preReq->b->b->b->m_or);
ASSERT_EQ(preReq->b->b->b->b, nullptr);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::COMPLETE);
missionMap[812]->SetMissionState(eMissionState::ACTIVE);
missionMap[813]->SetMissionState(eMissionState::ACTIVE);
missionMap[814]->SetMissionState(eMissionState::ACTIVE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::ACTIVE);
missionMap[812]->SetMissionState(eMissionState::COMPLETE);
missionMap[813]->SetMissionState(eMissionState::ACTIVE);
missionMap[814]->SetMissionState(eMissionState::ACTIVE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::ACTIVE);
missionMap[812]->SetMissionState(eMissionState::ACTIVE);
missionMap[813]->SetMissionState(eMissionState::COMPLETE);
missionMap[814]->SetMissionState(eMissionState::ACTIVE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::ACTIVE);
missionMap[812]->SetMissionState(eMissionState::ACTIVE);
missionMap[813]->SetMissionState(eMissionState::ACTIVE);
missionMap[814]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::ACTIVE);
missionMap[812]->SetMissionState(eMissionState::COMPLETE);
missionMap[813]->SetMissionState(eMissionState::ACTIVE);
missionMap[814]->SetMissionState(eMissionState::COMPLETE);
ASSERT_TRUE(preReq->Execute(missionMap));
missionMap[815]->SetMissionState(eMissionState::COMPLETE);
missionMap[812]->SetMissionState(eMissionState::ACTIVE);
missionMap[813]->SetMissionState(eMissionState::COMPLETE);
missionMap[814]->SetMissionState(eMissionState::ACTIVE);
ASSERT_TRUE(preReq->Execute(missionMap));
delete preReq;
};

/**
* Test that the structure of a mission with an expected state is created properly
*/
TEST_F(MissionPrerequisiteTest, MissionStatePrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("236:2");
missionMap[236] = new Mission();
ASSERT_EQ(preReq->a, 236);
ASSERT_EQ(preReq->sub, 2);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[236]->SetMissionState(eMissionState::COMPLETE);
ASSERT_FALSE(preReq->Execute(missionMap));
missionMap[236]->SetMissionState(eMissionState::ACTIVE);
ASSERT_TRUE(preReq->Execute(missionMap));
delete preReq;
};

/**
* Test that the structure of an or prerequisite for missions is created properly
*/
TEST_F(MissionPrerequisiteTest, AndMissionPrerequisiteInitializeTest) {
auto* preReq = new PrerequisiteExpression("(2061|1000)&(8091|1500)");
missionMap[2061] = new Mission();
missionMap[1000] = new Mission();
missionMap[8091] = new Mission();
missionMap[1500] = new Mission();
ASSERT_EQ(preReq->a, 0);
ASSERT_FALSE(preReq->m_or);

ASSERT_EQ(preReq->b->a, 2061);
ASSERT_TRUE(preReq->b->m_or);

ASSERT_EQ(preReq->b->b->a, 1000);
ASSERT_FALSE(preReq->b->b->m_or);

ASSERT_EQ(preReq->b->b->b->a, 0);
ASSERT_FALSE(preReq->b->b->b->m_or);

ASSERT_EQ(preReq->b->b->b->b->a, 8091);
ASSERT_TRUE(preReq->b->b->b->b->m_or);

ASSERT_EQ(preReq->b->b->b->b->b->a, 1500);
ASSERT_FALSE(preReq->b->b->b->b->b->m_or);

ASSERT_EQ(preReq->b->b->b->b->b->b, nullptr);
EXPECT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::COMPLETE);
missionMap[1000]->SetMissionState(eMissionState::ACTIVE);
missionMap[8091]->SetMissionState(eMissionState::ACTIVE);
missionMap[1500]->SetMissionState(eMissionState::ACTIVE);
EXPECT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::ACTIVE);
missionMap[1000]->SetMissionState(eMissionState::COMPLETE);
missionMap[8091]->SetMissionState(eMissionState::ACTIVE);
missionMap[1500]->SetMissionState(eMissionState::ACTIVE);
EXPECT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::ACTIVE);
missionMap[1000]->SetMissionState(eMissionState::ACTIVE);
missionMap[8091]->SetMissionState(eMissionState::COMPLETE);
missionMap[1500]->SetMissionState(eMissionState::ACTIVE);
EXPECT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::ACTIVE);
missionMap[1000]->SetMissionState(eMissionState::ACTIVE);
missionMap[8091]->SetMissionState(eMissionState::ACTIVE);
missionMap[1500]->SetMissionState(eMissionState::COMPLETE);
EXPECT_FALSE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::COMPLETE);
missionMap[1000]->SetMissionState(eMissionState::ACTIVE);
missionMap[8091]->SetMissionState(eMissionState::COMPLETE);
missionMap[1500]->SetMissionState(eMissionState::ACTIVE);
EXPECT_TRUE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::ACTIVE);
missionMap[1000]->SetMissionState(eMissionState::COMPLETE);
missionMap[8091]->SetMissionState(eMissionState::ACTIVE);
missionMap[1500]->SetMissionState(eMissionState::COMPLETE);
EXPECT_TRUE(preReq->Execute(missionMap));
missionMap[2061]->SetMissionState(eMissionState::COMPLETE);
missionMap[1000]->SetMissionState(eMissionState::COMPLETE);
missionMap[8091]->SetMissionState(eMissionState::COMPLETE);
missionMap[1500]->SetMissionState(eMissionState::COMPLETE);
EXPECT_TRUE(preReq->Execute(missionMap));
delete preReq;
};
Loading