ScummVM API documentation
dialogue_runtime.h
1#ifndef HARVESTER_NPC_DIALOGUE_RUNTIME_H
2#define HARVESTER_NPC_DIALOGUE_RUNTIME_H
3
4#include "common/error.h"
5#include "common/str.h"
6#include "harvester/script/script.h"
7
8namespace Harvester {
9
10class HarvesterEngine;
11class Flow;
12class Text;
13
15 int wavId;
16 const char *speakerId;
17 int headVariant;
18};
19
22 : fromTypedInput(false), fromEscape(false), fromGenericBye(false) {
23 }
24
25 bool fromTypedInput;
26 bool fromEscape;
27 bool fromGenericBye;
28};
29
31public:
32 virtual ~DialogueRuntimeCallbacks() {}
33
34 virtual Common::Error playDialogueLineWithVariant(int wavId, const Common::String &speakerId,
35 int headVariant) = 0;
36 virtual Common::Error playDialogueLine(int wavId, const Common::String &speakerId) = 0;
37 virtual Common::Error playDialogueEntrySequence(const DialogueLineEntry *lines, uint count) = 0;
38 virtual Common::Error playDialogueFst(const Common::String &path) = 0;
39 virtual Common::Error clearScreenToBlack() = 0;
40 virtual Common::Error showCdChangePrompt(int discNumber) = 0;
41 virtual Common::Error runKeywordMenu(const Common::String &topicBuffer, int topicBufferLineIndex,
42 Common::String &selectedTopic, DialogueKeywordMenuSelectionState &selection) = 0;
43 virtual Common::Error runResponseMenu(int responseLineIndex, int &responseIndex) = 0;
44 virtual Common::Error runResponseMenuText(const Common::String &responseLine, int &responseIndex) = 0;
45 virtual Common::Error runGameOverScreen() = 0;
46 virtual void assignTopicBuffer(Common::String &topicBuffer, int &topicBufferLineIndex,
47 int responseLineIndex, const char *label) = 0;
48 virtual bool matchesResponseLine(const Common::String &selectedTopic, int responseLineIndex) = 0;
49 virtual bool matchesAnyResponseLine(const Common::String &selectedTopic,
50 const int *responseLineIndices, uint responseLineCount) = 0;
51 virtual void queueDialogueInteractionIfNeeded(const InteractionResult &interaction) = 0;
52 virtual void applyImmediateDialogueInteractionEffects(InteractionResult &interaction) = 0;
53 virtual int getRandomNumber(int maxValue) = 0;
54 virtual void setActiveSpeakerPortrait(const Common::String &speakerId, int headVariant) = 0;
55};
56
58public:
60
61 DialogueRuntime(HarvesterEngine &engine, Script &script, Text &text,
62 Flow &flow, const ScriptExecutionContext &executionContext,
63 const Common::String &genericByeTopic,
64 DialogueRuntimeCallbacks &callbacks)
65 : _engine(engine), _script(script), _text(text),
66 _flow(flow), _executionContext(executionContext),
67 _genericByeTopic(genericByeTopic),
68 _callbacks(callbacks) {
69 }
70
71 HarvesterEngine &engine() const { return _engine; }
72 Script &startupScript() const { return _script; }
73 Text &startupText() const { return _text; }
74 Flow &startupFlow() const { return _flow; }
75 Common::String currentRoomName() const { return _executionContext.roomName(); }
76 const Common::String &genericByeTopic() const { return _genericByeTopic; }
77 bool executeActionTag(const Common::String &tag, InteractionResult &result,
78 bool allowTransitions = true) const {
79 return _script.executeActionTag(tag, result, allowTransitions, _executionContext);
80 }
81 void executeAndQueueAction(const Common::String &tag) const {
82 InteractionResult interaction;
83 if (executeActionTag(tag, interaction)) {
84 applyImmediateDialogueInteractionEffects(interaction);
85 queueDialogueInteractionIfNeeded(interaction);
86 }
87 }
88
89 Common::Error playDialogueLineWithVariant(int wavId, const Common::String &speakerId,
90 int headVariant) const {
91 return _callbacks.playDialogueLineWithVariant(wavId, speakerId, headVariant);
92 }
93 Common::Error playDialogueLine(int wavId, const Common::String &speakerId) const {
94 return _callbacks.playDialogueLine(wavId, speakerId);
95 }
96 Common::Error playDialogueEntrySequence(const DialogueLineEntry *lines, uint count) const {
97 return _callbacks.playDialogueEntrySequence(lines, count);
98 }
99 Common::Error playDialogueFst(const Common::String &path) const { return _callbacks.playDialogueFst(path); }
100 Common::Error clearScreenToBlack() const { return _callbacks.clearScreenToBlack(); }
101 Common::Error showCdChangePrompt(int discNumber) const { return _callbacks.showCdChangePrompt(discNumber); }
102 Common::Error runKeywordMenu(const Common::String &topicBuffer, int topicBufferLineIndex,
103 Common::String &selectedTopic) const {
104 _lastKeywordSelection = KeywordMenuSelectionState();
105 return _callbacks.runKeywordMenu(topicBuffer, topicBufferLineIndex, selectedTopic, _lastKeywordSelection);
106 }
107 Common::Error runResponseMenu(int responseLineIndex, int &responseIndex) const {
108 return _callbacks.runResponseMenu(responseLineIndex, responseIndex);
109 }
110 Common::Error runResponseMenuText(const Common::String &responseLine, int &responseIndex) const {
111 return _callbacks.runResponseMenuText(responseLine, responseIndex);
112 }
113 Common::Error runGameOverScreen() const { return _callbacks.runGameOverScreen(); }
114 void assignTopicBuffer(Common::String &topicBuffer, int &topicBufferLineIndex,
115 int responseLineIndex, const char *label) const {
116 _callbacks.assignTopicBuffer(topicBuffer, topicBufferLineIndex, responseLineIndex, label);
117 }
118 bool matchesResponseLine(const Common::String &selectedTopic, int responseLineIndex) const {
119 return _callbacks.matchesResponseLine(selectedTopic, responseLineIndex);
120 }
121 bool matchesAnyResponseLine(const Common::String &selectedTopic,
122 const int *responseLineIndices, uint responseLineCount) const {
123 return _callbacks.matchesAnyResponseLine(selectedTopic, responseLineIndices, responseLineCount);
124 }
125 bool lastKeywordSelectionWasTypedInput() const { return _lastKeywordSelection.fromTypedInput; }
126 bool lastKeywordSelectionWasGenericBye() const { return _lastKeywordSelection.fromGenericBye; }
127 void queueDialogueInteractionIfNeeded(const InteractionResult &interaction) const {
128 _callbacks.queueDialogueInteractionIfNeeded(interaction);
129 }
130 void applyImmediateDialogueInteractionEffects(InteractionResult &interaction) const {
131 _callbacks.applyImmediateDialogueInteractionEffects(interaction);
132 }
133 int getRandomNumber(int maxValue) const { return _callbacks.getRandomNumber(maxValue); }
134 void setActiveSpeakerPortrait(const Common::String &speakerId, int headVariant) const {
135 _callbacks.setActiveSpeakerPortrait(speakerId, headVariant);
136 }
137
138private:
139 HarvesterEngine &_engine;
140 Script &_script;
141 Text &_text;
142 Flow &_flow;
143 const ScriptExecutionContext _executionContext;
144 const Common::String &_genericByeTopic;
145 DialogueRuntimeCallbacks &_callbacks;
146 mutable KeywordMenuSelectionState _lastKeywordSelection;
147};
148
150public:
151 DialogueTopicBuffer(const DialogueRuntime &runtime, Common::String &text, int &lineIndex,
152 const char *label)
153 : _runtime(runtime), _text(text), _lineIndex(lineIndex), _label(label) {}
154
155 void assign(int responseLineIndex) const {
156 _runtime.assignTopicBuffer(_text, _lineIndex, responseLineIndex, _label);
157 }
158 void clear() const {
159 _text.clear();
160 _lineIndex = -1;
161 }
162
163private:
164 const DialogueRuntime &_runtime;
165 Common::String &_text;
166 int &_lineIndex;
167 const char *_label;
168};
169
170} // End of namespace Harvester
171
172#endif // HARVESTER_NPC_DIALOGUE_RUNTIME_H
Definition: error.h:81
Definition: str.h:59
Definition: dialogue_runtime.h:30
Definition: dialogue_runtime.h:57
Definition: dialogue_runtime.h:149
Definition: flow.h:45
Definition: harvester.h:47
Definition: script.h:269
Definition: script.h:342
Definition: text.h:55
Definition: dialogue_runtime.h:20
Definition: dialogue_runtime.h:14
Definition: script.h:311