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
|
|
|
*/
|
|
|
|
|
2010-01-02 22:30:43 +00:00
|
|
|
#include "common/config-manager.h"
|
2009-09-03 20:59:17 +00:00
|
|
|
#include "common/debug.h"
|
2010-01-02 22:30:43 +00:00
|
|
|
#include "common/events.h"
|
2009-09-03 20:59:17 +00:00
|
|
|
#include "common/savefile.h"
|
2010-01-02 22:30:43 +00:00
|
|
|
#include "common/system.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
|
2010-11-08 23:07:42 +00:00
|
|
|
#include "backends/audiocd/audiocd.h"
|
|
|
|
|
2009-09-05 08:16:35 +00:00
|
|
|
#include "engines/advancedDetector.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
#include "sound/mixer.h"
|
2010-01-26 22:48:45 +00:00
|
|
|
#include "sound/decoders/raw.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
|
2010-01-02 22:30:43 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2009-11-08 19:11:57 +00:00
|
|
|
#include "graphics/thumbnail.h"
|
2010-05-04 11:58:12 +00:00
|
|
|
|
2009-11-08 19:11:57 +00:00
|
|
|
#include "teenagent/console.h"
|
2010-01-02 22:30:43 +00:00
|
|
|
#include "teenagent/music.h"
|
|
|
|
#include "teenagent/objects.h"
|
|
|
|
#include "teenagent/pack.h"
|
|
|
|
#include "teenagent/scene.h"
|
|
|
|
#include "teenagent/teenagent.h"
|
2009-12-26 10:43:37 +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();
|
2011-01-31 07:44:40 +00:00
|
|
|
|
|
|
|
console = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TeenAgentEngine::~TeenAgentEngine() {
|
|
|
|
delete music;
|
|
|
|
|
|
|
|
delete console;
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 08:00:13 +00:00
|
|
|
bool TeenAgentEngine::trySelectedObject() {
|
|
|
|
InventoryObject *inv = inventory->selectedObject();
|
|
|
|
if (inv == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Resources *res = Resources::instance();
|
|
|
|
debug(0, "checking active object %u on %u", inv->id, dst_object->id);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-12-01 08:00:13 +00:00
|
|
|
//mouse time challenge hack:
|
|
|
|
if (
|
|
|
|
(res->dseg.get_byte(0) == 1 && inv->id == 49 && dst_object->id == 5) ||
|
|
|
|
(res->dseg.get_byte(0) == 2 && inv->id == 29 && dst_object->id == 5)
|
|
|
|
) {
|
|
|
|
//putting rock into hole or superglue on rock
|
|
|
|
processCallback(0x8d57);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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);
|
2010-01-10 20:58:59 +00:00
|
|
|
if (!processCallback(spot.callback))
|
2009-12-01 08:00:13 +00:00
|
|
|
debug(0, "fixme! display proper description");
|
2010-01-06 09:38:56 +00:00
|
|
|
inventory->resetSelectedObject();
|
2009-12-01 08:00:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//error
|
|
|
|
inventory->resetSelectedObject();
|
|
|
|
displayMessage(0x3457);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
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-12-01 08:00:13 +00:00
|
|
|
if (trySelectedObject())
|
|
|
|
break;
|
|
|
|
|
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);
|
2010-01-25 01:39:44 +00:00
|
|
|
if (callback == 0 || !processCallback(callback))
|
2010-01-06 09:38:56 +00:00
|
|
|
displayMessage(dst_object->description);
|
2009-09-15 08:54:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-09-15 20:21:18 +00:00
|
|
|
case kActionUse: {
|
2009-12-01 08:00:13 +00:00
|
|
|
if (trySelectedObject())
|
2009-09-15 08:54:06 +00:00
|
|
|
break;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-12-01 08:00:13 +00:00
|
|
|
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))
|
2010-01-06 09:38:56 +00:00
|
|
|
displayMessage(dst_object->description);
|
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-11-14 11:29:37 +00:00
|
|
|
action = kActionUse;
|
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-11-14 11:29:37 +00:00
|
|
|
else if (object->actor_orientation > 0)
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->setOrientation(object->actor_orientation);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-11-14 11:29:37 +00:00
|
|
|
action = kActionExamine;
|
2009-09-03 20:59:17 +00:00
|
|
|
if (object->actor_rect.valid())
|
2010-03-24 19:34:58 +00:00
|
|
|
scene->moveTo(dst, object->actor_orientation, true); //validate examine message. Original engine does not let you into walkboxes
|
2009-09-03 20:59:17 +00:00
|
|
|
dst_object = object;
|
2010-02-07 17:13:39 +00:00
|
|
|
} else if (!scene_busy) {
|
2010-01-06 10:11:38 +00:00
|
|
|
//do not reset anything while scene is busy, but allow interrupts while walking.
|
2009-09-03 20:59:17 +00:00
|
|
|
debug(0, "click %d, %d", point.x, point.y);
|
2009-11-14 11:29:37 +00:00
|
|
|
action = kActionNone;
|
2009-09-03 20:59:17 +00:00
|
|
|
scene->moveTo(point, 0, true);
|
|
|
|
dst_object = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 15:04:09 +00:00
|
|
|
void TeenAgentEngine::init() {
|
2010-01-08 18:03:34 +00:00
|
|
|
_mark_delay = 80;
|
|
|
|
_game_delay = 110;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-09-26 15:04:09 +00:00
|
|
|
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();
|
2009-12-26 10:43:37 +00:00
|
|
|
CursorMan.popCursor();
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TeenAgentEngine::loadGameState(int slot) {
|
|
|
|
debug(0, "loading from slot %d", slot);
|
2010-03-20 20:37:36 +00:00
|
|
|
Common::ScopedPtr<Common::InSaveFile>
|
2010-11-01 16:02:28 +00:00
|
|
|
in(_saveFileMan->openForLoading(Common::String::format("teenagent.%02d", slot)));
|
2010-03-20 20:37:36 +00:00
|
|
|
if (!in)
|
2010-11-01 16:02:28 +00:00
|
|
|
in.reset(_saveFileMan->openForLoading(Common::String::format("teenagent.%d", slot)));
|
2009-10-18 12:13:58 +00:00
|
|
|
|
2010-03-20 20:37:36 +00:00
|
|
|
if (!in)
|
2009-09-03 20:59:17 +00:00
|
|
|
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) {
|
|
|
|
return Common::kReadingFailed;
|
|
|
|
}
|
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);
|
2010-03-21 07:49:53 +00:00
|
|
|
inventory->reload();
|
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));
|
2009-12-27 18:21:49 +00:00
|
|
|
scene->setPalette(4);
|
2010-02-25 20:36:10 +00:00
|
|
|
scene->intro = false;
|
2009-09-03 20:59:17 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
|
|
|
|
debug(0, "saving to slot %d", slot);
|
2010-11-01 16:02:28 +00:00
|
|
|
Common::ScopedPtr<Common::OutSaveFile> out(_saveFileMan->openForSaving(Common::String::format("teenagent.%02d", slot)));
|
2010-03-20 20:37:36 +00:00
|
|
|
if (!out)
|
2010-03-20 13:55:07 +00:00
|
|
|
return Common::kWritingFailed;
|
2009-09-03 20:59:17 +00:00
|
|
|
|
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");
|
|
|
|
|
2010-03-20 20:37:36 +00:00
|
|
|
out->finalize();
|
2009-09-03 20:59:17 +00:00
|
|
|
return Common::kNoError;
|
|
|
|
}
|
|
|
|
|
2010-01-02 22:30:43 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
int TeenAgentEngine::skipEvents() const {
|
2010-01-02 22:30:43 +00:00
|
|
|
Common::EventManager *_event = _system->getEventManager();
|
2010-01-03 15:18:20 +00:00
|
|
|
Common::Event event;
|
|
|
|
while (_event->pollEvent(event)) {
|
|
|
|
switch(event.type) {
|
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
case Common::EVENT_RTL:
|
|
|
|
return -1;
|
|
|
|
case Common::EVENT_MAINMENU:
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
return 1;
|
|
|
|
case Common::EVENT_KEYDOWN:
|
|
|
|
if (event.kbd.ascii)
|
|
|
|
return 1;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-28 19:50:28 +00:00
|
|
|
bool TeenAgentEngine::showCDLogo() {
|
|
|
|
Common::File cdlogo;
|
|
|
|
if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
byte bg[0xfa00];
|
|
|
|
byte palette[0x400];
|
|
|
|
|
|
|
|
cdlogo.read(bg, sizeof(bg));
|
|
|
|
memset(palette, 0, sizeof(palette));
|
|
|
|
|
|
|
|
for(uint c = 0; c < 0x100; ++c) {
|
|
|
|
uint idx = c * 4;
|
|
|
|
cdlogo.read(palette + idx, 3);
|
|
|
|
palette[idx] *= 4;
|
|
|
|
palette[idx + 1] *= 4;
|
|
|
|
palette[idx + 2] *= 4;
|
|
|
|
}
|
2011-02-07 17:52:38 +00:00
|
|
|
_system->getPaletteManager()->setPalette(palette, 0, 0x100);
|
2010-04-28 19:50:28 +00:00
|
|
|
_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
|
|
|
|
_system->updateScreen();
|
|
|
|
|
|
|
|
for(uint i = 0; i < 20; ++i) {
|
|
|
|
int r = skipEvents();
|
|
|
|
if (r != 0)
|
|
|
|
return r > 0? true: false;
|
|
|
|
_system->delayMillis(100);
|
|
|
|
}
|
|
|
|
cdlogo.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
bool TeenAgentEngine::showLogo() {
|
2010-03-18 22:35:58 +00:00
|
|
|
FilePack logo;
|
2010-01-03 15:18:20 +00:00
|
|
|
if (!logo.open("unlogic.res"))
|
|
|
|
return true;
|
2010-01-02 22:30:43 +00:00
|
|
|
|
|
|
|
byte bg[0xfa00];
|
|
|
|
byte palette[0x400];
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-03-20 20:37:36 +00:00
|
|
|
Common::ScopedPtr<Common::SeekableReadStream> frame(logo.getStream(1));
|
|
|
|
if (!frame)
|
2010-01-02 22:30:43 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
frame->read(bg, sizeof(bg));
|
|
|
|
memset(palette, 0, sizeof(palette));
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-02 22:30:43 +00:00
|
|
|
for(uint c = 0; c < 0x100; ++c) {
|
|
|
|
uint idx = c * 4;
|
|
|
|
frame->read(palette + idx, 3);
|
|
|
|
palette[idx] *= 4;
|
|
|
|
palette[idx + 1] *= 4;
|
|
|
|
palette[idx + 2] *= 4;
|
|
|
|
}
|
2011-02-07 17:52:38 +00:00
|
|
|
_system->getPaletteManager()->setPalette(palette, 0, 0x100);
|
2010-01-02 22:30:43 +00:00
|
|
|
|
2010-03-18 23:30:29 +00:00
|
|
|
uint n = logo.fileCount();
|
2010-01-25 01:39:44 +00:00
|
|
|
for(uint f = 0; f < 4; ++f)
|
2010-01-02 22:30:43 +00:00
|
|
|
for(uint i = 2; i <= n; ++i) {
|
2010-01-03 15:18:20 +00:00
|
|
|
{
|
|
|
|
int r = skipEvents();
|
|
|
|
if (r != 0)
|
|
|
|
return r > 0? true: false;
|
2010-01-02 22:30:43 +00:00
|
|
|
}
|
2010-01-02 22:32:24 +00:00
|
|
|
_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-03-20 20:37:36 +00:00
|
|
|
frame.reset(logo.getStream(i));
|
|
|
|
if (!frame)
|
2010-01-02 22:32:24 +00:00
|
|
|
return true;
|
|
|
|
|
2010-01-02 22:30:43 +00:00
|
|
|
Surface s;
|
|
|
|
s.load(frame, Surface::kTypeOns);
|
|
|
|
if (s.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
_system->copyRectToScreen((const byte *)s.pixels, s.w, s.x, s.y, s.w, s.h);
|
|
|
|
_system->updateScreen();
|
|
|
|
|
|
|
|
_system->delayMillis(100);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
bool TeenAgentEngine::showMetropolis() {
|
|
|
|
_system->fillScreen(0);
|
|
|
|
_system->updateScreen();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-03-18 23:24:32 +00:00
|
|
|
FilePack varia;
|
|
|
|
varia.open("varia.res");
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
byte palette[0x400];
|
|
|
|
memset(palette, 0, sizeof(palette));
|
|
|
|
{
|
2010-03-20 20:37:36 +00:00
|
|
|
Common::ScopedPtr<Common::SeekableReadStream> s(varia.getStream(5));
|
2010-03-20 15:24:16 +00:00
|
|
|
for(uint c = 0; c < 0x400; c += 4) {
|
|
|
|
s->read(palette + c, 3);
|
|
|
|
palette[c] *= 4;
|
|
|
|
palette[c + 1] *= 4;
|
|
|
|
palette[c + 2] *= 4;
|
2010-01-03 15:18:20 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2011-02-07 17:52:38 +00:00
|
|
|
_system->getPaletteManager()->setPalette(palette, 0, 0x100);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
byte varia_6[21760], varia_9[18302];
|
2010-03-18 23:24:32 +00:00
|
|
|
varia.read(6, varia_6, sizeof(varia_6));
|
|
|
|
varia.read(9, varia_9, sizeof(varia_9));
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
byte colors[56 * 160 * 2];
|
|
|
|
memset(colors, 0, sizeof(colors));
|
|
|
|
|
|
|
|
int logo_y = -56;
|
|
|
|
for(uint f = 0; f < 300; ++f) {
|
|
|
|
{
|
|
|
|
int r = skipEvents();
|
|
|
|
if (r != 0)
|
|
|
|
return r > 0? true: false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::Surface *surface = _system->lockScreen();
|
|
|
|
if (logo_y > 0) {
|
|
|
|
surface->fillRect(Common::Rect(0, 0, 320, logo_y), 0);
|
|
|
|
}
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
{
|
|
|
|
//generate colors matrix
|
|
|
|
memmove(colors + 320, colors + 480, 8480);
|
|
|
|
for(uint c = 0; c < 17; ++c) {
|
2010-01-04 18:10:45 +00:00
|
|
|
byte x = (random.getRandomNumber(184) + 5) & 0xff;
|
|
|
|
uint offset = 8800 + random.getRandomNumber(158);
|
2010-01-04 18:06:59 +00:00
|
|
|
colors[offset++] = x;
|
|
|
|
colors[offset++] = x;
|
2010-01-03 15:18:20 +00:00
|
|
|
}
|
|
|
|
for(uint y = 1; y < 56; ++y) {
|
|
|
|
for(uint x = 1; x < 160; ++x) {
|
|
|
|
uint offset = y * 160 + x;
|
2010-01-25 01:39:44 +00:00
|
|
|
uint v =
|
|
|
|
(uint)colors[offset - 161] + colors[offset - 160] + colors[offset - 159] +
|
|
|
|
(uint)colors[offset - 1] + colors[offset + 1] +
|
2010-01-03 15:18:20 +00:00
|
|
|
(uint)colors[offset + 161] + colors[offset + 160] + colors[offset + 159];
|
|
|
|
v >>= 3;
|
|
|
|
colors[offset + 8960] = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memmove(colors, colors + 8960, 8960);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *dst = (byte *)surface->getBasePtr(0, 131);
|
|
|
|
byte *src = varia_6;
|
|
|
|
for(uint y = 0; y < 68; ++y) {
|
|
|
|
for(uint x = 0; x < 320; ++x) {
|
|
|
|
if (*src++ == 1) {
|
2010-01-03 15:25:07 +00:00
|
|
|
*dst++ = colors[19 * 160 + y / 2 * 160 + x / 2];
|
2010-01-25 01:39:44 +00:00
|
|
|
} else
|
2010-01-03 15:18:20 +00:00
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_system->unlockScreen();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
_system->copyRectToScreen(
|
2010-01-25 01:39:44 +00:00
|
|
|
varia_9 + (logo_y < 0? -logo_y * 320: 0), 320,
|
|
|
|
0, logo_y >= 0? logo_y: 0,
|
2010-01-03 15:18:20 +00:00
|
|
|
320, logo_y >= 0? 57: 57 + logo_y);
|
|
|
|
|
|
|
|
if (logo_y < 82 - 57)
|
|
|
|
++logo_y;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
|
|
|
|
2010-01-03 15:18:20 +00:00
|
|
|
_system->updateScreen();
|
|
|
|
_system->delayMillis(100);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
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-11-08 19:11:57 +00:00
|
|
|
console = new Console(this);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2011-01-31 07:44:40 +00:00
|
|
|
scene = new Scene(this, _system);
|
|
|
|
inventory = new Inventory(this);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-09-26 15:04:09 +00:00
|
|
|
init();
|
2009-09-03 20:59:17 +00:00
|
|
|
|
2009-12-26 10:43:37 +00:00
|
|
|
CursorMan.pushCursor(res->dseg.ptr(0x00da), 8, 12, 0, 0, 1);
|
2009-09-05 08:38:43 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
syncSoundSettings();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, music, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, false);
|
2010-05-07 07:56:57 +00:00
|
|
|
setMusic(1);
|
2009-09-03 20:59:17 +00:00
|
|
|
music->start();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2010-01-03 10:46:14 +00:00
|
|
|
int load_slot = Common::ConfigManager::instance().getInt("save_slot");
|
2010-01-02 22:40:17 +00:00
|
|
|
if (load_slot >= 0) {
|
|
|
|
loadGameState(load_slot);
|
|
|
|
} else {
|
2010-04-28 19:50:28 +00:00
|
|
|
if (!showCDLogo())
|
|
|
|
return Common::kNoError;
|
2010-01-03 15:18:20 +00:00
|
|
|
if (!showLogo())
|
|
|
|
return Common::kNoError;
|
|
|
|
if (!showMetropolis())
|
2010-01-03 10:46:14 +00:00
|
|
|
return Common::kNoError;
|
2010-01-02 22:40:17 +00:00
|
|
|
scene->intro = true;
|
|
|
|
scene_busy = true;
|
|
|
|
processCallback(0x24c);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2010-01-03 10:46:14 +00:00
|
|
|
CursorMan.showMouse(true);
|
|
|
|
|
2010-01-08 18:03:34 +00:00
|
|
|
uint32 game_timer = 0;
|
|
|
|
uint32 mark_timer = 0;
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
Common::Event event;
|
|
|
|
Common::Point mouse;
|
2010-01-05 20:58:41 +00:00
|
|
|
uint32 timer = _system->getMillis();
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
do {
|
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:
|
2010-02-21 04:04:13 +00:00
|
|
|
if ((event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) ||
|
2009-11-08 19:11:57 +00:00
|
|
|
event.kbd.ascii == '~' || event.kbd.ascii == '#') {
|
|
|
|
console->attach();
|
2010-02-21 04:04:13 +00:00
|
|
|
} else if (event.kbd.hasFlags(0) && event.kbd.keycode == Common::KEYCODE_F5) {
|
2009-12-07 19:16:18 +00:00
|
|
|
openMainMenuDialog();
|
2010-02-21 04:04:13 +00:00
|
|
|
} if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_f) {
|
2010-01-08 18:03:34 +00:00
|
|
|
_mark_delay = _mark_delay == 80? 40: 80;
|
|
|
|
debug(0, "mark_delay = %u", _mark_delay);
|
|
|
|
}
|
2009-11-08 19:11:57 +00:00
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2009-11-20 13:08:33 +00:00
|
|
|
if (scene->getId() < 0)
|
|
|
|
break;
|
2009-11-09 07:58:27 +00:00
|
|
|
examine(event.mouse, current_object);
|
|
|
|
break;
|
2009-09-03 20:59:17 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2009-11-09 07:58:27 +00:00
|
|
|
//if (current_object)
|
|
|
|
// debug(0, "%d, %s", current_object->id, current_object->name.c_str());
|
2009-11-20 13:08:33 +00:00
|
|
|
if (scene->getId() < 0)
|
|
|
|
break;
|
2010-04-07 07:45:50 +00:00
|
|
|
|
|
|
|
if (current_object == NULL)
|
|
|
|
break;
|
|
|
|
|
2009-11-09 07:58:27 +00:00
|
|
|
if (res->dseg.get_byte(0) == 3 && current_object->id == 1) {
|
2009-11-08 23:32:01 +00:00
|
|
|
processCallback(0x5189); //boo!
|
|
|
|
break;
|
|
|
|
}
|
2009-11-09 07:58:27 +00:00
|
|
|
if (res->dseg.get_byte(0) == 4 && current_object->id == 5) {
|
|
|
|
processCallback(0x99e0); //getting an anchor
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
use(current_object);
|
2009-09-03 20:59:17 +00:00
|
|
|
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
|
|
|
|
2010-01-03 16:43:59 +00:00
|
|
|
//game delays: slow 16, normal 11, fast 5, crazy 1
|
|
|
|
//mark delays: 4 * (3 - hero_speed), normal == 1
|
2010-01-05 20:58:41 +00:00
|
|
|
//game delays in 1/100th of seconds
|
|
|
|
uint32 new_timer = _system->getMillis();
|
|
|
|
uint32 delta = new_timer - timer;
|
|
|
|
timer = new_timer;
|
|
|
|
|
2010-01-05 22:09:16 +00:00
|
|
|
bool tick_game = game_timer <= delta;
|
|
|
|
if (tick_game)
|
2010-01-08 18:03:34 +00:00
|
|
|
game_timer = _game_delay - ((delta - game_timer) % _game_delay);
|
2010-01-05 22:09:16 +00:00
|
|
|
else
|
|
|
|
game_timer -= delta;
|
|
|
|
|
|
|
|
bool tick_mark = mark_timer <= delta;
|
|
|
|
if (tick_mark)
|
2010-01-08 18:03:34 +00:00
|
|
|
mark_timer = _mark_delay - ((delta - mark_timer) % _mark_delay);
|
2010-01-05 22:09:16 +00:00
|
|
|
else
|
|
|
|
mark_timer -= delta;
|
|
|
|
|
|
|
|
if (tick_game || tick_mark) {
|
|
|
|
bool b = scene->render(tick_game, tick_mark, delta);
|
2010-01-05 20:58:41 +00:00
|
|
|
if (!inventory->active() && !b && 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;
|
|
|
|
}
|
2010-01-05 20:58:41 +00:00
|
|
|
scene_busy = b;
|
2010-01-05 22:09:16 +00:00
|
|
|
}
|
2010-02-25 19:58:54 +00:00
|
|
|
_system->showMouse(scene->getMessage().empty() && !scene_busy);
|
2010-01-05 20:58:41 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
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);
|
2010-01-01 13:53:40 +00:00
|
|
|
#if 0
|
2009-09-03 20:59:17 +00:00
|
|
|
if (current_object) {
|
2010-01-01 13:53:40 +00:00
|
|
|
current_object->rect.render(surface, 0x80);
|
|
|
|
current_object->actor_rect.render(surface, 0x81);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
2010-01-01 13:53:40 +00:00
|
|
|
#endif
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2010-01-08 10:35:25 +00:00
|
|
|
inventory->render(surface, tick_game? 1: 0);
|
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
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
console->onFrame();
|
2009-11-08 19:11:57 +00:00
|
|
|
|
2010-01-05 20:58:41 +00:00
|
|
|
uint32 next_tick = MIN(game_timer, mark_timer);
|
|
|
|
if (next_tick > 0) {
|
|
|
|
_system->delayMillis(next_tick > 40? 40: next_tick);
|
|
|
|
}
|
2010-01-09 11:39:01 +00:00
|
|
|
} while (!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];
|
2010-01-13 15:17:22 +00:00
|
|
|
message += c != 0 && (signed char)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;
|
|
|
|
}
|
2009-11-17 22:59:17 +00:00
|
|
|
|
2010-02-07 17:13:39 +00:00
|
|
|
if (color == 0xd1) { //mark's
|
2009-11-17 22:59:17 +00:00
|
|
|
SceneEvent e(SceneEvent::kPlayAnimation);
|
|
|
|
e.animation = 0;
|
|
|
|
e.slot = 0x80;
|
|
|
|
scene->push(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SceneEvent event(SceneEvent::kMessage);
|
|
|
|
event.message = str;
|
|
|
|
event.color = color;
|
|
|
|
event.slot = 0;
|
|
|
|
event.dst.x = position % 320;
|
|
|
|
event.dst.y = position / 320;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SceneEvent e(SceneEvent::kPauseAnimation);
|
|
|
|
e.animation = 0;
|
|
|
|
e.slot = 0x80;
|
|
|
|
scene->push(e);
|
|
|
|
}
|
2009-11-08 20:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2009-11-12 10:32:29 +00:00
|
|
|
event.slot = 0;
|
2009-11-08 20:00:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-08 21:59:26 +00:00
|
|
|
void TeenAgentEngine::displayAsyncMessageInSlot(uint16 addr, byte slot, uint16 first_frame, uint16 last_frame, byte color) {
|
|
|
|
SceneEvent event(SceneEvent::kMessage);
|
|
|
|
event.message = parseMessage(addr);
|
2009-11-12 10:32:29 +00:00
|
|
|
event.slot = slot + 1;
|
2009-11-08 21:59:26 +00:00
|
|
|
event.color = color;
|
|
|
|
event.first_frame = first_frame;
|
|
|
|
event.last_frame = last_frame;
|
|
|
|
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-08 22:13:06 +00:00
|
|
|
void TeenAgentEngine::displayCredits(uint16 addr, uint16 timer) {
|
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;
|
2009-12-08 22:13:06 +00:00
|
|
|
event.timer = timer;
|
2009-09-13 09:54:53 +00:00
|
|
|
scene->push(event);
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 22:04:00 +00:00
|
|
|
void TeenAgentEngine::displayCredits() {
|
|
|
|
SceneEvent event(SceneEvent::kCredits);
|
|
|
|
event.message = parseMessage(0xe488);
|
|
|
|
event.dst.y = 200;
|
|
|
|
|
|
|
|
int lines = 1;
|
|
|
|
for(uint i = 0; i < event.message.size(); ++i)
|
|
|
|
if (event.message[i] == '\n')
|
|
|
|
++lines;
|
|
|
|
event.dst.x = (320 - Resources::instance()->font7.render(NULL, 0, 0, event.message, 0xd1)) / 2;
|
|
|
|
event.timer = 11 * lines - event.dst.y + 22;
|
|
|
|
//debug(0, "credits = %s", event.message.c_str());
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
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;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-10-31 18:49:47 +00:00
|
|
|
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-11-09 23:22:35 +00:00
|
|
|
void TeenAgentEngine::playAnimation(uint16 id, byte slot, bool async, bool ignore, bool loop) {
|
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-12 10:32:29 +00:00
|
|
|
event.slot = (slot + 1) | (ignore? 0x20: 0) | (loop? 0x80: 0);
|
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-11-09 07:58:27 +00:00
|
|
|
void TeenAgentEngine::playActorAnimation(uint16 id, bool async, bool ignore) {
|
2009-09-15 20:21:18 +00:00
|
|
|
SceneEvent event(SceneEvent::kPlayActorAnimation);
|
2009-09-09 20:42:44 +00:00
|
|
|
event.animation = id;
|
2009-11-09 07:58:27 +00:00
|
|
|
event.slot = ignore? 0x20: 0;
|
2009-09-09 20:42:44 +00:00
|
|
|
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-12-27 18:21:49 +00:00
|
|
|
if (scene->last_event_type() != SceneEvent::kCreditsMessage)
|
|
|
|
fadeOut();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
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);
|
2009-12-27 18:21:49 +00:00
|
|
|
fadeIn();
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 07:38:09 +00:00
|
|
|
void TeenAgentEngine::enableOn(bool enable) {
|
|
|
|
SceneEvent event(SceneEvent::kSetOn);
|
|
|
|
event.ons = 0;
|
|
|
|
event.color = enable? 1: 0;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-02-07 17:13:39 +00:00
|
|
|
void TeenAgentEngine::setFlag(uint16 addr, byte value) {
|
|
|
|
SceneEvent event(SceneEvent::kSetFlag);
|
|
|
|
event.callback = addr;
|
|
|
|
event.color = value;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2010-02-26 07:36:52 +00:00
|
|
|
byte TeenAgentEngine::getFlag(uint16 addr) {
|
|
|
|
return scene->peekFlagEvent(addr);
|
|
|
|
}
|
2010-02-07 17:13:39 +00:00
|
|
|
|
2009-09-03 20:59:17 +00:00
|
|
|
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;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
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-11-08 21:59:26 +00:00
|
|
|
void TeenAgentEngine::setTimerCallback(uint16 addr, uint16 frames) {
|
|
|
|
SceneEvent event(SceneEvent::kTimer);
|
|
|
|
event.callback = addr;
|
|
|
|
event.timer = frames;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
2009-11-07 12:00:56 +00:00
|
|
|
|
2009-11-17 22:45:41 +00:00
|
|
|
void TeenAgentEngine::shakeScreen() {
|
|
|
|
SceneEvent event(SceneEvent::kEffect);
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2009-12-27 18:21:49 +00:00
|
|
|
void TeenAgentEngine::fadeIn() {
|
|
|
|
SceneEvent event(SceneEvent::kFade);
|
|
|
|
event.orientation = 0;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TeenAgentEngine::fadeOut() {
|
|
|
|
SceneEvent event(SceneEvent::kFade);
|
|
|
|
event.orientation = 1;
|
|
|
|
scene->push(event);
|
|
|
|
}
|
|
|
|
|
2010-02-02 07:26:36 +00:00
|
|
|
void TeenAgentEngine::wait(uint16 frames) {
|
|
|
|
SceneEvent event(SceneEvent::kWait);
|
|
|
|
event.timer = frames * 10;
|
|
|
|
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();
|
2010-03-20 16:52:51 +00:00
|
|
|
uint size = res->sam_sam.getSize(id);
|
|
|
|
if (size == 0) {
|
2010-01-08 16:21:36 +00:00
|
|
|
warning("skipping invalid sound %u", id);
|
2009-09-03 20:59:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-19 11:22:14 +00:00
|
|
|
byte *data = (byte *)malloc(size);
|
2010-03-20 16:52:51 +00:00
|
|
|
res->sam_sam.read(id, data, size);
|
2009-09-05 15:04:37 +00:00
|
|
|
//debug(0, "playing %u samples...", size);
|
2009-09-15 08:54:06 +00:00
|
|
|
|
2010-01-30 15:26:54 +00:00
|
|
|
Audio::AudioStream *stream = Audio::makeRawStream(data, size, 11025, 0);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream); //dispose is YES by default
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TeenAgentEngine::setMusic(byte id) {
|
|
|
|
debug(0, "starting music %u", id);
|
2010-05-07 07:56:57 +00:00
|
|
|
Resources *res = Resources::instance();
|
|
|
|
|
|
|
|
if (id != 1) //intro music
|
|
|
|
*res->dseg.ptr(0xDB90) = id;
|
|
|
|
|
|
|
|
if (_gameDescription->flags & ADGF_CD) {
|
|
|
|
byte track2cd[] = {7, 2, 0, 9, 3, 6, 8, 10, 4, 5, 11};
|
|
|
|
if (id == 0 || id > 11 || track2cd[id - 1] == 0) {
|
|
|
|
debug(0, "no cd music for id %u", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
byte track = track2cd[id - 1];
|
|
|
|
debug(0, "playing cd track %u", track);
|
2010-06-15 04:13:12 +00:00
|
|
|
_system->getAudioCDManager()->play(track, -1, 0, 0);
|
2010-05-07 07:56:57 +00:00
|
|
|
} else if (music->load(id))
|
|
|
|
music->start();
|
2009-09-03 20:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2010-03-20 15:00:42 +00:00
|
|
|
case kSupportsSubtitleOptions:
|
2009-09-03 20:59:17 +00:00
|
|
|
case kSupportsLoadingDuringRuntime:
|
|
|
|
case kSupportsSavingDuringRuntime:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-09-04 20:08:33 +00:00
|
|
|
|
|
|
|
} // End of namespace TeenAgent
|