Skip to content

Commit

Permalink
Returned old mighty info portions system! (#382, #392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Nov 18, 2019
1 parent b3f45e1 commit 83417ce
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 129 deletions.
4 changes: 4 additions & 0 deletions src/xrGame/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ int psActorSleepTime = 1;

CActor::CActor() : CEntityAlive(), current_ik_cam_shift(0)
{
encyclopedia_registry = new CEncyclopediaRegistryWrapper();
game_news_registry = new CGameNewsRegistryWrapper();

// Cameras
cameras[eacFirstEye] = new CCameraFirstEye(this);
cameras[eacFirstEye]->Load("actor_firsteye_cam");
Expand Down Expand Up @@ -217,6 +219,8 @@ CActor::~CActor()
{
xr_delete(m_location_manager);
xr_delete(m_memory);

xr_delete(encyclopedia_registry);
xr_delete(game_news_registry);
#ifdef DEBUG
Device.seqRender.Remove(this);
Expand Down
6 changes: 6 additions & 0 deletions src/xrGame/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CInfoPortion;
struct GAME_NEWS_DATA;
class CActorCondition;
class CCustomOutfit;
class CKnownContactsRegistryWrapper;
class CEncyclopediaRegistryWrapper;
class CGameTaskRegistryWrapper;
class CGameNewsRegistryWrapper;
class CCharacterPhysicsSupport;
Expand Down Expand Up @@ -120,6 +122,9 @@ class CActor : public CEntityAlive,
void DumpTasks();
#endif

protected:
virtual void AddEncyclopediaArticle(const CInfoPortion* info_portion) const;

struct SDefNewsMsg
{
GAME_NEWS_DATA* news_data;
Expand All @@ -141,6 +146,7 @@ class CActor : public CEntityAlive,
virtual void StartTalk(CInventoryOwner* talk_partner);
void RunTalkDialog(CInventoryOwner* talk_partner, bool disable_break);
CActorStatisticMgr& StatisticMgr() { return *m_statistic_manager; }
CEncyclopediaRegistryWrapper* encyclopedia_registry;
CGameNewsRegistryWrapper* game_news_registry;
CCharacterPhysicsSupport* m_pPhysics_support;

Expand Down
94 changes: 41 additions & 53 deletions src/xrGame/InfoPortion.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch_script.h"
#include "xml_str_id_loader.h"
#include "Common/object_broker.h"
/*

#include "InfoPortion.h"
#include "GameObject.h"
#include "encyclopedia_article.h"
Expand All @@ -13,121 +13,109 @@
#include "xrScriptEngine/script_engine.hpp"
#include "ui/uixmlinit.h"

void INFO_DATA::load (IReader& stream)
void INFO_DATA::load(IReader& stream)
{
load_data(info_id, stream);
load_data(receive_time, stream);
}

void INFO_DATA::save (IWriter& stream)
void INFO_DATA::save(IWriter& stream)
{
save_data(info_id, stream);
save_data(receive_time, stream);
}

SInfoPortionData::SInfoPortionData() {}
SInfoPortionData::~SInfoPortionData() {}

SInfoPortionData::SInfoPortionData ()
{
}
SInfoPortionData::~SInfoPortionData ()
{
}
CInfoPortion::CInfoPortion()
{
}
CInfoPortion::CInfoPortion() {}
CInfoPortion::~CInfoPortion() {}

CInfoPortion::~CInfoPortion ()
{
}
void CInfoPortion::Load (shared_str info_id)
void CInfoPortion::Load(shared_str info_id)
{
m_InfoId = info_id;
inherited_shared::load_shared(m_InfoId, NULL);
inherited_shared::load_shared(m_InfoId, nullptr);
}

void CInfoPortion::load_shared (LPCSTR)
void CInfoPortion::load_shared(LPCSTR)
{
const ITEM_DATA* item_data = id_to_index::GetById(m_InfoId, true);
const ITEM_DATA* item_data = GetById(m_InfoId, true);

if(item_data==NULL)
if (item_data == nullptr)
{
Msg("! attempt to use non-existent INFOPORTION [%s]", m_InfoId.c_str());
if (ShadowOfChernobylMode || ClearSkyMode)
Msg("! attempt to use non-existent INFOPORTION [%s]", m_InfoId.c_str());
return;
}

CUIXml* pXML = item_data->_xml;
pXML->SetLocalRoot (pXML->GetRoot());
CUIXml* pXML = item_data->_xml;
pXML->SetLocalRoot(pXML->GetRoot());

//loading from XML
XML_NODE* pNode = pXML->NavigateToNode(id_to_index::tag_name, item_data->pos_in_file);
THROW3 (pNode, "info_portion id=", *item_data->id);
const XML_NODE pNode = pXML->NavigateToNode(tag_name, item_data->pos_in_file);
THROW3(pNode, "info_portion id=", *item_data->id);

//список названий диалогов
int dialogs_num = pXML->GetNodesNum(pNode, "dialog");
const int dialogs_num = pXML->GetNodesNum(pNode, "dialog");
info_data()->m_DialogNames.clear();
for(int i=0; i<dialogs_num; ++i)
for (int i = 0; i < dialogs_num; ++i)
{
shared_str dialog_name = pXML->Read(pNode, "dialog", i,"");
shared_str dialog_name = pXML->Read(pNode, "dialog", i, "");
info_data()->m_DialogNames.push_back(dialog_name);
}

//список названий порций информации, которые деактивируются,
//после получения этой порции
int disable_num = pXML->GetNodesNum(pNode, "disable");
const int disable_num = pXML->GetNodesNum(pNode, "disable");
info_data()->m_DisableInfo.clear();
for(i=0; i<disable_num; ++i)
for (int i = 0; i < disable_num; ++i)
{
shared_str info_id = pXML->Read(pNode, "disable", i,"");
shared_str info_id = pXML->Read(pNode, "disable", i, "");
info_data()->m_DisableInfo.push_back(info_id);
}

//имена скриптовых функций
info_data()->m_InfoScriptHelper.Load(pXML, pNode);

//индексы статей
info_data()->m_Articles.clear();
int articles_num = pXML->GetNodesNum(pNode, "article");
for(i=0; i<articles_num; ++i)
int articles_num = pXML->GetNodesNum(pNode, "article");
for (int i = 0; i < articles_num; ++i)
{
LPCSTR article_str_id = pXML->Read(pNode, "article", i, NULL);
cpcstr article_str_id = pXML->Read(pNode, "article", i, nullptr);
THROW(article_str_id);
info_data()->m_Articles.push_back(article_str_id);
info_data()->m_Articles.emplace_back(article_str_id);
}

info_data()->m_ArticlesDisable.clear();
articles_num = pXML->GetNodesNum(pNode, "article_disable");
for(i=0; i<articles_num; ++i)
for (int i = 0; i < articles_num; ++i)
{
LPCSTR article_str_id = pXML->Read(pNode, "article_disable", i, NULL);
cpcstr article_str_id = pXML->Read(pNode, "article_disable", i, nullptr);
THROW(article_str_id);
info_data()->m_ArticlesDisable.push_back(article_str_id);
info_data()->m_ArticlesDisable.emplace_back(article_str_id);
}
}

void CInfoPortion::InitXmlIdToIndex()
void CInfoPortion::InitXmlIdToIndex()
{
if(!id_to_index::tag_name)
id_to_index::tag_name = "info_portion";
if(!id_to_index::file_str)
id_to_index::file_str = pSettings->r_string("info_portions", "files");
if (!tag_name)
tag_name = "info_portion";
if (!file_str)
file_str = pSettings->r_string("info_portions", "files");
}
*/

void _destroy_item_data_vector_cont(T_VECTOR* vec)
{
T_VECTOR::iterator it = vec->begin();
T_VECTOR::iterator it_e = vec->end();
auto it = vec->begin();
auto it_e = vec->end();

xr_vector<CUIXml*> _tmp;
for (; it != it_e; ++it)
{
xr_vector<CUIXml*>::iterator it_f = std::find(_tmp.begin(), _tmp.end(), (*it)._xml);
auto it_f = std::find(_tmp.begin(), _tmp.end(), (*it)._xml);
if (it_f == _tmp.end())
_tmp.push_back((*it)._xml);
_tmp.emplace_back((*it)._xml);
}
delete_data(_tmp);
}
77 changes: 37 additions & 40 deletions src/xrGame/InfoPortion.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
/*

#include "shared_data.h"
#include "PhraseScript.h"

Expand All @@ -8,80 +8,77 @@

#include "PhraseDialogDefs.h"

struct SInfoPortionData : CSharedResource
{
SInfoPortionData ();
virtual ~SInfoPortionData ();
SInfoPortionData();
virtual ~SInfoPortionData();

//массив с именами диалогов, которые могут быть инициированы
//из этого InfoPortion
DIALOG_ID_VECTOR m_DialogNames;
DIALOG_ID_VECTOR m_DialogNames;

//список статей в энциклопедии, которые становятся известными
ARTICLE_ID_VECTOR m_Articles;
ARTICLE_ID_VECTOR m_Articles;
//список статей в энциклопедии, которые становятся неизвестными (на тот случай если
//нужно заменить одну статью другой)
ARTICLE_ID_VECTOR m_ArticlesDisable;
ARTICLE_ID_VECTOR m_ArticlesDisable;

//скриптовые действия, которые активируется после того как
//информацию получает персонаж
CDialogScriptHelper m_InfoScriptHelper;
CDialogScriptHelper m_InfoScriptHelper;

//массив с индексами тех порций информации, которые
//исчезнут, после получения этой info_portion
DEFINE_VECTOR (shared_str, INFO_ID_VECTOR, INFO_ID_VECTOR_IT);
INFO_ID_VECTOR m_DisableInfo;
using INFO_ID_VECTOR = xr_vector<shared_str>;
INFO_ID_VECTOR m_DisableInfo;
};

class CInfoPortion;
//квант - порция информации
class CInfoPortion : public CSharedClass<SInfoPortionData, shared_str, false>,
public CXML_IdToIndex<CInfoPortion>
{
private:
typedef CSharedClass<SInfoPortionData, shared_str, false> inherited_shared;
typedef CXML_IdToIndex<CInfoPortion> id_to_index;
using inherited_shared = CSharedClass<SInfoPortionData, shared_str, false>;
using id_to_index = CXML_IdToIndex<CInfoPortion>;

friend id_to_index;
public:
CInfoPortion (void);
virtual ~CInfoPortion (void);
CInfoPortion(void);
~CInfoPortion(void) override;

//инициализация info данными
//если info с таким id раньше не использовался
//он будет загружен из файла
virtual void Load (shared_str info_str_id);
const ARTICLE_ID_VECTOR& Articles () const {return info_data()->m_Articles;}
const ARTICLE_ID_VECTOR& ArticlesDisable () const {return info_data()->m_ArticlesDisable;}
const DIALOG_ID_VECTOR& DialogNames () const {return info_data()->m_DialogNames;}
const SInfoPortionData::INFO_ID_VECTOR& DisableInfos() const {return info_data()->m_DisableInfo;}
virtual void Load(shared_str info_str_id);
const ARTICLE_ID_VECTOR& Articles() const { return info_data()->m_Articles; }
const ARTICLE_ID_VECTOR& ArticlesDisable() const { return info_data()->m_ArticlesDisable; }
const DIALOG_ID_VECTOR& DialogNames() const { return info_data()->m_DialogNames; }
const SInfoPortionData::INFO_ID_VECTOR& DisableInfos() const { return info_data()->m_DisableInfo; }

void RunScriptActions (const CGameObject* pOwner)
{info_data()->m_InfoScriptHelper.Action(pOwner, NULL, NULL);}
void RunScriptActions(const CGameObject* pOwner)
{
info_data()->m_InfoScriptHelper.Action(pOwner, nullptr, nullptr);
}

//текстовое представление информации
shared_str GetText () const ;
shared_str GetText() const;

protected:
shared_str m_InfoId;
shared_str m_InfoId;

void load_shared (LPCSTR);
SInfoPortionData* info_data () { VERIFY(inherited_shared::get_sd()); return
inherited_shared::get_sd();}
const SInfoPortionData* info_data () const { VERIFY(inherited_shared::get_sd()); return
inherited_shared::get_sd();}
void load_shared(LPCSTR) override;

static void InitXmlIdToIndex();
};
*/
class CInfoPortion
{
shared_str m_InfoId;
SInfoPortionData* info_data()
{
VERIFY(inherited_shared::get_sd());
return inherited_shared::get_sd();
}

public:
void Load(const shared_str& info_id) { m_InfoId = info_id; }
const shared_str& InfoId() const { return m_InfoId; }
const SInfoPortionData* info_data() const
{
VERIFY(inherited_shared::get_sd());
return inherited_shared::get_sd();
}

static void InitXmlIdToIndex();
};
2 changes: 1 addition & 1 deletion src/xrGame/InventoryOwner.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CInventoryOwner : public CAttachmentOwner
virtual void TransferInfo(shared_str info_id, bool add_info) const;
//есть ли информация у персонажа
virtual bool HasInfo(shared_str info_id) const;
// virtual bool GetInfo (shared_str info_id, INFO_DATA&) const;
virtual bool GetInfo(shared_str info_id, INFO_DATA&) const;

#ifdef DEBUG
void DumpInfo() const;
Expand Down
Loading

0 comments on commit 83417ce

Please sign in to comment.