MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / SayPhrase

Method SayPhrase

ogsr_engine/xrGame/PhraseDialog.cpp:60–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58static bool PhraseGoodwillPred(const CPhrase* phrase1, const CPhrase* phrase2) { return phrase1->GoodwillLevel() > phrase2->GoodwillLevel(); }
59
60bool CPhraseDialog::SayPhrase(DIALOG_SHARED_PTR& phrase_dialog, const shared_str& phrase_id)
61{
62 THROW(phrase_dialog->IsInited());
63
64 phrase_dialog->m_SaidPhraseID = phrase_id;
65
66 bool first_is_speaking = phrase_dialog->FirstIsSpeaking();
67 phrase_dialog->m_bFirstIsSpeaking = !phrase_dialog->m_bFirstIsSpeaking;
68
69 const CGameObject* pSpeakerGO1 = smart_cast<const CGameObject*>(phrase_dialog->FirstSpeaker());
70 VERIFY(pSpeakerGO1);
71 const CGameObject* pSpeakerGO2 = smart_cast<const CGameObject*>(phrase_dialog->SecondSpeaker());
72 VERIFY(pSpeakerGO2);
73 if (!first_is_speaking)
74 std::swap(pSpeakerGO1, pSpeakerGO2);
75
76 CPhraseGraph::CVertex* phrase_vertex = phrase_dialog->data()->m_PhraseGraph.vertex(phrase_dialog->m_SaidPhraseID);
77 THROW(phrase_vertex);
78
79 CPhrase* last_phrase = phrase_vertex->data();
80
81 //вызвать скриптовую присоединенную функцию
82 //активируется после сказанной фразы
83 //первый параметр - тот кто говорит фразу, второй - тот кто слушает
84 last_phrase->m_PhraseScript.Action(pSpeakerGO1, pSpeakerGO2, *phrase_dialog->m_DialogId, phrase_id.c_str());
85
86 //больше нет фраз, чтоб говорить
87 phrase_dialog->m_PhraseVector.clear();
88 if (phrase_vertex->edges().empty())
89 {
90 phrase_dialog->m_bFinished = true;
91 }
92 else
93 {
94 //обновить список фраз, которые сейчас сможет говорить собеседник
95 for (xr_vector<CPhraseGraph::CEdge>::const_iterator it = phrase_vertex->edges().begin(); it != phrase_vertex->edges().end(); ++it)
96 {
97 const CPhraseGraph::CEdge& edge = *it;
98 CPhraseGraph::CVertex* next_phrase_vertex = phrase_dialog->data()->m_PhraseGraph.vertex(edge.vertex_id());
99 THROW(next_phrase_vertex);
100 shared_str next_phrase_id = next_phrase_vertex->vertex_id();
101 if (next_phrase_vertex->data()->m_PhraseScript.Precondition(pSpeakerGO2, pSpeakerGO1, *phrase_dialog->m_DialogId, phrase_id.c_str(), next_phrase_id.c_str()))
102 {
103 phrase_dialog->m_PhraseVector.push_back(next_phrase_vertex->data());
104#ifdef DEBUG
105 if (psAI_Flags.test(aiDialogs))
106 {
107 LPCSTR phrase_text = next_phrase_vertex->data()->GetText();
108 shared_str id = next_phrase_vertex->data()->GetID();
109 Msg("----added phrase text [%s]phrase_id=[%s] id=[%s] to dialog [%s]", phrase_text, phrase_id.c_str(), id.c_str(), *phrase_dialog->m_DialogId.c_str());
110 }
111#endif
112 }
113 }
114
115 R_ASSERT2(!phrase_dialog->m_PhraseVector.empty(), make_string("No available phrase to say, dialog[%s]", *phrase_dialog->m_DialogId));
116
117 //упорядочить списко по убыванию благосклонности

Callers

nothing calls this directly

Calls 15

MsgFunction · 0.85
make_stringFunction · 0.85
IsInitedMethod · 0.80
FirstIsSpeakingMethod · 0.80
FirstSpeakerMethod · 0.80
SecondSpeakerMethod · 0.80
swapFunction · 0.50
sortFunction · 0.50
vertexMethod · 0.45
dataMethod · 0.45
ActionMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected