aboutsummaryrefslogtreecommitdiff
path: root/engines/pink/objects/walk/walk_mgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/pink/objects/walk/walk_mgr.cpp')
-rw-r--r--engines/pink/objects/walk/walk_mgr.cpp136
1 files changed, 68 insertions, 68 deletions
diff --git a/engines/pink/objects/walk/walk_mgr.cpp b/engines/pink/objects/walk/walk_mgr.cpp
index 989f69e4af..c9c28f0ffc 100644
--- a/engines/pink/objects/walk/walk_mgr.cpp
+++ b/engines/pink/objects/walk/walk_mgr.cpp
@@ -30,14 +30,14 @@
namespace Pink {
WalkMgr::WalkMgr()
- : _isWalking(false), _leadActor(nullptr)
+ : _isWalking(false), _leadActor(nullptr)
{
}
void WalkMgr::deserialize(Pink::Archive &archive) {
- _leadActor = static_cast<LeadActor *>(archive.readObject());
- _locations.deserialize(archive);
+ _leadActor = static_cast<LeadActor *>(archive.readObject());
+ _locations.deserialize(archive);
}
WalkLocation *WalkMgr::findLocation(const Common::String &name) {
@@ -50,103 +50,103 @@ WalkLocation *WalkMgr::findLocation(const Common::String &name) {
}
void WalkMgr::toConsole() {
- debug("WalkMgr:");
- for (uint i = 0; i < _locations.size(); ++i) {
- _locations[i]->toConsole();
- }
+ debug("WalkMgr:");
+ for (uint i = 0; i < _locations.size(); ++i) {
+ _locations[i]->toConsole();
+ }
}
void WalkMgr::start(WalkLocation *destination) {
- if (_isWalking)
- return;
-
- if (_current.name.empty()) {
- _current.name = _locations[0]->getName();
- _current.coord = getLocationCoordinates(_locations[0]->getName());
- }
-
- _destination = destination;
-
- if (_current.name == _destination->getName()) {
- end();
- }
- else {
- _isWalking = true;
- WalkLocation *currentLocation = findLocation(_current.name);
- WalkShortestPath path(this);
- WalkLocation *nextLocation = path.next(currentLocation, _destination);
- initNextWayPoint(nextLocation);
- _leadActor->setAction(getWalkAction(), 0);
- }
+ if (_isWalking)
+ return;
+
+ if (_current.name.empty()) {
+ _current.name = _locations[0]->getName();
+ _current.coord = getLocationCoordinates(_locations[0]->getName());
+ }
+
+ _destination = destination;
+
+ if (_current.name == _destination->getName()) {
+ end();
+ }
+ else {
+ _isWalking = true;
+ WalkLocation *currentLocation = findLocation(_current.name);
+ WalkShortestPath path(this);
+ WalkLocation *nextLocation = path.next(currentLocation, _destination);
+ initNextWayPoint(nextLocation);
+ _leadActor->setAction(getWalkAction(), 0);
+ }
}
void WalkMgr::initNextWayPoint(WalkLocation *location) {
- _next.name = location->getName();
- _next.coord = getLocationCoordinates(location->getName());
+ _next.name = location->getName();
+ _next.coord = getLocationCoordinates(location->getName());
}
WalkAction *WalkMgr::getWalkAction() {
- Common::String walkActionName;
- if (_current.coord.z == _next.coord.z){
- if (_next.coord.x > _current.coord.x){
- walkActionName = Common::String::format("%dRight", _current.coord.z);
- }
- else walkActionName = Common::String::format("%dLeft", _next.coord.z);
- }
- else walkActionName = Common::String::format("%dTo%d", _current.coord.z, _next.coord.z);
+ Common::String walkActionName;
+ if (_current.coord.z == _next.coord.z){
+ if (_next.coord.x > _current.coord.x){
+ walkActionName = Common::String::format("%dRight", _current.coord.z);
+ }
+ else walkActionName = Common::String::format("%dLeft", _next.coord.z);
+ }
+ else walkActionName = Common::String::format("%dTo%d", _current.coord.z, _next.coord.z);
- Action *action = _leadActor->findAction(walkActionName);
+ Action *action = _leadActor->findAction(walkActionName);
- return static_cast<WalkAction*>(action);
+ return static_cast<WalkAction*>(action);
}
double WalkMgr::getLengthBetweenLocations(WalkLocation *first, WalkLocation *second) {
- Coordinates firstCoord = getLocationCoordinates(first->getName());
- Coordinates secondCoord = getLocationCoordinates(second->getName());
- return sqrt((secondCoord.x - firstCoord.x) * (secondCoord.x - firstCoord.x) +
- (secondCoord.y - firstCoord.y) * (secondCoord.y - firstCoord.y));
+ Coordinates firstCoord = getLocationCoordinates(first->getName());
+ Coordinates secondCoord = getLocationCoordinates(second->getName());
+ return sqrt((secondCoord.x - firstCoord.x) * (secondCoord.x - firstCoord.x) +
+ (secondCoord.y - firstCoord.y) * (secondCoord.y - firstCoord.y));
}
WalkMgr::Coordinates WalkMgr::getLocationCoordinates(const Common::String &locationName) {
- Coordinates coords;
- ActionCEL *action = static_cast<ActionCEL*>(_leadActor->findAction(locationName));
+ Coordinates coords;
+ ActionCEL *action = static_cast<ActionCEL*>(_leadActor->findAction(locationName));
- action->start(0);
- CelDecoder *decoder = action->getDecoder();
+ action->start(0);
+ CelDecoder *decoder = action->getDecoder();
- coords.x = decoder->getX() + decoder->getWidth() / 2;
- coords.y = decoder->getY() + decoder->getHeight() / 2;
- coords.z = action->getZ();
+ coords.x = decoder->getX() + decoder->getWidth() / 2;
+ coords.y = decoder->getY() + decoder->getHeight() / 2;
+ coords.z = action->getZ();
- action->end();
+ action->end();
- return coords;
+ return coords;
}
void WalkMgr::setCurrentWayPoint(WalkLocation *location) {
- _current.name = location->getName();
- _current.coord = getLocationCoordinates(_current.name);
+ _current.name = location->getName();
+ _current.coord = getLocationCoordinates(_current.name);
}
void WalkMgr::update() {
- if (_leadActor->isPlaying())
- return;
-
- WalkShortestPath path(this);
- _current = _next;
- WalkLocation *next = path.next(findLocation(_current.name), _destination);
- if (next){
- initNextWayPoint(next);
- _leadActor->setAction(getWalkAction(), 0);
- }
- else end();
+ if (_leadActor->isPlaying())
+ return;
+
+ WalkShortestPath path(this);
+ _current = _next;
+ WalkLocation *next = path.next(findLocation(_current.name), _destination);
+ if (next){
+ initNextWayPoint(next);
+ _leadActor->setAction(getWalkAction(), 0);
+ }
+ else end();
}
void WalkMgr::end() {
- _isWalking = false;
- _leadActor->onWalkEnd();
+ _isWalking = false;
+ _leadActor->onWalkEnd();
}
} // End of namespace Pink