ScummVM API documentation
message.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 SCI_ENGINE_MESSAGE_H
23 #define SCI_ENGINE_MESSAGE_H
24 
25 #include "sci/resource/resource.h"
26 #include "sci/engine/vm_types.h"
27 #include "common/stack.h"
28 
29 namespace Sci {
30 
31 class SegManager;
32 struct MessageRecord;
33 
34 struct MessageTuple {
35  byte noun;
36  byte verb;
37  byte cond;
38  byte seq;
39 
40  MessageTuple(byte noun_ = 0, byte verb_ = 0, byte cond_ = 0, byte seq_ = 1)
41  : noun(noun_), verb(verb_), cond(cond_), seq(seq_) { }
42 
43  Common::String toString() const {
44  return Common::String::format("noun %d, verb %d, cond %d, seq %d",
45  noun, verb, cond, seq);
46  }
47 };
48 
49 class CursorStack : public Common::Stack<MessageTuple> {
50 public:
51  CursorStack() : Common::Stack<MessageTuple>(), _module(0) {}
52 
53  void init(int module, MessageTuple t) {
54  clear();
55  push(t);
56  _module = module;
57  }
58 
59  int getModule() const { return _module; }
60  void setModule(int module) { _module = module; }
61 
62 private:
63  int _module;
64 };
65 
67 
68 class MessageState {
69 public:
70  MessageState(SegManager *segMan) : _segMan(segMan), _lastReturnedModule(0) { }
71  int getMessage(int module, const MessageTuple &t, reg_t buf);
72  int nextMessage(reg_t buf);
73  int messageSize(int module, MessageTuple &t);
74  bool messageRef(int module, const MessageTuple &t, MessageTuple &ref);
75  void lastQuery(int &module, MessageTuple &tuple);
76  void pushCursorStack();
77  void popCursorStack();
78 
79 private:
80  bool getRecord(CursorStack &stack, bool recurse, MessageRecord &record);
81  void outputString(reg_t buf, const Common::String &str);
82  Common::String processString(const char *s, uint32 maxLength);
83  int hexDigitToWrongInt(char h);
84  bool stringHex(Common::String &outStr, const Common::String &inStr, uint &index);
85  bool stringLit(Common::String &outStr, const Common::String &inStr, uint &index);
86  bool stringStage(Common::String &outStr, const Common::String &inStr, uint &index);
87 
88  CursorStack _cursorStack;
89  CursorStackStack _cursorStackStack;
90  MessageTuple _lastReturned;
91  int _lastReturnedModule;
92 
93  SegManager *_segMan;
94 };
95 
96 } // End of namespace Sci
97 
98 #endif // SCI_ENGINE_MESSAGE_H
Definition: message.h:49
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: console.h:28
Definition: seg_manager.h:48
Definition: message.h:34
Definition: message.h:68
Definition: stack.h:102
Definition: vm_types.h:39