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 
32 namespace Common {
33 struct Event;
34 class ReadStream;
35 }
36 
37 namespace Hugo {
38 
39 enum 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 
50 struct 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 
67 struct 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 
76 typedef Background *ObjectList;
77 
78 class Parser {
79 public:
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 freeParser();
90  void keyHandler(Common::Event event);
91  void actionHandler(Common::Event event);
92  void loadArrayReqs(Common::SeekableReadStream &in);
93  void loadBackgroundObjects(Common::ReadStream &in);
94  void loadCatchallList(Common::ReadStream &in);
95  void loadCmdList(Common::ReadStream &in);
96  void switchTurbo();
97  const char *useBG(const char *name);
98 
99  virtual void lineHandler() = 0;
100  virtual void showInventory() const = 0;
101  virtual void takeObject(Object *obj) = 0;
102 
103 protected:
104  HugoEngine *_vm;
105 
106  int16 _cmdLineIndex; // Index into line
107  uint32 _cmdLineTick; // For flashing cursor
108  char _cmdLineCursor;
109  Command _cmdLine; // Build command line
110  uint16 _backgroundObjectsSize;
111  uint16 _cmdListSize;
112 
113  uint16 **_arrayReqs;
114  Background **_backgroundObjects;
115  Background *_catchallList;
116  cmd **_cmdList;
117 
118  const char *findNoun() const;
119  const char *findVerb() const;
120  void readBG(Common::ReadStream &in, Background &curBG);
121  void readCmd(Common::ReadStream &in, cmd &curCmd);
122  void showDosInventory() const;
123 
124  bool _checkDoubleF1Fl; // Flag used to display user help or instructions
125  uint16 _getIndex; // Index into ring buffer
126  uint16 _putIndex;
127  char _ringBuffer[32]; // Ring buffer
128 
129 private:
130  static const int kBlinksPerSec = 2; // Cursor blinks per second
131 };
132 
133 class Parser_v1d : public Parser {
134 public:
135  Parser_v1d(HugoEngine *vm);
136  ~Parser_v1d() override;
137 
138  void lineHandler() override;
139  void showInventory() const override;
140  void takeObject(Object *obj) override;
141 
142 protected:
143  virtual void dropObject(Object *obj);
144 
145  const char *findNextNoun(const char *noun) const;
146  bool isBackgroundWord_v1(const char *noun, const char *verb, ObjectList obj) const;
147  bool isCatchallVerb_v1(bool testNounFl, const char *noun, const char *verb, ObjectList obj) const;
148  bool isGenericVerb_v1(const char *word, Object *obj);
149  bool isNear_v1(const char *verb, const char *noun, Object *obj, char *comment) const;
150  bool isObjectVerb_v1(const char *word, Object *obj);
151 };
152 
153 class Parser_v2d : public Parser_v1d {
154 public:
155  Parser_v2d(HugoEngine *vm);
156  ~Parser_v2d() override;
157 
158  void lineHandler() override;
159 };
160 
161 class Parser_v3d : public Parser_v1d {
162 public:
163  Parser_v3d(HugoEngine *vm);
164  ~Parser_v3d() override;
165 
166  void lineHandler() override;
167 protected:
168  void dropObject(Object *obj) override;
169  bool isBackgroundWord_v3(ObjectList obj) const;
170  bool isCatchallVerb_v3(ObjectList obj) const;
171  bool isGenericVerb_v3(Object *obj, char *comment);
172  bool isNear_v3(Object *obj, const char *verb, char *comment) const;
173  bool isObjectVerb_v3(Object *obj, char *comment);
174  void takeObject(Object *obj) override;
175 };
176 
177 class Parser_v1w : public Parser_v3d {
178 public:
179  Parser_v1w(HugoEngine *vm);
180  ~Parser_v1w() override;
181 
182  void showInventory() const override;
183 
184  void lineHandler() override;
185 };
186 
187 } // End of namespace Hugo
188 
189 #endif //HUGO_PARSER_H
Definition: console.h:27
Definition: parser.h:161
Definition: stream.h:745
Definition: parser.h:67
Definition: parser.h:78
Definition: events.h:199
Definition: algorithm.h:29
Definition: parser.h:153
Definition: parser.h:177
Definition: stream.h:385
Definition: hugo.h:210
Definition: game.h:142
Definition: parser.h:50
Definition: parser.h:133