~ubuntu-branches/debian/jessie/scummvm/jessie

« back to all changes in this revision

Viewing changes to engines/tsage/debugger.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * $URL$
 
22
 * $Id$
 
23
 *
 
24
 */
 
25
 
 
26
#include "tsage/debugger.h"
 
27
#include "tsage/globals.h"
 
28
#include "tsage/graphics.h"
 
29
#include "tsage/ringworld_logic.h"
 
30
 
 
31
namespace tSage {
 
32
 
 
33
Debugger::Debugger() : GUI::Debugger() {
 
34
        DCmd_Register("continue",               WRAP_METHOD(Debugger, Cmd_Exit));
 
35
        DCmd_Register("scene",                  WRAP_METHOD(Debugger, Cmd_Scene));
 
36
        DCmd_Register("walk_regions",   WRAP_METHOD(Debugger, Cmd_WalkRegions));
 
37
        DCmd_Register("priority_regions",       WRAP_METHOD(Debugger, Cmd_PriorityRegions));
 
38
        DCmd_Register("setflag",                WRAP_METHOD(Debugger, Cmd_SetFlag));
 
39
        DCmd_Register("getflag",                WRAP_METHOD(Debugger, Cmd_GetFlag));
 
40
        DCmd_Register("clearflag",              WRAP_METHOD(Debugger, Cmd_ClearFlag));
 
41
        DCmd_Register("listobjects",    WRAP_METHOD(Debugger, Cmd_ListObjects));
 
42
        DCmd_Register("moveobject",             WRAP_METHOD(Debugger, Cmd_MoveObject));
 
43
 
 
44
        DCmd_Register("item",                   WRAP_METHOD(Debugger, Cmd_Item));
 
45
}
 
46
 
 
47
static int strToInt(const char *s) {
 
48
        if (!*s)
 
49
                // No string at all
 
50
                return 0;
 
51
        else if (toupper(s[strlen(s) - 1]) != 'H')
 
52
                // Standard decimal string
 
53
                return atoi(s);
 
54
 
 
55
        // Hexadecimal string
 
56
        uint tmp = 0;
 
57
        int read = sscanf(s, "%xh", &tmp);
 
58
        if (read < 1)
 
59
                error("strToInt failed on string \"%s\"", s);
 
60
        return (int)tmp;
 
61
}
 
62
 
 
63
/**
 
64
 * This command loads up the specified new scene number
 
65
 */
 
66
bool Debugger::Cmd_Scene(int argc, const char **argv) {
 
67
        if (argc < 2) {
 
68
                DebugPrintf("Usage: %s <scene number> [prior scene #]\n", argv[0]);
 
69
                return true;
 
70
        } else {
 
71
                if (argc == 3)
 
72
                        _globals->_sceneManager._sceneNumber = strToInt(argv[2]);
 
73
 
 
74
                _globals->_sceneManager.changeScene(strToInt(argv[1]));
 
75
                return false;
 
76
        }
 
77
}
 
78
 
 
79
/**
 
80
 * This command draws the walk regions onto the screen
 
81
 */
 
82
bool Debugger::Cmd_WalkRegions(int argc, const char **argv) {
 
83
        if (argc != 1) {
 
84
                DebugPrintf("Usage: %s\n", argv[0]);
 
85
                return true;
 
86
        }
 
87
 
 
88
        // Color index to use for the first walk region
 
89
        int color = 16;
 
90
 
 
91
        // Lock the background surface for access
 
92
        Graphics::Surface destSurface = _globals->_sceneManager._scene->_backSurface.lockSurface();
 
93
 
 
94
        // Loop through drawing each walk region in a different color to the background surface
 
95
        Common::String regionsDesc;
 
96
 
 
97
        for (uint regionIndex = 0; regionIndex < _globals->_walkRegions._regionList.size(); ++regionIndex, ++color) {
 
98
                WalkRegion &wr = _globals->_walkRegions._regionList[regionIndex];
 
99
 
 
100
                for (int yp = wr._bounds.top; yp < wr._bounds.bottom; ++yp) {
 
101
                        LineSliceSet sliceSet = wr.getLineSlices(yp);
 
102
 
 
103
                        for (uint idx = 0; idx < sliceSet.items.size(); ++idx)
 
104
                                destSurface.hLine(sliceSet.items[idx].xs - _globals->_sceneOffset.x, yp,
 
105
                                sliceSet.items[idx].xe - _globals->_sceneOffset.x, color);
 
106
                }
 
107
 
 
108
                regionsDesc += Common::String::format("Region #%d d bounds=%d,%d,%d,%d\n",
 
109
                                        regionIndex, wr._bounds.left, wr._bounds.top, wr._bounds.right, wr._bounds.bottom);
 
110
        }
 
111
 
 
112
        // Release the surface
 
113
        _globals->_sceneManager._scene->_backSurface.unlockSurface();
 
114
 
 
115
        // Mark the scene as requiring a full redraw
 
116
        _globals->_paneRefreshFlag[0] = 2;
 
117
 
 
118
        DebugPrintf("Total regions = %d\n", _globals->_walkRegions._regionList.size());
 
119
        DebugPrintf("%s\n", regionsDesc.c_str());
 
120
 
 
121
        return false;
 
122
}
 
123
 
 
124
/*
 
125
 * This command draws the priority regions onto the screen
 
126
 */
 
127
bool Debugger::Cmd_PriorityRegions(int argc, const char **argv) {
 
128
        int regionNum = 0;
 
129
 
 
130
        // Check for an optional specific region to display
 
131
        if (argc == 2)
 
132
                regionNum = strToInt(argv[1]);
 
133
 
 
134
        // Color index to use for the first priority region
 
135
        int color = 16;
 
136
        int count = 0;
 
137
 
 
138
        // Lock the background surface for access
 
139
        Graphics::Surface destSurface = _globals->_sceneManager._scene->_backSurface.lockSurface();
 
140
 
 
141
        Common::List<Region>::iterator i = _globals->_sceneManager._scene->_priorities.begin();
 
142
        Common::String regionsDesc;
 
143
 
 
144
        for (; i != _globals->_sceneManager._scene->_priorities.end(); ++i, ++color, ++count) {
 
145
                Region &r = *i;
 
146
 
 
147
                if ((regionNum == 0) || (regionNum == (count + 1))) {
 
148
                        for (int y = 0; y < destSurface.h; ++y) {
 
149
                                byte *destP = (byte *)destSurface.getBasePtr(0, y);
 
150
 
 
151
                                for (int x = 0; x < destSurface.w; ++x) {
 
152
                                        if (r.contains(Common::Point(_globals->_sceneManager._scene->_sceneBounds.left + x,
 
153
                                                        _globals->_sceneManager._scene->_sceneBounds.top + y)))
 
154
                                                *destP = color;
 
155
                                        ++destP;
 
156
                                }
 
157
                        }
 
158
                }
 
159
 
 
160
                regionsDesc += Common::String::format("Region Priority = %d bounds=%d,%d,%d,%d\n",
 
161
                        r._regionId, r._bounds.left, r._bounds.top, r._bounds.right, r._bounds.bottom);
 
162
        }
 
163
 
 
164
        // Release the surface
 
165
        _globals->_sceneManager._scene->_backSurface.unlockSurface();
 
166
 
 
167
        // Mark the scene as requiring a full redraw
 
168
        _globals->_paneRefreshFlag[0] = 2;
 
169
 
 
170
        DebugPrintf("Total regions = %d\n", count);
 
171
        DebugPrintf("%s", regionsDesc.c_str());
 
172
 
 
173
        return true;
 
174
}
 
175
 
 
176
/*
 
177
 * This command sets a flag
 
178
 */
 
179
bool Debugger::Cmd_SetFlag(int argc, const char **argv) {
 
180
        // Check for a flag to set
 
181
        if (argc != 2) {
 
182
                DebugPrintf("Usage: %s <flag number>\n", argv[0]);
 
183
                return true;
 
184
        }
 
185
 
 
186
        int flagNum = strToInt(argv[1]);
 
187
        _globals->setFlag(flagNum);
 
188
        return true;
 
189
}
 
190
 
 
191
/*
 
192
 * This command gets the value of a flag
 
193
 */
 
194
bool Debugger::Cmd_GetFlag(int argc, const char **argv) {
 
195
        // Check for an flag to display
 
196
        if (argc != 2) {
 
197
                DebugPrintf("Usage: %s <flag number>\n", argv[0]);
 
198
                return true;
 
199
        }
 
200
 
 
201
        int flagNum = strToInt(argv[1]);
 
202
        DebugPrintf("Value: %d\n", _globals->getFlag(flagNum));
 
203
        return true;
 
204
}
 
205
 
 
206
/*
 
207
 * This command clears a flag
 
208
 */
 
209
bool Debugger::Cmd_ClearFlag(int argc, const char **argv) {
 
210
        // Check for a flag to clear
 
211
        if (argc != 2) {
 
212
                DebugPrintf("Usage: %s <flag number>\n", argv[0]);
 
213
                return true;
 
214
        }
 
215
 
 
216
        int flagNum = strToInt(argv[1]);
 
217
        _globals->clearFlag(flagNum);
 
218
        return true;
 
219
}
 
220
 
 
221
/*
 
222
 * This command lists the objects available, and their ID
 
223
 */
 
224
bool Debugger::Cmd_ListObjects(int argc, const char **argv) {
 
225
        if (argc != 1) {
 
226
                DebugPrintf("Usage: %s\n", argv[0]);
 
227
                return true;
 
228
        }
 
229
        
 
230
        DebugPrintf("Available objects for this game are:\n");
 
231
        DebugPrintf("0 - Stunner\n");
 
232
        DebugPrintf("1 - Scanner\n");
 
233
        DebugPrintf("2 - Stasis Box\n");
 
234
        DebugPrintf("3 - Info Disk\n");
 
235
        DebugPrintf("4 - Stasis Negator\n");
 
236
        DebugPrintf("5 - Key Device\n");
 
237
        DebugPrintf("6 - Medkit\n");
 
238
        DebugPrintf("7 - Ladder\n");
 
239
        DebugPrintf("8 - Rope\n");
 
240
        DebugPrintf("9 - Key\n");
 
241
        DebugPrintf("10 - Translator\n");
 
242
        DebugPrintf("11 - Ale\n");
 
243
        DebugPrintf("12 - Paper\n");
 
244
        DebugPrintf("13 - Waldos\n");
 
245
        DebugPrintf("14 - Stasis Box 2\n");
 
246
        DebugPrintf("15 - Ring\n");
 
247
        DebugPrintf("16 - Cloak\n");
 
248
        DebugPrintf("17 - Tunic\n");
 
249
        DebugPrintf("18 - Candle\n");
 
250
        DebugPrintf("19 - Straw\n");
 
251
        DebugPrintf("20 - Scimitar\n");
 
252
        DebugPrintf("21 - Sword\n");
 
253
        DebugPrintf("22 - Helmet\n");
 
254
        DebugPrintf("23 - Items\n");
 
255
        DebugPrintf("24 - Concentrator\n");
 
256
        DebugPrintf("25 - Nullifier\n");
 
257
        DebugPrintf("26 - Peg\n");
 
258
        DebugPrintf("27 - Vial\n");
 
259
        DebugPrintf("28 - Jacket\n");
 
260
        DebugPrintf("29 - Tunic 2\n");
 
261
        DebugPrintf("30 - Bone\n");
 
262
        DebugPrintf("31 - Empty Jar\n");
 
263
        DebugPrintf("32 - Jar\n");
 
264
        return true;
 
265
}
 
266
 
 
267
/*
 
268
 * This command gets an item, or move it to a room
 
269
 */
 
270
bool Debugger::Cmd_MoveObject(int argc, const char **argv) {
 
271
        // Check for a flag to clear
 
272
        if ((argc < 2) || (argc > 3)){
 
273
                DebugPrintf("Usage: %s <object number> [<scene number>]\n", argv[0]);
 
274
                DebugPrintf("If no scene is specified, the object will be added to inventory\n");
 
275
                return true;
 
276
        }
 
277
 
 
278
        int objNum = strToInt(argv[1]);
 
279
        int sceneNum = 1;
 
280
        if (argc == 3)
 
281
                sceneNum = strToInt(argv[2]);
 
282
 
 
283
        switch (objNum) {
 
284
        case OBJECT_STUNNER:
 
285
                RING_INVENTORY._stunner._sceneNumber = sceneNum;
 
286
                break;
 
287
        case OBJECT_SCANNER:
 
288
                RING_INVENTORY._scanner._sceneNumber = sceneNum;
 
289
                break;
 
290
        case OBJECT_STASIS_BOX:
 
291
                RING_INVENTORY._stasisBox._sceneNumber = sceneNum;
 
292
                break;
 
293
        case OBJECT_INFODISK:
 
294
                RING_INVENTORY._infoDisk._sceneNumber = sceneNum;
 
295
                break;
 
296
        case OBJECT_STASIS_NEGATOR:
 
297
                RING_INVENTORY._stasisNegator._sceneNumber = sceneNum;
 
298
                break;
 
299
        case OBJECT_KEY_DEVICE:
 
300
                RING_INVENTORY._keyDevice._sceneNumber = sceneNum;
 
301
                break;
 
302
        case OBJECT_MEDKIT:
 
303
                RING_INVENTORY._medkit._sceneNumber = sceneNum;
 
304
                break;
 
305
        case OBJECT_LADDER:
 
306
                RING_INVENTORY._ladder._sceneNumber = sceneNum;
 
307
                break;
 
308
        case OBJECT_ROPE:
 
309
                RING_INVENTORY._rope._sceneNumber = sceneNum;
 
310
                break;
 
311
        case OBJECT_KEY:
 
312
                RING_INVENTORY._key._sceneNumber = sceneNum;
 
313
                break;
 
314
        case OBJECT_TRANSLATOR:
 
315
                RING_INVENTORY._translator._sceneNumber = sceneNum;
 
316
                break;
 
317
        case OBJECT_ALE:
 
318
                RING_INVENTORY._ale._sceneNumber = sceneNum;
 
319
                break;
 
320
        case OBJECT_PAPER:
 
321
                RING_INVENTORY._paper._sceneNumber = sceneNum;
 
322
                break;
 
323
        case OBJECT_WALDOS:
 
324
                RING_INVENTORY._waldos._sceneNumber = sceneNum;
 
325
                break;
 
326
        case OBJECT_STASIS_BOX2:
 
327
                RING_INVENTORY._stasisBox2._sceneNumber = sceneNum;
 
328
                break;
 
329
        case OBJECT_RING:
 
330
                RING_INVENTORY._ring._sceneNumber = sceneNum;
 
331
                break;
 
332
        case OBJECT_CLOAK:
 
333
                RING_INVENTORY._cloak._sceneNumber = sceneNum;
 
334
                break;
 
335
        case OBJECT_TUNIC:
 
336
                RING_INVENTORY._tunic._sceneNumber = sceneNum;
 
337
                break;
 
338
        case OBJECT_CANDLE:
 
339
                RING_INVENTORY._candle._sceneNumber = sceneNum;
 
340
                break;
 
341
        case OBJECT_STRAW:
 
342
                RING_INVENTORY._straw._sceneNumber = sceneNum;
 
343
                break;
 
344
        case OBJECT_SCIMITAR:
 
345
                RING_INVENTORY._scimitar._sceneNumber = sceneNum;
 
346
                break;
 
347
        case OBJECT_SWORD:
 
348
                RING_INVENTORY._sword._sceneNumber = sceneNum;
 
349
                break;
 
350
        case OBJECT_HELMET:
 
351
                RING_INVENTORY._helmet._sceneNumber = sceneNum;
 
352
                break;
 
353
        case OBJECT_ITEMS:
 
354
                RING_INVENTORY._items._sceneNumber = sceneNum;
 
355
                break;
 
356
        case OBJECT_CONCENTRATOR:
 
357
                RING_INVENTORY._concentrator._sceneNumber = sceneNum;
 
358
                break;
 
359
        case OBJECT_NULLIFIER:
 
360
                RING_INVENTORY._nullifier._sceneNumber = sceneNum;
 
361
                break;
 
362
        case OBJECT_PEG:
 
363
                RING_INVENTORY._peg._sceneNumber = sceneNum;
 
364
                break;
 
365
        case OBJECT_VIAL:
 
366
                RING_INVENTORY._vial._sceneNumber = sceneNum;
 
367
                break;
 
368
        case OBJECT_JACKET:
 
369
                RING_INVENTORY._jacket._sceneNumber = sceneNum;
 
370
                break;
 
371
        case OBJECT_TUNIC2:
 
372
                RING_INVENTORY._tunic2._sceneNumber = sceneNum;
 
373
                break;
 
374
        case OBJECT_BONE:
 
375
                RING_INVENTORY._bone._sceneNumber = sceneNum;
 
376
                break;
 
377
        case OBJECT_EMPTY_JAR:
 
378
                RING_INVENTORY._emptyJar._sceneNumber = sceneNum;
 
379
                break;
 
380
        case OBJECT_JAR:
 
381
                RING_INVENTORY._jar._sceneNumber = sceneNum;
 
382
                break;
 
383
        default:
 
384
                DebugPrintf("Invlid object Id %s\n", argv[1]);
 
385
        }
 
386
 
 
387
        return true;
 
388
}
 
389
 
 
390
/**
 
391
 * Give a specified item to the player
 
392
 */
 
393
bool Debugger::Cmd_Item(int argc, const char **argv) {
 
394
        RING_INVENTORY._stasisBox._sceneNumber = 1;
 
395
        return true;
 
396
}
 
397
 
 
398
 
 
399
} // End of namespace tSage