2009-08-04 13:27:04 +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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-10-06 00:44:08 +00:00
|
|
|
#include "asylum/views/scene.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
|
2010-10-06 00:44:08 +00:00
|
|
|
#include "asylum/resources/actor.h"
|
2010-11-03 04:29:56 +00:00
|
|
|
#include "asylum/resources/encounters.h"
|
2010-11-05 04:14:46 +00:00
|
|
|
#include "asylum/resources/object.h"
|
|
|
|
#include "asylum/resources/polygons.h"
|
2010-12-02 09:29:26 +00:00
|
|
|
#include "asylum/resources/script.h"
|
2010-11-04 22:19:02 +00:00
|
|
|
#include "asylum/resources/special.h"
|
2010-11-05 04:14:46 +00:00
|
|
|
#include "asylum/resources/worldstats.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
|
2010-10-06 00:44:08 +00:00
|
|
|
#include "asylum/system/config.h"
|
2010-11-05 04:14:46 +00:00
|
|
|
#include "asylum/system/cursor.h"
|
|
|
|
#include "asylum/system/graphics.h"
|
|
|
|
#include "asylum/system/screen.h"
|
|
|
|
#include "asylum/system/speech.h"
|
|
|
|
#include "asylum/system/text.h"
|
|
|
|
|
2010-11-08 21:08:50 +00:00
|
|
|
#include "asylum/views/scenetitle.h"
|
|
|
|
|
2010-11-05 04:14:46 +00:00
|
|
|
#include "asylum/asylum.h"
|
|
|
|
#include "asylum/respack.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
#include "asylum/staticres.h"
|
|
|
|
|
2010-11-05 04:14:46 +00:00
|
|
|
#include "common/file.h"
|
|
|
|
|
2009-08-04 13:27:04 +00:00
|
|
|
namespace Asylum {
|
|
|
|
|
|
|
|
#define SCREEN_EDGES 40
|
|
|
|
#define SCROLL_STEP 10
|
|
|
|
|
|
|
|
int g_debugPolygons;
|
2010-11-04 22:14:44 +00:00
|
|
|
int g_debugObjects;
|
2009-12-05 20:51:46 +00:00
|
|
|
int g_debugScrolling;
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
Scene::Scene(AsylumEngine *engine): _vm(engine),
|
2010-12-02 09:29:36 +00:00
|
|
|
_polygons(NULL), _ws(NULL) {
|
2010-11-09 00:58:34 +00:00
|
|
|
|
|
|
|
// Initialize data
|
|
|
|
_packId = kResourcePackInvalid;
|
2010-12-02 09:29:14 +00:00
|
|
|
_playerIndex = 0;
|
2010-12-01 19:22:42 +00:00
|
|
|
|
2010-12-02 09:29:42 +00:00
|
|
|
_hitAreaChapter7Counter = 0;
|
2010-12-02 09:29:59 +00:00
|
|
|
_chapter5FrameIndex = 0;
|
2010-12-02 09:29:42 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
g_debugPolygons = 0;
|
|
|
|
g_debugObjects = 0;
|
|
|
|
g_debugScrolling = 0;
|
2010-11-08 21:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene() {
|
2010-11-09 00:58:34 +00:00
|
|
|
// Unload the associated resources
|
|
|
|
getResource()->unload(_packId);
|
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
// Clear script queue
|
|
|
|
getScript()->reset();
|
|
|
|
|
2010-11-16 14:24:27 +00:00
|
|
|
delete _polygons;
|
|
|
|
delete _ws;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2010-11-16 14:24:27 +00:00
|
|
|
// Zero passed pointers
|
|
|
|
_vm = NULL;
|
2010-11-08 21:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::enter(ResourcePackId packId) {
|
|
|
|
_vm->setGameFlag(kGameFlagScriptProcessing);
|
|
|
|
|
|
|
|
getCursor()->hide();
|
|
|
|
|
2010-12-02 09:29:14 +00:00
|
|
|
_playerIndex = 0;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Load the scene data
|
|
|
|
load(packId);
|
|
|
|
|
|
|
|
// Set wheel indices
|
2010-11-09 03:04:33 +00:00
|
|
|
_ws->setWheelObjects();
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Adjust object priority
|
|
|
|
if (_ws->objects.size() > 0) {
|
|
|
|
int32 priority = 4091;
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < _ws->objects.size(); i++) {
|
|
|
|
Object *object = _ws->objects[i];
|
|
|
|
object->setPriority(priority);
|
|
|
|
object->flags &= ~kObjectFlagC000;
|
|
|
|
priority -= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the cursor to magnifying glass
|
2010-12-02 11:10:46 +00:00
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceMagnifyingGlass]);
|
2010-11-08 21:09:13 +00:00
|
|
|
getCursor()->show();
|
|
|
|
|
|
|
|
// Clear the graphic queue
|
|
|
|
getScreen()->clearGraphicsInQueue();
|
|
|
|
|
|
|
|
_ws->sceneRectIdx = 0;
|
|
|
|
_ws->motionStatus = 1;
|
|
|
|
|
|
|
|
// Update current player bounding rectangle
|
|
|
|
Actor *player = getActor();
|
|
|
|
Common::Rect *boundingRect = player->getBoundingRect();
|
2010-11-16 14:24:57 +00:00
|
|
|
boundingRect->bottom = (int16)player->getPoint2()->y;
|
|
|
|
boundingRect->right = (int16)(player->getPoint2()->x * 2);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Adjust scene bounding rect
|
|
|
|
_ws->boundingRect = Common::Rect(195, 115, 445 - boundingRect->right, 345 - boundingRect->bottom);
|
|
|
|
|
|
|
|
// Hide actor
|
|
|
|
player->hide();
|
2010-11-16 14:24:46 +00:00
|
|
|
player->enable();
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Update current player coordinates
|
2010-11-16 14:24:57 +00:00
|
|
|
player->getPoint1()->x -= player->getPoint2()->x;
|
|
|
|
player->getPoint1()->y -= player->getPoint2()->y;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Update all other actors
|
|
|
|
if (_ws->actors.size() > 1) {
|
|
|
|
for (uint32 i = 1; i < _ws->actors.size(); i++) {
|
|
|
|
Actor *actor = _ws->actors[i];
|
|
|
|
|
|
|
|
actor->hide();
|
2010-11-27 00:03:04 +00:00
|
|
|
actor->setDirection(kDirectionNO);
|
2010-11-16 14:24:46 +00:00
|
|
|
actor->enable();
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2010-11-16 14:24:57 +00:00
|
|
|
actor->getPoint1()->x -= actor->getPoint2()->x;
|
|
|
|
actor->getPoint1()->y -= actor->getPoint2()->y;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2010-11-16 14:24:57 +00:00
|
|
|
actor->getBoundingRect()->bottom = (int16)actor->getPoint2()->y;
|
|
|
|
actor->getBoundingRect()->right = (int16)(2 * actor->getPoint2()->x);
|
2010-11-08 21:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Queue scene script
|
|
|
|
if (_ws->scriptIndex)
|
2010-12-02 09:29:26 +00:00
|
|
|
getScript()->queueScript(_ws->scriptIndex, 0);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Clear the graphic queue (FIXME: not sure why we need to do this again)
|
|
|
|
getScreen()->clearGraphicsInQueue();
|
|
|
|
|
2010-11-28 01:27:07 +00:00
|
|
|
// Load transparency tables
|
|
|
|
getScreen()->setupTransTables(3, _ws->cellShadeMask1, _ws->cellShadeMask2, _ws->cellShadeMask3);
|
|
|
|
getScreen()->selectTransTable(1);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Setup font
|
|
|
|
getText()->loadFont(_ws->font1);
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
// Preload graphics (we are just showing the loading screen
|
|
|
|
preload();
|
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
// Play scene intro dialog
|
|
|
|
playIntroSpeech();
|
|
|
|
|
|
|
|
// Set actor type
|
|
|
|
_ws->actorType = actorType[_ws->chapter];
|
|
|
|
|
|
|
|
// Play intro music
|
2010-11-10 12:08:38 +00:00
|
|
|
if (_ws->musicCurrentResourceIndex != kMusicStopped && _ws->chapter != kChapter1)
|
2010-12-01 19:22:37 +00:00
|
|
|
getSound()->playMusic(MAKE_RESOURCE(kResourcePackMusic, _ws->musicCurrentResourceIndex));
|
|
|
|
else
|
|
|
|
getSound()->playMusic(kResourceNone, 0);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Update global values
|
2010-11-16 14:24:46 +00:00
|
|
|
_vm->lastScreenUpdate = 1;
|
|
|
|
getSharedData()->setFlag(kFlagScene1, true);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2010-11-16 14:24:46 +00:00
|
|
|
player->setLastScreenUpdate(_vm->screenUpdateCount);
|
|
|
|
player->enable();
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
if (_ws->chapter == kChapter9) {
|
|
|
|
changePlayer(1);
|
2010-11-27 00:02:55 +00:00
|
|
|
_ws->nextPlayer = kActorInvalid;
|
2010-11-08 21:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::load(ResourcePackId packId) {
|
2010-11-09 00:58:40 +00:00
|
|
|
// Setup resource manager
|
2010-11-08 21:08:56 +00:00
|
|
|
_packId = packId;
|
2010-11-09 00:58:40 +00:00
|
|
|
getResource()->setMusicPackId(packId);
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
char filename[10];
|
2010-11-08 21:08:56 +00:00
|
|
|
sprintf(filename, SCENE_FILE_MASK, _packId);
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
char sceneTag[6];
|
|
|
|
Common::File* fd = new Common::File;
|
2009-09-09 22:50:34 +00:00
|
|
|
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!Common::File::exists(filename))
|
2009-09-19 12:24:53 +00:00
|
|
|
error("Scene file doesn't exist %s", filename);
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
fd->open(filename);
|
2009-08-06 00:04:09 +00:00
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
if (!fd->isOpen())
|
|
|
|
error("Failed to load scene file %s", filename);
|
|
|
|
|
|
|
|
fd->read(sceneTag, 6);
|
|
|
|
|
2009-09-21 19:11:49 +00:00
|
|
|
if (Common::String(sceneTag, 6) != "DFISCN")
|
2009-09-19 12:24:53 +00:00
|
|
|
error("The file isn't recognized as scene %s", filename);
|
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
_ws = new WorldStats(_vm);
|
|
|
|
_ws->load(fd);
|
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
_polygons = new Polygons(fd);
|
2010-12-01 19:22:37 +00:00
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
getScript()->load(fd);
|
2009-09-19 12:24:53 +00:00
|
|
|
|
|
|
|
fd->close();
|
|
|
|
delete fd;
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
_vm->resetFlags();
|
2009-11-24 11:25:30 +00:00
|
|
|
_ws->field_120 = -1;
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
int32 tick = _vm->getTick();
|
2010-11-07 19:36:21 +00:00
|
|
|
for (uint32 a = 0; a < _ws->actors.size(); a++)
|
2010-12-02 09:30:15 +00:00
|
|
|
_ws->actors[a]->setLastScreenUpdate(tick);
|
2009-11-24 11:25:30 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
getCursor()->show();
|
2009-11-24 11:25:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Event handling
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-01 19:22:37 +00:00
|
|
|
bool Scene::handleEvent(const AsylumEvent &evt) {
|
2010-12-01 19:22:42 +00:00
|
|
|
switch ((uint32)evt.type) {
|
|
|
|
default:
|
|
|
|
break;
|
2010-12-01 19:21:56 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
case EVENT_ASYLUM_INIT:
|
|
|
|
return init();
|
2010-11-16 14:24:27 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
case EVENT_ASYLUM_ACTIVATE:
|
2010-12-02 04:34:43 +00:00
|
|
|
case Common::EVENT_RBUTTONUP:
|
2010-12-01 19:22:42 +00:00
|
|
|
activate();
|
|
|
|
break;
|
2010-11-16 14:24:27 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
case EVENT_ASYLUM_UPDATE:
|
|
|
|
return update();
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-12-02 09:29:42 +00:00
|
|
|
if (evt.kbd.flags & Common::KBD_CTRL)
|
|
|
|
_isCTRLPressed = true;
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
return key(evt);
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2010-12-02 09:29:42 +00:00
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
if (!(evt.kbd.flags & Common::KBD_CTRL))
|
|
|
|
_isCTRLPressed = false;
|
|
|
|
break;
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2010-12-02 04:34:43 +00:00
|
|
|
case Common::EVENT_MBUTTONDOWN:
|
2010-12-01 19:22:42 +00:00
|
|
|
return clickDown(evt);
|
|
|
|
}
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-12-06 17:06:14 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
void Scene::activate() {
|
|
|
|
Actor *player = getActor();
|
2009-08-04 13:27:04 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
if (player->getStatus() == kActorStatus1)
|
|
|
|
player->updateStatus(kActorStatusEnabled);
|
2010-11-03 04:29:37 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
if (player->getStatus() == kActorStatus12)
|
|
|
|
player->updateStatus(kActorStatus14);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Scene::init() {
|
|
|
|
if (getSharedData()->getFlag((kFlag3))) { // this flag is set during an encounter
|
|
|
|
getSharedData()->setFlag(kFlag3, false);
|
|
|
|
|
|
|
|
// The original test for flag 1001 but doesn't use the result
|
2010-12-01 19:22:37 +00:00
|
|
|
return true;
|
2010-12-01 19:22:42 +00:00
|
|
|
}
|
2009-08-19 21:51:43 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceScrollUp]);
|
2010-12-01 19:22:42 +00:00
|
|
|
_ws->coordinates[0] = -1;
|
|
|
|
getScreen()->clear();
|
|
|
|
getText()->loadFont(_ws->font1);
|
2009-08-19 21:51:43 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
ResourceId paletteResource = _ws->actions[getActor()->getActionIndex3()]->paletteResourceId;
|
|
|
|
if (!paletteResource)
|
|
|
|
paletteResource = _ws->currentPaletteId;
|
2009-11-22 21:15:09 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
getScreen()->setPalette(paletteResource);
|
|
|
|
getScreen()->setGammaLevel(paletteResource, 0);
|
2010-12-02 02:34:09 +00:00
|
|
|
getScreen()->makeGreyPalette();
|
2010-12-01 19:22:42 +00:00
|
|
|
getScreen()->setupTransTables(3, _ws->cellShadeMask1, _ws->cellShadeMask2, _ws->cellShadeMask3);
|
|
|
|
getScreen()->selectTransTable(1);
|
2010-11-08 21:09:22 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
getCursor()->show();
|
2010-12-01 19:22:37 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
bool Scene::update() {
|
|
|
|
if (getEncounter()->getFlag1()) {
|
|
|
|
getEncounter()->setFlag1(false);
|
|
|
|
|
|
|
|
// Enable player
|
|
|
|
getActor()->updateStatus(kActorStatusEnabled);
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
uint32 ticks = _vm->getTick();
|
|
|
|
|
|
|
|
if (!getSharedData()->getFlag(kFlagRedraw)) {
|
|
|
|
if (updateScreen())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
getSharedData()->setFlag(kFlagRedraw, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ticks > getSharedData()->getNextScreenUpdate()) {
|
|
|
|
if (getSharedData()->getFlag(kFlagRedraw)) {
|
|
|
|
if (getSharedData()->getMatteBarHeight() <= 0)
|
|
|
|
getScreen()->copyBackBufferToScreen();
|
|
|
|
else
|
|
|
|
error("[Scene::update] Not implemented!");
|
|
|
|
|
|
|
|
// Original also sets an unused value to 0
|
|
|
|
getSharedData()->setData(39, getSharedData()->getData(39) ^ 1);
|
|
|
|
|
|
|
|
getSharedData()->setFlag(kFlagRedraw, false);
|
|
|
|
getSharedData()->setNextScreenUpdate(ticks + 55);
|
|
|
|
++_vm->screenUpdateCount;
|
|
|
|
}
|
|
|
|
}
|
2010-12-01 19:22:37 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
return true;
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
bool Scene::key(const AsylumEvent &evt) {
|
2010-12-02 09:29:42 +00:00
|
|
|
warning("[Scene::key] Not implemented!");
|
|
|
|
|
|
|
|
return true;
|
2010-12-01 19:22:42 +00:00
|
|
|
}
|
2010-11-16 14:24:27 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
bool Scene::clickDown(const AsylumEvent &evt) {
|
|
|
|
_vm->lastScreenUpdate = 0;
|
2010-11-16 14:24:27 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
if (getSharedData()->getFlag(kFlag2)) {
|
2010-12-02 04:34:43 +00:00
|
|
|
stopSpeech();
|
2010-12-01 19:22:42 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-10 20:45:19 +00:00
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
switch (evt.type) {
|
|
|
|
default:
|
|
|
|
break;
|
2010-11-10 20:45:19 +00:00
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
if (getSpeech()->getSoundResourceId())
|
|
|
|
stopSpeech();
|
|
|
|
|
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10) {
|
|
|
|
player->updateStatus(kActorStatusEnabled);
|
|
|
|
getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 5));
|
|
|
|
} else if (player->getStatus() != kActorStatusDisabled) {
|
|
|
|
player->updateStatus(kActorStatus1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_MBUTTONDOWN:
|
|
|
|
if (player->getStatus() != kActorStatusDisabled) {
|
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10)
|
|
|
|
player->updateStatus(kActorStatusEnabled);
|
|
|
|
else
|
|
|
|
player->updateStatus(kActorStatus6);
|
|
|
|
}
|
|
|
|
break;
|
2010-12-01 19:22:42 +00:00
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2010-12-02 11:10:46 +00:00
|
|
|
if (getCursor()->getState() & kCursorStateRight)
|
2010-12-02 04:34:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (getSpeech()->getSoundResourceId())
|
|
|
|
stopSpeech();
|
|
|
|
|
|
|
|
if (player->getStatus() == kActorStatusDisabled)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (player->getField638()) {
|
|
|
|
if (hitTestPlayer()) {
|
|
|
|
player->setField638(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
HitType type = kHitNone;
|
|
|
|
int32 res = hitTestScene(type);
|
|
|
|
|
|
|
|
if (res == -1)
|
|
|
|
getSpeech()->playIndexed(2);
|
|
|
|
else
|
|
|
|
handleHit(res, type);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hitTestPlayer() || player->getStatus() >= kActorStatus11 || !player->getReaction(0)) {
|
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10) {
|
|
|
|
playerReaction();
|
|
|
|
} else {
|
|
|
|
HitType type = kHitNone;
|
|
|
|
int32 res = hitTest(type);
|
|
|
|
if (res != -1)
|
|
|
|
handleHit(res, type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10) {
|
|
|
|
getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 5));
|
|
|
|
player->updateStatus(kActorStatusEnabled);
|
|
|
|
} else {
|
|
|
|
getSound()->playSound(MAKE_RESOURCE(kResourcePackSound, 2));
|
|
|
|
player->updateStatus(kActorStatus6);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2010-12-01 19:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scene update
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-01 19:22:52 +00:00
|
|
|
bool Scene::updateScreen() {
|
|
|
|
// Original has a frame counter (for showing fps)
|
|
|
|
|
|
|
|
if (updateScene())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Config.performance <= 4) {
|
|
|
|
// TODO when Config.performance <= 4, we need to skip drawing frames to screen
|
|
|
|
|
|
|
|
if (drawScene())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (drawScene())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
getActor()->drawNumber();
|
|
|
|
|
|
|
|
// Original handle all debug commands here (we do it as part of each update command)
|
|
|
|
|
|
|
|
if (getSharedData()->getFlag(kFlagScene1)) {
|
|
|
|
getScreen()->clear();
|
|
|
|
|
2010-12-02 09:30:24 +00:00
|
|
|
getScreen()->setupPaletteAndStartFade(0, 0, 0);
|
|
|
|
updateScene();
|
|
|
|
drawScene();
|
|
|
|
getScreen()->copyBackBufferToScreen();
|
2010-12-01 19:22:52 +00:00
|
|
|
|
2010-12-02 09:30:24 +00:00
|
|
|
getScreen()->stopFadeAndSetPalette(getWorld()->currentPaletteId, 100, 10);
|
|
|
|
drawScene();
|
|
|
|
getScreen()->copyBackBufferToScreen();
|
2010-12-01 19:22:52 +00:00
|
|
|
|
|
|
|
getSharedData()->setFlag(kFlagScene1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getSpeech()->getSoundResourceId() != 0) {
|
2010-12-02 09:29:36 +00:00
|
|
|
if (getSound()->isPlaying(getSpeech()->getSoundResourceId())) {
|
2010-12-01 19:22:52 +00:00
|
|
|
getSpeech()->prepareSpeech();
|
|
|
|
} else {
|
|
|
|
getSpeech()->resetResourceIds();
|
|
|
|
_vm->clearGameFlag(kGameFlag219);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getWorld()->chapter == kChapter5) {
|
|
|
|
if (_vm->isGameFlagSet(kGameFlag249))
|
2010-12-02 09:29:59 +00:00
|
|
|
drawChapter5();
|
2010-12-01 19:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
bool Scene::updateScene() {
|
2010-11-03 04:29:37 +00:00
|
|
|
#ifdef DEBUG_SCENE_TIMES
|
2010-11-03 04:28:14 +00:00
|
|
|
#define MESURE_TICKS(func) { \
|
|
|
|
int32 startTick =_vm->getTick(); \
|
|
|
|
func(); \
|
|
|
|
debugC(kDebugLevelScene, #func " Time: %d", _vm->getTick() - startTick); \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define MESURE_TICKS(func) func();
|
|
|
|
#endif
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-11-03 04:28:14 +00:00
|
|
|
// Update each part of the scene
|
2010-12-01 19:22:37 +00:00
|
|
|
if (getSharedData()->getMatteBarHeight() != 170 || getSharedData()->getMattePlaySound()) {
|
|
|
|
MESURE_TICKS(updateMouse);
|
|
|
|
MESURE_TICKS(updateActors);
|
|
|
|
MESURE_TICKS(updateObjects);
|
|
|
|
MESURE_TICKS(updateAmbientSounds);
|
|
|
|
MESURE_TICKS(updateMusic);
|
|
|
|
MESURE_TICKS(updateAdjustScreen);
|
|
|
|
|
|
|
|
// Update Debug
|
|
|
|
if (g_debugPolygons)
|
|
|
|
debugShowPolygons();
|
|
|
|
if (g_debugObjects)
|
|
|
|
debugShowObjects();
|
|
|
|
}
|
2009-12-05 20:51:46 +00:00
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
return getScript()->process();
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 11:14:42 +00:00
|
|
|
void Scene::updateMouse() {
|
2010-12-02 09:30:15 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
Common::Point mouse = getCursor()->position();
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
Common::Point pt;
|
|
|
|
player->adjustCoordinates(&pt);
|
|
|
|
|
|
|
|
Common::Rect actorRect;
|
|
|
|
if (_ws->chapter != kChapter2 || _playerIndex != 10) {
|
|
|
|
actorRect.left = pt.x + 20;
|
|
|
|
actorRect.top = pt.y;
|
|
|
|
actorRect.right = (int16)(pt.x + 2 * player->getPoint2()->x);
|
|
|
|
actorRect.bottom = (int16)(pt.y + player->getPoint2()->y);
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
actorRect.left = pt.x + 50;
|
|
|
|
actorRect.top = pt.y + 60;
|
|
|
|
actorRect.right = (int16)(pt.x + getActor(10)->getPoint2()->x + 10);
|
|
|
|
actorRect.bottom = (int16)(pt.y + getActor(10)->getPoint2()->y - 20);
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
ActorDirection newDirection = kDirectionInvalid;
|
2009-09-09 11:14:42 +00:00
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
if (mouse.x < actorRect.left) {
|
|
|
|
if (mouse.y >= actorRect.top) {
|
|
|
|
if (mouse.y > actorRect.bottom) {
|
|
|
|
if (player->getDirection() == kDirectionO) {
|
|
|
|
if ((mouse.y - actorRect.bottom) > 10)
|
|
|
|
newDirection = kDirectionSO;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionS) {
|
|
|
|
if ((actorRect.left - mouse.x) > 10)
|
|
|
|
newDirection = kDirectionSO;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionSO;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionNO) {
|
|
|
|
if ((mouse.y - actorRect.top) > 10)
|
|
|
|
newDirection = kDirectionO;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionSO) {
|
|
|
|
if ((actorRect.bottom - mouse.y) > 10)
|
|
|
|
newDirection = kDirectionO;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionO;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() != kDirectionN) {
|
|
|
|
if (player->getDirection() == kDirectionO) {
|
|
|
|
if ((actorRect.top - mouse.y) > 10)
|
|
|
|
newDirection = kDirectionNO;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionNO;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if ((actorRect.left - mouse.x) > 10)
|
|
|
|
newDirection = kDirectionNO;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if (mouse.x <= actorRect.right) {
|
|
|
|
if (mouse.y >= actorRect.top) {
|
|
|
|
if (mouse.y > actorRect.bottom) {
|
|
|
|
if (player->getDirection() == kDirectionSO) {
|
|
|
|
if ((mouse.x - actorRect.left) > 10)
|
|
|
|
newDirection = kDirectionS;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionSE) {
|
|
|
|
if ((actorRect.right - mouse.x) > 10)
|
|
|
|
newDirection = kDirectionS;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionS;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionNO) {
|
|
|
|
if ((mouse.x - actorRect.left) > 10)
|
|
|
|
newDirection = kDirectionN;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionNE) {
|
|
|
|
if ((actorRect.right - mouse.x) > 10)
|
|
|
|
newDirection = kDirectionN;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionN;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if (mouse.y < actorRect.top) {
|
|
|
|
if (player->getDirection() != kDirectionN) {
|
|
|
|
if (player->getDirection() == kDirectionE) {
|
|
|
|
if ((actorRect.top - mouse.y) > 10)
|
|
|
|
newDirection = kDirectionNE;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionNE;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if ((mouse.x - actorRect.right) > 10)
|
|
|
|
newDirection = kDirectionNE;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if (mouse.y <= actorRect.bottom) {
|
|
|
|
if (player->getDirection() == kDirectionSE) {
|
|
|
|
if ((actorRect.bottom - mouse.y) > 10)
|
|
|
|
newDirection = kDirectionE;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getDirection() == kDirectionNE) {
|
|
|
|
if ((mouse.y - actorRect.top) > 10)
|
|
|
|
newDirection = kDirectionE;
|
2009-09-09 11:14:42 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
newDirection = kDirectionE;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if ( player->getDirection() == kDirectionS) {
|
|
|
|
if ((mouse.x - actorRect.right) > 10)
|
|
|
|
newDirection = kDirectionSE;
|
|
|
|
} else if ((player->getDirection() != kDirectionE || (mouse.y - actorRect.bottom) > 10)) {
|
|
|
|
newDirection = kDirectionSE;
|
2009-09-09 11:14:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
updateCursor(newDirection, actorRect);
|
2009-09-09 11:14:42 +00:00
|
|
|
|
2010-12-02 09:30:24 +00:00
|
|
|
if (newDirection >= kDirectionN)
|
2010-12-02 09:30:15 +00:00
|
|
|
if (player->getStatus() == kActorStatus1 || player->getStatus() == kActorStatus12)
|
|
|
|
player->updateFromDirection(newDirection);
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
|
|
|
|
void Scene::updateActors() {
|
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::updateActors] WorldStats not initialized properly!");
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < _ws->actors.size(); i++)
|
|
|
|
_ws->actors[i]->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateObjects() {
|
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::updateObjects] WorldStats not initialized properly!");
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < _ws->objects.size(); i++)
|
|
|
|
_ws->objects[i]->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateAmbientSounds() {
|
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::updateAmbientSounds] WorldStats not initialized properly!");
|
|
|
|
|
|
|
|
if (Config.performance <= 3)
|
|
|
|
return;
|
|
|
|
|
2010-12-02 09:30:15 +00:00
|
|
|
// The original loops for each actor, but the volume calculation is always the same
|
|
|
|
|
|
|
|
for (int32 i = 0; i < _ws->numAmbientSounds; i++) {
|
2010-12-02 04:34:47 +00:00
|
|
|
bool processSound = true;
|
|
|
|
AmbientSoundItem *snd = &_ws->ambientSounds[i];
|
2010-12-02 09:30:15 +00:00
|
|
|
uint32 *ambientTick = getSharedData()->getAmbientTick(i);
|
2010-12-02 04:34:47 +00:00
|
|
|
|
|
|
|
for (int32 f = 0; f < 6; f++) {
|
|
|
|
GameFlag gameFlag = snd->flagNum[f];
|
|
|
|
if (gameFlag >= 0) {
|
|
|
|
if (_vm->isGameFlagNotSet(gameFlag)) {
|
|
|
|
processSound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_vm->isGameFlagSet((GameFlag)-gameFlag)) {
|
|
|
|
processSound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (processSound) {
|
|
|
|
if (_vm->sound()->isPlaying(snd->resourceId)) {
|
2010-12-02 09:30:15 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
if (snd->field_0) {
|
2010-12-02 09:30:15 +00:00
|
|
|
int32 volume = Config.ambientVolume + getSound()->calculateVolumeAdjustement(snd->x, snd->y, snd->attenuation, snd->delta);
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
if (volume <= 0) {
|
|
|
|
if (volume < -10000)
|
|
|
|
volume = -10000;
|
2010-12-02 09:30:15 +00:00
|
|
|
|
|
|
|
getSound()->setVolume(snd->resourceId, volume);
|
|
|
|
} else {
|
|
|
|
getSound()->setVolume(snd->resourceId, 0);
|
|
|
|
}
|
2010-12-02 04:34:47 +00:00
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
int32 panning = (snd->field_0) ? getSound()->calculatePanningAtPoint(snd->x, snd->y) : 0;
|
|
|
|
|
|
|
|
int32 volume = 0;
|
|
|
|
if (snd->field_0)
|
2010-12-02 04:34:47 +00:00
|
|
|
volume = getSound()->calculateVolumeAdjustement(snd->x, snd->y, snd->attenuation, snd->delta);
|
2010-12-02 09:30:15 +00:00
|
|
|
else
|
|
|
|
volume = -pow((double)snd->delta, 2);
|
|
|
|
|
|
|
|
volume += Config.ambientVolume;
|
|
|
|
|
|
|
|
|
|
|
|
if (LOBYTE(snd->flags) & 1) {
|
|
|
|
|
|
|
|
getSound()->playSound(snd->resourceId, true, volume, panning);
|
|
|
|
|
|
|
|
} else if (LOBYTE(snd->flags) & 2) {
|
2010-12-02 04:34:47 +00:00
|
|
|
if (_vm->getRandom(10000) < 10) {
|
|
|
|
if (snd->field_0) {
|
|
|
|
getSound()->playSound(snd->resourceId, false, volume, panning);
|
|
|
|
} else {
|
2010-12-02 09:30:15 +00:00
|
|
|
int32 tmpVol = volume + _vm->getRandom(500) * ((((_vm->getRandom(100) >= 50) - 1) & 2) - 1);
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
if (tmpVol <= -10000)
|
2010-12-02 09:30:15 +00:00
|
|
|
tmpVol = -10000;
|
|
|
|
|
|
|
|
if (tmpVol >= 0)
|
2010-12-02 04:34:47 +00:00
|
|
|
tmpVol = 0;
|
2010-12-02 09:30:15 +00:00
|
|
|
else if (tmpVol <= -10000)
|
|
|
|
tmpVol = -10000;
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
getSound()->playSound(snd->resourceId, false, tmpVol, _vm->getRandom(20001) - 10000);
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if (LOBYTE(snd->flags) & 4) {
|
|
|
|
if (*ambientTick > _vm->getTick()) {
|
|
|
|
if (snd->nextTick >= 0)
|
|
|
|
*ambientTick = 60000 * snd->nextTick + _vm->getTick();
|
|
|
|
else
|
|
|
|
*ambientTick = _vm->getTick() - 1000 * snd->nextTick;
|
|
|
|
|
|
|
|
getSound()->playSound(snd->resourceId, false, volume, panning);
|
2010-12-02 04:34:47 +00:00
|
|
|
}
|
2010-12-02 09:30:15 +00:00
|
|
|
} else if (LOBYTE(snd->flags) & 8) {
|
|
|
|
if (_vm->getGameFlagByIndex(85 + i)) {
|
|
|
|
getSound()->playSound(snd->resourceId, false, volume, panning);
|
|
|
|
_vm->setGameFlagByIndex(85 + i);
|
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_vm->sound()->isPlaying(snd->resourceId))
|
|
|
|
_vm->sound()->stop(snd->resourceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateMusic() {
|
|
|
|
//warning("[Scene::updateMusic] not implemented!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateAdjustScreen() {
|
|
|
|
if (g_debugScrolling) {
|
|
|
|
debugScreenScrolling();
|
|
|
|
} else {
|
|
|
|
updateCoordinates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::updateCoordinates() {
|
|
|
|
Actor *act = getActor();
|
|
|
|
int32 newXLeft = -1;
|
|
|
|
int32 newYTop = -1;
|
|
|
|
Common::Rect b = _ws->boundingRect;
|
|
|
|
|
|
|
|
if (_ws->motionStatus == 1) {
|
|
|
|
int32 posX = act->getPoint1()->x - _ws->xLeft;
|
|
|
|
int32 posY = act->getPoint1()->y - _ws->yTop;
|
|
|
|
|
|
|
|
if (posX < b.left || posX > b.right) {
|
|
|
|
int32 newRBounds = posX - b.right;
|
|
|
|
newXLeft = newRBounds + _ws->xLeft;
|
|
|
|
_ws->xLeft += newRBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (posY < b.top || posY > b.bottom) {
|
|
|
|
int32 newBBounds = posY - b.bottom;
|
|
|
|
newYTop = newBBounds + _ws->yTop;
|
|
|
|
_ws->yTop += newBBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newXLeft < 0)
|
|
|
|
newXLeft = _ws->xLeft = 0;
|
|
|
|
|
|
|
|
if (newXLeft > _ws->width - 640)
|
|
|
|
newXLeft = _ws->xLeft = _ws->width - 640;
|
|
|
|
|
|
|
|
if (newYTop < 0)
|
|
|
|
newYTop = _ws->yTop = 0;
|
|
|
|
|
|
|
|
if (newYTop > _ws->height - 480)
|
|
|
|
newYTop = _ws->yTop = _ws->height - 480;
|
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 rectIndex = _ws->sceneRectIdx;
|
|
|
|
b = _ws->sceneRects[rectIndex];
|
|
|
|
|
|
|
|
if (newXLeft < b.left)
|
|
|
|
newXLeft = _ws->xLeft = b.left;
|
|
|
|
|
|
|
|
if (newYTop < b.top)
|
|
|
|
newYTop = _ws->yTop = b.top;
|
|
|
|
|
|
|
|
if (newXLeft + 639 > b.right)
|
|
|
|
newXLeft = _ws->xLeft = b.right - 639;
|
|
|
|
|
|
|
|
if (newYTop + 479 > b.bottom)
|
|
|
|
newYTop = _ws->yTop = b.bottom - 479;
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
void Scene::updateCursor(ActorDirection direction, Common::Rect rect) {
|
2009-12-23 12:13:41 +00:00
|
|
|
HitType type = kHitNone;
|
2010-12-02 11:10:46 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
int16 rightLimit = rect.right - 10;
|
|
|
|
Common::Point mouse = getCursor()->position();
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
if (getEncounter()->getFlag6()) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceTalkNPC])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceTalkNPC], 0, 2);
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
if (getCursor()->getState() & kCursorStateRight) {
|
|
|
|
if (player->getStatus() == kActorStatus1 || player->getStatus() == kActorStatus12) {
|
|
|
|
|
|
|
|
ResourceId resourceId =_ws->cursorResources[direction];
|
|
|
|
|
|
|
|
if (direction >= kDirectionN && getCursor()->graphicResourceId != resourceId)
|
|
|
|
getCursor()->set(resourceId, 0, 2);
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
2010-12-02 11:10:46 +00:00
|
|
|
|
|
|
|
return;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceHand])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceHand], 0, 2);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player->getField638()) {
|
|
|
|
if (mouse.x >= rect.left && mouse.x <= rightLimit && mouse.y >= rect.top && mouse.y <= rect.bottom && hitTestPlayer()) {
|
|
|
|
|
|
|
|
ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 31];
|
|
|
|
if (getCursor()->graphicResourceId != id)
|
|
|
|
getCursor()->set(id, 0, 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (hitTestScene(type) == -1) {
|
|
|
|
ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 31];
|
|
|
|
if (getCursor()->graphicResourceId != id)
|
|
|
|
getCursor()->set(id, 0, 0);
|
2009-12-23 12:13:41 +00:00
|
|
|
} else {
|
2010-12-02 11:10:46 +00:00
|
|
|
ResourceId id = _ws->cursorResourcesAlternate[player->getField638() + 47];
|
|
|
|
uint32 frameCount = GraphicResource::getFrameCount(_vm, id);
|
|
|
|
if (getCursor()->graphicResourceId != id)
|
|
|
|
getCursor()->set(id, 0, ((frameCount <= 1) - 1) & 2);
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-02 11:10:46 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mouse.x >= rect.left && mouse.x <= rightLimit && mouse.y >= rect.top && mouse.y <= rect.bottom && hitTestPlayer()) {
|
|
|
|
if (player->getReaction(0)) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceGrabPointer])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceGrabPointer], 0, 2);
|
|
|
|
|
|
|
|
return;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
2010-12-02 11:10:46 +00:00
|
|
|
}
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
int32 index = hitTest(type);
|
|
|
|
if (index == -1) {
|
|
|
|
if (_ws->chapter != kChapter2 || _playerIndex != 10) {
|
|
|
|
if (getCursor()->flags || getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceMagnifyingGlass])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceMagnifyingGlass], 0, 2);
|
|
|
|
} else {
|
|
|
|
if (getCursor()->flags || getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceTalkNPC2])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceTalkNPC2], 0, 2);
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
2010-12-02 11:10:46 +00:00
|
|
|
|
|
|
|
return;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
int32 actionType = 0;
|
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
error("[Scene::updateCursor] Invalid hit type!");
|
|
|
|
break;
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:46 +00:00
|
|
|
case kHitActionArea:
|
|
|
|
actionType = _ws->actions[index]->actionType;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHitObject:
|
|
|
|
actionType = _ws->objects[index]->actionType;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHitActor:
|
|
|
|
actionType = getActor(index)->actionType;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actionType & kActionTypeFind) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceMagnifyingGlass] || getCursor()->flags != 2)
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceMagnifyingGlass], 0, 2);
|
|
|
|
} else if (actionType & kActionTypeTalk) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceTalkNPC])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceTalkNPC], 0, 2);
|
|
|
|
} else if (actionType & kActionTypeGrab) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceHand])
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceHand], 0, 2);
|
|
|
|
} else if (actionType & kActionType16) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceTalkNPC2] || getCursor()->flags != 2)
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceTalkNPC2], 0, 2);
|
|
|
|
} else if (_ws->chapter != kChapter2 && _playerIndex != 10) {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceMagnifyingGlass] || getCursor()->flags)
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceMagnifyingGlass], 0, 2);
|
|
|
|
} else {
|
|
|
|
if (getCursor()->graphicResourceId != _ws->cursorResources[kCursorResourceTalkNPC2] || getCursor()->flags)
|
|
|
|
getCursor()->set(_ws->cursorResources[kCursorResourceTalkNPC2], 0, 2);
|
|
|
|
}
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// HitTest
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-02 04:34:43 +00:00
|
|
|
int32 Scene::hitTest(HitType &type) {
|
2009-12-23 12:13:41 +00:00
|
|
|
type = kHitNone;
|
2010-12-02 06:14:47 +00:00
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
int32 targetIdx = hitTestObject();
|
2009-12-23 12:13:41 +00:00
|
|
|
if (targetIdx == -1) {
|
2010-12-02 06:14:47 +00:00
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
targetIdx = hitTestActionArea();
|
2009-12-23 12:13:41 +00:00
|
|
|
if (targetIdx == -1) {
|
2010-12-02 06:14:47 +00:00
|
|
|
|
|
|
|
targetIdx = hitTestActor();
|
|
|
|
type = kHitActor;
|
|
|
|
|
2009-12-23 12:13:41 +00:00
|
|
|
} else {
|
|
|
|
type = kHitActionArea;
|
|
|
|
}
|
|
|
|
} else {
|
2010-11-04 22:14:44 +00:00
|
|
|
type = kHitObject;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
2010-12-02 06:14:47 +00:00
|
|
|
|
2009-12-23 12:13:41 +00:00
|
|
|
return targetIdx;
|
|
|
|
}
|
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
int32 Scene::hitTestScene(HitType &type) {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::hitTestScene] WorldStats not initialized properly!");
|
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
const Common::Point pt = getCursor()->position();
|
|
|
|
|
2010-01-13 11:53:51 +00:00
|
|
|
int32 top = pt.x + _ws->xLeft;
|
|
|
|
int32 left = pt.y + _ws->yTop;
|
2009-12-23 12:13:41 +00:00
|
|
|
type = kHitNone;
|
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
int32 index = findActionArea(kActionAreaType2, Common::Point(top, left));
|
|
|
|
if (index != -1) {
|
|
|
|
if (_ws->actions[index]->actionType & kActionType8) {
|
2009-12-23 12:13:41 +00:00
|
|
|
type = kHitActionArea;
|
2010-12-02 06:14:47 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check objects
|
|
|
|
for (uint i = 0; i < _ws->objects.size(); i++) {
|
|
|
|
Object *object = _ws->objects[i];
|
|
|
|
|
|
|
|
if (object->isOnScreen() && object->actionType & kActionType8) {
|
|
|
|
if (hitTestPixel(object->getResourceId(),
|
|
|
|
object->getFrameIndex(),
|
|
|
|
top - object->x,
|
|
|
|
left - object->y,
|
|
|
|
object->flags & kObjectFlag1000)) {
|
|
|
|
type = kHitObject;
|
|
|
|
return i;
|
|
|
|
}
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
// Check actors
|
|
|
|
for (uint i = 0; i < _ws->actors.size(); i++) {
|
|
|
|
Actor *actor = _ws->actors[i];
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
if (actor->actionType & kActionType8) {
|
|
|
|
uint32 frameIndex = (actor->getFrameIndex() >= actor->getFrameCount() ? 2 * actor->getFrameCount() - (actor->getFrameIndex() + 1) : actor->getFrameIndex());
|
|
|
|
|
|
|
|
if (hitTestPixel(actor->getResourceId(),
|
|
|
|
frameIndex,
|
|
|
|
top - actor->getPoint()->x - actor->getPoint1()->x,
|
|
|
|
left - actor->getPoint()->y - actor->getPoint1()->y,
|
|
|
|
actor->getDirection() >= kDirectionSE)) {
|
|
|
|
type = kHitActor;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
int32 Scene::hitTestActionArea() {
|
|
|
|
const Common::Point pt = getCursor()->position();
|
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
int32 targetIdx = findActionArea(kActionAreaType2, Common::Point(_ws->xLeft + pt.x, _ws->yTop + pt.y));
|
2010-12-02 04:34:47 +00:00
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
if ( targetIdx == -1 || !(_ws->actions[targetIdx]->actionType & (kActionTypeFind | kActionTypeTalk | kActionTypeGrab | kActionType16)))
|
|
|
|
return -1;
|
2010-12-02 04:34:47 +00:00
|
|
|
|
|
|
|
return targetIdx;
|
|
|
|
}
|
|
|
|
|
2010-12-02 11:10:51 +00:00
|
|
|
ActorIndex Scene::hitTestActor() {
|
|
|
|
const Common::Point mouse = getCursor()->position();
|
2010-12-02 04:34:43 +00:00
|
|
|
|
2010-12-02 11:10:51 +00:00
|
|
|
if (_ws->actors.size() == 0)
|
|
|
|
return -1;
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:51 +00:00
|
|
|
// Check actors 13 to 20
|
|
|
|
if (_ws->actors.size() >= 20) {
|
|
|
|
for (uint i = 13; i < 21; i++) {
|
|
|
|
Actor *actor = getActor(i);
|
|
|
|
|
|
|
|
if (!actor->isOnScreen() || !actor->actionType)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Common::Rect rect = GraphicResource::getFrameRect(_vm, getActor(12)->getResourceId(), 0);
|
|
|
|
|
|
|
|
int32 x = _ws->xLeft + mouse.x - (actor->getPoint1()->x + actor->getPoint()->x);
|
|
|
|
int32 y = _ws->yTop + mouse.y - (actor->getPoint1()->y + actor->getPoint()->y);
|
|
|
|
|
|
|
|
if (x > (rect.left - 20)
|
|
|
|
&& x < (rect.width() + rect.left + 20)
|
|
|
|
&& y > (rect.top - 20)
|
|
|
|
&& y < (rect.height() + rect.top + 20))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check Actor 11
|
|
|
|
if (_ws->actors.size() >= 11) {
|
|
|
|
Actor *actor11 = getActor(11);
|
|
|
|
if (actor11->isOnScreen() && actor11->actionType) {
|
|
|
|
int x = mouse.x + _ws->xLeft - actor11->getPoint1()->x;
|
|
|
|
int y = mouse.y + _ws->yTop - actor11->getPoint1()->y;
|
|
|
|
|
|
|
|
if (actor11->getBoundingRect()->contains(x, y))
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
}
|
2009-12-23 12:13:41 +00:00
|
|
|
|
2010-12-02 11:10:51 +00:00
|
|
|
switch (_ws->chapter) {
|
|
|
|
default:
|
|
|
|
for (int i = _ws->actors.size() - 1; i >= 0 ; i--) {
|
|
|
|
Actor *actor = getActor(i);
|
|
|
|
|
|
|
|
int32 hitFrame;
|
|
|
|
if (actor->getFrameIndex() >= actor->getFrameCount())
|
|
|
|
hitFrame = 2 * actor->getFrameIndex() - actor->getFrameCount() - 1;
|
|
|
|
else
|
|
|
|
hitFrame = actor->getFrameIndex();
|
|
|
|
|
|
|
|
if (hitTestPixel(actor->getResourceId(),
|
|
|
|
hitFrame,
|
|
|
|
_ws->xLeft - actor->getPoint()->x - actor->getPoint1()->x,
|
|
|
|
_ws->yTop - actor->getPoint()->y - actor->getPoint1()->y,
|
|
|
|
actor->getDirection() >= kDirectionSE))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter8:
|
|
|
|
error("[Scene::hitTestActor] Not implemented (chapter 8)!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter11:
|
|
|
|
error("[Scene::hitTestActor] Not implemented (chapter 11)!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2009-12-23 12:13:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
bool Scene::hitTestPlayer() {
|
|
|
|
const Common::Point pt = getCursor()->position();
|
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
Common::Point point;
|
|
|
|
|
|
|
|
player->adjustCoordinates(&point);
|
|
|
|
|
|
|
|
uint32 frameIndex = (player->getFrameIndex() >= player->getFrameCount() ? 2 * player->getFrameCount() - (player->getFrameIndex() + 1) : player->getFrameIndex());
|
|
|
|
|
|
|
|
return hitTestPixel(player->getResourceId(),
|
|
|
|
frameIndex,
|
|
|
|
pt.x - player->getPoint()->x - point.x,
|
|
|
|
pt.y - player->getPoint()->y - point.y,
|
|
|
|
player->getDirection() >= kDirectionSE);
|
2010-12-02 04:34:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
int32 Scene::hitTestObject() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
2010-12-02 04:34:47 +00:00
|
|
|
error("[Scene::hitTestObject] WorldStats not initialized properly!");
|
2009-09-20 21:10:43 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
const Common::Point pt = getCursor()->position();
|
2009-12-04 06:15:51 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
for (uint32 i = 0; i < _ws->objects.size(); i++) {
|
|
|
|
Object *object = _ws->objects[i];
|
2010-12-02 06:14:47 +00:00
|
|
|
if (object->isOnScreen() && object->actionType)
|
|
|
|
if (hitTestPixel(object->getResourceId(),
|
|
|
|
object->getFrameIndex(),
|
|
|
|
_ws->xLeft + pt.x - object->x,
|
|
|
|
_ws->yTop + pt.y - object->y,
|
|
|
|
object->flags & kObjectFlag1000))
|
|
|
|
return i;
|
2009-12-04 06:15:51 +00:00
|
|
|
}
|
2010-12-02 06:14:47 +00:00
|
|
|
|
|
|
|
return -1;
|
2009-12-04 06:15:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
bool Scene::hitTestPixel(ResourceId resourceId, int32 frame, int16 x, int16 y, bool flipped) {
|
2010-12-02 09:29:14 +00:00
|
|
|
Common::Rect rect = GraphicResource::getFrameRect(_vm, resourceId, frame);
|
|
|
|
|
|
|
|
// TODO we need to test each pixel of the surface!
|
|
|
|
|
|
|
|
return rect.contains(x, y);
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Hit actions
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-02 04:34:47 +00:00
|
|
|
void Scene::handleHit(int32 index, HitType type) {
|
2010-12-02 09:29:14 +00:00
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHitActionArea:
|
2010-12-02 09:29:26 +00:00
|
|
|
if (!getScript()->isInQueue(_ws->actions[index]->scriptIndex))
|
|
|
|
getScript()->queueScript(_ws->actions[index]->scriptIndex, _playerIndex);
|
2010-12-02 09:29:14 +00:00
|
|
|
|
|
|
|
switch (_ws->chapter) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter2:
|
|
|
|
hitAreaChapter2(_ws->actions[index]->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter7:
|
|
|
|
hitAreaChapter7(_ws->actions[index]->id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter11:
|
|
|
|
hitAreaChapter11(_ws->actions[index]->id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHitObject: {
|
|
|
|
Object *object = _ws->objects[index];
|
|
|
|
|
|
|
|
if (object->getSoundResourceId()) {
|
|
|
|
if (getSound()->isPlaying(object->getSoundResourceId())) {
|
|
|
|
getSound()->stop(object->getSoundResourceId());
|
|
|
|
object->setSoundResourceId(kResourceNone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
if (!getScript()->isInQueue(object->getScriptIndex()))
|
|
|
|
getScript()->queueScript(object->getScriptIndex(), _playerIndex);
|
2010-12-02 09:29:14 +00:00
|
|
|
|
|
|
|
// Original executes special script hit functions, but since there is none, we can skip this part
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kHitActor: {
|
|
|
|
Actor *actor = _ws->actors[index];
|
|
|
|
|
|
|
|
if (actor->actionType & (kActionTypeFind | kActionType16)) {
|
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
if (getScript()->isInQueue(actor->getScriptIndex()))
|
|
|
|
getScript()->queueScript(actor->getScriptIndex(), _playerIndex);
|
2010-12-02 09:29:14 +00:00
|
|
|
|
|
|
|
} else if (actor->actionType & kActionTypeTalk) {
|
|
|
|
|
|
|
|
if (getSound()->isPlaying(actor->getSoundResourceId())) {
|
|
|
|
if (actor->getStatus() != kActorStatusEnabled)
|
|
|
|
actor->updateStatus(kActorStatusEnabled);
|
|
|
|
|
|
|
|
getSound()->stop(actor->getSoundResourceId());
|
|
|
|
actor->setSoundResourceId(kResourceNone);
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:26 +00:00
|
|
|
if (getScript()->isInQueue(actor->getScriptIndex()))
|
|
|
|
getScript()->queueScript(actor->getScriptIndex(), _playerIndex);
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (_ws->chapter) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter2:
|
|
|
|
hitActorChapter2(index);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kChapter11:
|
|
|
|
hitActorChapter11(index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-11-03 04:28:14 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
void Scene::playerReaction() {
|
|
|
|
error("[Scene::playerReaction] Not implemented!");
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:14 +00:00
|
|
|
void Scene::hitAreaChapter2(int32 id) {
|
2010-12-02 09:29:42 +00:00
|
|
|
if (id == 783)
|
|
|
|
getActor()->setField638(6);
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::hitAreaChapter7(int32 id) {
|
2010-12-02 09:29:42 +00:00
|
|
|
switch (id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1088:
|
|
|
|
if (_isCTRLPressed)
|
|
|
|
_vm->setGameFlag(kGameFlag1144);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2504:
|
|
|
|
if (++_hitAreaChapter7Counter > 20) {
|
|
|
|
_vm->setGameFlag(kGameFlag1108);
|
|
|
|
getActor(1)->setPosition(570, 225, kDirectionN, 0);
|
|
|
|
getActor(1)->show();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::hitAreaChapter11(int32 id) {
|
2010-12-02 09:29:42 +00:00
|
|
|
if (id == 1670)
|
|
|
|
_ws->field_E849C = 666;
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::hitActorChapter2(ActorIndex index) {
|
2010-12-02 09:29:42 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
|
|
|
|
if (player->getStatus() != kActorStatus14 && player->getStatus() != kActorStatus12)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (index == 11) {
|
|
|
|
player->faceTarget(index + 9, kDirectionFromActor);
|
|
|
|
player->updateStatus(kActorStatus15);
|
|
|
|
|
|
|
|
Actor *actor11 = getActor(index);
|
|
|
|
|
|
|
|
Common::Point pointPlayer(player->getPoint1()->x + player->getPoint2()->x, player->getPoint1()->y + player->getPoint2()->y);
|
|
|
|
Common::Point pointActor11(actor11->getPoint1()->x + actor11->getPoint2()->x, actor11->getPoint1()->y + actor11->getPoint2()->y);
|
|
|
|
|
|
|
|
if (Actor::distance(pointPlayer, pointActor11) < 150) {
|
|
|
|
if (actor11->getStatus() == kActorStatus12)
|
|
|
|
actor11->updateStatus(kActorStatus18);
|
|
|
|
|
|
|
|
if (actor11->getStatus() == kActorStatusEnabled)
|
|
|
|
actor11->updateStatus(kActorStatus14);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSharedData()->setData(38, index);
|
|
|
|
|
|
|
|
} else if (index > 12) {
|
|
|
|
player->faceTarget(index + 9, kDirectionFromActor);
|
|
|
|
player->updateStatus(kActorStatus15);
|
|
|
|
getSharedData()->setData(38, index);
|
|
|
|
}
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::hitActorChapter11(ActorIndex index) {
|
2010-12-02 09:29:42 +00:00
|
|
|
if (_ws->field_E848C < 3)
|
|
|
|
_ws->field_E849C = index;
|
2010-12-02 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helpers
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-11-08 21:09:13 +00:00
|
|
|
void Scene::playIntroSpeech() {
|
2010-11-09 03:04:33 +00:00
|
|
|
ResourceId resourceId;
|
|
|
|
|
|
|
|
switch (_packId) {
|
|
|
|
default:
|
|
|
|
resourceId = (ResourceId)_packId;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kResourcePackCourtyardAndChapel:
|
|
|
|
resourceId = getSpeech()->playScene(4, 3);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kResourcePackCave:
|
|
|
|
resourceId = getSpeech()->playScene(4, 6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case kResourcePackLaboratory:
|
|
|
|
resourceId = getSpeech()->playScene(4, 7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-16 14:24:54 +00:00
|
|
|
getScreen()->clear();
|
2010-12-02 09:29:59 +00:00
|
|
|
getScreen()->setupPaletteAndStartFade(0, 0, 0);
|
2010-11-09 03:04:33 +00:00
|
|
|
|
2010-12-02 09:29:59 +00:00
|
|
|
do {
|
|
|
|
// Poll events (this ensure we don't freeze the screen)
|
|
|
|
Common::Event ev;
|
|
|
|
_vm->getEventManager()->pollEvent(ev);
|
|
|
|
|
|
|
|
} while (getSound()->isPlaying(resourceId));
|
2010-11-08 21:09:13 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:43 +00:00
|
|
|
void Scene::stopSpeech() {
|
|
|
|
if (_vm->isGameFlagSet(kGameFlag219)) {
|
|
|
|
if (getSpeech()->getSoundResourceId() != kResourceNone && getSound()->isPlaying(getSpeech()->getSoundResourceId()))
|
|
|
|
getSound()->stopAll(getSpeech()->getSoundResourceId());
|
|
|
|
else if (getSpeech()->getTick())
|
|
|
|
getSpeech()->setTick(_vm->getTick());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
bool Scene::pointIntersectsRect(Common::Point point, Common::Rect rect) {
|
|
|
|
if (rect.top || rect.left || rect.bottom || rect.right) {
|
|
|
|
Common::Rational res((rect.bottom - rect.top) * (point.x - rect.left), rect.right - rect.left);
|
2010-03-12 11:48:28 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
return (bool)(point.y > rect.top ? 1 + res.toInt() : res.toInt());
|
2009-09-13 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-12 11:48:28 +00:00
|
|
|
|
2010-12-02 06:15:02 +00:00
|
|
|
bool Scene::rectIntersect(int32 x, int32 y, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3) {
|
|
|
|
return (x >= x3 && y >= y3 && x1 >= x2 && y1 >= y2);
|
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:59 +00:00
|
|
|
void Scene::adjustCoordinates(Common::Point *point) {
|
|
|
|
point->x = _ws->xLeft + getCursor()->position().x;
|
|
|
|
point->y = _ws->yTop + getCursor()->position().y;
|
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
Actor* Scene::getActor(ActorIndex index) {
|
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::getActor] WorldStats not initialized properly!");
|
2010-03-12 11:48:28 +00:00
|
|
|
|
2010-12-02 09:29:14 +00:00
|
|
|
ActorIndex computedIndex = (index != -1) ? index : _playerIndex;
|
2010-03-12 11:48:28 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
if (computedIndex < 0 || computedIndex >= (int16)_ws->actors.size())
|
|
|
|
error("[Scene::getActor] Invalid actor index: %d ([0-%d] allowed)", computedIndex, _ws->actors.size() - 1);
|
2010-03-12 11:48:28 +00:00
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
return _ws->actors[computedIndex];
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
bool Scene::updateSceneCoordinates(int32 tX, int32 tY, int32 A0, bool checkSceneCoords, int32 *param) {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::updateSceneCoordinates] WorldStats not initialized properly!");
|
|
|
|
|
2010-11-03 04:28:35 +00:00
|
|
|
Common::Rect *sr = &_ws->sceneRects[_ws->sceneRectIdx];
|
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
int32 *targetX = &_ws->coordinates[0];
|
|
|
|
int32 *targetY = &_ws->coordinates[1];
|
|
|
|
int32 *coord3 = &_ws->coordinates[2];
|
|
|
|
|
|
|
|
*targetX = tX;
|
|
|
|
*targetY = tY;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
*coord3 = A0;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
|
|
|
// Adjust coordinates
|
|
|
|
if (checkSceneCoords)
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetX + 640 > _ws->width)
|
|
|
|
*targetX = _ws->width - 640;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetX < sr->left)
|
|
|
|
*targetX = sr->left;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetY < sr->top)
|
|
|
|
*targetY = sr->top;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetX + 640 > sr->right)
|
|
|
|
*targetX = sr->right - 640;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetY + 480 < sr->bottom)
|
|
|
|
*targetY = sr->bottom - 480;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
|
|
|
if (checkSceneCoords)
|
2010-11-05 13:36:24 +00:00
|
|
|
if (*targetY + 480 > _ws->height)
|
|
|
|
*targetY = _ws->height - 480;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
|
|
|
// Adjust scene offsets & coordinates
|
2010-11-16 14:24:46 +00:00
|
|
|
getSharedData()->setSceneOffset(0);
|
|
|
|
getSharedData()->setSceneXLeft(_ws->xLeft);
|
|
|
|
getSharedData()->setSceneYTop(_ws->yTop);
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
int32 diffX = *targetX - _ws->xLeft;
|
|
|
|
int32 diffY = *targetY - _ws->yTop;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
|
|
|
if (abs(diffX) <= abs(diffY)) {
|
2010-11-05 13:36:24 +00:00
|
|
|
if (_ws->yTop > *targetY)
|
|
|
|
*coord3 = -*coord3;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-16 14:24:46 +00:00
|
|
|
getSharedData()->setSceneOffsetAdd(Common::Rational(*coord3, diffY) * diffX);
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (param != NULL && abs(diffY) <= abs(*coord3)) {
|
|
|
|
*targetX = -1;
|
2010-11-03 04:28:35 +00:00
|
|
|
*param = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2010-11-05 13:36:24 +00:00
|
|
|
if (_ws->xLeft > *targetX)
|
|
|
|
*coord3 = -*coord3;
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-16 14:24:46 +00:00
|
|
|
getSharedData()->setSceneOffsetAdd(Common::Rational(*coord3, diffX) * diffY);
|
2010-11-03 04:28:35 +00:00
|
|
|
|
2010-11-05 13:36:24 +00:00
|
|
|
if (param != NULL && abs(diffX) <= abs(*coord3)) {
|
|
|
|
*targetX = -1;
|
2010-11-03 04:28:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-02 04:34:47 +00:00
|
|
|
|
2010-12-02 06:14:47 +00:00
|
|
|
int32 Scene::findActionArea(ActionAreaType type, const Common::Point pt) {
|
2010-12-02 04:34:47 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::findActionArea] WorldStats not initialized properly!");
|
|
|
|
|
|
|
|
if (!_polygons)
|
|
|
|
error("[Scene::findActionArea] Polygons not initialized properly!");
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// This is a VERY loose implementation of the target
|
|
|
|
// function, as this doesn't do any of the flag checking
|
|
|
|
// the original did
|
|
|
|
int32 targetIdx = -1;
|
|
|
|
for (uint32 i = 0; i < _ws->actions.size(); i++) {
|
|
|
|
ActionArea *a = _ws->actions[i];
|
|
|
|
PolyDefinitions p = _polygons->entries[a->polyIdx];
|
|
|
|
if (p.contains(pt.x, pt.y)) {
|
|
|
|
targetIdx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return targetIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Scene::isInActionArea(const Common::Point &pt, ActionArea *area) {
|
|
|
|
error("[Scene::isInActionArea] Not implemented!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Scene::changePlayer(ActorIndex index) {
|
|
|
|
error("[Scene::changePlayer] not implemented");
|
|
|
|
}
|
|
|
|
|
2010-11-03 04:29:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scene drawing
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-01 19:22:42 +00:00
|
|
|
void Scene::preload() {
|
|
|
|
if (!Config.showSceneLoading)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SceneTitle *title = new SceneTitle(_vm);
|
|
|
|
title->load();
|
|
|
|
|
|
|
|
do {
|
|
|
|
title->update(_vm->getTick());
|
|
|
|
|
|
|
|
getScreen()->copyBackBufferToScreen();
|
|
|
|
g_system->updateScreen();
|
|
|
|
|
|
|
|
g_system->delayMillis(10);
|
|
|
|
|
|
|
|
// Poll events (this ensure we don't freeze the screen)
|
|
|
|
Common::Event ev;
|
|
|
|
_vm->getEventManager()->pollEvent(ev);
|
|
|
|
|
|
|
|
} while (!title->loadingComplete());
|
|
|
|
|
|
|
|
delete title;
|
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
bool Scene::drawScene() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::drawScene] WorldStats not initialized properly!");
|
|
|
|
|
2009-09-21 19:11:49 +00:00
|
|
|
_vm->screen()->clearGraphicsInQueue();
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
if (getSharedData()->getFlag(kFlagRedraw)) {
|
2010-11-16 14:24:54 +00:00
|
|
|
_vm->screen()->clear();
|
2010-12-01 19:22:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-12-05 20:51:46 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
// Draw scene background
|
|
|
|
getScreen()->draw(_ws->backgroundImage, 0, -_ws->xLeft, -_ws->yTop, 0, false);
|
2010-11-03 04:29:43 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
// Draw actors on the update list
|
|
|
|
buildUpdateList();
|
|
|
|
processUpdateList();
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
if (_ws->chapter == kChapter11)
|
|
|
|
checkVisibleActorsPriority();
|
2009-11-14 03:46:38 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
// Queue updates
|
|
|
|
for (uint32 i = 0; i < _ws->actors.size(); i++)
|
|
|
|
_ws->actors[i]->draw();
|
2010-11-03 04:29:43 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
for (uint32 i = 0; i < _ws->objects.size(); i++)
|
|
|
|
_ws->objects[i]->draw();
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
Actor *player = getActor();
|
|
|
|
if (player->getStatus() == kActorStatus6 || player->getStatus() == kActorStatus10)
|
|
|
|
player->updateAndDraw();
|
|
|
|
else
|
|
|
|
player->setNumberFlag01(0);
|
|
|
|
|
|
|
|
_vm->screen()->drawGraphicsInQueue();
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-12-01 19:22:52 +00:00
|
|
|
return false;
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:29:43 +00:00
|
|
|
bool Scene::updateListCompare(const UpdateItem &item1, const UpdateItem &item2) {
|
2010-12-02 04:34:47 +00:00
|
|
|
return (item1.priority - item2.priority < 0) ? false : true;
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::buildUpdateList() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::buildUpdateList] WorldStats not initialized properly!");
|
|
|
|
|
2010-11-03 04:29:43 +00:00
|
|
|
_updateList.clear();
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < _ws->actors.size(); i++) {
|
|
|
|
Actor *actor = _ws->actors[i];
|
|
|
|
|
|
|
|
if (actor->isVisible()) {
|
|
|
|
UpdateItem item;
|
|
|
|
item.index = i;
|
2010-11-16 14:24:57 +00:00
|
|
|
item.priority = actor->getPoint1()->y + actor->getPoint2()->y;
|
2010-11-03 04:29:43 +00:00
|
|
|
|
|
|
|
_updateList.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the list (the original uses qsort, so we may have to revert to that if our sort isn't behaving the same)
|
|
|
|
Common::sort(_updateList.begin(), _updateList.end(), &Scene::updateListCompare);
|
|
|
|
}
|
|
|
|
|
2010-11-03 04:29:47 +00:00
|
|
|
void Scene::processUpdateList() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::processUpdateList] WorldStats not initialized properly!");
|
|
|
|
|
2010-11-03 04:29:47 +00:00
|
|
|
for (uint32 i = 0; i < _updateList.size(); i++) {
|
|
|
|
Actor *actor = getActor(_updateList[i].index);
|
|
|
|
int32 priority = _updateList[i].priority;
|
|
|
|
Common::Point point;
|
|
|
|
|
|
|
|
// Check priority
|
|
|
|
if (priority < 0) {
|
|
|
|
actor->setPriority(abs(priority));
|
2009-11-14 03:46:38 +00:00
|
|
|
continue;
|
2010-11-03 04:29:47 +00:00
|
|
|
}
|
2009-11-14 03:46:38 +00:00
|
|
|
|
2010-11-03 04:29:47 +00:00
|
|
|
actor->setPriority(3);
|
|
|
|
|
|
|
|
if (actor->getField944() == 1 || actor->getField944() == 4) {
|
|
|
|
actor->setPriority(1);
|
|
|
|
} else {
|
|
|
|
actor->setField938(1);
|
|
|
|
actor->setField934(0);
|
2010-11-16 14:24:57 +00:00
|
|
|
point.x = actor->getPoint1()->x + actor->getPoint2()->x;
|
|
|
|
point.y = actor->getPoint1()->y + actor->getPoint2()->y;
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-16 14:24:57 +00:00
|
|
|
int32 bottomRight = actor->getBoundingRect()->bottom + actor->getPoint1()->y + 4;
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-16 14:24:46 +00:00
|
|
|
if (_ws->chapter == kChapter11 && _updateList[i].index != getPlayerIndex())
|
2010-11-03 04:29:47 +00:00
|
|
|
bottomRight += 20;
|
|
|
|
|
|
|
|
// Our actor rect
|
2010-11-16 14:24:57 +00:00
|
|
|
Common::Rect actorRect(actor->getPoint1()->x, actor->getPoint1()->y, actor->getPoint1()->x + actor->getBoundingRect()->right, bottomRight);
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// Process objects
|
2010-11-07 19:36:21 +00:00
|
|
|
for (uint32 j = 0; j < _ws->objects.size(); j++) {
|
2010-11-04 22:14:44 +00:00
|
|
|
Object *object = _ws->objects[i];
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// Skip hidden objects
|
|
|
|
if (!object->isOnScreen())
|
2010-11-03 04:29:47 +00:00
|
|
|
continue;
|
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// Rect for the object
|
|
|
|
Common::Rect objectRect(object->x, object->y, object->x + object->getBoundingRect()->right, object->y + object->getBoundingRect()->bottom);
|
2010-11-03 04:29:43 +00:00
|
|
|
|
2010-11-03 04:29:47 +00:00
|
|
|
// Check that the rects are contained
|
2010-11-04 22:14:44 +00:00
|
|
|
if (!objectRect.contains(actorRect)) {
|
|
|
|
if (BYTE1(object->flags) & kObjectFlag20)
|
|
|
|
if (!(BYTE1(object->flags) & kObjectFlag80))
|
|
|
|
object->flags = BYTE1(object->flags) | kObjectFlag40;
|
2010-11-03 04:29:43 +00:00
|
|
|
continue;
|
2009-09-21 19:11:49 +00:00
|
|
|
}
|
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// Check if it intersects with either the object rect or the related polygon
|
2010-11-03 04:29:47 +00:00
|
|
|
bool intersects = false;
|
2010-11-04 22:14:44 +00:00
|
|
|
if (object->flags & kObjectFlag2) {
|
|
|
|
intersects = pointIntersectsRect(point, *object->getRect());
|
2009-09-21 19:11:49 +00:00
|
|
|
} else {
|
2010-11-04 22:14:44 +00:00
|
|
|
if (object->flags & kObjectFlag40) {
|
|
|
|
PolyDefinitions *poly = &_polygons->entries[object->getPolygonIndex()];
|
2010-11-16 14:24:17 +00:00
|
|
|
if (point.x > 0 && point.y > 0 && poly->count() > 0)
|
2010-11-03 04:29:47 +00:00
|
|
|
intersects = poly->contains(point);
|
2010-11-03 04:29:43 +00:00
|
|
|
else
|
2010-11-04 22:14:44 +00:00
|
|
|
warning ("[drawActorsAndObjects] trying to find intersection of uninitialized point");
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
2009-09-21 19:11:49 +00:00
|
|
|
}
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// Adjust object flags
|
|
|
|
if (BYTE1(object->flags) & kObjectFlag80 || intersects) {
|
|
|
|
if (BYTE1(object->flags) & kObjectFlag20)
|
|
|
|
object->flags = (BYTE1(object->flags) & 0xBF) | kObjectFlag80;
|
2010-11-03 04:29:47 +00:00
|
|
|
} else {
|
2010-11-04 22:14:44 +00:00
|
|
|
if (BYTE1(object->flags) & kObjectFlag20) {
|
|
|
|
object->flags = BYTE1(object->flags) | kObjectFlag40;
|
2010-11-03 04:29:47 +00:00
|
|
|
}
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
2010-11-03 04:29:47 +00:00
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
if (object->flags & kObjectFlag4) {
|
2010-11-03 04:29:47 +00:00
|
|
|
if (intersects && LOBYTE(actor->flags) & kActorFlagMasked) {
|
|
|
|
error("[Scene::processUpdateList] Assigning mask to masked character [%s]", actor->getName());
|
|
|
|
} else {
|
2010-11-28 23:35:38 +00:00
|
|
|
object->adjustCoordinates(&point);
|
2010-11-04 22:14:44 +00:00
|
|
|
actor->setObjectIndex(j);
|
2010-11-03 04:29:47 +00:00
|
|
|
actor->flags |= kActorFlagMasked;
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (intersects) {
|
2010-11-04 22:14:44 +00:00
|
|
|
if (actor->getPriority() < object->getPriority()) {
|
2010-11-03 04:29:47 +00:00
|
|
|
actor->setField934(1);
|
2010-11-04 22:14:44 +00:00
|
|
|
actor->setPriority(object->getPriority() + 3);
|
2010-11-03 04:29:47 +00:00
|
|
|
|
|
|
|
if (_updateList[i].index > _updateList[0].index) {
|
|
|
|
error("[Scene::processUpdateList] list update not implemented!");
|
|
|
|
}
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
2009-09-21 19:11:49 +00:00
|
|
|
} else {
|
2010-11-04 22:14:44 +00:00
|
|
|
if (actor->getPriority() > object->getPriority() || actor->getPriority() == 1) {
|
2010-11-03 04:29:47 +00:00
|
|
|
actor->setField934(1);
|
2010-11-04 22:14:44 +00:00
|
|
|
actor->setPriority(object->getPriority() - 1);
|
2010-11-03 04:29:47 +00:00
|
|
|
|
|
|
|
if (_updateList[i].index > _updateList[0].index) {
|
|
|
|
error("[Scene::processUpdateList] list update not implemented!");
|
|
|
|
}
|
2010-11-03 04:29:43 +00:00
|
|
|
}
|
2009-09-21 19:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-04 22:14:44 +00:00
|
|
|
} // end processing objects
|
2010-11-03 04:29:47 +00:00
|
|
|
|
|
|
|
// Update all other actors
|
|
|
|
for (uint32 k = 0; k < _updateList.size(); k++) {
|
|
|
|
Actor *actor2 = getActor(_updateList[k].index);
|
|
|
|
|
|
|
|
if (actor2->isVisible() && actor2->getField944() != 1 && actor2->getField944() != 4 && _updateList[k].index != _updateList[i].index) {
|
|
|
|
|
2010-11-16 14:24:57 +00:00
|
|
|
Common::Rect actor2Rect(actor2->getPoint1()->x, actor2->getPoint1()->y, actor2->getPoint1()->x + actor2->getBoundingRect()->right, actor2->getPoint1()->y + actor2->getBoundingRect()->bottom);
|
2010-11-03 04:29:47 +00:00
|
|
|
|
|
|
|
if (actor2Rect.contains(actorRect)) {
|
|
|
|
|
|
|
|
// Inferior
|
2010-11-16 14:24:57 +00:00
|
|
|
if ((actor2->getPoint1()->y + actor2->getPoint2()->y) > (actor->getPoint1()->y + actor->getPoint2()->y)) {
|
2010-11-03 04:29:47 +00:00
|
|
|
if (actor->getPriority() <= actor2->getPriority()) {
|
|
|
|
if (actor->getField934() || actor2->getNumberValue01()) {
|
|
|
|
if (!actor2->getNumberValue01())
|
|
|
|
actor2->setPriority(actor->getPriority() - 1);
|
|
|
|
} else {
|
|
|
|
actor->setPriority(actor2->getPriority() + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Superior
|
2010-11-16 14:24:57 +00:00
|
|
|
if ((actor2->getPoint1()->y + actor2->getPoint2()->y) < (actor->getPoint1()->y + actor->getPoint2()->y)) {
|
2010-11-03 04:29:47 +00:00
|
|
|
if (actor->getPriority() >= actor2->getPriority()) {
|
|
|
|
if (actor->getField934() || actor2->getNumberValue01()) {
|
|
|
|
if (!actor2->getNumberValue01())
|
|
|
|
actor2->setPriority(actor->getPriority() + 1);
|
|
|
|
} else {
|
|
|
|
actor->setPriority(actor2->getPriority() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actor->getField974())
|
|
|
|
getActor(actor->getField980())->setPriority(-actor->getPriority());
|
2009-09-21 19:11:49 +00:00
|
|
|
}
|
2010-11-03 04:29:47 +00:00
|
|
|
} // end processing actors
|
|
|
|
|
|
|
|
|
|
|
|
// Go through the list from the end
|
|
|
|
if (_updateList.size() > 1) {
|
|
|
|
for (int i = _ws->actors.size() - 1; i >= 0; --i) {
|
|
|
|
Actor *actor = _ws->actors[i];
|
|
|
|
|
|
|
|
// Skip hidden actors
|
|
|
|
if (!actor->isVisible())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (actor->getField944() != 1 && actor->getField944() != 4) {
|
|
|
|
error("[Scene::processUpdateList] list update not implemented!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-03 04:29:56 +00:00
|
|
|
void Scene::checkVisibleActorsPriority() {
|
2010-12-02 06:15:02 +00:00
|
|
|
for (uint i = 2; i < 9; i++)
|
|
|
|
if (getActor(i)->isVisible())
|
|
|
|
adjustActorPriority(i);
|
|
|
|
|
|
|
|
for (uint i = 16; i < 18; i++)
|
|
|
|
if (getActor(i)->isVisible())
|
|
|
|
adjustActorPriority(i);
|
2010-11-03 04:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::adjustActorPriority(ActorIndex index) {
|
2010-12-02 06:15:02 +00:00
|
|
|
Actor* actor0 = getActor(0);
|
|
|
|
Actor* actor = getActor(index);
|
|
|
|
|
|
|
|
if (rectIntersect(actor0->getPoint1()->x,
|
|
|
|
actor0->getPoint1()->y,
|
|
|
|
actor0->getPoint1()->x + actor0->getBoundingRect()->right,
|
|
|
|
actor0->getPoint1()->y + actor0->getBoundingRect()->bottom + 4,
|
|
|
|
actor->getPoint1()->x,
|
|
|
|
actor->getPoint1()->y,
|
|
|
|
actor->getPoint1()->x + actor0->getBoundingRect()->right,
|
|
|
|
actor->getPoint1()->y + actor0->getBoundingRect()->bottom)) {
|
|
|
|
if (actor->getPriority() < actor0->getPriority())
|
|
|
|
actor0->setPriority(actor->getPriority());
|
|
|
|
}
|
2010-11-03 04:29:56 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 09:29:59 +00:00
|
|
|
void Scene::drawChapter5() {
|
|
|
|
if (getSharedData()->getFlag(kFlagSkipDrawScene))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (uint y = 0; y < 512; y = y + 64) {
|
|
|
|
for (uint x = 0; x < 704; x = x + 64) {
|
|
|
|
getScreen()->draw(MAKE_RESOURCE(kResourcePackShared, 58), _chapter5FrameIndex, x + (_ws->xLeft % 64) / 8, y + (_ws->yTop % 64) / 8, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_chapter5FrameIndex = (_chapter5FrameIndex + 1) % GraphicResource::getFrameCount(_vm, MAKE_RESOURCE(kResourcePackShared, 58));
|
|
|
|
}
|
|
|
|
|
2010-12-02 02:34:09 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Debug
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-12-01 19:22:37 +00:00
|
|
|
void Scene::debugScreenScrolling() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::debugScreenScrolling] WorldStats not initialized properly!");
|
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
Common::Rect rect = GraphicResource::getFrameRect(_vm, _ws->backgroundImage, 0);
|
|
|
|
|
2009-09-21 19:11:49 +00:00
|
|
|
// Horizontal scrolling
|
2010-11-08 21:09:13 +00:00
|
|
|
if (getCursor()->position().x < SCREEN_EDGES && _ws->xLeft >= SCROLL_STEP)
|
2009-12-05 20:51:46 +00:00
|
|
|
_ws->xLeft -= SCROLL_STEP;
|
2010-12-01 19:22:37 +00:00
|
|
|
else if (getCursor()->position().x > 640 - SCREEN_EDGES && _ws->xLeft <= rect.width() - 640 - SCROLL_STEP)
|
2009-12-05 20:51:46 +00:00
|
|
|
_ws->xLeft += SCROLL_STEP;
|
2009-08-19 21:51:43 +00:00
|
|
|
|
|
|
|
// Vertical scrolling
|
2010-11-08 21:09:13 +00:00
|
|
|
if (getCursor()->position().y < SCREEN_EDGES && _ws->yTop >= SCROLL_STEP)
|
2009-12-05 20:51:46 +00:00
|
|
|
_ws->yTop -= SCROLL_STEP;
|
2010-12-01 19:22:37 +00:00
|
|
|
else if (getCursor()->position().y > 480 - SCREEN_EDGES && _ws->yTop <= rect.height() - 480 - SCROLL_STEP)
|
2009-12-05 20:51:46 +00:00
|
|
|
_ws->yTop += SCROLL_STEP;
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WALK REGION DEBUG
|
|
|
|
void Scene::debugShowWalkRegion(PolyDefinitions *poly) {
|
|
|
|
Graphics::Surface surface;
|
|
|
|
surface.create(poly->boundingRect.right - poly->boundingRect.left + 1,
|
2009-09-21 19:11:49 +00:00
|
|
|
poly->boundingRect.bottom - poly->boundingRect.top + 1,
|
|
|
|
1);
|
2009-08-19 21:51:43 +00:00
|
|
|
|
|
|
|
// Draw all lines in Polygon
|
2010-11-16 14:24:17 +00:00
|
|
|
for (uint32 i = 0; i < poly->count(); i++) {
|
2009-08-19 21:51:43 +00:00
|
|
|
surface.drawLine(
|
2009-09-21 19:11:49 +00:00
|
|
|
poly->points[i].x - poly->boundingRect.left,
|
|
|
|
poly->points[i].y - poly->boundingRect.top,
|
2010-11-16 14:24:17 +00:00
|
|
|
poly->points[(i+1) % poly->count()].x - poly->boundingRect.left,
|
|
|
|
poly->points[(i+1) % poly->count()].y - poly->boundingRect.top, 0x3A);
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
getScreen()->copyToBackBufferClipped(&surface, poly->boundingRect.left, poly->boundingRect.top);
|
2009-08-19 21:51:43 +00:00
|
|
|
|
|
|
|
surface.free();
|
|
|
|
}
|
|
|
|
|
|
|
|
// POLYGONS DEBUG
|
|
|
|
void Scene::debugShowPolygons() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_polygons)
|
|
|
|
error("[Scene::debugShowPolygons] Polygons not initialized properly!");
|
|
|
|
|
2009-12-04 03:14:07 +00:00
|
|
|
for (int32 p = 0; p < _polygons->numEntries; p++) {
|
2009-08-19 21:51:43 +00:00
|
|
|
Graphics::Surface surface;
|
2009-09-19 12:24:53 +00:00
|
|
|
PolyDefinitions poly = _polygons->entries[p];
|
2009-08-19 21:51:43 +00:00
|
|
|
surface.create(poly.boundingRect.right - poly.boundingRect.left + 1,
|
2009-09-21 19:11:49 +00:00
|
|
|
poly.boundingRect.bottom - poly.boundingRect.top + 1,
|
|
|
|
1);
|
|
|
|
|
2009-08-19 21:51:43 +00:00
|
|
|
// Draw all lines in Polygon
|
2010-11-16 14:24:17 +00:00
|
|
|
for (uint32 i = 0; i < poly.count(); i++) {
|
2009-08-19 21:51:43 +00:00
|
|
|
surface.drawLine(
|
2009-09-21 19:11:49 +00:00
|
|
|
poly.points[i].x - poly.boundingRect.left,
|
|
|
|
poly.points[i].y - poly.boundingRect.top,
|
2010-11-16 14:24:17 +00:00
|
|
|
poly.points[(i+1) % poly.count()].x - poly.boundingRect.left,
|
|
|
|
poly.points[(i+1) % poly.count()].y - poly.boundingRect.top, 0xFF);
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-12-01 19:22:37 +00:00
|
|
|
getScreen()->copyToBackBufferClipped(&surface, poly.boundingRect.left, poly.boundingRect.top);
|
2009-08-19 21:51:43 +00:00
|
|
|
|
|
|
|
surface.free();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// OBJECT DEBUGGING
|
|
|
|
void Scene::debugShowObjects() {
|
2010-11-16 14:24:27 +00:00
|
|
|
if (!_ws)
|
|
|
|
error("[Scene::debugShowObjects] WorldStats not initialized properly!");
|
|
|
|
|
2010-11-07 19:36:21 +00:00
|
|
|
for (uint32 p = 0; p < _ws->objects.size(); p++) {
|
2009-08-19 21:51:43 +00:00
|
|
|
Graphics::Surface surface;
|
2010-11-04 22:14:44 +00:00
|
|
|
Object *object = _ws->objects[p];
|
2009-08-19 21:51:43 +00:00
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
if (object->flags & 0x20) {
|
|
|
|
surface.create(object->getBoundingRect()->right - object->getBoundingRect()->left + 1,
|
|
|
|
object->getBoundingRect()->bottom - object->getBoundingRect()->top + 1,
|
2009-09-21 19:11:49 +00:00
|
|
|
1);
|
2010-11-04 22:14:44 +00:00
|
|
|
surface.frameRect(*object->getBoundingRect(), 0x22);
|
2010-12-01 19:22:37 +00:00
|
|
|
getScreen()->copyToBackBufferClipped(&surface, object->x, object->y);
|
2009-08-19 21:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
surface.free();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 22:14:44 +00:00
|
|
|
// ACTOR DEBUGGING
|
2009-09-20 19:21:59 +00:00
|
|
|
void Scene::debugShowActors() {
|
2010-11-07 19:36:21 +00:00
|
|
|
for (uint32 p = 0; p < _ws->actors.size(); p++) {
|
2009-09-20 19:21:59 +00:00
|
|
|
Graphics::Surface surface;
|
2010-11-03 04:28:35 +00:00
|
|
|
Actor *a = _ws->actors[p];
|
2009-09-20 19:21:59 +00:00
|
|
|
|
2010-11-03 04:28:35 +00:00
|
|
|
if (a->flags & 2) {
|
2010-11-03 04:29:18 +00:00
|
|
|
surface.create(a->getBoundingRect()->right - a->getBoundingRect()->left + 1,
|
|
|
|
a->getBoundingRect()->bottom - a->getBoundingRect()->top + 1,
|
2009-09-21 19:11:49 +00:00
|
|
|
1);
|
2010-11-03 04:29:18 +00:00
|
|
|
surface.frameRect(*a->getBoundingRect(), 0x22);
|
2010-12-01 19:22:37 +00:00
|
|
|
getScreen()->copyToBackBufferClipped(&surface, a->getPoint()->x, a->getPoint()->y);
|
2009-09-20 19:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
surface.free();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 13:27:04 +00:00
|
|
|
} // end of namespace Asylum
|