ScummVM API documentation
parser.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/*
23 * This code is based on original Hugo Trilogy source code
24 *
25 * Copyright (c) 1989-1995 David P. Gray
26 *
27 */
28
29#ifndef HUGO_PARSER_H
30#define HUGO_PARSER_H
31
32namespace Common {
33struct Event;
34class ReadStream;
35}
36
37namespace Hugo {
38
39enum seqTextParser {
40 kTBExit = 0, kTBMaze, kTBNoPoint, kTBNoun, kTBVerb,
41 kTBEh, kTBUnusual, kTBHave, kTBNoUse, kTBDontHave,
42 kTBNeed, kTBOk, kCmtAny1, kCmtAny2, kCmtAny3,
43 kCmtClose, kTBIntro, kTBOutro, kTBUnusual_1d, kCmtAny4,
44 kCmtAny5, kTBExit_1d, kTBEh_1d, kTBEh_2d, kTBNoUse_2d
45};
46
50struct cmd {
51 uint16 _verbIndex; // the verb
52 uint16 _reqIndex; // ptr to list of required objects
53 uint16 _textDataNoCarryIndex; // ptr to string if any of above not carried
54 byte _reqState; // required state for verb to be done
55 byte _newState; // new states if verb done
56 uint16 _textDataWrongIndex; // ptr to string if wrong state
57 uint16 _textDataDoneIndex; // ptr to string if verb done
58 uint16 _actIndex; // Ptr to action list if verb done
59};
60
67struct Background {
68 uint16 _verbIndex;
69 uint16 _nounIndex;
70 int _commentIndex; // Index of comment produced on match
71 bool _matchFl; // TRUE if noun must match when present
72 byte _roomState; // "State" of room. Comments might differ.
73 byte _bonusIndex; // Index of bonus score (0 = no bonus)
74};
75
76typedef Background *ObjectList;
77
78class Parser {
79public:
80 Parser(HugoEngine *vm);
81 virtual ~Parser();
82
83 bool isWordPresent(char **wordArr) const;
84
85 uint16 getCmdDefaultVerbIdx(const uint16 index) const;
86
87 void charHandler();
88 void command(const char *format, ...);
89 void resetCommandLine();
90 void freeParser();
91 void keyHandler(Common::Event event);
92 void actionHandler(Common::Event event);
93 void loadArrayReqs(Common::SeekableReadStream &in);
94 void loadBackgroundObjects(Common::ReadStream &in);
95 void loadCatchallList(Common::ReadStream &in);
96 void loadCmdList(Common::ReadStream &in);
97 void switchTurbo();
98 const char *useBG(const char *name);
99
100 virtual void lineHandler() = 0;
101 virtual void showInventory() const = 0;
102 virtual void takeObject(Object *obj) = 0;
103
104protected:
105 HugoEngine *_vm;
106
107 int16 _cmdLineIndex; // Index into line
108 uint32 _cmdLineTick; // For flashing cursor
109 char _cmdLineCursor;
110 Command _cmdLine; // Build command line
111 uint16 _backgroundObjectsSize;
112 uint16 _cmdListSize;
113
114 uint16 **_arrayReqs;
115 Background **_backgroundObjects;
116 Background *_catchallList;
117 cmd **_cmdList;
118
119 const char *findNoun() const;
120 const char *findVerb() const;
121 void readBG(Common::ReadStream &in, Background &curBG);
122 void readCmd(Common::ReadStream &in, cmd &curCmd);
123 void showDosInventory() const;
124#ifdef USE_TTS
125 void sayInventory(const char *intro, const char *outro, int nounIndex2) const;
126#endif
127 void endGamePrompt();
128
129 bool _checkDoubleF1Fl; // Flag used to display user help or instructions
130 uint16 _getIndex; // Index into ring buffer
131 uint16 _putIndex;
132 char _ringBuffer[32]; // Ring buffer
133
134private:
135 static const int kBlinksPerSec = 2; // Cursor blinks per second
136};
137
138class Parser_v1d : public Parser {
139public:
141 ~Parser_v1d() override;
142
143 void lineHandler() override;
144 void showInventory() const override;
145 void takeObject(Object *obj) override;
146
147protected:
148 virtual void dropObject(Object *obj);
149
150 const char *findNextNoun(const char *noun) const;
151 bool isBackgroundWord_v1(const char *noun, const char *verb, ObjectList obj) const;
152 bool isCatchallVerb_v1(bool testNounFl, const char *noun, const char *verb, ObjectList obj) const;
153 bool isGenericVerb_v1(const char *word, Object *obj);
154 bool isNear_v1(const char *verb, const char *noun, Object *obj, char *comment) const;
155 bool isObjectVerb_v1(const char *word, Object *obj);
156};
157
158class Parser_v2d : public Parser_v1d {
159public:
161 ~Parser_v2d() override;
162
163 void lineHandler() override;
164
165protected:
166 bool isBackgroundWord_v2(const char *noun, const char *verb, ObjectList obj) const;
167 bool isCatchallVerb_v2(bool testNounFl, const char *noun, const char *verb, ObjectList obj) const;
168 bool isGenericVerb_v2(const char *word, Object *obj);
169 bool isObjectVerb_v2(const char *word, Object *obj);
170};
171
172class Parser_v3d : public Parser_v1d {
173public:
175 ~Parser_v3d() override;
176
177 void lineHandler() override;
178protected:
179 void dropObject(Object *obj) override;
180 bool isBackgroundWord_v3(ObjectList obj) const;
181 bool isCatchallVerb_v3(ObjectList obj) const;
182 bool isGenericVerb_v3(Object *obj, char *comment);
183 bool isNear_v3(Object *obj, const char *verb, char *comment) const;
184 bool isObjectVerb_v3(Object *obj, char *comment);
185 void takeObject(Object *obj) override;
186};
187
188class Parser_v1w : public Parser_v3d {
189public:
191 ~Parser_v1w() override;
192
193 void showInventory() const override;
194
195 void lineHandler() override;
196};
197
198} // End of namespace Hugo
199
200#endif //HUGO_PARSER_H
Definition: stream.h:385
Definition: stream.h:745
Definition: hugo.h:219
Definition: parser.h:138
Definition: parser.h:188
Definition: parser.h:158
Definition: parser.h:172
Definition: parser.h:78
Definition: algorithm.h:29
Definition: console.h:27
Definition: events.h:218
Definition: parser.h:67
Definition: game.h:143
Definition: parser.h:50