void Rails::setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength) { WalkNode ¤tNode = _nodes[nodeIndex]; currentNode._active = true; *routeIndexP++ = nodeIndex; // Get the index of the ultimate source position (the player) int subIndex = _nodes.size() - 2; int distanceVal = _nodes[nodeIndex]._distances[subIndex]; if (distanceVal & flags) { routeLength += distanceVal & 0x3FFF; if (routeLength < _routeLength) { // Found a new shorter route to destination, so set up the route with the found one _routeIndexes.clear(); for (int i = 0; routeIndexP != &_tempRoute[i]; ++i) _routeIndexes.push(_tempRoute[i]); _routeLength = routeLength; } } else { for (int idx = _nodes.size() - 2; idx > 0; --idx) { int nodePos = idx - 1; if (!_nodes[nodePos]._active && ((currentNode._distances[nodePos] & flags) != 0)) setupRouteNode(routeIndexP, nodePos, 0x8000, routeLength + (distanceVal & 0x3fff)); } } currentNode._active = false; }
void MadsPlayer::setupRouteNode(int *routeIndexP, int nodeIndex, int flags, int routeLength) { SceneNodeList &nodes = _madsVm->scene()->getSceneResources()._nodes; SceneNode ¤tNode = nodes[nodeIndex]; currentNode.active = true; *routeIndexP++ = nodeIndex; int subIndex = nodes.size() - 2; int indexVal = nodes[nodeIndex].indexes[subIndex]; if (indexVal & flags) { routeLength += indexVal & 0x3FFF; if (routeLength < _routeLength) { // Found a new shorter route to destination, so set up the route with the found one Common::copy(_tempRoute, routeIndexP, _routeIndexes); _routeCount = routeIndexP - _tempRoute; _routeLength = indexVal & 0x3FFF; } } else { for (int idx = nodes.size() - 2; idx > 0; --idx) { int nodePos = idx - 1; if (!nodes[nodePos].active && ((currentNode.indexes[nodePos] & flags) != 0)) setupRouteNode(routeIndexP, nodePos, 0x8000, indexVal & 0x3fff); } } currentNode.active = false; }
void Rails::setupRoute(bool bitFlag, const Common::Point &srcPos, const Common::Point &destPos) { // Reset the nodes in as being inactive for (uint i = 0; i < _nodes.size(); ++i) _nodes[i]._active = false; // Set the two extra walk nodes to the start and destination positions setNodePosition(_nodes.size() - 2, srcPos); setNodePosition(_nodes.size() - 1, destPos); // Start constructing route node list _routeLength = 0x3FFF; _routeIndexes.clear(); // Recursively form a route from the destination walk node back to the player's position setupRouteNode(&_tempRoute[0], _nodes.size() - 1, bitFlag ? 0xC000 : 0x8000, 0); _next = 0; if (_routeIndexes.size() > 0) { Common::Point currPos = srcPos; for (int routeCtr = size() - 1; (routeCtr >= 0) && !_next; --routeCtr) { int idx = _routeIndexes[routeCtr]; const Common::Point &pt = _nodes[idx]._walkPos; _next = scanPath(currPos, pt); currPos = pt; } } }
void MadsPlayer::setupRoute(bool bitFlag) { // Reset the flag set of nodes in use SceneNodeList &nodes = _madsVm->scene()->getSceneResources()._nodes; for (uint i = 0; i < nodes.size(); ++i) nodes[i].active = false; // Start constructing route node list _routeLength = 0x3FFF; _routeCount = 0; setupRouteNode(_tempRoute, nodes.size() - 1, bitFlag ? 0xC000 : 0x8000, 0); }