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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MADS_ACTION_H
24 #define MADS_ACTION_H
25 
26 #include "common/scummsys.h"
27 #include "common/serializer.h"
28 #include "common/str.h"
29 
30 namespace MADS {
31 
32 enum TriggerMode {
33 	SEQUENCE_TRIGGER_NONE = -1,
34 	SEQUENCE_TRIGGER_PARSER = 0,		// Triggers parser
35 	SEQUENCE_TRIGGER_DAEMON = 1,		// Triggers step/daemon code
36 	SEQUENCE_TRIGGER_PREPARE = 2		// Triggers preparser
37 };
38 
39 enum InterAwaiting {
40 	AWAITING_NONE = 0,
41 	AWAITING_COMMAND = 1,       // Initial state: waiting for a command verb
42 	AWAITING_THIS = 2,			// Waiting for object
43 	AWAITING_THAT = 3,			// Waiting for a second object
44 	AWAITING_RIGHT_MOUSE = 4	// Waiting for mouse button release
45 };
46 
47 enum {
48 	VERB_NONE = 0,
49 	VERB_LOOK = 3,
50 	VERB_TAKE = 4,
51 	VERB_PUSH = 5,
52 	VERB_OPEN = 6,
53 	VERB_PUT = 7,
54 	VERB_TALKTO = 8,
55 	VERB_GIVE = 9,
56 	VERB_PULL = 10,
57 	VERB_CLOSE = 11,
58 	VERB_THROW = 12,
59 	VERB_WALKTO = 13
60 };
61 
62 enum VerbType { VERB_ONLY, VERB_THIS, VERB_THAT, VERB_INIT };
63 
64 enum PrepType {
65 	PREP_NONE, PREP_WITH, PREP_TO, PREP_AT, PREP_FROM, PREP_ON, PREP_IN,
66 	PREP_UNDER, PREP_BEHIND, PREP_RELATIONAL = 0xff
67 };
68 
69 enum ScrCategory {
70 	CAT_NONE = 0, CAT_COMMAND = 1, CAT_INV_LIST = 2, CAT_INV_VOCAB = 3,
71 	CAT_HOTSPOT = 4, CAT_INV_ANIM = 5, CAT_TALK_ENTRY = 6, CAT_INV_SCROLLER = 7,
72 	CAT_12 = 12
73 };
74 
75 class MADSEngine;
76 
77 struct ActionDetails {
78 	int _verbId;
79 	int _objectNameId;
80 	int _indirectObjectId;
81 
82 	/**
83 	 * Synchronize the action details
84 	 */
85 	void synchronize(Common::Serializer &s);
86 };
87 
88 struct ActionSavedFields {
89 	bool _commandError;
90 	int _commandSource;
91 	int _command;
92 	int _mainObject;
93 	int _secondObject;
94 	int _mainObjectSource;
95 	int _secondObjectSource;
96 	int _articleNumber;
97 	int _lookFlag;
98 
99 	/**
100 	* Synchronize the saved action details
101 	*/
102 	void synchronize(Common::Serializer &s);
103 };
104 
105 class MADSAction {
106 private:
107 	MADSEngine *_vm;
108 	Common::String _statusText;
109 
110 	void appendVocab(int vocabId, bool capitalize = false);
111 
112 	void startWalkingDirectly(int walkType);
113 public:
114 	ActionDetails _action, _activeAction;
115 	int _articleNumber;
116 	bool _lookFlag;
117 	int _selectedRow;
118 	bool _textChanged;
119 	int _selectedAction;
120 	int _statusTextIndex;
121 	int _hotspotId;
122 	ActionSavedFields _savedFields;
123 	Common::String _sentence;
124 
125 	VerbType _verbType;
126 	PrepType _prepType;
127 	ScrCategory _commandSource;
128 	ScrCategory _mainObjectSource;
129 	int _secondObject;
130 	ScrCategory _secondObjectSource;
131 	ScrCategory _recentCommandSource;
132 	bool _pointEstablished;
133 	int  _recentCommand;
134 	InterAwaiting _interAwaiting;
135 	bool _inProgress;
136 	int _pickedWord;
137 
138 public:
139 	MADSAction(MADSEngine *vm);
140 
141 	void clear();
142 	void set();
statusText()143 	const Common::String &statusText() const { return _statusText; }
144 	void refresh();
145 
146 	/**
147 	 * Accepts the currently defined sentence from the ScreenObjects parser.
148 	 * Copies the data, and checks to see if the action requires the player
149 	 * to walk to the given hotspot.
150 	 */
151 	void startAction();
152 
153 	void checkAction();
154 	bool isAction(int verbId, int objectNameId = 0, int indirectObjectId = 0);
155 	bool isObject(int objectNameId);
156 	bool isTarget(int objectNameId);
157 
158 	/**
159 	 * Check the result of the current action on the sentence
160 	 * with the provision that the action is not yet complete.
161 	 */
162 	void checkActionAtMousePos();
163 
164 	/**
165 	* Execute a click within the scene
166 	*/
167 	void leftClick();
168 
169 	/**
170 	* Synchronize the saved action details
171 	*/
172 	void synchronize(Common::Serializer &s);
173 };
174 
175 } // End of namespace MADS
176 
177 #endif /* MADS_ACTION_H */
178