aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232013-01-17 15:19:28 +0000
committerWillem Jan Palenstijn2013-05-08 20:47:40 +0200
commit18ce1acc12fe0bd58b6b93b8accb840cd7244356 (patch)
tree689a683ead927a6ca0522daf669f9d08c9674738
parent9ea07e0925d679e8f3e33aa34c0403c3f58d5f1c (diff)
downloadscummvm-rg350-18ce1acc12fe0bd58b6b93b8accb840cd7244356.tar.gz
scummvm-rg350-18ce1acc12fe0bd58b6b93b8accb840cd7244356.tar.bz2
scummvm-rg350-18ce1acc12fe0bd58b6b93b8accb840cd7244356.zip
NEVERHOOD: Rework the car track scenes in Module2500 and Module2700
- Move findClosestTrack code from several scenes to new Tracks::findTrackPoint - Remove const kScene2706 arrays and use it from the dat instead
-rw-r--r--engines/neverhood/gamemodule.cpp8
-rw-r--r--engines/neverhood/module1600.cpp20
-rw-r--r--engines/neverhood/module1600.h6
-rw-r--r--engines/neverhood/module2500.cpp82
-rw-r--r--engines/neverhood/module2500.h7
-rw-r--r--engines/neverhood/module2700.cpp203
-rw-r--r--engines/neverhood/module2700.h20
-rw-r--r--engines/neverhood/staticdata.cpp2
-rw-r--r--engines/neverhood/staticdata.h2
9 files changed, 166 insertions, 184 deletions
diff --git a/engines/neverhood/gamemodule.cpp b/engines/neverhood/gamemodule.cpp
index 6ba3e98261..d037cf55c0 100644
--- a/engines/neverhood/gamemodule.cpp
+++ b/engines/neverhood/gamemodule.cpp
@@ -399,10 +399,10 @@ void GameModule::startup() {
setGlobalVar(V_SHRINK_LIGHTS_ON, 0);
// <<<DEBUG
-#if 0
+#if 1
_vm->gameState().which = 0;
- _vm->gameState().sceneNum = 14;
- createModule(2700, -1);
+ _vm->gameState().sceneNum = 0;
+ createModule(2500, -1);
#endif
#if 0
_vm->gameState().sceneNum = 5;
@@ -417,7 +417,7 @@ void GameModule::startup() {
_vm->gameState().sceneNum = 5;
createModule(2200, -1);
#endif
-#if 1
+#if 0
_vm->gameState().sceneNum = 7;
createModule(2200, -1);
#endif
diff --git a/engines/neverhood/module1600.cpp b/engines/neverhood/module1600.cpp
index a2f06e1197..54f715a0c5 100644
--- a/engines/neverhood/module1600.cpp
+++ b/engines/neverhood/module1600.cpp
@@ -988,6 +988,24 @@ void AsCommonCarConnector::update() {
AnimatedSprite::update();
}
+void Tracks::findTrackPoint(NPoint pt, int &minMatchTrackIndex, int &minMatchDistance,
+ DataResource &dataResource) {
+ const uint trackCount = size();
+ minMatchTrackIndex = -1;
+ minMatchDistance = 640;
+ for (uint trackIndex = 0; trackIndex < trackCount; trackIndex++) {
+ NPointArray *pointList = dataResource.getPointArray((*this)[trackIndex]->trackPointsName);
+ for (uint pointIndex = 0; pointIndex < pointList->size(); pointIndex++) {
+ NPoint testPt = (*pointList)[pointIndex];
+ int distance = calcDistance(testPt.x, testPt.y, pt.x, pt.y);
+ if (distance < minMatchDistance) {
+ minMatchTrackIndex = trackIndex;
+ minMatchDistance = distance;
+ }
+ }
+ }
+}
+
Scene1608::Scene1608(NeverhoodEngine *vm, Module *parentModule, int which)
: Scene(vm, parentModule), _asCar(NULL), _countdown1(0) {
@@ -1082,7 +1100,7 @@ Scene1608::Scene1608(NeverhoodEngine *vm, Module *parentModule, int which)
// NOTE: Not in the else because 'which' is set to 1 in the true branch
if (which == 1) {
- // Klaymen entering riding the car
+ // Klaymen riding the car
_vm->gameState().which = 1;
_dataResource.load(0x003C0492);
_roomPathPoints = _dataResource.getPointArray(calcHash("meArchroArchRoomPath"));
diff --git a/engines/neverhood/module1600.h b/engines/neverhood/module1600.h
index 0c567e693f..eaf8986637 100644
--- a/engines/neverhood/module1600.h
+++ b/engines/neverhood/module1600.h
@@ -121,6 +121,12 @@ protected:
void update();
};
+class Tracks : public Common::Array<SceneInfo2700*> {
+public:
+ void findTrackPoint(NPoint pt, int &minMatchTrackIndex, int &minMatchDistance,
+ DataResource &dataResource);
+};
+
class Scene1608 : public Scene {
public:
Scene1608(NeverhoodEngine *vm, Module *parentModule, int which);
diff --git a/engines/neverhood/module2500.cpp b/engines/neverhood/module2500.cpp
index ba5b140767..851ee61722 100644
--- a/engines/neverhood/module2500.cpp
+++ b/engines/neverhood/module2500.cpp
@@ -220,9 +220,9 @@ void Module2500::createScene2704(int which, uint32 sceneInfoId, int16 value, con
Scene2501::Scene2501(NeverhoodEngine *vm, Module *parentModule, int which)
: Scene(vm, parentModule) {
- _sceneInfos[0] = _vm->_staticData->getSceneInfo2700(0x004B2628);
- _sceneInfos[1] = _vm->_staticData->getSceneInfo2700(0x004B264C);
- _sceneInfos[2] = _vm->_staticData->getSceneInfo2700(0x004B2670);
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B2628));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B264C));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B2670));
setGlobalVar(V_CAR_DELTA_X, 1);
SetUpdateHandler(&Scene2501::update);
@@ -283,14 +283,13 @@ Scene2501::Scene2501(NeverhoodEngine *vm, Module *parentModule, int which)
_asCarConnectorShadow = insertSprite<AsCommonCarConnectorShadow>(_asCar, _ssTrackShadowBackground->getSurface(), 4);
insertSprite<AsCommonCarConnector>(_asCar);
- _pointListsCount = 3;
_newTrackIndex = -1;
_dataResource.load(calcHash("Ashooded"));
- _trackPoints = _dataResource.getPointArray(_sceneInfos[_currTrackIndex]->pointListName);
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
_asCar->setPathPoints(_trackPoints);
- if (which >= 0 && _sceneInfos[_currTrackIndex]->which2 == which) {
+ if (which >= 0 && _tracks[_currTrackIndex]->which2 == which) {
NPoint testPoint = (*_trackPoints)[_trackPoints->size() - 1];
sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
if (testPoint.x < 0 || testPoint.x >= 640 || testPoint.y < 0 || testPoint.y >= 480)
@@ -331,7 +330,7 @@ void Scene2501::update() {
_klayman = NULL;
_carStatus = 0;
}
- updateKlaymanCliprect();
+ updateKlaymanClipRect();
}
void Scene2501::upCarAtHome() {
@@ -341,13 +340,13 @@ void Scene2501::upCarAtHome() {
sendMessage(_asCar, 0x200A, 0);
SetUpdateHandler(&Scene2501::upGettingOutOfCar);
} else {
- findClosestTrack(_mouseClickPos);
+ moveCarToPoint(_mouseClickPos);
SetMessageHandler(&Scene2501::hmRidingCar);
SetUpdateHandler(&Scene2501::upRidingCar);
}
_mouseClicked = false;
}
- updateKlaymanCliprect();
+ updateKlaymanClipRect();
}
void Scene2501::upGettingOutOfCar() {
@@ -368,13 +367,13 @@ void Scene2501::upGettingOutOfCar() {
_klayman->handleUpdate();
_carStatus = 0;
}
- updateKlaymanCliprect();
+ updateKlaymanClipRect();
}
void Scene2501::upRidingCar() {
Scene::update();
if (_mouseClicked) {
- findClosestTrack(_mouseClickPos);
+ moveCarToPoint(_mouseClickPos);
_mouseClicked = false;
}
}
@@ -397,24 +396,24 @@ uint32 Scene2501::hmRidingCar(int messageNum, const MessageParam &param, Entity
uint32 messageResult = Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x2005:
- if (_sceneInfos[_currTrackIndex]->which1 < 0 && _newTrackIndex >= 0)
+ if (_tracks[_currTrackIndex]->which1 < 0 && _newTrackIndex >= 0)
changeTrack();
- else if (_sceneInfos[_currTrackIndex]->which1 == 0) {
+ else if (_tracks[_currTrackIndex]->which1 == 0) {
SetMessageHandler(&Scene2501::hmCarAtHome);
SetUpdateHandler(&Scene2501::upCarAtHome);
sendMessage(_asCar, 0x200F, 1);
- } else if (_sceneInfos[_currTrackIndex]->which1 > 0)
- leaveScene(_sceneInfos[_currTrackIndex]->which1);
+ } else if (_tracks[_currTrackIndex]->which1 > 0)
+ leaveScene(_tracks[_currTrackIndex]->which1);
break;
case 0x2006:
- if (_sceneInfos[_currTrackIndex]->which2 < 0 && _newTrackIndex >= 0)
+ if (_tracks[_currTrackIndex]->which2 < 0 && _newTrackIndex >= 0)
changeTrack();
- else if (_sceneInfos[_currTrackIndex]->which2 == 0) {
+ else if (_tracks[_currTrackIndex]->which2 == 0) {
SetMessageHandler(&Scene2501::hmCarAtHome);
SetUpdateHandler(&Scene2501::upCarAtHome);
sendMessage(_asCar, 0x200F, 1);
- } else if (_sceneInfos[_currTrackIndex]->which2 > 0)
- leaveScene(_sceneInfos[_currTrackIndex]->which2);
+ } else if (_tracks[_currTrackIndex]->which2 > 0)
+ leaveScene(_tracks[_currTrackIndex]->which2);
break;
case 0x200D:
sendMessage(_parentModule, 0x200D, 0);
@@ -436,34 +435,9 @@ uint32 Scene2501::hmCarAtHome(int messageNum, const MessageParam &param, Entity
return messageResult;
}
-void Scene2501::changeTrack() {
- _currTrackIndex = _newTrackIndex;
- _trackPoints = _dataResource.getPointArray(_sceneInfos[_currTrackIndex]->pointListName);
- _asCar->setPathPoints(_trackPoints);
- if (_currTrackIndex == 0)
- sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
- else
- sendMessage(_asCar, 0x2002, 0);
- sendPointMessage(_asCar, 0x2004, _clickPoint);
- _newTrackIndex = -1;
-}
-
-void Scene2501::findClosestTrack(NPoint &pt) {
- // TODO NOTE This is uses with minor variations in other scenes, maybe merge them?
- int minMatchDistance = 640;
- int minMatchTrackIndex = -1;
- // Find the track which contains a point closest to pt
- for (int infoIndex = 0; infoIndex < _pointListsCount; infoIndex++) {
- NPointArray *pointList = _dataResource.getPointArray(_sceneInfos[infoIndex]->pointListName);
- for (uint pointIndex = 0; pointIndex < pointList->size(); pointIndex++) {
- NPoint testPt = (*pointList)[pointIndex];
- int distance = calcDistance(testPt.x, testPt.y, pt.x, pt.y);
- if (distance < minMatchDistance) {
- minMatchTrackIndex = infoIndex;
- minMatchDistance = distance;
- }
- }
- }
+void Scene2501::moveCarToPoint(NPoint &pt) {
+ int minMatchTrackIndex, minMatchDistance;
+ _tracks.findTrackPoint(pt, minMatchTrackIndex, minMatchDistance, _dataResource);
if (minMatchTrackIndex >= 0 && minMatchTrackIndex != _currTrackIndex) {
_newTrackIndex = minMatchTrackIndex;
_clickPoint = pt;
@@ -477,7 +451,19 @@ void Scene2501::findClosestTrack(NPoint &pt) {
}
}
-void Scene2501::updateKlaymanCliprect() {
+void Scene2501::changeTrack() {
+ _currTrackIndex = _newTrackIndex;
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
+ _asCar->setPathPoints(_trackPoints);
+ if (_currTrackIndex == 0)
+ sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
+ else
+ sendMessage(_asCar, 0x2002, 0);
+ sendPointMessage(_asCar, 0x2004, _clickPoint);
+ _newTrackIndex = -1;
+}
+
+void Scene2501::updateKlaymanClipRect() {
if (_kmScene2501->getX() <= 211)
_kmScene2501->setClipRect(0, 0, 640, 480);
else
diff --git a/engines/neverhood/module2500.h b/engines/neverhood/module2500.h
index 38a1a431fa..9a7e9442f1 100644
--- a/engines/neverhood/module2500.h
+++ b/engines/neverhood/module2500.h
@@ -60,11 +60,10 @@ protected:
Sprite *_asIdleCarLower;
Sprite *_asIdleCarFull;
Klayman *_kmScene2501;
+ Tracks _tracks;
NPointArray *_trackPoints;
- SceneInfo2700 *_sceneInfos[3];
int _currTrackIndex;
NPoint _clickPoint;
- int _pointListsCount;
int _newTrackIndex;
int _carStatus;
bool _klaymanInCar;
@@ -75,9 +74,9 @@ protected:
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
uint32 hmRidingCar(int messageNum, const MessageParam &param, Entity *sender);
uint32 hmCarAtHome(int messageNum, const MessageParam &param, Entity *sender);
- void findClosestTrack(NPoint &pt);
+ void moveCarToPoint(NPoint &pt);
void changeTrack();
- void updateKlaymanCliprect();
+ void updateKlaymanClipRect();
};
class SsScene2504Button : public StaticSprite {
diff --git a/engines/neverhood/module2700.cpp b/engines/neverhood/module2700.cpp
index d4f46ea2ca..07273f9a07 100644
--- a/engines/neverhood/module2700.cpp
+++ b/engines/neverhood/module2700.cpp
@@ -528,12 +528,12 @@ uint32 Module2700::handleMessage(int messageNum, const MessageParam &param, Enti
return messageResult;
}
-void Module2700::createScene2703(int which, uint32 sceneInfoId) {
- _childObject = new Scene2703(_vm, this, which, sceneInfoId);
+void Module2700::createScene2703(int which, uint32 trackInfoId) {
+ _childObject = new Scene2703(_vm, this, which, trackInfoId);
}
-void Module2700::createScene2704(int which, uint32 sceneInfoId, int16 value, const uint32 *staticSprites, const NRect *clipRect) {
- _childObject = new Scene2704(_vm, this, which, sceneInfoId, value, staticSprites, clipRect);
+void Module2700::createScene2704(int which, uint32 trackInfoId, int16 value, const uint32 *staticSprites, const NRect *clipRect) {
+ _childObject = new Scene2704(_vm, this, which, trackInfoId, value, staticSprites, clipRect);
}
static const NPoint kCarShadowOffsets[] = {
@@ -619,11 +619,11 @@ Scene2701::Scene2701(NeverhoodEngine *vm, Module *parentModule, int which)
Sprite *tempSprite;
NRect clipRect;
- SceneInfo2700 *sceneInfo = _vm->_staticData->getSceneInfo2700(0x004B2240);
+ SceneInfo2700 *tracks = _vm->_staticData->getSceneInfo2700(0x004B2240);
setGlobalVar(V_CAR_DELTA_X, 1);
- setBackground(sceneInfo->bgFilename);
- setPalette(sceneInfo->bgFilename);
+ setBackground(tracks->bgFilename);
+ setPalette(tracks->bgFilename);
_palette->addPalette(calcHash("paPodFloor"), 65, 31, 65);
_palette->addPalette(calcHash("paKlayFloor"), 0, 65, 0);
insertScreenMouse(0x08B08180);
@@ -631,8 +631,8 @@ Scene2701::Scene2701(NeverhoodEngine *vm, Module *parentModule, int which)
tempSprite = insertStaticSprite(0x1E086325, 1200);
clipRect.set(0, 0, 640, tempSprite->getDrawRect().y2());
- if (sceneInfo->bgShadowFilename) {
- _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(sceneInfo->bgShadowFilename);
+ if (tracks->bgShadowFilename) {
+ _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(tracks->bgShadowFilename);
addEntity(_ssTrackShadowBackground);
_asCar = insertSprite<AsCommonCar>(this, 320, 240);
_asCarShadow = insertSprite<AsCommonCarShadow>(_asCar, _ssTrackShadowBackground->getSurface(), 4);
@@ -644,10 +644,10 @@ Scene2701::Scene2701(NeverhoodEngine *vm, Module *parentModule, int which)
}
_asCarConnector = insertSprite<AsCommonCarConnector>(_asCar);
- _which1 = sceneInfo->which1;
- _which2 = sceneInfo->which2;
- _dataResource.load(sceneInfo->dataResourceFilename);
- _trackPoints = _dataResource.getPointArray(sceneInfo->pointListName);
+ _which1 = tracks->which1;
+ _which2 = tracks->which2;
+ _dataResource.load(tracks->dataResourceFilename);
+ _trackPoints = _dataResource.getPointArray(tracks->trackPointsName);
_asCar->setPathPoints(_trackPoints);
if (which == _which2) {
@@ -713,18 +713,8 @@ uint32 Scene2701::hmCarAtHome(int messageNum, const MessageParam &param, Entity
return 0;
}
-static const uint32 kScene2702Infos[2][3] = {
- {0x004B5F68, 0x004B5F8C, 0x004B5FB0},
- {0x004B5FD8, 0x004B5FFC, 0x004B6020}
-};
-
-
Scene2702::Scene2702(NeverhoodEngine *vm, Module *parentModule, int which)
- : Scene(vm, parentModule), _isInLight(true), _newTrackIndex(-1), _count(3) {
-
- for (int i = 0; i < 2; i++)
- for (int j = 0; j < 3; j++)
- _sceneInfos[i][j] = _vm->_staticData->getSceneInfo2700(kScene2702Infos[i][j]);
+ : Scene(vm, parentModule), _isInLight(true), _newTrackIndex(-1) {
SetMessageHandler(&Scene2702::handleMessage);
SetUpdateHandler(&Scene2702::update);
@@ -746,38 +736,48 @@ Scene2702::Scene2702(NeverhoodEngine *vm, Module *parentModule, int which)
_dataResource.load(0x04310014);
if (which == 1) {
- _currSceneInfos = _sceneInfos[1];
+ _isUpperTrack = false;
_currTrackIndex = 1;
} else if (which == 2) {
- _currSceneInfos = _sceneInfos[1];
+ _isUpperTrack = false;
_currTrackIndex = 2;
_palette->addPalette(calcHash("paPodShade"), 65, 31, 65);
_palette->addPalette(calcHash("paKlayShade"), 0, 65, 0);
_isInLight = false;
} else if (which == 3) {
- _currSceneInfos = _sceneInfos[0];
+ _isUpperTrack = true;
_currTrackIndex = 0;
} else if (which == 4) {
- _currSceneInfos = _sceneInfos[0];
+ _isUpperTrack = true;
_currTrackIndex = 2;
_palette->addPalette(calcHash("paPodShade"), 65, 31, 65);
_palette->addPalette(calcHash("paKlayShade"), 0, 65, 0);
_isInLight = false;
} else if (which == 5) {
- _currSceneInfos = _sceneInfos[0];
+ _isUpperTrack = true;
_currTrackIndex = 1;
_palette->addPalette(calcHash("paPodShade"), 65, 31, 65);
_palette->addPalette(calcHash("paKlayShade"), 0, 65, 0);
_isInLight = false;
} else {
- _currSceneInfos = _sceneInfos[1];
+ _isUpperTrack = false;
_currTrackIndex = 0;
}
- _trackPoints = _dataResource.getPointArray(_currSceneInfos[_currTrackIndex]->pointListName);
+ if (_isUpperTrack) {
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B5F68));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B5F8C));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B5FB0));
+ } else {
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B5FD8));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B5FFC));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B6020));
+ }
+
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
_asCar->setPathPoints(_trackPoints);
- if (which == _currSceneInfos[_currTrackIndex]->which2) {
+ if (which == _tracks[_currTrackIndex]->which2) {
sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
sendMessage(_asCar, 0x2007, 150);
} else {
@@ -808,21 +808,21 @@ uint32 Scene2702::handleMessage(int messageNum, const MessageParam &param, Entit
Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x0001:
- findClosestTrack(param.asPoint());
+ moveCarToPoint(param.asPoint());
break;
case 0x2005:
if (_newTrackIndex >= 0) {
- if (_currSceneInfos[_currTrackIndex]->which1 < 0)
+ if (_tracks[_currTrackIndex]->which1 < 0)
changeTrack();
- } else if (_currSceneInfos[_currTrackIndex]->which1 >= 0)
- leaveScene(_currSceneInfos[_currTrackIndex]->which1);
+ } else if (_tracks[_currTrackIndex]->which1 >= 0)
+ leaveScene(_tracks[_currTrackIndex]->which1);
break;
case 0x2006:
if (_newTrackIndex >= 0) {
- if (_currSceneInfos[_currTrackIndex]->which2 < 0)
+ if (_tracks[_currTrackIndex]->which2 < 0)
changeTrack();
- } else if (_currSceneInfos[_currTrackIndex]->which2 >= 0)
- leaveScene(_currSceneInfos[_currTrackIndex]->which2);
+ } else if (_tracks[_currTrackIndex]->which2 >= 0)
+ leaveScene(_tracks[_currTrackIndex]->which2);
break;
case 0x200D:
sendMessage(_parentModule, 0x200D, 0);
@@ -831,25 +831,13 @@ uint32 Scene2702::handleMessage(int messageNum, const MessageParam &param, Entit
return 0;
}
-void Scene2702::findClosestTrack(NPoint pt) {
- int minMatchTrackIndex = -1;
- int minMatchDistance = 640;
- // Find the track which contains a point closest to pt
- for (int infoIndex = 0; infoIndex < _count; infoIndex++) {
- NPointArray *pointList = _dataResource.getPointArray(_currSceneInfos[infoIndex]->pointListName);
- for (uint pointIndex = 0; pointIndex < pointList->size(); pointIndex++) {
- NPoint testPt = (*pointList)[pointIndex];
- int distance = calcDistance(testPt.x, testPt.y, pt.x, pt.y);
- if (distance < minMatchDistance) {
- minMatchTrackIndex = infoIndex;
- minMatchDistance = distance;
- }
- }
- }
+void Scene2702::moveCarToPoint(NPoint pt) {
+ int minMatchTrackIndex, minMatchDistance;
+ _tracks.findTrackPoint(pt, minMatchTrackIndex, minMatchDistance, _dataResource);
if (minMatchTrackIndex >= 0 && minMatchTrackIndex != _currTrackIndex) {
_newTrackIndex = minMatchTrackIndex;
_newTrackDestX = pt.x;
- if (_currSceneInfos == _sceneInfos[0]) {
+ if (_isUpperTrack) {
if (_currTrackIndex == 0)
sendMessage(_asCar, 0x2003, _trackPoints->size() - 1);
else
@@ -866,9 +854,9 @@ void Scene2702::findClosestTrack(NPoint pt) {
void Scene2702::changeTrack() {
_currTrackIndex = _newTrackIndex;
- _trackPoints = _dataResource.getPointArray(_currSceneInfos[_currTrackIndex]->pointListName);
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
_asCar->setPathPoints(_trackPoints);
- if (_currSceneInfos == _sceneInfos[0]) {
+ if (_isUpperTrack) {
if (_currTrackIndex == 0)
sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
else
@@ -881,25 +869,25 @@ void Scene2702::changeTrack() {
_newTrackIndex = -1;
}
-Scene2703::Scene2703(NeverhoodEngine *vm, Module *parentModule, int which, uint32 sceneInfoId)
+Scene2703::Scene2703(NeverhoodEngine *vm, Module *parentModule, int which, uint32 trackInfoId)
: Scene(vm, parentModule) {
- SceneInfo2700 *sceneInfo = _vm->_staticData->getSceneInfo2700(sceneInfoId);
+ SceneInfo2700 *tracks = _vm->_staticData->getSceneInfo2700(trackInfoId);
SetMessageHandler(&Scene2703::handleMessage);
SetUpdateHandler(&Scene2703::update);
- setBackground(sceneInfo->bgFilename);
- setPalette(sceneInfo->bgFilename);
+ setBackground(tracks->bgFilename);
+ setPalette(tracks->bgFilename);
_palette->addPalette(calcHash("paPodShade"), 65, 31, 65);
_palette->addPalette(calcHash("paKlayShade"), 0, 65, 0);
addEntity(_palette);
- insertScreenMouse(sceneInfo->mouseCursorFilename);
+ insertScreenMouse(tracks->mouseCursorFilename);
_palStatus = 2;
- if (sceneInfo->bgShadowFilename) {
- _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(sceneInfo->bgShadowFilename);
+ if (tracks->bgShadowFilename) {
+ _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(tracks->bgShadowFilename);
addEntity(_ssTrackShadowBackground);
_asCar = insertSprite<AsCommonCar>(this, 320, 240);
_asCarShadow = insertSprite<AsCommonCarShadow>(_asCar, _ssTrackShadowBackground->getSurface(), 4);
@@ -912,10 +900,10 @@ Scene2703::Scene2703(NeverhoodEngine *vm, Module *parentModule, int which, uint3
}
_asCarConnector = insertSprite<AsCommonCarConnector>(_asCar);
- _which1 = sceneInfo->which1;
- _which2 = sceneInfo->which2;
- _dataResource.load(sceneInfo->dataResourceFilename);
- _trackPoints = _dataResource.getPointArray(sceneInfo->pointListName);
+ _which1 = tracks->which1;
+ _which2 = tracks->which2;
+ _dataResource.load(tracks->dataResourceFilename);
+ _trackPoints = _dataResource.getPointArray(tracks->trackPointsName);
_asCar->setPathPoints(_trackPoints);
if (which == _which2) {
@@ -994,31 +982,31 @@ uint32 Scene2703::handleMessage(int messageNum, const MessageParam &param, Entit
return 0;
}
-Scene2704::Scene2704(NeverhoodEngine *vm, Module *parentModule, int which, uint32 sceneInfoId, int16 value,
+Scene2704::Scene2704(NeverhoodEngine *vm, Module *parentModule, int which, uint32 trackInfoId, int16 value,
const uint32 *staticSprites, const NRect *clipRect)
: Scene(vm, parentModule) {
- SceneInfo2700 *sceneInfo = _vm->_staticData->getSceneInfo2700(sceneInfoId);
+ SceneInfo2700 *tracks = _vm->_staticData->getSceneInfo2700(trackInfoId);
SetMessageHandler(&Scene2704::handleMessage);
SetUpdateHandler(&Scene2704::update);
- setBackground(sceneInfo->bgFilename);
- setPalette(sceneInfo->bgFilename);
+ setBackground(tracks->bgFilename);
+ setPalette(tracks->bgFilename);
- if (sceneInfo->exPaletteFilename1)
- _palette->addPalette(sceneInfo->exPaletteFilename1, 0, 65, 0);
+ if (tracks->exPaletteFilename1)
+ _palette->addPalette(tracks->exPaletteFilename1, 0, 65, 0);
- if (sceneInfo->exPaletteFilename2)
- _palette->addPalette(sceneInfo->exPaletteFilename2, 65, 31, 65);
+ if (tracks->exPaletteFilename2)
+ _palette->addPalette(tracks->exPaletteFilename2, 65, 31, 65);
while (staticSprites && *staticSprites)
insertStaticSprite(*staticSprites++, 1100);
- insertScreenMouse(sceneInfo->mouseCursorFilename);
+ insertScreenMouse(tracks->mouseCursorFilename);
- if (sceneInfo->bgShadowFilename) {
- _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(sceneInfo->bgShadowFilename);
+ if (tracks->bgShadowFilename) {
+ _ssTrackShadowBackground = createSprite<SsCommonTrackShadowBackground>(tracks->bgShadowFilename);
addEntity(_ssTrackShadowBackground);
_asCar = insertSprite<AsCommonCar>(this, 320, 240);
_asCarShadow = insertSprite<AsCommonCarShadow>(_asCar, _ssTrackShadowBackground->getSurface(), 4);
@@ -1031,10 +1019,10 @@ Scene2704::Scene2704(NeverhoodEngine *vm, Module *parentModule, int which, uint3
}
_asCarConnector = insertSprite<AsCommonCarConnector>(_asCar);
- _which1 = sceneInfo->which1;
- _which2 = sceneInfo->which2;
- _dataResource.load(sceneInfo->dataResourceFilename);
- _trackPoints = _dataResource.getPointArray(sceneInfo->pointListName);
+ _which1 = tracks->which1;
+ _which2 = tracks->which2;
+ _dataResource.load(tracks->dataResourceFilename);
+ _trackPoints = _dataResource.getPointArray(tracks->trackPointsName);
_asCar->setPathPoints(_trackPoints);
if (which == _which2) {
@@ -1093,17 +1081,14 @@ uint32 Scene2704::handleMessage(int messageNum, const MessageParam &param, Entit
return 0;
}
-static const int kSceneInfo2706Count = 3;
-static const struct { const char *pointListName; int which1, which2; } kSceneInfo2706[] = {
- {"me06slotSlotPath2", 4, -1},
- {"me06slotSlotPath3", -1, 6},
- {"me06slotSlotPath4", -1, 5}
-};
-
Scene2706::Scene2706(NeverhoodEngine *vm, Module *parentModule, int which)
: Scene(vm, parentModule), _newTrackIndex(-1) {
SetMessageHandler(&Scene2706::handleMessage);
+
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B22A0));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B22C4));
+ _tracks.push_back(_vm->_staticData->getSceneInfo2700(0x004B22E8));
setBackground(0x18808B88);
setPalette(0x18808B88);
@@ -1131,10 +1116,10 @@ Scene2706::Scene2706(NeverhoodEngine *vm, Module *parentModule, int which)
else
_currTrackIndex = 0;
- _trackPoints = _dataResource.getPointArray(calcHash(kSceneInfo2706[_currTrackIndex].pointListName));
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
_asCar->setPathPoints(_trackPoints);
- if (which == kSceneInfo2706[_currTrackIndex].which2) {
+ if (which == _tracks[_currTrackIndex]->which2) {
sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
if (which == 5)
sendMessage(_asCar, 0x2007, 50);
@@ -1154,21 +1139,21 @@ uint32 Scene2706::handleMessage(int messageNum, const MessageParam &param, Entit
Scene::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x0001:
- findClosestTrack(param.asPoint());
+ moveCarToPoint(param.asPoint());
break;
case 0x2005:
if (_newTrackIndex >= 0) {
- if (kSceneInfo2706[_currTrackIndex].which1 < 0)
+ if (_tracks[_currTrackIndex]->which1 < 0)
changeTrack();
- } else if (kSceneInfo2706[_currTrackIndex].which1 >= 0)
- leaveScene(kSceneInfo2706[_currTrackIndex].which1);
+ } else if (_tracks[_currTrackIndex]->which1 >= 0)
+ leaveScene(_tracks[_currTrackIndex]->which1);
break;
case 0x2006:
if (_newTrackIndex >= 0) {
- if (kSceneInfo2706[_currTrackIndex].which2 < 0)
+ if (_tracks[_currTrackIndex]->which2 < 0)
changeTrack();
- } else if (kSceneInfo2706[_currTrackIndex].which2 >= 0)
- leaveScene(kSceneInfo2706[_currTrackIndex].which2);
+ } else if (_tracks[_currTrackIndex]->which2 >= 0)
+ leaveScene(_tracks[_currTrackIndex]->which2);
break;
case 0x200D:
sendMessage(_parentModule, 0x200D, 0);
@@ -1177,21 +1162,9 @@ uint32 Scene2706::handleMessage(int messageNum, const MessageParam &param, Entit
return 0;
}
-void Scene2706::findClosestTrack(NPoint pt) {
- int minMatchTrackIndex = -1;
- int minMatchDistance = 640;
- // Find the track which contains a point closest to pt
- for (int infoIndex = 0; infoIndex < kSceneInfo2706Count; infoIndex++) {
- NPointArray *pointList = _dataResource.getPointArray(calcHash(kSceneInfo2706[infoIndex].pointListName));
- for (uint pointIndex = 0; pointIndex < pointList->size(); pointIndex++) {
- NPoint testPt = (*pointList)[pointIndex];
- int distance = calcDistance(testPt.x, testPt.y, pt.x, pt.y);
- if (distance < minMatchDistance) {
- minMatchTrackIndex = infoIndex;
- minMatchDistance = distance;
- }
- }
- }
+void Scene2706::moveCarToPoint(NPoint pt) {
+ int minMatchTrackIndex, minMatchDistance;
+ _tracks.findTrackPoint(pt, minMatchTrackIndex, minMatchDistance, _dataResource);
if (minMatchTrackIndex >= 0 && minMatchTrackIndex != _currTrackIndex) {
_newTrackIndex = minMatchTrackIndex;
_newTrackDestX = pt.x;
@@ -1207,7 +1180,7 @@ void Scene2706::findClosestTrack(NPoint pt) {
void Scene2706::changeTrack() {
_currTrackIndex = _newTrackIndex;
- _trackPoints = _dataResource.getPointArray(calcHash(kSceneInfo2706[_currTrackIndex].pointListName));
+ _trackPoints = _dataResource.getPointArray(_tracks[_currTrackIndex]->trackPointsName);
_asCar->setPathPoints(_trackPoints);
if (_currTrackIndex == 0)
sendMessage(_asCar, 0x2002, _trackPoints->size() - 1);
diff --git a/engines/neverhood/module2700.h b/engines/neverhood/module2700.h
index 68c471c58d..5861c2e4b5 100644
--- a/engines/neverhood/module2700.h
+++ b/engines/neverhood/module2700.h
@@ -45,8 +45,8 @@ protected:
void createScene(int sceneNum, int which);
void updateScene();
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
- void createScene2703(int which, uint32 sceneInfoId);
- void createScene2704(int which, uint32 sceneInfoId, int16 value, const uint32 *staticSprites = NULL, const NRect *clipRect = NULL);
+ void createScene2703(int which, uint32 trackInfoId);
+ void createScene2704(int which, uint32 trackInfoId, int16 value, const uint32 *staticSprites = NULL, const NRect *clipRect = NULL);
};
class SsCommonTrackShadowBackground : public StaticSprite {
@@ -108,21 +108,20 @@ protected:
Sprite *_asCarTrackShadow;
Sprite *_asCarConnectorShadow;
int16 _newTrackDestX;
- int _currTrackIndex, _newTrackIndex;
- int _count;
bool _isInLight;
- SceneInfo2700 *_sceneInfos[2][3];
- SceneInfo2700 **_currSceneInfos;
+ int _currTrackIndex, _newTrackIndex;
+ bool _isUpperTrack;
+ Tracks _tracks;
NPointArray *_trackPoints;
void update();
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
- void findClosestTrack(NPoint pt);
+ void moveCarToPoint(NPoint pt);
void changeTrack();
};
class Scene2703 : public Scene {
public:
- Scene2703(NeverhoodEngine *vm, Module *parentModule, int which, uint32 sceneInfoId);
+ Scene2703(NeverhoodEngine *vm, Module *parentModule, int which, uint32 trackInfoId);
protected:
AsCommonCar *_asCar;
Sprite *_ssTrackShadowBackground;
@@ -139,7 +138,7 @@ protected:
class Scene2704 : public Scene {
public:
- Scene2704(NeverhoodEngine *vm, Module *parentModule, int which, uint32 sceneInfoId, int16 value,
+ Scene2704(NeverhoodEngine *vm, Module *parentModule, int which, uint32 trackInfoId, int16 value,
const uint32 *staticSprites = NULL, const NRect *clipRect = NULL);
protected:
AsCommonCar *_asCar;
@@ -166,9 +165,10 @@ protected:
Sprite *_asCarConnectorShadow;
int16 _newTrackDestX;
int _currTrackIndex, _newTrackIndex;
+ Tracks _tracks;
NPointArray *_trackPoints;
uint32 handleMessage(int messageNum, const MessageParam &param, Entity *sender);
- void findClosestTrack(NPoint pt);
+ void moveCarToPoint(NPoint pt);
void changeTrack();
};
diff --git a/engines/neverhood/staticdata.cpp b/engines/neverhood/staticdata.cpp
index 31f9f5e014..cf272e573a 100644
--- a/engines/neverhood/staticdata.cpp
+++ b/engines/neverhood/staticdata.cpp
@@ -149,7 +149,7 @@ void StaticData::load(const char *filename) {
sceneInfo2700->bgFilename = fd.readUint32LE();
sceneInfo2700->bgShadowFilename = fd.readUint32LE();
sceneInfo2700->dataResourceFilename = fd.readUint32LE();
- sceneInfo2700->pointListName = fd.readUint32LE();
+ sceneInfo2700->trackPointsName = fd.readUint32LE();
sceneInfo2700->rectListName = fd.readUint32LE();
sceneInfo2700->exPaletteFilename2 = fd.readUint32LE();
sceneInfo2700->exPaletteFilename1 = fd.readUint32LE();
diff --git a/engines/neverhood/staticdata.h b/engines/neverhood/staticdata.h
index f9a8b71f80..874a8a52e0 100644
--- a/engines/neverhood/staticdata.h
+++ b/engines/neverhood/staticdata.h
@@ -82,7 +82,7 @@ struct SceneInfo2700 {
uint32 bgFilename;
uint32 bgShadowFilename;
uint32 dataResourceFilename;
- uint32 pointListName;
+ uint32 trackPointsName;
uint32 rectListName;
uint32 exPaletteFilename2;
uint32 exPaletteFilename1;