ScummVM API documentation
talk.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SHERLOCK_TALK_H
23 #define SHERLOCK_TALK_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/rect.h"
28 #include "common/stream.h"
29 #include "common/stack.h"
30 #include "sherlock/objects.h"
31 #include "sherlock/saveload.h"
32 
33 namespace Sherlock {
34 
35 #define SPEAKER_REMOVE 0x80
36 #define MAX_TALK_SEQUENCES 11
37 
38 enum {
39  OP_SWITCH_SPEAKER = 0,
40  OP_RUN_CANIMATION = 1,
41  OP_ASSIGN_PORTRAIT_LOCATION = 2,
42  OP_PAUSE = 3,
43  OP_REMOVE_PORTRAIT = 4,
44  OP_CLEAR_WINDOW = 5,
45  OP_ADJUST_OBJ_SEQUENCE = 6,
46  OP_WALK_TO_COORDS = 7,
47  OP_PAUSE_WITHOUT_CONTROL = 8,
48  OP_BANISH_WINDOW = 9,
49  OP_SUMMON_WINDOW = 10,
50  OP_SET_FLAG = 11,
51  OP_SFX_COMMAND = 12,
52  OP_TOGGLE_OBJECT = 13,
53  OP_STEALTH_MODE_ACTIVE = 14,
54  OP_IF_STATEMENT = 15,
55  OP_ELSE_STATEMENT = 16,
56  OP_END_IF_STATEMENT = 17,
57  OP_STEALTH_MODE_DEACTIVATE = 18,
58  OP_TURN_HOLMES_OFF = 19,
59  OP_TURN_HOLMES_ON = 20,
60  OP_GOTO_SCENE = 21,
61  OP_PLAY_PROLOGUE = 22,
62  OP_ADD_ITEM_TO_INVENTORY = 23,
63  OP_SET_OBJECT = 24,
64  OP_CALL_TALK_FILE = 25,
65  OP_MOVE_MOUSE = 26,
66  OP_DISPLAY_INFO_LINE = 27,
67  OP_CLEAR_INFO_LINE = 28,
68  OP_WALK_TO_CANIMATION = 29,
69  OP_REMOVE_ITEM_FROM_INVENTORY = 30,
70  OP_ENABLE_END_KEY = 31,
71  OP_DISABLE_END_KEY = 32,
72  OP_END_TEXT_WINDOW = 33,
73 
74  OP_MOUSE_OFF_ON = 34,
75  OP_SET_WALK_CONTROL = 35,
76  OP_SET_TALK_SEQUENCE = 36,
77  OP_PLAY_SONG = 37,
78  OP_WALK_HOLMES_AND_NPC_TO_CANIM = 38,
79  OP_SET_NPC_PATH_DEST = 39,
80  OP_NEXT_SONG = 40,
81  OP_SET_NPC_PATH_PAUSE = 41,
82  OP_NEED_PASSWORD = 42,
83  OP_SET_SCENE_ENTRY_FLAG = 43,
84  OP_WALK_NPC_TO_CANIM = 44,
85  OP_WALK_NPC_TO_COORDS = 45,
86  OP_WALK_HOLMES_AND_NPC_TO_COORDS = 46,
87  OP_SET_NPC_TALK_FILE = 47,
88  OP_TURN_NPC_OFF = 48,
89  OP_TURN_NPC_ON = 49,
90  OP_NPC_DESC_ON_OFF = 50,
91  OP_NPC_PATH_PAUSE_TAKING_NOTES = 51,
92  OP_NPC_PATH_PAUSE_LOOKING_HOLMES = 52,
93  OP_ENABLE_TALK_INTERRUPTS = 53,
94  OP_DISABLE_TALK_INTERRUPTS = 54,
95  OP_SET_NPC_INFO_LINE = 55,
96  OP_SET_NPC_POSITION = 56,
97  OP_NPC_PATH_LABEL = 57,
98  OP_PATH_GOTO_LABEL = 58,
99  OP_PATH_IF_FLAG_GOTO_LABEL = 59,
100  OP_NPC_WALK_GRAPHICS = 60,
101  OP_NPC_VERB = 61,
102  OP_NPC_VERB_CANIM = 62,
103  OP_NPC_VERB_SCRIPT = 63,
104  OP_RESTORE_PEOPLE_SEQUENCE = 64,
105  OP_NPC_VERB_TARGET = 65,
106  OP_TURN_SOUNDS_OFF = 66,
107  OP_NULL = 67
108 };
109 
110 enum OpcodeReturn { RET_EXIT = -1, RET_SUCCESS = 0, RET_CONTINUE = 1 };
111 
112 class SherlockEngine;
113 class Talk;
114 namespace Scalpel { class ScalpelUserInterface; }
115 
116 typedef OpcodeReturn(Talk::*OpcodeMethod)(const byte *&str);
117 
119  int _objNum;
120  Common::Array<byte> _sequences;
121  Object *_obj; // Pointer to the bgshape that these values go to
122  short _frameNumber; // Frame number in frame sequence to draw
123  short _sequenceNumber; // Start frame of sequences that are repeated
124  int _seqStack; // Allows gosubs to return to calling frame
125  int _seqTo; // Allows 1-5, 8-3 type sequences encoded
126  int _seqCounter; // How many times this sequence has been executed
127  int _seqCounter2;
128 
129  SequenceEntry();
130 };
131 
133  Common::String _name;
134  int _currentIndex;
135  int _select;
136 };
137 
138 struct Statement {
139  Common::String _statement;
140  Common::String _reply;
141  Common::String _linkFile;
142  Common::String _voiceFile;
143  Common::Array<int> _required;
144  Common::Array<int> _modified;
145  int _portraitSide;
146  int _quotient;
147  int _talkMap;
148  Common::Rect _talkPos;
149  int _journal;
150 
154  void load(Common::SeekableReadStream &s, bool isRoseTattoo);
155 };
156 
158  bool _data[32];
159 
161  bool &operator[](int index) { return _data[index]; }
162 };
163 
164 class Talk {
165  friend class Scalpel::ScalpelUserInterface;
166 private:
170  void stripVoiceCommands();
171 protected:
172  SherlockEngine *_vm;
173  OpcodeMethod *_opcodeTable;
174  Common::Stack<SequenceEntry> _savedSequences;
175  Common::Stack<ScriptStackEntry> _scriptStack;
176  Common::Array<TalkHistoryEntry> _talkHistory;
177  int _talkIndex;
178  int _scriptSelect;
179  int _talkStealth;
180  int _talkToFlag;
181  int _scriptSaveIndex;
182  int _3doSpeechIndex;
183 
184  // These fields are used solely by doScript, but are fields because all the script opcodes are
185  // separate methods now, and need access to these fields
186  int _yp;
187  int _charCount;
188  int _line;
189  int _wait;
190  bool _pauseFlag;
191  bool _endStr, _noTextYet;
192  int _seqCount;
193  const byte *_scriptStart, *_scriptEnd;
194 protected:
195  Talk(SherlockEngine *vm);
196 
197  OpcodeReturn cmdAddItemToInventory(const byte *&str);
198  OpcodeReturn cmdAdjustObjectSequence(const byte *&str);
199  OpcodeReturn cmdBanishWindow(const byte *&str);
200  OpcodeReturn cmdDisableEndKey(const byte *&str);
201  OpcodeReturn cmdEnableEndKey(const byte *&str);
202  OpcodeReturn cmdEndTextWindow(const byte *&str);
203  OpcodeReturn cmdHolmesOff(const byte *&str);
204  OpcodeReturn cmdHolmesOn(const byte *&str);
205  OpcodeReturn cmdPause(const byte *&str);
206  OpcodeReturn cmdPauseWithoutControl(const byte *&str);
207  OpcodeReturn cmdRemoveItemFromInventory(const byte *&str);
208  OpcodeReturn cmdRunCAnimation(const byte *&str);
209  OpcodeReturn cmdSetFlag(const byte *&str);
210  OpcodeReturn cmdSetObject(const byte *&str);
211  OpcodeReturn cmdStealthModeActivate(const byte *&str);
212  OpcodeReturn cmdStealthModeDeactivate(const byte *&str);
213  OpcodeReturn cmdToggleObject(const byte *&str);
214  OpcodeReturn cmdWalkToCAnimation(const byte *&str);
215 protected:
219  bool isOpcode(byte checkCharacter);
220 
224  void setTalkMap();
225 
230  virtual int waitForMore(int delay);
231 
235  virtual void talkInterface(const byte *&str) = 0;
236 
240  virtual void talkWait(const byte *&str);
241 
245  virtual void showTalk() = 0;
246 
250  virtual void nothingToSay() = 0;
251 
255  virtual void switchSpeaker() {}
256 public:
257  Common::Array<Statement> _statements;
258  bool _talkToAbort;
259  int _talkCounter;
260  int _talkTo;
261  int _scriptMoreFlag;
262  bool _openTalkWindow;
263  Common::String _scriptName;
264  bool _moreTalkUp, _moreTalkDown;
265  int _converseNum;
266  const byte *_opcodes;
267  int _speaker;
268 public:
269  static Talk *init(SherlockEngine *vm);
270  virtual ~Talk() {}
271 
275  Statement &operator[](int idx) { return _statements[idx]; }
276 
285  virtual void talkTo(const Common::String &filename);
286 
291  void doScript(const Common::String &script);
292 
299  void initTalk(int objNum);
300 
304  void freeTalkVars();
305 
310  virtual void loadTalkFile(const Common::String &filename);
311 
316  void pushSequence(int speaker);
317 
321  virtual void pushSequenceEntry(Object *obj) = 0;
322 
326  virtual void clearSequences() = 0;
327 
331  void popStack();
332 
336  void synchronize(Serializer &s);
337 
341  virtual void drawInterface() {}
342 
347  virtual bool displayTalk(bool slamIt) { return false; }
348 
352  virtual int talkLine(int lineNum, int stateNum, byte color, int lineY, bool slamIt) { return 0; }
353 
358  virtual void pullSequence(int slot = -1) = 0;
359 
363  virtual bool isSequencesEmpty() const = 0;
364 };
365 
366 } // End of namespace Sherlock
367 
368 #endif
Definition: str.h:59
Definition: scalpel_user_interface.h:58
virtual void drawInterface()
Definition: talk.h:341
Definition: talk.h:138
Definition: talk.h:164
Definition: animation.h:29
Definition: rect.h:144
Definition: stream.h:745
Definition: serializer.h:79
Definition: talk.h:118
virtual int talkLine(int lineNum, int stateNum, byte color, int lineY, bool slamIt)
Definition: talk.h:352
Definition: sherlock.h:76
Definition: objects.h:363
virtual void switchSpeaker()
Definition: talk.h:255
Definition: talk.h:132
virtual bool displayTalk(bool slamIt)
Definition: talk.h:347
Definition: stack.h:102
Definition: talk.h:157
Statement & operator[](int idx)
Definition: talk.h:275