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
24 #include "common/system.h"
25
26 #include "parallaction/parallaction.h"
27 #include "parallaction/debug.h"
28
29 namespace Parallaction {
30
31
Debugger(Parallaction * vm)32 Debugger::Debugger(Parallaction *vm)
33 : GUI::Debugger() {
34 _vm = vm;
35 _mouseState = MOUSE_ENABLED_SHOW;
36
37 registerCmd("continue", WRAP_METHOD(Debugger, cmdExit));
38 registerCmd("location", WRAP_METHOD(Debugger, Cmd_Location));
39 registerCmd("give", WRAP_METHOD(Debugger, Cmd_Give));
40 registerCmd("zones", WRAP_METHOD(Debugger, Cmd_Zones));
41 registerCmd("animations", WRAP_METHOD(Debugger, Cmd_Animations));
42 registerCmd("globalflags",WRAP_METHOD(Debugger, Cmd_GlobalFlags));
43 registerCmd("toggleglobalflag",WRAP_METHOD(Debugger, Cmd_ToggleGlobalFlag));
44 registerCmd("localflags", WRAP_METHOD(Debugger, Cmd_LocalFlags));
45 registerCmd("locations", WRAP_METHOD(Debugger, Cmd_Locations));
46 registerCmd("gfxobjects", WRAP_METHOD(Debugger, Cmd_GfxObjects));
47 registerCmd("programs", WRAP_METHOD(Debugger, Cmd_Programs));
48 registerCmd("showmouse", WRAP_METHOD(Debugger, Cmd_ShowMouse));
49 }
50
51
preEnter()52 void Debugger::preEnter() {
53 _mouseState = _vm->_input->getMouseState();
54 _vm->pauseEngine(true);
55 }
56
57
postEnter()58 void Debugger::postEnter() {
59 _vm->pauseEngine(false);
60 _vm->_input->setMouseState(_mouseState);
61 _vm->_input->setArrowCursor(); // unselects the active item, if any
62 }
63
Cmd_Location(int argc,const char ** argv)64 bool Debugger::Cmd_Location(int argc, const char **argv) {
65
66 const char *character; // = _vm->_char.getName();
67 const char *location; // = _vm->_location._name;
68
69 char tmp[PATH_LEN];
70
71 switch (argc) {
72 case 3:
73 character = const_cast<char *>(argv[2]);
74 location = const_cast<char *>(argv[1]);
75 sprintf(tmp, "%s.%s", location, character);
76 _vm->scheduleLocationSwitch(tmp);
77 break;
78
79 case 2:
80 location = const_cast<char *>(argv[1]);
81 _vm->scheduleLocationSwitch(location);
82 break;
83
84 case 1:
85 debugPrintf("location <location name> [character name]\n");
86
87 }
88
89 return true;
90 }
91
Cmd_Locations(int argc,const char ** argv)92 bool Debugger::Cmd_Locations(int argc, const char **argv) {
93
94 debugPrintf("+------------------------------+---------+\n"
95 "| location name | flags |\n"
96 "+------------------------------+---------+\n");
97 for (uint i = 0; i < _vm->_numLocations; i++) {
98 debugPrintf("|%-30s| %08x|\n", _vm->_locationNames[i], _vm->_localFlags[i]);
99 }
100 debugPrintf("+------------------------------+---------+\n");
101
102 return true;
103 }
104
Cmd_GlobalFlags(int argc,const char ** argv)105 bool Debugger::Cmd_GlobalFlags(int argc, const char **argv) {
106
107 uint32 flags = g_globalFlags;
108
109 debugPrintf("+------------------------------+---------+\n"
110 "| flag name | value |\n"
111 "+------------------------------+---------+\n");
112 for (uint i = 0; i < _vm->_globalFlagsNames->count(); i++) {
113 const char *value = ((flags & (1 << i)) == 0) ? "OFF" : "ON";
114 debugPrintf("|%-30s| %-6s|\n", _vm->_globalFlagsNames->item(i), value);
115 }
116 debugPrintf("+------------------------------+---------+\n");
117
118 return true;
119 }
120
Cmd_ToggleGlobalFlag(int argc,const char ** argv)121 bool Debugger::Cmd_ToggleGlobalFlag(int argc, const char **argv) {
122
123 int i;
124
125 switch (argc) {
126 case 2:
127 i = _vm->_globalFlagsNames->lookup(argv[1]);
128 if (i == Table::notFound) {
129 debugPrintf("invalid flag '%s'\n", argv[1]);
130 } else {
131 i--;
132 if ((g_globalFlags & (1 << i)) == 0)
133 g_globalFlags |= (1 << i);
134 else
135 g_globalFlags &= ~(1 << i);
136 }
137 break;
138
139 default:
140 debugPrintf("toggleglobalflag <flag name>\n");
141
142 }
143
144 return true;
145 }
146
Cmd_LocalFlags(int argc,const char ** argv)147 bool Debugger::Cmd_LocalFlags(int argc, const char **argv) {
148
149 uint32 flags = _vm->getLocationFlags();
150
151 debugPrintf("+------------------------------+---------+\n"
152 "| flag name | value |\n"
153 "+------------------------------+---------+\n");
154 for (uint i = 0; i < _vm->_localFlagNames->count(); i++) {
155 const char *value = ((flags & (1 << i)) == 0) ? "OFF" : "ON";
156 debugPrintf("|%-30s| %-6s|\n", _vm->_localFlagNames->item(i), value);
157 }
158 debugPrintf("+------------------------------+---------+\n");
159
160 return true;
161 }
162
Cmd_Give(int argc,const char ** argv)163 bool Debugger::Cmd_Give(int argc, const char **argv) {
164
165 if (argc == 1) {
166 debugPrintf("give <item name>\n");
167 } else {
168 int index = _vm->_objectsNames->lookup(argv[1]);
169 if (index != Table::notFound)
170 _vm->addInventoryItem(index + 4);
171 else
172 debugPrintf("invalid item name '%s'\n", argv[1]);
173 }
174
175 return true;
176 }
177
178
Cmd_Zones(int argc,const char ** argv)179 bool Debugger::Cmd_Zones(int argc, const char **argv) {
180
181 ZoneList::iterator b = _vm->_location._zones.begin();
182 ZoneList::iterator e = _vm->_location._zones.end();
183 Common::Rect r;
184
185 debugPrintf("+--------------------+---+---+---+---+--------+--------+\n"
186 "| name | l | t | r | b | type | flag |\n"
187 "+--------------------+---+---+---+---+--------+--------+\n");
188 for ( ; b != e; ++b) {
189 ZonePtr z = *b;
190 z->getRect(r);
191 debugPrintf("|%-20s|%3i|%3i|%3i|%3i|%8x|%8x|\n", z->_name, r.left, r.top, r.right, r.bottom, z->_type, z->_flags );
192 }
193 debugPrintf("+--------------------+---+---+---+---+--------+--------+\n");
194
195
196 return true;
197 }
198
decodeZoneFlags(uint32 flags)199 Common::String Debugger::decodeZoneFlags(uint32 flags) {
200 const char *descs[33] = {
201 "none", // 0
202 "closed", // 1
203 "active", // 2
204 "remove", // 4
205 "acting", // 8
206 "locked", // 0x10
207 "fixed", // 0x20
208 "noname", // 0x40
209 "nomasked", // 0x80
210 "looping", // 0x100
211 "added", // 0x200
212 "character",// 0x400
213 "nowalk", // 0x800
214 "yourself", // 0x1000
215 "scaled", // 0x2000
216 "selfuse", // 0x4000
217 "0x8000", // 0x8000
218 "0x10000",
219 "0x20000",
220 "0x40000",
221 "0x80000",
222 "0x100000",
223 "0x200000",
224 "0x400000",
225 "0x800000",
226 "isanimation", // 0x1000000
227 "animlinked", // 0x2000000
228 "0x4000000",
229 "0x8000000",
230 "0x10000000",
231 "0x20000000",
232 "0x40000000",
233 "0x80000000"
234 };
235
236 uint32 mask = 1;
237 const char *matches[32];
238 uint numMatches = 0;
239 for (uint32 i = 1; i < 32; i++, mask<<=1) {
240 if (flags & mask) {
241 matches[numMatches] = descs[i];
242 numMatches++;
243 }
244 }
245 if (numMatches == 0) {
246 matches[0] = descs[0];
247 numMatches = 1;
248 }
249
250 Common::String s(matches[0]);
251 for (uint32 j = 1; j < numMatches; j++) {
252 s += '+';
253 s += matches[j];
254 }
255 return s;
256 }
257
Cmd_Animations(int argc,const char ** argv)258 bool Debugger::Cmd_Animations(int argc, const char **argv) {
259
260 AnimationList::iterator b = _vm->_location._animations.begin();
261 AnimationList::iterator e = _vm->_location._animations.end();
262 Common::String flags;
263
264 debugPrintf("+--------------------+----+----+----+---+--------+----------------------------------------+\n"
265 "| name | x | y | z | f | type | flags | \n"
266 "+--------------------+----+----+----+---+--------+----------------------------------------+\n");
267 for ( ; b != e; ++b) {
268 AnimationPtr a = *b;
269 flags = decodeZoneFlags(a->_flags);
270 debugPrintf("|%-20s|%4i|%4i|%4i|%3i|%8x|%-40s|\n", a->_name, a->getX(), a->getY(), a->getZ(), a->getF(), a->_type, flags.c_str() );
271 }
272 debugPrintf("+--------------------+---+---+---+---+--------+----------------------------------------+\n");
273
274
275 return true;
276 }
277
Cmd_GfxObjects(int argc,const char ** argv)278 bool Debugger::Cmd_GfxObjects(int argc, const char **argv) {
279
280 const char *objType[] = { "DOOR", "GET", "ANIM" };
281
282 debugPrintf("+--------------------+-----+-----+-----+-----+-----+-------+-----+--------+\n"
283 "| name | x | y | w | h | z | layer | f | type |\n"
284 "+--------------------+-----+-----+-----+-----+-----+-------+-----+--------+\n");
285
286 GfxObjArray::iterator b = _vm->_gfx->_sceneObjects.begin();
287 GfxObjArray::iterator e = _vm->_gfx->_sceneObjects.end();
288 Common::Rect r;
289
290 for ( ; b != e; ++b) {
291 GfxObj *obj = *b;
292 obj->getRect(obj->frame, r);
293 debugPrintf("|%-20s|%5i|%5i|%5i|%5i|%5i|%7i|%5i|%8s|\n", obj->getName(), r.left, r.top, r.width(), r.height(),
294 obj->z, obj->layer, obj->frame, objType[obj->type]);
295 }
296
297 debugPrintf("+--------------------+-----+-----+-----+-----+-----+-------+-----+--------+\n");
298
299 return true;
300 }
301
Cmd_Programs(int argc,const char ** argv)302 bool Debugger::Cmd_Programs(int argc, const char** argv) {
303
304 ProgramList::iterator b = _vm->_location._programs.begin();
305 ProgramList::iterator e = _vm->_location._programs.end();
306
307 const char *status[] = { "idle", "running", "completed" };
308
309 int i = 1;
310
311 debugPrintf("+---+--------------------+--------+----------+\n"
312 "| # | bound animation | size | status |\n"
313 "+---+--------------------+--------+----------+\n");
314 for ( ; b != e; b++, i++) {
315 ProgramPtr p = *b;
316 debugPrintf("|%3i|%-20s|%8i|%-10s|\n", i, p->_anim->_name, p->_instructions.size(), status[p->_status] );
317 }
318 debugPrintf("+---+--------------------+--------+----------+\n");
319
320 return true;
321 }
322
Cmd_ShowMouse(int argc,const char ** argv)323 bool Debugger::Cmd_ShowMouse(int argc, const char** argv) {
324 _mouseState = MOUSE_ENABLED_SHOW;
325 return true;
326 }
327
328 } // namespace Parallaction
329