1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "m4/m4.h"
#include "m4/console.h"
#include "m4/scene.h"
#include "m4/staticres.h"
namespace M4 {
Console::Console(M4Engine *vm) : GUI::Debugger() {
_vm = vm;
DCmd_Register("scene", WRAP_METHOD(Console, cmdLoadScene));
DCmd_Register("start", WRAP_METHOD(Console, cmdStartingScene));
DCmd_Register("scene_info", WRAP_METHOD(Console, cmdSceneInfo));
DCmd_Register("show_hotspots", WRAP_METHOD(Console, cmdShowHotSpots));
DCmd_Register("list_hotspots", WRAP_METHOD(Console, cmdListHotSpots));
DCmd_Register("play_sound", WRAP_METHOD(Console, cmdPlaySound));
DCmd_Register("play_dsr_sound", WRAP_METHOD(Console, cmdPlayDSRSound));
DCmd_Register("show_resources", WRAP_METHOD(Console, cmdShowResources));
DCmd_Register("show_codes", WRAP_METHOD(Console, cmdShowCodes));
DCmd_Register("dump_file", WRAP_METHOD(Console, cmdDumpFile));
DCmd_Register("sprite", WRAP_METHOD(Console, cmdShowSprite));
DCmd_Register("start_conv", WRAP_METHOD(Console, cmdStartConversation));
DCmd_Register("textview", WRAP_METHOD(Console, cmdShowTextview));
DCmd_Register("animview", WRAP_METHOD(Console, cmdShowAnimview));
DCmd_Register("anim", WRAP_METHOD(Console, cmdPlayAnimation));
DCmd_Register("object", WRAP_METHOD(Console, cmdObject));
}
Console::~Console() {
}
static int strToInt(const char *s) {
if (!*s)
// No string at all
return 0;
else if (toupper(s[strlen(s) - 1]) != 'H')
// Standard decimal string
return atoi(s);
// Hexadecimal string
uint tmp;
sscanf(s, "%xh", &tmp);
return (int)tmp;
}
bool Console::cmdLoadScene(int argc, const char **argv) {
if (argc != 2) {
DebugPrintf("Usage: %s <scene number>\n", argv[0]);
return true;
} else {
if (_vm->isM4())
_vm->_kernel->newRoom = atoi(argv[1]);
else
_vm->_scene->loadScene(atoi(argv[1]));
return false;
}
}
bool Console::cmdStartingScene(int argc, const char **argv) {
if (_vm->getGameType() != GType_Riddle) {
if (_vm->isM4())
_vm->_kernel->newRoom = FIRST_SCENE;
else
_vm->_scene->loadScene(FIRST_SCENE);
return false;
} else {
DebugPrintf("%s: Riddle of Master Lu is not supported", argv[0]);
return true;
}
}
bool Console::cmdShowHotSpots(int argc, const char **argv) {
_vm->_scene->showHotSpots();
return false;
}
bool Console::cmdSceneInfo(int argc, const char **argv) {
DebugPrintf("Current scene is: %i\n", _vm->_scene->getCurrentScene());
if (_vm->isM4()) {
DebugPrintf("Scene resources:\n");
DebugPrintf("artBase: %s\n", _vm->_scene->getSceneResources().artBase);
DebugPrintf("pictureBase: %s\n", _vm->_scene->getSceneResources().pictureBase);
DebugPrintf("hotspotCount: %i\n", _vm->_scene->getSceneResources().hotspotCount);
DebugPrintf("parallaxCount: %i\n", _vm->_scene->getSceneResources().parallaxCount);
DebugPrintf("propsCount: %i\n", _vm->_scene->getSceneResources().propsCount);
DebugPrintf("frontY: %i\n", _vm->_scene->getSceneResources().frontY);
DebugPrintf("backY: %i\n", _vm->_scene->getSceneResources().backY);
DebugPrintf("frontScale: %i\n", _vm->_scene->getSceneResources().frontScale);
DebugPrintf("backScale: %i\n", _vm->_scene->getSceneResources().backScale);
DebugPrintf("depthTable: ");
for (uint i = 0; i < 16; i++)
DebugPrintf("%i ", _vm->_scene->getSceneResources().depthTable[i]);
DebugPrintf("\n");
DebugPrintf("railNodeCount: %i\n", _vm->_scene->getSceneResources().railNodeCount);
}
return true;
}
bool Console::cmdListHotSpots(int argc, const char **argv) {
DebugPrintf("Scene hotspots\n");
_vm->_scene->getSceneResources().hotspots->dump();
if (_vm->isM4()) {
DebugPrintf("Scene parallax\n");
_vm->_scene->getSceneResources().parallax->dump();
DebugPrintf("Scene props\n");
_vm->_scene->getSceneResources().props->dump();
}
return true;
}
bool Console::cmdPlaySound(int argc, const char **argv) {
if (argc != 2) {
DebugPrintf("Usage: %s <sound file>\n", argv[0]);
} else {
_vm->_sound->playSound(argv[1], 255, false);
}
return true;
}
bool Console::cmdPlayDSRSound(int argc, const char **argv) {
if (argc != 2 && argc != 3) {
DebugPrintf("Usage: %s <sound index> <DSR file>\n", argv[0]);
DebugPrintf("The DSR file parameter is optional, and specifies which DSR to load\n", argv[0]);
} else {
if (argc == 3)
_vm->_sound->loadDSRFile(argv[2]);
_vm->_sound->playDSRSound(atoi(argv[1]), 255, false);
}
return true;
}
bool Console::cmdShowResources(int argc, const char **argv) {
_vm->res()->dump();
return true;
}
bool Console::cmdShowCodes(int argc, const char **argv) {
if (_vm->getGameType() != GType_RexNebular)
_vm->_scene->showCodes();
else
DebugPrintf("Pathfinding codes not done yet for Rex Nebular");
return false;
}
bool Console::cmdDumpFile(int argc, const char **argv) {
if (argc != 2 && argc != 3) {
DebugPrintf("Usage: %s <file> <uncompress>\n", argv[0]);
DebugPrintf("If uncompress is 1, the file is uncompressed (for MADS games)\n");
} else {
if (argc == 2) {
_vm->dumpFile(strdup(argv[1]));
} else {
if (argc == 3 && atoi(argv[2]) == 1)
_vm->dumpFile(strdup(argv[1]), true);
else
_vm->dumpFile(strdup(argv[1]));
}
}
return true;
}
bool Console::cmdShowSprite(int argc, const char **argv) {
View *view = _vm->_viewManager->getView(VIEWID_SCENE);
if (view == NULL)
DebugPrintf("The scene view isn't currently active\n");
else if (argc < 2)
DebugPrintf("Usage: %s resource_name\n", argv[0]);
else {
char resourceName[20];
strncpy(resourceName, argv[1], 15);
resourceName[15] = '\0';
if (!strchr(resourceName, '.'))
strcat(resourceName, ".SS");
_vm->_viewManager->moveToFront(view);
Common::SeekableReadStream *data = _vm->res()->get(resourceName);
SpriteAsset *asset = new SpriteAsset(_vm, data, data->size(), resourceName);
_vm->res()->toss(resourceName);
RGBList *palData = new RGBList(asset->getColorCount(), asset->getPalette(), true);
_vm->_palette->addRange(palData);
// Get the scene background surface
M4Surface *bg = _vm->_scene->getBackgroundSurface();
// Write the sprite onto the screen
int x = 0, y = 0, yMax = 0;
for (int index = 0; index < asset->getCount(); index++) {
M4Sprite *spr = asset->getFrame(index);
spr->translate(palData); // sprite pixel translation
if ((x + spr->width() >= bg->width()) && (yMax != 0)) {
x = 0;
y += yMax;
yMax = 0;
}
if (y >= bg->height())
break;
// FIXME: We assume that the transparent color is the color of the top left pixel
byte *transparentColor = (byte *)spr->pixels;
spr->copyTo(bg, x, y, (int)*transparentColor);
x += spr->width();
yMax = MAX(yMax, spr->height());
}
view->restore(0, 0, view->width(), view->height());
return false;
}
return true;
}
bool Console::cmdStartConversation(int argc, const char **argv) {
if (argc != 2) {
DebugPrintf("Usage: %s <conversation file name>\n", argv[0]);
return true;
} else {
_vm->_converse->startConversation(argv[1]);
return false;
}
}
bool Console::cmdShowTextview(int argc, const char **argv) {
if (argc != 2) {
DebugPrintf("Usage: %s <txr resource>\n", argv[0]);
return true;
}
_vm->_viewManager->showTextView(argv[1], false);
return false;
}
bool Console::cmdShowAnimview(int argc, const char **argv) {
if (argc != 2) {
DebugPrintf("Usage: %s <res resource>\n", argv[0]);
return true;
}
char resName[80];
strcpy(resName, "@");
strcat(resName, *argv[1] == '@' ? argv[1] + 1 : argv[1]);
_vm->_viewManager->showAnimView(resName, false);
return false;
}
bool Console::cmdPlayAnimation(int argc, const char **argv) {
View *view = _vm->_viewManager->getView(VIEWID_SCENE);
if (view == NULL) {
DebugPrintf("The scene view isn't currently active\n");
} else if (argc != 2 && argc != 3) {
DebugPrintf("Usage: %s <anim resource (*.aa)> <fullscreen>\n", argv[0]);
DebugPrintf("If fullscreen is 1, the screen palette is replaced with the palette of the animation\n");
} else {
char resourceName[20];
strncpy(resourceName, argv[1], 15);
resourceName[15] = '\0';
if (!strchr(resourceName, '.'))
strcat(resourceName, ".AA");
_vm->_viewManager->moveToFront(view);
if (argc == 3 && atoi(argv[2]) == 1)
_vm->_animation->loadFullScreen(resourceName);
else
_vm->_animation->load(resourceName);
_vm->_animation->start();
view->restore(0, 0, view->width(), view->height());
return false;
}
return true;
}
bool Console::cmdObject(int argc, const char **argv) {
if (_vm->isM4()) {
DebugPrintf("Command not implemented for M4 games\n");
} else if (argc == 1) {
DebugPrintf("Usage: object ['list' | '#objnum']\n");
} else if (!strcmp(argv[1], "list")) {
// List of objects
for (uint objStart = 0; objStart < _vm->_globals->getObjectsSize(); objStart += 5) {
DebugPrintf("%2d - ", objStart);
for (uint objId = objStart; objId < MIN<uint>(_vm->_globals->getObjectsSize(), objStart + 5); ++objId) {
if (objId != objStart) DebugPrintf(", ");
uint16 descId = _vm->_globals->getObject(objId)->descId;
DebugPrintf("%s", _vm->_globals->getVocab(descId));
}
DebugPrintf("\n");
}
DebugPrintf("\n");
} else {
// Print the details of a specific object
int id = strToInt(argv[1]);
if ((id < 0) || (id >= (int)_vm->_globals->getObjectsSize()))
DebugPrintf("Invalid object specified\n");
else {
const MadsObject *obj = _vm->_globals->getObject(id);
DebugPrintf("Object #%d (%s) room=%d article=%d/%s vocabs=%d", id, _vm->_globals->getVocab(obj->descId),
obj->roomNumber, (int)obj->article, englishMADSArticleList[obj->article], obj->vocabCount);
if (obj->vocabCount > 0) {
DebugPrintf(" - ");
for (int i = 0; i < obj->vocabCount; ++i) {
if (i != 0) DebugPrintf(", ");
DebugPrintf("%s (%d)/%d", _vm->_globals->getVocab(obj->vocabList[i].vocabId),
obj->vocabList[i].vocabId, obj->vocabList[i].unk);
}
}
DebugPrintf("\n");
}
}
return true;
}
} // End of namespace M4
|