/* 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 3 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, see .
*
*/
#include "tsage/debugger.h"
#include "tsage/globals.h"
#include "tsage/graphics.h"
#include "tsage/ringworld/ringworld_logic.h"
#include "tsage/blue_force/blueforce_logic.h"
#include "tsage/ringworld2/ringworld2_logic.h"
namespace TsAGE {
Debugger::Debugger() : GUI::Debugger() {
registerCmd("continue", WRAP_METHOD(Debugger, cmdExit));
registerCmd("scene", WRAP_METHOD(Debugger, Cmd_Scene));
registerCmd("walk_regions", WRAP_METHOD(Debugger, Cmd_WalkRegions));
registerCmd("priority_regions", WRAP_METHOD(Debugger, Cmd_PriorityRegions));
registerCmd("scene_regions", WRAP_METHOD(Debugger, Cmd_SceneRegions));
registerCmd("setflag", WRAP_METHOD(Debugger, Cmd_SetFlag));
registerCmd("getflag", WRAP_METHOD(Debugger, Cmd_GetFlag));
registerCmd("clearflag", WRAP_METHOD(Debugger, Cmd_ClearFlag));
registerCmd("listobjects", WRAP_METHOD(Debugger, Cmd_ListObjects));
registerCmd("moveobject", WRAP_METHOD(Debugger, Cmd_MoveObject));
registerCmd("hotspots", WRAP_METHOD(Debugger, Cmd_Hotspots));
registerCmd("sound", WRAP_METHOD(Debugger, Cmd_Sound));
registerCmd("setdebug", WRAP_METHOD(Debugger, Cmd_SetOutpostAlphaDebug));
}
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 = 0;
int read = sscanf(s, "%xh", &tmp);
if (read < 1)
error("strToInt failed on string \"%s\"", s);
return (int)tmp;
}
/**
* This command loads up the specified new scene number
*/
bool Debugger::Cmd_Scene(int argc, const char **argv) {
if (argc < 2) {
debugPrintf("Usage: %s [prior scene #]\n", argv[0]);
return true;
}
if (argc == 3)
g_globals->_sceneManager._sceneNumber = strToInt(argv[2]);
g_globals->_sceneManager.changeScene(strToInt(argv[1]));
return false;
}
/**
* This command draws the walk regions onto the screen
*/
bool Debugger::Cmd_WalkRegions(int argc, const char **argv) {
if (argc != 1) {
debugPrintf("Usage: %s\n", argv[0]);
return true;
}
// Color index to use for the first walk region
int color = 16;
// Lock the background surface for access
Graphics::Surface destSurface = g_globals->_sceneManager._scene->_backSurface.lockSurface();
// Loop through drawing each walk region in a different color to the background surface
Common::String regionsDesc;
for (uint regionIndex = 0; regionIndex < g_globals->_walkRegions._regionList.size(); ++regionIndex, ++color) {
WalkRegion &wr = g_globals->_walkRegions._regionList[regionIndex];
// Skip the region if it's in the list of explicitly disabled regions
if (contains(g_globals->_walkRegions._disabledRegions, (int)regionIndex + 1))
continue;
for (int yp = wr._bounds.top; yp < wr._bounds.bottom; ++yp) {
LineSliceSet sliceSet = wr.getLineSlices(yp);
for (uint idx = 0; idx < sliceSet.items.size(); ++idx)
destSurface.hLine(sliceSet.items[idx].xs - g_globals->_sceneOffset.x, yp,
sliceSet.items[idx].xe - g_globals->_sceneOffset.x, color);
}
regionsDesc += Common::String::format("Region #%d d bounds=%d,%d,%d,%d\n",
regionIndex, wr._bounds.left, wr._bounds.top, wr._bounds.right, wr._bounds.bottom);
}
// Release the surface
g_globals->_sceneManager._scene->_backSurface.unlockSurface();
// Mark the scene as requiring a full redraw
g_globals->_paneRefreshFlag[0] = 2;
debugPrintf("Total regions = %d\n", g_globals->_walkRegions._regionList.size());
debugPrintf("%s\n", regionsDesc.c_str());
return false;
}
/*
* This command draws the priority regions onto the screen
*/
bool Debugger::Cmd_PriorityRegions(int argc, const char **argv) {
int regionNum = 0;
// Check for an optional specific region to display
if (argc == 2)
regionNum = strToInt(argv[1]);
// Color index to use for the first priority region
int color = 16;
int count = 0;
// Lock the background surface for access
Graphics::Surface destSurface = g_globals->_sceneManager._scene->_backSurface.lockSurface();
Common::List::iterator i = g_globals->_sceneManager._scene->_priorities.begin();
Common::String regionsDesc;
for (; i != g_globals->_sceneManager._scene->_priorities.end(); ++i, ++color, ++count) {
Region &r = *i;
if ((regionNum == 0) || (regionNum == (count + 1))) {
for (int y = 0; y < destSurface.h; ++y) {
byte *destP = (byte *)destSurface.getBasePtr(0, y);
for (int x = 0; x < destSurface.w; ++x) {
if (r.contains(Common::Point(g_globals->_sceneManager._scene->_sceneBounds.left + x,
g_globals->_sceneManager._scene->_sceneBounds.top + y)))
*destP = color;
++destP;
}
}
}
regionsDesc += Common::String::format("Region Priority = %d bounds=%d,%d,%d,%d\n",
r._regionId, r._bounds.left, r._bounds.top, r._bounds.right, r._bounds.bottom);
}
// Release the surface
g_globals->_sceneManager._scene->_backSurface.unlockSurface();
// Mark the scene as requiring a full redraw
g_globals->_paneRefreshFlag[0] = 2;
debugPrintf("Total regions = %d\n", count);
debugPrintf("%s", regionsDesc.c_str());
return true;
}
/*
* This command draws the scene regions onto the screen. These are the regions
* used by hotspots that have non-rectangular areas.
*/
bool Debugger::Cmd_SceneRegions(int argc, const char **argv) {
int regionNum = 0;
// Check for an optional specific region to display
if (argc == 2)
regionNum = strToInt(argv[1]);
// Color index to use for the first priority region
int color = 16;
int count = 0;
// Lock the background surface for access
Graphics::Surface destSurface = g_globals->_sceneManager._scene->_backSurface.lockSurface();
Common::List::iterator i = g_globals->_sceneRegions.begin();
Common::String regionsDesc;
for (; i != g_globals->_sceneRegions.end(); ++i, ++color, ++count) {
Region &r = *i;
if ((regionNum == 0) || (regionNum == (count + 1))) {
for (int y = 0; y < destSurface.h; ++y) {
byte *destP = (byte *)destSurface.getBasePtr(0, y);
for (int x = 0; x < destSurface.w; ++x) {
if (r.contains(Common::Point(g_globals->_sceneManager._scene->_sceneBounds.left + x,
g_globals->_sceneManager._scene->_sceneBounds.top + y)))
*destP = color;
++destP;
}
}
}
regionsDesc += Common::String::format("Region id = %d bounds=%d,%d,%d,%d\n",
r._regionId, r._bounds.left, r._bounds.top, r._bounds.right, r._bounds.bottom);
}
// Release the surface
g_globals->_sceneManager._scene->_backSurface.unlockSurface();
// Mark the scene as requiring a full redraw
g_globals->_paneRefreshFlag[0] = 2;
debugPrintf("Total regions = %d\n", count);
debugPrintf("%s", regionsDesc.c_str());
return true;
}
/*
* This command sets a flag
*/
bool Debugger::Cmd_SetFlag(int argc, const char **argv) {
// Check for a flag to set
if (argc != 2) {
debugPrintf("Usage: %s \n", argv[0]);
return true;
}
int flagNum = strToInt(argv[1]);
g_globals->setFlag(flagNum);
return true;
}
/*
* This command gets the value of a flag
*/
bool Debugger::Cmd_GetFlag(int argc, const char **argv) {
// Check for a flag to display
if (argc != 2) {
debugPrintf("Usage: %s \n", argv[0]);
return true;
}
int flagNum = strToInt(argv[1]);
debugPrintf("Value: %d\n", g_globals->getFlag(flagNum));
return true;
}
/*
* This command clears a flag
*/
bool Debugger::Cmd_ClearFlag(int argc, const char **argv) {
// Check for a flag to clear
if (argc != 2) {
debugPrintf("Usage: %s \n", argv[0]);
return true;
}
int flagNum = strToInt(argv[1]);
g_globals->clearFlag(flagNum);
return true;
}
/**
* Show any active hotspot areas in the scene
*/
bool Debugger::Cmd_Hotspots(int argc, const char **argv) {
int colIndex = 16;
const Rect &sceneBounds = g_globals->_sceneManager._scene->_sceneBounds;
// Lock the background surface for access
Graphics::Surface destSurface = g_globals->_sceneManager._scene->_backSurface.lockSurface();
// Iterate through the scene items
SynchronizedList::iterator i;
for (i = g_globals->_sceneItems.reverse_begin(); i != g_globals->_sceneItems.end(); --i, ++colIndex) {
SceneItem *o = *i;
// Draw the contents of the hotspot area
if (o->_sceneRegionId == 0) {
// Scene item doesn't use a region, so fill in the entire area
if ((o->_bounds.right > o->_bounds.left) && (o->_bounds.bottom > o->_bounds.top))
destSurface.fillRect(Rect(o->_bounds.left - sceneBounds.left, o->_bounds.top - sceneBounds.top,
o->_bounds.right - sceneBounds.left - 1, o->_bounds.bottom - sceneBounds.top - 1), colIndex);
} else {
// Scene uses a region, so get it and use it to fill out only the correct parts
SceneRegions::iterator ri = g_globals->_sceneRegions.begin();
while ((ri != g_globals->_sceneRegions.end()) && ((*ri)._regionId != o->_sceneRegionId))
++ri;
if (ri != g_globals->_sceneRegions.end()) {
// Fill out the areas defined by the region
Region &r = *ri;
for (int y = r._bounds.top; y < r._bounds.bottom; ++y) {
LineSliceSet set = r.getLineSlices(y);
for (uint p = 0; p < set.items.size(); ++p)
destSurface.hLine(set.items[p].xs - sceneBounds.left, y - sceneBounds.top,
set.items[p].xe - sceneBounds.left - 1, colIndex);
}
}
}
}
// Release the surface
g_globals->_sceneManager._scene->_backSurface.unlockSurface();
// Mark the scene as requiring a full redraw
g_globals->_paneRefreshFlag[0] = 2;
return false;
}
/**
* Play the specified sound
*/
bool Debugger::Cmd_Sound(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: %s \n", argv[0]);
return true;
}
int soundNum = strToInt(argv[1]);
g_globals->_soundHandler.play(soundNum);
return false;
}
/**
* Activate internal debugger, when available
*/
bool Debugger::Cmd_SetOutpostAlphaDebug(int argc, const char **argv) {
debugPrintf("Not available in this game\n");
return true;
}
/*
* This command lists the objects available, and their ID
*/
bool DemoDebugger::Cmd_ListObjects(int argc, const char **argv) {
debugPrintf("Not available in Demo\n");
return true;
}
bool DemoDebugger::Cmd_MoveObject(int argc, const char **argv) {
debugPrintf("Not available in Demo\n");
return true;
}
#ifdef ENABLE_RINGWORLD
/*
* This command lists the objects available, and their ID
*/
bool RingworldDebugger::Cmd_ListObjects(int argc, const char **argv) {
if (argc != 1) {
debugPrintf("Usage: %s\n", argv[0]);
return true;
}
debugPrintf("Available objects for this game are:\n");
debugPrintf("0 - Stunner\n");
debugPrintf("1 - Scanner\n");
debugPrintf("2 - Stasis Box\n");
debugPrintf("3 - Info Disk\n");
debugPrintf("4 - Stasis Negator\n");
debugPrintf("5 - Key Device\n");
debugPrintf("6 - Medkit\n");
debugPrintf("7 - Ladder\n");
debugPrintf("8 - Rope\n");
debugPrintf("9 - Key\n");
debugPrintf("10 - Translator\n");
debugPrintf("11 - Ale\n");
debugPrintf("12 - Paper\n");
debugPrintf("13 - Waldos\n");
debugPrintf("14 - Stasis Box 2\n");
debugPrintf("15 - Ring\n");
debugPrintf("16 - Cloak\n");
debugPrintf("17 - Tunic\n");
debugPrintf("18 - Candle\n");
debugPrintf("19 - Straw\n");
debugPrintf("20 - Scimitar\n");
debugPrintf("21 - Sword\n");
debugPrintf("22 - Helmet\n");
debugPrintf("23 - Items\n");
debugPrintf("24 - Concentrator\n");
debugPrintf("25 - Nullifier\n");
debugPrintf("26 - Peg\n");
debugPrintf("27 - Vial\n");
debugPrintf("28 - Jacket\n");
debugPrintf("29 - Tunic 2\n");
debugPrintf("30 - Bone\n");
debugPrintf("31 - Empty Jar\n");
debugPrintf("32 - Jar\n");
return true;
}
/*
* This command gets an item, or move it to a room
*/
bool RingworldDebugger::Cmd_MoveObject(int argc, const char **argv) {
// Check for a flag to clear
if ((argc < 2) || (argc > 3)){
debugPrintf("Usage: %s