diff options
Diffstat (limited to 'engines/pink/objects/walk')
-rw-r--r-- | engines/pink/objects/walk/walk_mgr.cpp | 30 | ||||
-rw-r--r-- | engines/pink/objects/walk/walk_mgr.h | 2 | ||||
-rw-r--r-- | engines/pink/objects/walk/walk_shortest_path.cpp | 15 | ||||
-rw-r--r-- | engines/pink/objects/walk/walk_shortest_path.h | 8 |
4 files changed, 24 insertions, 31 deletions
diff --git a/engines/pink/objects/walk/walk_mgr.cpp b/engines/pink/objects/walk/walk_mgr.cpp index c9c28f0ffc..5b57107a44 100644 --- a/engines/pink/objects/walk/walk_mgr.cpp +++ b/engines/pink/objects/walk/walk_mgr.cpp @@ -30,10 +30,7 @@ namespace Pink { WalkMgr::WalkMgr() - : _isWalking(false), _leadActor(nullptr) -{ - -} + : _isWalking(false), _leadActor(nullptr) {} void WalkMgr::deserialize(Pink::Archive &archive) { _leadActor = static_cast<LeadActor *>(archive.readObject()); @@ -42,9 +39,8 @@ void WalkMgr::deserialize(Pink::Archive &archive) { WalkLocation *WalkMgr::findLocation(const Common::String &name) { for (uint i = 0; i < _locations.size(); ++i) { - if (_locations[i]->getName() == name) { + if (_locations[i]->getName() == name) return _locations[i]; - } } return nullptr; } @@ -69,8 +65,7 @@ void WalkMgr::start(WalkLocation *destination) { if (_current.name == _destination->getName()) { end(); - } - else { + } else { _isWalking = true; WalkLocation *currentLocation = findLocation(_current.name); WalkShortestPath path(this); @@ -87,17 +82,16 @@ void WalkMgr::initNextWayPoint(WalkLocation *location) { WalkAction *WalkMgr::getWalkAction() { Common::String walkActionName; - if (_current.coord.z == _next.coord.z){ - if (_next.coord.x > _current.coord.x){ + 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); + } 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); - return static_cast<WalkAction*>(action); } @@ -136,11 +130,11 @@ void WalkMgr::update() { WalkShortestPath path(this); _current = _next; WalkLocation *next = path.next(findLocation(_current.name), _destination); - if (next){ + if (next) { initNextWayPoint(next); _leadActor->setAction(getWalkAction(), 0); - } - else end(); + } else + end(); } diff --git a/engines/pink/objects/walk/walk_mgr.h b/engines/pink/objects/walk/walk_mgr.h index 64bd16e48b..9060f08a20 100644 --- a/engines/pink/objects/walk/walk_mgr.h +++ b/engines/pink/objects/walk/walk_mgr.h @@ -63,7 +63,7 @@ private: LeadActor *_leadActor; WalkLocation *_destination; - Array<WalkLocation*> _locations; + Array<WalkLocation *> _locations; WayPoint _current; WayPoint _next; bool _isWalking; diff --git a/engines/pink/objects/walk/walk_shortest_path.cpp b/engines/pink/objects/walk/walk_shortest_path.cpp index 376e638d91..4f16f54328 100644 --- a/engines/pink/objects/walk/walk_shortest_path.cpp +++ b/engines/pink/objects/walk/walk_shortest_path.cpp @@ -34,7 +34,7 @@ WalkLocation *WalkShortestPath::next(WalkLocation *start, WalkLocation *destinat if (start == destination) return nullptr; add(start, 0.0, 0); - while (build() != destination); + while (build() != destination) {} return getNearestNeighbor(destination); } @@ -94,13 +94,13 @@ double WalkShortestPath::getLengthToNearestNeigbor(WalkLocation *location) { Common::StringArray &neighbors = location->getNeigbors(); for (uint i = 0; i < neighbors.size(); ++i) { WalkLocation *neighbor = _manager->findLocation(neighbors[i]); - if (!isLocationVisited(neighbor)){ + if (!isLocationVisited(neighbor)) { double length = _manager->getLengthBetweenLocations(location, neighbor); if (minLength >= 0.0) { if (length < minLength) minLength = length; - } - else minLength = length; + } else + minLength = length; } } @@ -113,15 +113,14 @@ WalkLocation *WalkShortestPath::findNearestNeighbor(WalkLocation *location) { Common::StringArray &neighbors = location->getNeigbors(); for (uint i = 0; i < neighbors.size(); ++i) { WalkLocation *neighbor = _manager->findLocation(neighbors[i]); - if (!isLocationVisited(neighbor)){ + if (!isLocationVisited(neighbor)) { double length = _manager->getLengthBetweenLocations(location, neighbor); if (minLength >= 0.0) { if (length < minLength) { nearest = neighbor; minLength = length; } - } - else { + } else { nearest = neighbor; minLength = length; } @@ -149,7 +148,7 @@ bool WalkShortestPath::isLocationVisited(WalkLocation *location) { void WalkShortestPath::remove(WalkLocation *location) { for (uint i = 0; i < _locations.size(); ++i) { - if (_locations[i] == location){ + if (_locations[i] == location) { _locations.remove_at(i); _weight.remove_at(i); break; diff --git a/engines/pink/objects/walk/walk_shortest_path.h b/engines/pink/objects/walk/walk_shortest_path.h index a3ec85df1d..441b6e6a88 100644 --- a/engines/pink/objects/walk/walk_shortest_path.h +++ b/engines/pink/objects/walk/walk_shortest_path.h @@ -48,11 +48,11 @@ private: WalkMgr *_manager; - Common::Array<WalkLocation*> _locations; - Common::Array<WalkLocation*> _toVisit; + Common::Array<WalkLocation *> _locations; + Common::Array<WalkLocation *> _toVisit; Common::Array<double> _weight; - Common::Array<WalkLocation*> _visited; - Common::Array<WalkLocation*> _nearestNeigbor; + Common::Array<WalkLocation *> _visited; + Common::Array<WalkLocation *> _nearestNeigbor; }; } // End of namespace Pink |