forked from scummvm/scummvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugconsole.cpp
212 lines (178 loc) · 5.76 KB
/
debugconsole.cpp
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
/* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "darkseed/darkseed.h"
#include "darkseed/debugconsole.h"
namespace Darkseed {
DebugConsole::DebugConsole(TosText *tosText) : _tosText(tosText) {
registerCmd("tostext", WRAP_METHOD(DebugConsole, Cmd_tostext));
registerCmd("dt", WRAP_METHOD(DebugConsole, Cmd_dt));
registerCmd("getvar", WRAP_METHOD(DebugConsole, Cmd_getvar));
registerCmd("setvar", WRAP_METHOD(DebugConsole, Cmd_setvar));
registerCmd("enablePathfinderOverlay", WRAP_METHOD(DebugConsole, Cmd_enablePathfinderOverlay));
registerCmd("info", WRAP_METHOD(DebugConsole, Cmd_info));
registerCmd("gotoRoom", WRAP_METHOD(DebugConsole, Cmd_gotoRoom));
registerCmd("invAdd", WRAP_METHOD(DebugConsole, Cmd_invAdd));
registerCmd("invRemove", WRAP_METHOD(DebugConsole, Cmd_invRemove));
registerCmd("changeDay", WRAP_METHOD(DebugConsole, Cmd_changeDay));
registerCmd("searchTos", WRAP_METHOD(DebugConsole, Cmd_searchTos));
}
DebugConsole::~DebugConsole() {
}
bool DebugConsole::Cmd_tostext(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: tostext <index>\n");
return true;
}
uint16 textIdx = atoi(argv[1]);
if (textIdx < _tosText->getNumEntries()) {
debugPrintf("%s\n", _tosText->getText(textIdx).c_str());
} else {
debugPrintf("index too large!\n");
}
return true;
}
bool DebugConsole::Cmd_dt(int argc, const char **argv) {
printDayAndTime();
return true;
}
bool DebugConsole::Cmd_getvar(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: getvar <index>\n");
return true;
}
int16 varIdx = (int16)atoi(argv[1]);
if (validateObjVarIndex(varIdx)) {
debugPrintf("Object Var: %d\n", g_engine->_objectVar.getVar(varIdx));
}
return true;
}
bool DebugConsole::Cmd_setvar(int argc, const char **argv) {
if (argc != 3) {
debugPrintf("Usage: setvar <index> <newValue>\n");
return true;
}
int16 varIdx = (int16)atoi(argv[1]);
int16 newValue = (int16)atoi(argv[2]);
if (validateObjVarIndex(varIdx)) {
g_engine->_objectVar[varIdx] = newValue;
}
return true;
}
bool DebugConsole::Cmd_enablePathfinderOverlay(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: enablePathfinderOverlay <true | t | false | f>\n");
return true;
}
if (!strcmp(argv[1], "true") || !strcmp(argv[1], "t")) {
g_engine->_debugShowWalkPath = true;
} else if (!strcmp(argv[1], "false") || !strcmp(argv[1], "f")) {
g_engine->_debugShowWalkPath = false;
}
return true;
}
bool DebugConsole::validateObjVarIndex(int16 varIdx) {
if (varIdx >= Objects::MAX_OBJECTS) {
debugPrintf("Index must be less than %d\n", Objects::MAX_OBJECTS);
return false;
}
if (varIdx < 0) {
debugPrintf("Index cannot be negative\n");
return false;
}
return true;
}
bool DebugConsole::Cmd_info(int argc, const char **argv) {
printDayAndTime();
debugPrintf("\nRoom info:\n");
debugPrintf("Room number: %d\n", g_engine->_room->_roomNumber);
return true;
}
bool DebugConsole::Cmd_gotoRoom(int argc, const char **argv) {
if (argc < 2 || argc > 3) {
debugPrintf("Usage: gotoRoom <roomNumber> <entranceNumber>\n");
return true;
}
int16 roomNumber = (int16)atoi(argv[1]);
int entranceNumber = 0;
if (argc == 3) {
entranceNumber = (int16)atoi(argv[2]);
}
g_engine->debugTeleportToRoom(roomNumber, entranceNumber);
return true;
}
bool DebugConsole::Cmd_invAdd(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: invAdd <objNum>\n");
return true;
}
uint8 objNum = (uint8)atoi(argv[1]);
g_engine->_inventory.addItem(objNum);
return true;
}
bool DebugConsole::Cmd_invRemove(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: invRemove <objNum>\n");
return true;
}
uint8 objNum = (uint8)atoi(argv[1]);
g_engine->_inventory.removeItem(objNum);
return true;
}
bool DebugConsole::Cmd_changeDay(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: changeDay <newDay>\n");
return true;
}
uint8 newDay = (uint8)atoi(argv[1]);
if (newDay < 1 || newDay > 3) {
debugPrintf("Error: Day must be in range of 1 .. 3\n");
return true;
}
g_engine->_currentDay = newDay;
debugPrintf("Current day changed.\n");
printDayAndTime();
return true;
}
bool DebugConsole::Cmd_searchTos(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: searchTos \"search string\"\n");
return true;
}
Common::String searchString = Common::String(argv[1]);
searchString.toLowercase();
for (int i = 0; i < g_engine->_tosText->getNumEntries(); i++) {
Common::String entry = g_engine->_tosText->getText(i);
entry.toLowercase();
if (entry.contains(searchString)) {
debugPrintf("% 3d: %s\n", i, entry.c_str());
}
}
return true;
}
void DebugConsole::printDayAndTime() {
int hour = g_engine->_currentTimeInSeconds / 60 / 60 + 1;
debugPrintf("Day %d at %d:%02d%s (%d seconds)\n",
g_engine->_currentDay,
hour % 12,
(g_engine->_currentTimeInSeconds / 60) % 60,
hour < 12 ? "AM" : "PM", g_engine->_currentTimeInSeconds);
}
} // End of namespace Darkseed