aboutsummaryrefslogtreecommitdiff
path: root/engines/pink/objects/walk
diff options
context:
space:
mode:
Diffstat (limited to 'engines/pink/objects/walk')
-rw-r--r--engines/pink/objects/walk/walk_location.cpp14
-rw-r--r--engines/pink/objects/walk/walk_location.h8
-rw-r--r--engines/pink/objects/walk/walk_mgr.cpp136
-rw-r--r--engines/pink/objects/walk/walk_mgr.h54
-rw-r--r--engines/pink/objects/walk/walk_shortest_path.cpp192
-rw-r--r--engines/pink/objects/walk/walk_shortest_path.h38
6 files changed, 221 insertions, 221 deletions
diff --git a/engines/pink/objects/walk/walk_location.cpp b/engines/pink/objects/walk/walk_location.cpp
index ec2dbc9be9..dd16882396 100644
--- a/engines/pink/objects/walk/walk_location.cpp
+++ b/engines/pink/objects/walk/walk_location.cpp
@@ -28,16 +28,16 @@
namespace Pink {
void WalkLocation::deserialize(Pink::Archive &archive) {
- NamedObject::deserialize(archive);
- _neighbors.deserialize(archive);
+ NamedObject::deserialize(archive);
+ _neighbors.deserialize(archive);
}
void WalkLocation::toConsole() {
- debug("\tWalkLocation: _name =%s", _name.c_str());
- debug("\tNeighbors:");
- for (uint i = 0; i < _neighbors.size(); ++i) {
- debug("\t\t%s", _neighbors[i].c_str());
- }
+ debug("\tWalkLocation: _name =%s", _name.c_str());
+ debug("\tNeighbors:");
+ for (uint i = 0; i < _neighbors.size(); ++i) {
+ debug("\t\t%s", _neighbors[i].c_str());
+ }
}
} // End of namespace Pink
diff --git a/engines/pink/objects/walk/walk_location.h b/engines/pink/objects/walk/walk_location.h
index ef1cbab192..1f77584076 100644
--- a/engines/pink/objects/walk/walk_location.h
+++ b/engines/pink/objects/walk/walk_location.h
@@ -28,12 +28,12 @@ namespace Pink {
class WalkLocation : public NamedObject {
public:
- virtual void deserialize(Archive &archive);
- void toConsole() override;
- Common::StringArray &getNeigbors() { return _neighbors;}
+ virtual void deserialize(Archive &archive);
+ void toConsole() override;
+ Common::StringArray &getNeigbors() { return _neighbors;}
private:
- StringArray _neighbors;
+ StringArray _neighbors;
};
} // End of namespace Pink
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
diff --git a/engines/pink/objects/walk/walk_mgr.h b/engines/pink/objects/walk/walk_mgr.h
index 994796942b..64bd16e48b 100644
--- a/engines/pink/objects/walk/walk_mgr.h
+++ b/engines/pink/objects/walk/walk_mgr.h
@@ -34,39 +34,39 @@ class WalkAction;
class WalkMgr : public Object {
public:
- WalkMgr();
- virtual void deserialize(Archive &archive);
- void toConsole() override;
+ WalkMgr();
+ virtual void deserialize(Archive &archive);
+ void toConsole() override;
- WalkLocation *findLocation(const Common::String &name);
- void start(WalkLocation *destination);
- void update();
+ WalkLocation *findLocation(const Common::String &name);
+ void start(WalkLocation *destination);
+ void update();
- double getLengthBetweenLocations(WalkLocation *first, WalkLocation *second);
- void setCurrentWayPoint(WalkLocation *location);
+ double getLengthBetweenLocations(WalkLocation *first, WalkLocation *second);
+ void setCurrentWayPoint(WalkLocation *location);
private:
- struct Coordinates {
- int x;
- int y;
- int z;
- };
- struct WayPoint {
- Common::String name;
- Coordinates coord;
- };
+ struct Coordinates {
+ int x;
+ int y;
+ int z;
+ };
+ struct WayPoint {
+ Common::String name;
+ Coordinates coord;
+ };
- Coordinates getLocationCoordinates(const Common::String &locationName);
- void end();
- void initNextWayPoint(WalkLocation *location);
- WalkAction *getWalkAction();
+ Coordinates getLocationCoordinates(const Common::String &locationName);
+ void end();
+ void initNextWayPoint(WalkLocation *location);
+ WalkAction *getWalkAction();
- LeadActor *_leadActor;
- WalkLocation *_destination;
- Array<WalkLocation*> _locations;
- WayPoint _current;
- WayPoint _next;
- bool _isWalking;
+ LeadActor *_leadActor;
+ WalkLocation *_destination;
+ Array<WalkLocation*> _locations;
+ WayPoint _current;
+ WayPoint _next;
+ bool _isWalking;
};
} // End of namespace Pink
diff --git a/engines/pink/objects/walk/walk_shortest_path.cpp b/engines/pink/objects/walk/walk_shortest_path.cpp
index 26253235bd..376e638d91 100644
--- a/engines/pink/objects/walk/walk_shortest_path.cpp
+++ b/engines/pink/objects/walk/walk_shortest_path.cpp
@@ -27,134 +27,134 @@
namespace Pink {
WalkShortestPath::WalkShortestPath(WalkMgr *manager)
- : _manager(manager)
+ : _manager(manager)
{}
WalkLocation *WalkShortestPath::next(WalkLocation *start, WalkLocation *destination) {
- if (start == destination)
- return nullptr;
- add(start, 0.0, 0);
- while (build() != destination);
- return getNearestNeighbor(destination);
+ if (start == destination)
+ return nullptr;
+ add(start, 0.0, 0);
+ while (build() != destination);
+ return getNearestNeighbor(destination);
}
void WalkShortestPath::add(WalkLocation *wl, double val, WalkLocation *nearest) {
- _locations.push_back(wl);
- _visited.push_back(wl);
- _weight.push_back(val);
- _nearestNeigbor.push_back(nearest);
+ _locations.push_back(wl);
+ _visited.push_back(wl);
+ _weight.push_back(val);
+ _nearestNeigbor.push_back(nearest);
}
WalkLocation *WalkShortestPath::build() {
- WalkLocation *nearest = nullptr;
- WalkLocation *location = nullptr;
- double len = -1.0;
- addLocationsToVisit();
- for (uint i = 0; i < _toVisit.size(); ++i) {
- double curLen = getLengthToNearestNeigbor(_toVisit[i]);
- if (curLen < 0) {
- remove(_toVisit[i]);
- continue;
- }
- curLen += getWeight(_toVisit[i]);
- if (len < 0.0 || len > curLen) {
- len = curLen;
- location = _toVisit[i];
- nearest = getNearestNeighbor(_toVisit[i]);
- if (!nearest)
- nearest = findNearestNeighbor(_toVisit[i]);
- }
- }
-
- WalkLocation *neighbor = findNearestNeighbor(location);
- if (neighbor)
- add(neighbor, len, nearest);
-
- return neighbor;
+ WalkLocation *nearest = nullptr;
+ WalkLocation *location = nullptr;
+ double len = -1.0;
+ addLocationsToVisit();
+ for (uint i = 0; i < _toVisit.size(); ++i) {
+ double curLen = getLengthToNearestNeigbor(_toVisit[i]);
+ if (curLen < 0) {
+ remove(_toVisit[i]);
+ continue;
+ }
+ curLen += getWeight(_toVisit[i]);
+ if (len < 0.0 || len > curLen) {
+ len = curLen;
+ location = _toVisit[i];
+ nearest = getNearestNeighbor(_toVisit[i]);
+ if (!nearest)
+ nearest = findNearestNeighbor(_toVisit[i]);
+ }
+ }
+
+ WalkLocation *neighbor = findNearestNeighbor(location);
+ if (neighbor)
+ add(neighbor, len, nearest);
+
+ return neighbor;
}
WalkLocation *WalkShortestPath::getNearestNeighbor(WalkLocation *location) {
- for(uint i = 0; i < _visited.size(); ++i){
- if (_visited[i] == location)
- return _nearestNeigbor[i];
- }
+ for(uint i = 0; i < _visited.size(); ++i){
+ if (_visited[i] == location)
+ return _nearestNeigbor[i];
+ }
- return nullptr;
+ return nullptr;
}
void WalkShortestPath::addLocationsToVisit() {
- _toVisit.resize(_locations.size());
- for (uint i = 0; i < _locations.size(); ++i) {
- _toVisit[i] = _locations[i];
- }
+ _toVisit.resize(_locations.size());
+ for (uint i = 0; i < _locations.size(); ++i) {
+ _toVisit[i] = _locations[i];
+ }
}
double WalkShortestPath::getLengthToNearestNeigbor(WalkLocation *location) {
- double minLength = -1.0;
+ double minLength = -1.0;
Common::StringArray &neighbors = location->getNeigbors();
- for (uint i = 0; i < neighbors.size(); ++i) {
- WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
- if (!isLocationVisited(neighbor)){
- double length = _manager->getLengthBetweenLocations(location, neighbor);
- if (minLength >= 0.0) {
- if (length < minLength)
- minLength = length;
- }
- else minLength = length;
- }
- }
-
- return minLength;
+ for (uint i = 0; i < neighbors.size(); ++i) {
+ WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
+ if (!isLocationVisited(neighbor)){
+ double length = _manager->getLengthBetweenLocations(location, neighbor);
+ if (minLength >= 0.0) {
+ if (length < minLength)
+ minLength = length;
+ }
+ else minLength = length;
+ }
+ }
+
+ return minLength;
}
WalkLocation *WalkShortestPath::findNearestNeighbor(WalkLocation *location) {
- double minLength = -1.0;
- WalkLocation *nearest = nullptr;
- Common::StringArray &neighbors = location->getNeigbors();
- for (uint i = 0; i < neighbors.size(); ++i) {
- WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
- if (!isLocationVisited(neighbor)){
- double length = _manager->getLengthBetweenLocations(location, neighbor);
- if (minLength >= 0.0) {
- if (length < minLength) {
- nearest = neighbor;
- minLength = length;
- }
- }
- else {
- nearest = neighbor;
- minLength = length;
- }
- }
- }
-
- return nearest;
+ double minLength = -1.0;
+ WalkLocation *nearest = nullptr;
+ Common::StringArray &neighbors = location->getNeigbors();
+ for (uint i = 0; i < neighbors.size(); ++i) {
+ WalkLocation *neighbor = _manager->findLocation(neighbors[i]);
+ if (!isLocationVisited(neighbor)){
+ double length = _manager->getLengthBetweenLocations(location, neighbor);
+ if (minLength >= 0.0) {
+ if (length < minLength) {
+ nearest = neighbor;
+ minLength = length;
+ }
+ }
+ else {
+ nearest = neighbor;
+ minLength = length;
+ }
+ }
+ }
+
+ return nearest;
}
double WalkShortestPath::getWeight(WalkLocation *location) {
- for (uint i = 0; i < _locations.size(); ++i) {
- if (_locations[i] == location)
- return _weight[i];
- }
- return 0.0;
+ for (uint i = 0; i < _locations.size(); ++i) {
+ if (_locations[i] == location)
+ return _weight[i];
+ }
+ return 0.0;
}
bool WalkShortestPath::isLocationVisited(WalkLocation *location) {
- for (uint i = 0; i < _visited.size(); ++i) {
- if (_visited[i] == location)
- return true;
- }
- return false;
+ for (uint i = 0; i < _visited.size(); ++i) {
+ if (_visited[i] == location)
+ return true;
+ }
+ return false;
}
void WalkShortestPath::remove(WalkLocation *location) {
- for (uint i = 0; i < _locations.size(); ++i) {
- if (_locations[i] == location){
- _locations.remove_at(i);
- _weight.remove_at(i);
- break;
- }
- }
+ for (uint i = 0; i < _locations.size(); ++i) {
+ if (_locations[i] == location){
+ _locations.remove_at(i);
+ _weight.remove_at(i);
+ break;
+ }
+ }
}
} // End of namespace Pink
diff --git a/engines/pink/objects/walk/walk_shortest_path.h b/engines/pink/objects/walk/walk_shortest_path.h
index deb7770061..a3ec85df1d 100644
--- a/engines/pink/objects/walk/walk_shortest_path.h
+++ b/engines/pink/objects/walk/walk_shortest_path.h
@@ -32,27 +32,27 @@ class WalkMgr;
class WalkShortestPath {
public:
- WalkShortestPath(WalkMgr *manager);
- WalkLocation *next(WalkLocation *start, WalkLocation *destination);
+ WalkShortestPath(WalkMgr *manager);
+ WalkLocation *next(WalkLocation *start, WalkLocation *destination);
private:
- void add(WalkLocation *wl, double val, WalkLocation *nearest);
- void remove(WalkLocation *location);
- WalkLocation *build();
- WalkLocation *getNearestNeighbor(WalkLocation *location);
- WalkLocation *findNearestNeighbor(WalkLocation *location);
- double getLengthToNearestNeigbor(WalkLocation *location);
- double getWeight(WalkLocation *location);
- void addLocationsToVisit();
- bool isLocationVisited(WalkLocation *location);
-
-
- WalkMgr *_manager;
- Common::Array<WalkLocation*> _locations;
- Common::Array<WalkLocation*> _toVisit;
- Common::Array<double> _weight;
- Common::Array<WalkLocation*> _visited;
- Common::Array<WalkLocation*> _nearestNeigbor;
+ void add(WalkLocation *wl, double val, WalkLocation *nearest);
+ void remove(WalkLocation *location);
+ WalkLocation *build();
+ WalkLocation *getNearestNeighbor(WalkLocation *location);
+ WalkLocation *findNearestNeighbor(WalkLocation *location);
+ double getLengthToNearestNeigbor(WalkLocation *location);
+ double getWeight(WalkLocation *location);
+ void addLocationsToVisit();
+ bool isLocationVisited(WalkLocation *location);
+
+
+ WalkMgr *_manager;
+ Common::Array<WalkLocation*> _locations;
+ Common::Array<WalkLocation*> _toVisit;
+ Common::Array<double> _weight;
+ Common::Array<WalkLocation*> _visited;
+ Common::Array<WalkLocation*> _nearestNeigbor;
};
} // End of namespace Pink