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