2009-09-03 20:59:17 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
2009-09-03 21:20:13 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2009-09-03 20:59:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "teenagent/teenagent.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/config-manager.h"
|
2009-09-05 08:16:35 +00:00
|
|
|
#include "engines/advancedDetector.h"
|
2009-09-03 20:59:17 +00:00
|
|
|
#include "sound/mixer.h"
|
2009-11-08 19:11:57 +00:00
|
|
|
#include "graphics/thumbnail.h"
|
2009-09-04 20:08:33 +00:00
|
|
|
#include "teenagent/scene.h"
|
|
|
|
#include "teenagent/objects.h"
|
|
|
|
#include "teenagent/music.h"
|
2009-11-08 19:11:57 +00:00
|
|
|
#include "teenagent/console.h"
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-04 20:08:33 +00:00
|
|
|
namespace TeenAgent {
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-15 20:21:18 +00:00
|
|
|
TeenAgentEngine::TeenAgentEngine(OSystem *system, const ADGameDescription *gd) : Engine(system), action(kActionNone), _gameDescription(gd) {
|
2009-09-03 20:59:17 +00:00
|
|
|
music = new MusicPlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::processObject() {
|
|
|
|
if (dst_object == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Resources *res = Resources::instance();
|
2009-09-03 20:59:17 +00:00
|
|
|
switch (action) {
|
2009-09-15 20:21:18 +00:00
|
|
|
case kActionExamine: {
|
2009-09-15 07:41:05 +00:00
|
|
|
byte *dcall = res->dseg.ptr(0xb5ce);
|
2009-09-03 20:59:17 +00:00
|
|
|
dcall = res->dseg.ptr(READ_LE_UINT16(dcall + scene->getId() * 2 - 2));
|
|
|
|
dcall += 2 * dst_object->id - 2;
|
|
|
|
uint16 callback = READ_LE_UINT16(dcall);
|
2009-09-05 17:15:28 +00:00
|
|
|
if (callback == 0 || !processCallback(callback)) {
|
2009-09-26 15:04:09 +00:00
|
|
|
Common::String desc = dst_object->description;
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->displayMessage(desc);
|
|
|
|
//debug(0, "%s[%u]: description: %s", current_object->name, current_object->id, desc.c_str());
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-09-15 20:21:18 +00:00
|
|
|
case kActionUse: {
|
2009-09-15 08:54:06 +00:00
|
|
|
InventoryObject *inv = inventory->selectedObject();
|
|
|
|
if (inv != NULL) {
|
2009-09-26 15:04:09 +00:00
|
|
|
const Common::Array<UseHotspot> &hotspots = use_hotspots[scene->getId() - 1];
|
|
|
|
for (uint i = 0; i < hotspots.size(); ++i) {
|
|
|
|
const UseHotspot &spot = hotspots[i];
|
|
|
|
if (spot.inventory_id == inv->id && dst_object->id == spot.object_id) {
|
2009-11-07 09:19:49 +00:00
|
|
|
debug(0, "use object on hotspot!");
|
|
|
|
spot.dump();
|
|
|
|
if (spot.actor_x != 0xffff && spot.actor_y != 0xffff)
|
|
|
|
moveTo(spot.actor_x, spot.actor_y, spot.orientation);
|
2009-09-15 08:54:06 +00:00
|
|
|
inventory->resetSelectedObject();
|
2009-09-26 15:04:09 +00:00
|
|
|
if (!processCallback(TO_LE_16(spot.callback)))
|
2009-09-15 08:54:06 +00:00
|
|
|
debug(0, "fixme! display proper description");
|
|
|
|
return;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
|
|
|
//error
|
|
|
|
inventory->resetSelectedObject();
|
|
|
|
displayMessage(0x3457);
|
|
|
|
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
byte *dcall = res->dseg.ptr(0xb89c);
|
|
|
|
dcall = res->dseg.ptr(READ_LE_UINT16(dcall + scene->getId() * 2 - 2));
|
|
|
|
dcall += 2 * dst_object->id - 2;
|
|
|
|
uint16 callback = READ_LE_UINT16(dcall);
|
|
|
|
if (!processCallback(callback))
|
2009-09-26 15:04:09 +00:00
|
|
|
scene->displayMessage(dst_object->description);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-15 20:21:18 +00:00
|
|
|
case kActionNone:
|
2009-09-03 20:59:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TeenAgentEngine::use(Object *object) {
|
|
|
|
if (object == NULL || scene->eventRunning())
|
|
|
|
return;
|
|
|
|
|
|
|
|
dst_object = object;
|
|
|
|
object->rect.dump();
|
|
|
|
object->actor_rect.dump();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-05 17:15:28 +00:00
|
|
|
if (object->actor_rect.valid())
|
|
|
|
scene->moveTo(Common::Point(object->actor_rect.right, object->actor_rect.bottom), object->actor_orientation);
|
2009-09-03 20:59:17 +00:00
|
|
|
if (object->actor_orientation > 0)
|
|
|
|
scene->setOrientation(object->actor_orientation);
|
2009-09-15 20:21:18 +00:00
|
|
|
action = kActionUse;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::examine(const Common::Point &point, Object *object) {
|
|
|
|
if (scene->eventRunning())
|
|
|
|
return;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
if (object != NULL) {
|
|
|
|
Common::Point dst = object->actor_rect.center();
|
|
|
|
debug(0, "click %d, %d, object %d, %d", point.x, point.y, dst.x, dst.y);
|
|
|
|
if (object->actor_rect.valid())
|
|
|
|
scene->moveTo(dst, object->actor_orientation);
|
2009-09-15 20:21:18 +00:00
|
|
|
action = kActionExamine;
|
2009-09-03 20:59:17 +00:00
|
|
|
dst_object = object;
|
|
|
|
} else {
|
|
|
|
debug(0, "click %d, %d", point.x, point.y);
|
|
|
|
scene->moveTo(point, 0, true);
|
|
|
|
dst_object = NULL;
|
2009-09-15 20:21:18 +00:00
|
|
|
action = kActionNone;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 15:04:09 +00:00
|
|
|
void TeenAgentEngine::init() {
|
|
|
|
Resources * res = Resources::instance();
|
|
|
|
use_hotspots.resize(42);
|
|
|
|
byte *scene_hotspots = res->dseg.ptr(0xbb87);
|
2009-09-30 16:16:53 +00:00
|
|
|
for (byte i = 0; i < 42; ++i) {
|
2009-09-26 15:04:09 +00:00
|
|
|
Common::Array<UseHotspot> & hotspots = use_hotspots[i];
|
|
|
|
byte * hotspots_ptr = res->dseg.ptr(READ_LE_UINT16(scene_hotspots + i * 2));
|
2009-09-30 16:16:53 +00:00
|
|
|
while (*hotspots_ptr) {
|
2009-09-26 15:04:09 +00:00
|
|
|
UseHotspot h;
|
|
|
|
h.load(hotspots_ptr);
|
|
|
|
hotspots_ptr += 9;
|
|
|
|
hotspots.push_back(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
void TeenAgentEngine::deinit() {
|
|
|
|
_mixer->stopAll();
|
|
|
|
delete scene;
|
|
|
|
scene = NULL;
|
|
|
|
delete inventory;
|
|
|
|
inventory = NULL;
|
|
|
|
//delete music;
|
|
|
|
//music = NULL;
|
2009-09-26 15:04:09 +00:00
|
|
|
use_hotspots.clear();
|
2009-09-03 20:59:17 +00:00
|
|
|
Resources::instance()->deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TeenAgentEngine::loadGameState(int slot) {
|
|
|
|
debug(0, "loading from slot %d", slot);
|
2009-10-18 12:13:58 +00:00
|
|
|
Common::InSaveFile *in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot));
|
|
|
|
if (in == NULL)
|
|
|
|
in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot));
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
if (in == NULL)
|
|
|
|
return Common::kReadPermissionDenied;
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Resources *res = Resources::instance();
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
assert(res->dseg.size() >= 0x6478 + 0x777a);
|
|
|
|
char data[0x777a];
|
2009-10-18 12:13:58 +00:00
|
|
|
in->seek(0);
|
2009-09-03 20:59:17 +00:00
|
|
|
if (in->read(data, 0x777a) != 0x777a) {
|
|
|
|
delete in;
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
delete in;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
memcpy(res->dseg.ptr(0x6478), data, sizeof(data));
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->clear();
|
2009-10-31 19:03:44 +00:00
|
|
|
inventory->activate(false);
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
setMusic(Resources::instance()->dseg.get_byte(0xDB90));
|
|
|
|
|
|
|
|
int id = res->dseg.get_byte(0xB4F3);
|
|
|
|
uint16 x = res->dseg.get_word(0x64AF), y = res->dseg.get_word(0x64B1);
|
2009-11-08 19:11:57 +00:00
|
|
|
scene->loadObjectData();
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->init(id, Common::Point(x, y));
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
|
|
|
|
debug(0, "saving to slot %d", slot);
|
2009-10-18 12:13:58 +00:00
|
|
|
Common::OutSaveFile *out = _saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot));
|
2009-09-03 20:59:17 +00:00
|
|
|
if (out == NULL)
|
|
|
|
return Common::kWritePermissionDenied;
|
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Resources *res = Resources::instance();
|
2009-09-03 20:59:17 +00:00
|
|
|
res->dseg.set_byte(0xB4F3, scene->getId());
|
|
|
|
Common::Point pos = scene->getPosition();
|
|
|
|
res->dseg.set_word(0x64AF, pos.x);
|
|
|
|
res->dseg.set_word(0x64B1, pos.y);
|
|
|
|
|
|
|
|
assert(res->dseg.size() >= 0x6478 + 0x777a);
|
|
|
|
strncpy((char *)res->dseg.ptr(0x6478), desc, 0x16);
|
|
|
|
out->write(res->dseg.ptr(0x6478), 0x777a);
|
2009-10-18 12:13:58 +00:00
|
|
|
if (!Graphics::saveThumbnail(*out))
|
|
|
|
warning("saveThumbnail failed");
|
2009-09-03 20:59:17 +00:00
|
|
|
delete out;
|
2009-10-18 12:13:58 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TeenAgentEngine::run() {
|
2009-09-15 07:41:05 +00:00
|
|
|
Resources *res = Resources::instance();
|
2009-09-05 08:16:35 +00:00
|
|
|
if (!res->loadArchives(_gameDescription))
|
|
|
|
return Common::kUnknownError;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Common::EventManager *_event = _system->getEventManager();
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
initGraphics(320, 200, false);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
scene = new Scene;
|
|
|
|
inventory = new Inventory;
|
2009-11-08 19:11:57 +00:00
|
|
|
console = new Console(this);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->init(this, _system);
|
|
|
|
inventory->init(this);
|
2009-09-26 15:04:09 +00:00
|
|
|
|
|
|
|
init();
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-09-05 08:38:43 +00:00
|
|
|
_system->setMouseCursor(res->dseg.ptr(0x00da), 8, 12, 0, 0, 1);
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
syncSoundSettings();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-13 10:50:29 +00:00
|
|
|
music->load(1);
|
2009-09-03 20:59:17 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, music, -1, 255, 0, true, false);
|
|
|
|
music->start();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
{
|
|
|
|
int load_slot = Common::ConfigManager::instance().getInt("save_slot");
|
|
|
|
debug(0, "slot: %d", load_slot);
|
2009-09-13 10:50:29 +00:00
|
|
|
if (load_slot >= 0) {
|
2009-09-03 20:59:17 +00:00
|
|
|
loadGameState(load_slot);
|
2009-09-13 10:50:29 +00:00
|
|
|
} else {
|
|
|
|
scene->intro = true;
|
|
|
|
scene_busy = true;
|
|
|
|
processCallback(0x24c);
|
|
|
|
}
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 frame = 0;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
Common::Event event;
|
|
|
|
Common::Point mouse;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
do {
|
|
|
|
_system->showMouse(true);
|
|
|
|
uint32 t0 = _system->getMillis();
|
2009-09-26 15:04:09 +00:00
|
|
|
Object *current_object = scene->findObject(mouse);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
while (_event->pollEvent(event)) {
|
|
|
|
if (event.type == Common::EVENT_RTL) {
|
|
|
|
deinit();
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
|
|
|
if ((!scene_busy && inventory->processEvent(event)) || scene->processEvent(event))
|
2009-09-03 20:59:17 +00:00
|
|
|
continue;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
//debug(0, "event");
|
2009-09-15 08:54:06 +00:00
|
|
|
switch (event.type) {
|
2009-11-08 19:11:57 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
if ((event.kbd.flags == Common::KBD_CTRL && event.kbd.keycode == 'd') ||
|
|
|
|
event.kbd.ascii == '~' || event.kbd.ascii == '#') {
|
|
|
|
console->attach();
|
|
|
|
}
|
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
examine(event.mouse, current_object);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
use(current_object);
|
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
mouse = event.mouse;
|
|
|
|
break;
|
2009-09-15 08:54:06 +00:00
|
|
|
default:
|
|
|
|
;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
uint32 f0 = frame * 10 / 25, f1 = (frame + 1) * 10 / 25;
|
|
|
|
if (f0 != f1) {
|
|
|
|
bool b = scene->render(_system);
|
|
|
|
scene_busy = b;
|
2009-09-15 20:21:18 +00:00
|
|
|
if (!inventory->active() && !scene_busy && action != kActionNone) {
|
2009-09-03 20:59:17 +00:00
|
|
|
processObject();
|
2009-09-15 20:21:18 +00:00
|
|
|
action = kActionNone;
|
2009-09-03 20:59:17 +00:00
|
|
|
dst_object = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool busy = inventory->active() || scene_busy;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
Graphics::Surface *surface = _system->lockScreen();
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
if (!busy) {
|
|
|
|
InventoryObject *selected_object = inventory->selectedObject();
|
|
|
|
if (current_object || selected_object) {
|
|
|
|
Common::String name;
|
|
|
|
if (selected_object) {
|
|
|
|
name += selected_object->name;
|
|
|
|
name += " & ";
|
|
|
|
}
|
|
|
|
if (current_object)
|
|
|
|
name += current_object->name;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-11-08 19:11:57 +00:00
|
|
|
uint w = res->font7.render(NULL, 0, 0, name, 0xd1);
|
|
|
|
res->font7.render(surface, (320 - w) / 2, 180, name, 0xd1, true);
|
2009-09-03 20:59:17 +00:00
|
|
|
if (current_object) {
|
2009-09-05 08:45:32 +00:00
|
|
|
//current_object->rect.render(surface, 0x80);
|
|
|
|
//current_object->actor_rect.render(surface, 0x81);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
inventory->render(surface);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
_system->unlockScreen();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
_system->updateScreen();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-11-08 19:11:57 +00:00
|
|
|
if (console->isAttached()) {
|
|
|
|
console->onFrame();
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
uint32 dt = _system->getMillis() - t0;
|
|
|
|
if (dt < 40)
|
|
|
|
_system->delayMillis(40 - dt);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
++frame;
|
2009-09-04 20:09:29 +00:00
|
|
|
} while (!_event->shouldQuit());
|
2009-09-03 20:59:17 +00:00
|
|
|
|
|
|
|
deinit();
|
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2009-09-13 09:54:53 +00:00
|
|
|
Common::String TeenAgentEngine::parseMessage(uint16 addr) {
|
2009-09-03 20:59:17 +00:00
|
|
|
Common::String message;
|
|
|
|
for (
|
2009-09-15 08:54:06 +00:00
|
|
|
const char *str = (const char *)Resources::instance()->dseg.ptr(addr);
|
|
|
|
str[0] != 0 || str[1] != 0;
|
|
|
|
++str) {
|
2009-09-03 20:59:17 +00:00
|
|
|
char c = str[0];
|
2009-09-15 08:54:06 +00:00
|
|
|
message += c != 0 && c != -1 ? c : '\n';
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
2009-09-13 09:54:53 +00:00
|
|
|
if (message.empty()) {
|
|
|
|
warning("empty message parsed for %04x", addr);
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2009-11-08 20:00:31 +00:00
|
|
|
void TeenAgentEngine::displayMessage(const Common::String &str, byte color, uint16 position) {
|
|
|
|
if (str.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SceneEvent event(SceneEvent::kMessage);
|
|
|
|
event.message = str;
|
|
|
|
event.color = color;
|
|
|
|
event.slot = 4;
|
|
|
|
event.dst.x = position % 320;
|
|
|
|
event.dst.y = position / 320;
|
|
|
|
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::displayMessage(uint16 addr, byte color, uint16 position) {
|
|
|
|
displayMessage(parseMessage(addr), color, position);
|
|
|
|
}
|
2009-09-13 09:54:53 +00:00
|
|
|
|
2009-11-08 20:00:31 +00:00
|
|
|
void TeenAgentEngine::displayAsyncMessage(uint16 addr, uint16 position, uint16 first_frame, uint16 last_frame, byte color) {
|
|
|
|
SceneEvent event(SceneEvent::kMessage);
|
|
|
|
event.message = parseMessage(addr);
|
|
|
|
event.slot = 4;
|
|
|
|
event.color = color;
|
|
|
|
event.dst.x = position % 320;
|
|
|
|
event.dst.y = position / 320;
|
|
|
|
event.first_frame = first_frame;
|
|
|
|
event.last_frame = last_frame;
|
|
|
|
|
|
|
|
scene->push(event);
|
2009-09-13 09:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::displayCredits(uint16 addr) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kCreditsMessage);
|
2009-09-13 09:54:53 +00:00
|
|
|
|
2009-09-15 07:41:05 +00:00
|
|
|
const byte *src = Resources::instance()->dseg.ptr(addr);
|
2009-09-13 09:54:53 +00:00
|
|
|
event.orientation = *src++;
|
|
|
|
event.color = *src++;
|
2009-10-31 18:49:47 +00:00
|
|
|
event.lan = 8;
|
2009-09-13 09:54:53 +00:00
|
|
|
|
|
|
|
event.dst.y = *src;
|
2009-09-15 08:54:06 +00:00
|
|
|
while (true) {
|
2009-09-13 09:54:53 +00:00
|
|
|
++src; //skip y position
|
|
|
|
Common::String line((const char *)src);
|
|
|
|
event.message += line;
|
|
|
|
src += line.size() + 1;
|
|
|
|
if (*src == 0)
|
|
|
|
break;
|
|
|
|
event.message += "\n";
|
|
|
|
}
|
2009-11-08 19:11:57 +00:00
|
|
|
int w = Resources::instance()->font8.render(NULL, 0, 0, event.message, 0xd1);
|
2009-09-13 09:54:53 +00:00
|
|
|
event.dst.x = (320 - w) / 2;
|
|
|
|
scene->push(event);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 18:49:47 +00:00
|
|
|
void TeenAgentEngine::displayCutsceneMessage(uint16 addr, uint16 position) {
|
|
|
|
SceneEvent event(SceneEvent::kCreditsMessage);
|
|
|
|
|
|
|
|
event.message = parseMessage(addr);
|
|
|
|
event.dst.x = position % 320;
|
|
|
|
event.dst.y = position / 320;
|
|
|
|
event.lan = 7;
|
|
|
|
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-15 08:54:06 +00:00
|
|
|
void TeenAgentEngine::moveTo(const Common::Point &dst, byte o, bool warp) {
|
2009-09-05 15:04:37 +00:00
|
|
|
moveTo(dst.x, dst.y, o, warp);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-05 17:15:28 +00:00
|
|
|
void TeenAgentEngine::moveTo(Object *obj) {
|
|
|
|
moveTo(obj->actor_rect.right, obj->actor_rect.bottom, obj->actor_orientation);
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:04:37 +00:00
|
|
|
void TeenAgentEngine::moveTo(uint16 x, uint16 y, byte o, bool warp) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kWalk);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.dst.x = x;
|
|
|
|
event.dst.y = y;
|
2009-11-07 09:19:49 +00:00
|
|
|
if (o > 4) {
|
|
|
|
warning("invalid orientation %d", o);
|
|
|
|
o = 0;
|
|
|
|
}
|
2009-09-05 15:04:37 +00:00
|
|
|
event.orientation = o;
|
2009-09-15 08:54:06 +00:00
|
|
|
event.color = warp ? 1 : 0;
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2009-09-05 17:15:28 +00:00
|
|
|
void TeenAgentEngine::moveRel(int16 x, int16 y, byte o, bool warp) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kWalk);
|
2009-09-05 17:15:28 +00:00
|
|
|
event.dst.x = x;
|
|
|
|
event.dst.y = y;
|
|
|
|
event.orientation = o;
|
2009-09-15 08:54:06 +00:00
|
|
|
event.color = (warp ? 1 : 0) | 2;
|
2009-09-05 17:15:28 +00:00
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
void TeenAgentEngine::playAnimation(uint16 id, byte slot, bool async) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kPlayAnimation);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.animation = id;
|
2009-11-08 20:00:31 +00:00
|
|
|
event.slot = slot;
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->push(event);
|
2009-09-09 20:42:44 +00:00
|
|
|
if (!async)
|
|
|
|
waitAnimation();
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 20:42:44 +00:00
|
|
|
void TeenAgentEngine::playActorAnimation(uint16 id, bool async) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kPlayActorAnimation);
|
2009-09-09 20:42:44 +00:00
|
|
|
event.animation = id;
|
|
|
|
scene->push(event);
|
|
|
|
if (!async)
|
|
|
|
waitAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
void TeenAgentEngine::loadScene(byte id, const Common::Point &pos, byte o) {
|
|
|
|
loadScene(id, pos.x, pos.y, o);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::loadScene(byte id, uint16 x, uint16 y, byte o) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kLoadScene);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.scene = id;
|
|
|
|
event.dst.x = x;
|
|
|
|
event.dst.y = y;
|
|
|
|
event.orientation = o;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::setOns(byte id, byte value, byte scene_id) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kSetOn);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.ons = id + 1;
|
|
|
|
event.color = value;
|
|
|
|
event.scene = scene_id;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::setLan(byte id, byte value, byte scene_id) {
|
|
|
|
if (id == 0)
|
|
|
|
error("setting lan 0 is invalid");
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kSetLan);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.lan = id;
|
|
|
|
event.color = value;
|
|
|
|
event.scene = scene_id;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::reloadLan() {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kSetLan);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.lan = 0;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TeenAgentEngine::playMusic(byte id) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kPlayMusic);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.music = id;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::playSound(byte id, byte skip_frames) {
|
2009-09-06 09:43:06 +00:00
|
|
|
if (skip_frames > 0)
|
|
|
|
--skip_frames;
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kPlaySound);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.sound = id;
|
|
|
|
event.color = skip_frames;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::enableObject(byte id, byte scene_id) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kEnableObject);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.object = id + 1;
|
|
|
|
event.color = 1;
|
|
|
|
event.scene = scene_id;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::disableObject(byte id, byte scene_id) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kEnableObject);
|
2009-09-03 20:59:17 +00:00
|
|
|
event.object = id + 1;
|
|
|
|
event.color = 0;
|
|
|
|
event.scene = scene_id;
|
|
|
|
scene->push(event);
|
2009-09-13 12:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::hideActor() {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kHideActor);
|
2009-09-13 12:48:57 +00:00
|
|
|
event.color = 1;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::showActor() {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kHideActor);
|
2009-09-13 12:48:57 +00:00
|
|
|
event.color = 0;
|
|
|
|
scene->push(event);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::waitAnimation() {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kWaitForAnimation);
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2009-11-07 12:00:56 +00:00
|
|
|
void TeenAgentEngine::waitLanAnimationFrame(byte slot, uint16 frame) {
|
|
|
|
SceneEvent event(SceneEvent::kWaitLanAnimationFrame);
|
|
|
|
if (frame > 0)
|
|
|
|
--frame;
|
|
|
|
|
2009-11-08 20:00:31 +00:00
|
|
|
event.slot = slot - 1;
|
2009-11-07 12:00:56 +00:00
|
|
|
event.animation = frame;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
void TeenAgentEngine::playSoundNow(byte id) {
|
2009-09-15 07:41:05 +00:00
|
|
|
Resources *res = Resources::instance();
|
|
|
|
Common::SeekableReadStream *in = res->sam_sam.getStream(id);
|
2009-09-03 20:59:17 +00:00
|
|
|
if (in == NULL) {
|
|
|
|
debug(0, "skipping invalid sound %u", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint size = in->size();
|
|
|
|
char *data = new char[size];
|
|
|
|
in->read(data, size);
|
2009-09-05 15:04:37 +00:00
|
|
|
//debug(0, "playing %u samples...", size);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
_mixer->playRaw(Audio::Mixer::kSFXSoundType, &_soundHandle, data, size, 11025, Audio::Mixer::FLAG_AUTOFREE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TeenAgentEngine::setMusic(byte id) {
|
|
|
|
debug(0, "starting music %u", id);
|
|
|
|
if (!music->load(id))
|
|
|
|
return;
|
|
|
|
*Resources::instance()->dseg.ptr(0xDB90) = id;
|
|
|
|
music->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TeenAgentEngine::hasFeature(EngineFeature f) const {
|
2009-09-15 08:54:06 +00:00
|
|
|
switch (f) {
|
2009-09-03 20:59:17 +00:00
|
|
|
case kSupportsRTL:
|
|
|
|
case kSupportsLoadingDuringRuntime:
|
|
|
|
case kSupportsSavingDuringRuntime:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 20:08:33 +00:00
|
|
|
|
|
|
|
} // End of namespace TeenAgent
|