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 #include "teenagent/console.h"
24 #include "teenagent/resources.h"
25 #include "teenagent/teenagent.h"
26
27 namespace TeenAgent {
28
Console(TeenAgentEngine * engine)29 Console::Console(TeenAgentEngine *engine) : _engine(engine) {
30 registerCmd("enable_object", WRAP_METHOD(Console, enableObject));
31 registerCmd("disable_object", WRAP_METHOD(Console, enableObject));
32 registerCmd("set_ons", WRAP_METHOD(Console, setOns));
33 registerCmd("set_music", WRAP_METHOD(Console, setMusic));
34 registerCmd("animation", WRAP_METHOD(Console, playAnimation));
35 registerCmd("actor_animation", WRAP_METHOD(Console, playActorAnimation));
36 registerCmd("call", WRAP_METHOD(Console, call));
37 registerCmd("playSound", WRAP_METHOD(Console, playSound));
38 registerCmd("playVoice", WRAP_METHOD(Console, playVoice));
39 }
40
enableObject(int argc,const char ** argv)41 bool Console::enableObject(int argc, const char **argv) {
42 if (argc < 2) {
43 debugPrintf("usage: %s object_id [scene_id]\n", argv[0]);
44 return true;
45 }
46
47 int id = atoi(argv[1]);
48 if (id < 0) {
49 debugPrintf("object id %d is invalid\n", id);
50 return true;
51 }
52
53 int scene_id = 0;
54 if (argc > 2) {
55 scene_id = atoi(argv[2]);
56 if (scene_id < 0) {
57 debugPrintf("scene id %d is invalid\n", scene_id);
58 return true;
59 }
60 }
61
62 if (strcmp(argv[0], "disable_object") == 0)
63 _engine->disableObject(id, scene_id);
64 else
65 _engine->enableObject(id, scene_id);
66
67 return true;
68 }
69
setOns(int argc,const char ** argv)70 bool Console::setOns(int argc, const char **argv) {
71 if (argc < 3) {
72 debugPrintf("usage: %s index(0-3) value [scene_id]\n", argv[0]);
73 return true;
74 }
75
76 int index = atoi(argv[1]);
77 if (index < 0 || index > 3) {
78 debugPrintf("index %d is invalid\n", index);
79 return true;
80 }
81
82 int value = 0;
83 value = atoi(argv[2]);
84 if (value < 0) {
85 debugPrintf("invalid value\n");
86 return true;
87 }
88
89 int scene_id = 0;
90 if (argc > 3) {
91 scene_id = atoi(argv[3]);
92 if (scene_id < 0) {
93 debugPrintf("scene id %d is invalid\n", scene_id);
94 return true;
95 }
96 }
97
98 _engine->setOns(index, value, scene_id);
99 return true;
100 }
101
setMusic(int argc,const char ** argv)102 bool Console::setMusic(int argc, const char **argv) {
103 if (argc < 2) {
104 debugPrintf("usage: %s index(1-11)\n", argv[0]);
105 return true;
106 }
107
108 int index = atoi(argv[1]);
109 if (index <= 0 || index > 11) {
110 debugPrintf("invalid value\n");
111 return true;
112 }
113
114 _engine->setMusic(index);
115 return true;
116 }
117
playAnimation(int argc,const char ** argv)118 bool Console::playAnimation(int argc, const char **argv) {
119 if (argc < 3) {
120 debugPrintf("usage: %s id slot(0-3)\n", argv[0]);
121 return true;
122 }
123
124 int id = atoi(argv[1]);
125 int slot = atoi(argv[2]);
126 if (id < 0 || slot < 0 || slot > 3) {
127 debugPrintf("invalid slot or animation id\n");
128 return true;
129 }
130
131 _engine->playAnimation(id, slot);
132 return true;
133 }
134
playActorAnimation(int argc,const char ** argv)135 bool Console::playActorAnimation(int argc, const char **argv) {
136 if (argc < 2) {
137 debugPrintf("usage: %s id\n", argv[0]);
138 return true;
139 }
140
141 int id = atoi(argv[1]);
142 if (id < 0) {
143 debugPrintf("invalid animation id\n");
144 return true;
145 }
146
147 _engine->playActorAnimation(id);
148 return true;
149 }
150
call(int argc,const char ** argv)151 bool Console::call(int argc, const char **argv) {
152 if (argc < 2) {
153 debugPrintf("usage: %s 0xHEXADDR\n", argv[0]);
154 return true;
155 }
156
157 uint addr;
158 if (sscanf(argv[1], "0x%x", &addr) != 1) {
159 debugPrintf("invalid address\n");
160 return true;
161 }
162
163 if (!_engine->processCallback(addr))
164 debugPrintf("calling callback %04x failed\n", addr);
165
166 return true;
167 }
168
playSound(int argc,const char ** argv)169 bool Console::playSound(int argc, const char **argv) {
170 uint32 fileCount = _engine->res->sam_sam.fileCount();
171 if (argc < 2) {
172 debugPrintf("usage: %s index(1-%d)\n", argv[0], fileCount);
173 return true;
174 }
175
176 uint index = atoi(argv[1]);
177 if (index <= 0 || index > fileCount) {
178 debugPrintf("invalid value\n");
179 return true;
180 }
181
182 _engine->playSoundNow(&_engine->res->sam_sam, index);
183 return true;
184 }
185
playVoice(int argc,const char ** argv)186 bool Console::playVoice(int argc, const char **argv) {
187 uint32 fileCount = _engine->res->voices.fileCount();
188 if (argc < 2) {
189 debugPrintf("usage: %s index(1-%d)\n", argv[0], fileCount);
190 return true;
191 }
192
193 uint index = atoi(argv[1]);
194 if (index <= 0 || index > fileCount) {
195 debugPrintf("invalid value\n");
196 return true;
197 }
198
199 _engine->playSoundNow(&_engine->res->voices, index);
200 return true;
201 }
202
203 }
204