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 QUEEN_COMMAND_H
24 #define QUEEN_COMMAND_H
25 
26 #include "common/util.h"
27 #include "queen/structs.h"
28 
29 namespace Queen {
30 
31 class QueenEngine;
32 
33 class CmdText {
34 public:
35 
36 	static CmdText *makeCmdTextInstance(uint8 y, QueenEngine *vm);
37 
38 	CmdText(uint8 y, QueenEngine *vm);
~CmdText()39 	virtual ~CmdText() {}
40 
41 	//! reset the command sentence
42 	void clear();
43 
44 	//! display the command sentence using the specified color
45 	void display(InkColor color, const char *command = 0, bool outlined = false);
46 
47 	//! display a temporary command sentence using the specified parameters
48 	void displayTemp(InkColor color, Verb v);
49 
50 	//! display a temporary command sentence using the specified parameters
51 	virtual void displayTemp(InkColor color, const char *name, bool outlined);
52 
53 	//! set the verb for the command sentence
54 	void setVerb(Verb v);
55 
56 	//! set the link word (between verb and object) for the command sentence
57 	virtual void addLinkWord(Verb v);
58 
59 	//! add an object name to the command sentence
60 	virtual void addObject(const char *objName);
61 
62 	//! returns true if the command sentence is empty
isEmpty()63 	bool isEmpty() const { return _command[0] == 0; }
64 
65 	enum {
66 		MAX_COMMAND_LEN = 256,
67 		COMMAND_Y_POS   = 151
68 	};
69 
70 protected:
71 
72 	//! buffer containing the current command sentence
73 	char _command[MAX_COMMAND_LEN];
74 
75 	uint8 _y;
76 
77 	QueenEngine *_vm;
78 };
79 
80 struct CmdState {
81 
82 	void init();
83 
84 	Verb oldVerb, verb;
85 	Verb action;
86 	int16 oldNoun, noun;
87 	int commandLevel;
88 	int16 subject[2];
89 
90 	Verb selAction;
91 	int16 selNoun;
92 };
93 
94 class Command {
95 public:
96 
97 	Command(QueenEngine *vm);
98 	~Command();
99 
100 	//! initialize command construction
101 	void clear(bool clearTexts);
102 
103 	//! execute last constructed command
104 	void executeCurrentAction();
105 
106 	//! get player input and construct command from it
107 	void updatePlayer();
108 
109 	//! read all command arrays from stream
110 	void readCommandsFrom(byte *&ptr);
111 
112 	enum {
113 		MAX_MATCHING_CMDS = 50
114 	};
115 
116 private:
117 
118 	//! get a reference to the ObjectData for the specified room object
119 	ObjectData *findObjectData(uint16 objRoomNum) const;
120 
121 	//! get a reference to the ItemData for the specified inventory object
122 	ItemData *findItemData(Verb invNum) const;
123 
124 	//! execute the current command
125 	int16 executeCommand(uint16 comId, int16 condResult);
126 
127 	//! move Joe to the specified position, handling new room switching
128 	int16 makeJoeWalkTo(int16 x, int16 y, int16 objNum, Verb v, bool mustWalk);
129 
130 	//! update command state with current selected action
131 	void grabCurrentSelection();
132 
133 	//! update command state with current selected object
134 	void grabSelectedObject(int16 objNum, uint16 objState, uint16 objName);
135 
136 	//! update command state with current selected inventory object
137 	void grabSelectedItem();
138 
139 	//! update command state with current selected room object
140 	void grabSelectedNoun();
141 
142 	//! update command state with current selected verb
143 	void grabSelectedVerb();
144 
145 	//! if the description is a cutaway file, execute it
146 	bool executeIfCutaway(const char *description);
147 
148 	//! if the description is a dialog file, execute it
149 	bool executeIfDialog(const char *description);
150 
151 	//! handle a wrong/invalid user action
152 	bool handleWrongAction();
153 
154 	//! make Joe speak something for a wrong/invalid action
155 	void sayInvalidAction(Verb action, int16 subj1, int16 subj2);
156 
157 	//! update an object state
158 	void changeObjectState(Verb action, int16 obj, int16 song, bool cutDone);
159 
160 	//! reset current action
161 	void cleanupCurrentAction();
162 
163 	//! OPEN_CLOSE_OTHER(OBJECT_DATA[S][4])
164 	void openOrCloseAssociatedObject(Verb action, int16 obj);
165 
166 	//! update gamestates - P1_SET_CONDITIONS
167 	int16 setConditions(uint16 command, bool lastCmd);
168 
169 	//! turn on/off areas - P2_SET_AREAS
170 	void setAreas(uint16 command);
171 
172 	//! hide/show objects, redisplay if in the same room as Joe - P3_SET_OBJECTS
173 	void setObjects(uint16 command);
174 
175 	//! inserts/deletes items (inventory) - P4_SET_ITEMS
176 	void setItems(uint16 command);
177 
178 	//! update description for object and returns description number to use
179 	uint16 nextObjectDescription(ObjectDescription *objDesc, uint16 firstDesc);
180 
181 	//! speak description of selected object
182 	void lookAtSelectedObject();
183 
184 	//! get the current object under the cursor
185 	void lookForCurrentObject(int16 cx, int16 cy);
186 
187 	//! get the current icon panel under the cursor (inventory item or verb)
188 	void lookForCurrentIcon(int16 cx, int16 cy);
189 
190 	//! returns true if the verb is an action verb
isVerbAction(Verb v)191 	bool isVerbAction(Verb v) const { return (v >= VERB_PANEL_COMMAND_FIRST && v <= VERB_PANEL_COMMAND_LAST) || (v == VERB_WALK_TO); }
192 
193 	//! return true if the verb is an inventory item
isVerbInv(Verb v)194 	bool isVerbInv(Verb v) const { return v >= VERB_INV_FIRST && v <= VERB_INV_LAST; }
195 
196 	//! returns true if the specified verb is an inventory scroll
isVerbInvScroll(Verb v)197 	bool isVerbInvScroll(Verb v) const { return v == VERB_SCROLL_UP || v == VERB_SCROLL_DOWN; }
198 
199 	//! commands list for each possible action
200 	CmdListData *_cmdList;
201 	uint16 _numCmdList;
202 
203 	//! commands list for areas
204 	CmdArea *_cmdArea;
205 	uint16 _numCmdArea;
206 
207 	//! commands list for objects
208 	CmdObject *_cmdObject;
209 	uint16 _numCmdObject;
210 
211 	//! commands list for inventory
212 	CmdInventory *_cmdInventory;
213 	uint16 _numCmdInventory;
214 
215 	//! commands list for gamestate
216 	CmdGameState *_cmdGameState;
217 	uint16 _numCmdGameState;
218 
219 	//! textual form of the command (displayed between room and panel areas)
220 	CmdText *_cmdText;
221 
222 	//! flag indicating that the current command is fully constructed
223 	bool _parse;
224 
225 	//! state of current constructed command
226 	CmdState _state;
227 
228 	//! last user selection
229 	int _mouseKey, _selPosX, _selPosY;
230 
231 	QueenEngine *_vm;
232 };
233 
234 } // End of namespace Queen
235 
236 #endif
237