Skip to content

Commit

Permalink
NEW GAME REQUIRED! Fixed task objectives not being saved (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Mar 27, 2022
1 parent c5ef6c7 commit 147edc4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
33 changes: 30 additions & 3 deletions src/xrGame/GameTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ u16 storyId2GameId(ALife::_STORY_ID id)
return u16(-1);
}

SGameTaskObjective::SGameTaskObjective()
: m_task_state(eTaskStateDummy),
m_task_type(eTaskTypeDummy),
m_idx(ROOT_TASK_OBJECTIVE) {}

SGameTaskObjective::SGameTaskObjective(CGameTask* parent, TASK_OBJECTIVE_ID idx)
: m_parent(parent),
m_task_state(eTaskStateDummy),
Expand All @@ -63,6 +68,12 @@ SGameTaskObjective::SGameTaskObjective(CGameTask* parent, TASK_OBJECTIVE_ID idx)
CGameTask::CGameTask()
: SGameTaskObjective(this, ROOT_TASK_OBJECTIVE) {}

CGameTask::CGameTask(const TASK_ID& id)
: SGameTaskObjective(this, ROOT_TASK_OBJECTIVE)
{
Load(id);
}

void CGameTask::Load(const TASK_ID& id)
{
m_ID = id;
Expand All @@ -85,7 +96,7 @@ void CGameTask::Load(const TASK_ID& id)
m_Title = g_gameTaskXml->Read(g_gameTaskXml->GetLocalRoot(), "title", 0, nullptr);
m_priority = g_gameTaskXml->ReadAttribInt(g_gameTaskXml->GetLocalRoot(), "prio", -1);

#ifdef DEBUG
#ifdef DEBUG
if (m_priority == u32(-1))
{
Msg("Game Task [%s] has no priority", id.c_str());
Expand Down Expand Up @@ -605,15 +616,31 @@ void SGameTaskObjective::load(IReader& stream)
void CGameTask::save(IWriter& stream)
{
save_data(m_ID, stream);
SGameTaskObjective::save(stream);
save_data(m_priority, stream);
SGameTaskObjective::save(stream);

const u32 count = static_cast<u32>(m_Objectives.size());
save_data(count, stream);

for (auto& objective : m_Objectives)
save_data(objective, stream);
}

void CGameTask::load(IReader& stream)
{
load_data(m_ID, stream);
SGameTaskObjective::load(stream);
load_data(m_priority, stream);
SGameTaskObjective::load(stream);

u32 count;
load_data(count, stream);
m_Objectives.resize(count);

for (u32 i = 0; i < count; ++i)
{
m_Objectives[i].m_parent = this;
load_data(m_Objectives[i], stream);
}

CommitScriptHelperContents();
CreateMapLocation(true);
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/GameTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SGameTaskObjective : public ISerializable
task_state_functors m_lua_functions_on_fail;

public:
SGameTaskObjective();
SGameTaskObjective(CGameTask* parent, TASK_OBJECTIVE_ID idx);

CGameTask* GetParent() const { return m_parent; }
Expand Down Expand Up @@ -171,7 +172,9 @@ class CGameTask final : public SGameTaskObjective, public Noncopyable

public:
CGameTask();
CGameTask(const TASK_ID& id);

public:
void Load(const TASK_ID& id);

void save(IWriter& stream) override;
Expand Down
4 changes: 1 addition & 3 deletions src/xrGame/GametaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ CGameTask* CGameTaskManager::GiveGameTaskToActor(const TASK_ID& id,
{
if (bCheckExisting && HasGameTask(id, false))
return nullptr;
//CGameTask* t = xr_new<CGameTask>(id);
CGameTask* t = xr_new<CGameTask>();
t->Load(id);

CGameTask* t = xr_new<CGameTask>(id);
return GiveGameTaskToActor(t, timeToComplete, bCheckExisting, timer_ttl);
}

Expand Down

0 comments on commit 147edc4

Please sign in to comment.