diff options
author | Eugene Sandulenko | 2016-05-21 13:17:15 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-05-22 00:45:05 +0200 |
commit | 441f630ec53a2ece2f2afe46520cd73801069c5f (patch) | |
tree | 6154a3437a982fa49610ff5c8967519e2b0b8827 /engines/scumm/he | |
parent | 44333f74533f4d5a6c519923e31072fd7d87ac02 (diff) | |
download | scummvm-rg350-441f630ec53a2ece2f2afe46520cd73801069c5f.tar.gz scummvm-rg350-441f630ec53a2ece2f2afe46520cd73801069c5f.tar.bz2 scummvm-rg350-441f630ec53a2ece2f2afe46520cd73801069c5f.zip |
SCUMM HE: Added stub for Tree class
Diffstat (limited to 'engines/scumm/he')
-rw-r--r-- | engines/scumm/he/moonbase/ai_tree.cpp | 222 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/ai_tree.h | 21 |
2 files changed, 231 insertions, 12 deletions
diff --git a/engines/scumm/he/moonbase/ai_tree.cpp b/engines/scumm/he/moonbase/ai_tree.cpp new file mode 100644 index 0000000000..2335d567e9 --- /dev/null +++ b/engines/scumm/he/moonbase/ai_tree.cpp @@ -0,0 +1,222 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "scumm/he/moonbase/ai_tree.h" +#include "scumm/he/moonbase/ai_main.h" + +namespace Scumm { + +Tree::Tree() { + pBaseNode = new Node; + _maxDepth = MAX_DEPTH; + _maxNodes = MAX_NODES; +} + +Tree::Tree(IContainedObject *contents) { + pBaseNode = new Node; + pBaseNode->setContainedObject(contents); + _maxDepth = MAX_DEPTH; + _maxNodes = MAX_NODES; +} + +Tree::Tree(IContainedObject *contents, int maxDepth) { + pBaseNode = new Node; + pBaseNode->setContainedObject(contents); + _maxDepth = maxDepth; + _maxNodes = MAX_NODES; +} + +Tree::Tree(IContainedObject *contents, int maxDepth, int maxNodes) { + pBaseNode = new Node; + pBaseNode->setContainedObject(contents); + _maxDepth = maxDepth; + _maxNodes = maxNodes; +} + +void Tree::duplicateTree(Node *sourceNode, Node *destNode) { + Common::Array<Node *> vUnvisited = sourceNode->getChildren(); + + while (vUnvisited.size()) { + Node *newNode = new Node(*(vUnvisited.end())); + newNode->setParent(destNode); + (destNode->getChildren()).push_back(newNode); + duplicateTree(*(vUnvisited.end()), newNode); + vUnvisited.pop_back(); + } +} + +Tree::Tree(const Tree *sourceTree) { + pBaseNode = new Node(sourceTree->getBaseNode()); + _maxDepth = sourceTree->getMaxDepth(); + _maxNodes = sourceTree->getMaxNodes(); + + duplicateTree(sourceTree->getBaseNode(), pBaseNode); +} + +Tree::~Tree() { + // Delete all nodes + Node *pNodeItr = pBaseNode; + + // Depth first traversal of nodes to delete them + while (pNodeItr != NULL) { + // If any children are left, move to one of them + if (!(pNodeItr->getChildren().empty())) { + int size = (pNodeItr->getChildren()).size(); + pNodeItr = pNodeItr->popChild(); + } else { + // Delete this node, and move up to the parent for further processing + Node *pTemp = pNodeItr; + pNodeItr = pNodeItr->getParent(); + delete pTemp; + pTemp = NULL; + } + } +} + + +Node *Tree::aStarSearch() { + return NULL; +#if 0 + fnpMMap mmfpOpen; + + Node *currentNode = NULL; + float currentT; + + Node *retNode = NULL; + + float temp = pBaseNode->getContainedObject()->calcT(); + + if (static_cast<int>(temp) != SUCCESS) { + + mmfpOpen.insert(fnpMMap::value_type(pBaseNode->getObjectT(), pBaseNode)); + + while (mmfpOpen.size() && (retNode == NULL)) { + currentNode = mmfpOpen.begin()->second; + mmfpOpen.erase(mmfpOpen.begin()); + + if ((currentNode->getDepth() < _maxDepth) && (Node::getNodeCount() < _maxNodes)) { + // Generate nodes + int numChildren = currentNode->generateChildren(); + Common::Array<Node *> vChildren = currentNode->getChildren(); + + for (Common::Array<Node *>::iterator i = vChildren.begin(); i != vChildren.end(); i++) { + IContainedObject *pTemp = (*i)->getContainedObject(); + currentT = pTemp->calcT(); + + if (currentT == SUCCESS) retNode = *i; + else mmfpOpen.insert(fnpMMap::value_type(currentT, (*i))); + } + } else { + retNode = currentNode; + } + } + } else { + retNode = pBaseNode; + } + + return retNode; +#endif +} + + +Node *Tree::aStarSearch_singlePassInit() { + Node *retNode = NULL; + + currentChildIndex = 1; + + float temp = pBaseNode->getContainedObject()->calcT(); + + if (static_cast<int>(temp) != SUCCESS) { + //_currentMap.insert(fnpMMap::value_type(pBaseNode->getObjectT(), pBaseNode)); + //assert(_currentMap.size()); + } else { + retNode = pBaseNode; + } + + return retNode; +} + +Node *Tree::aStarSearch_singlePass(Node **currentNode) { + currentNode = NULL; + float currentT; + + Node *retNode = NULL; + +#if 0 + static int maxTime = 0; + + if (currentChildIndex == 1) { + maxTime = getPlayerMaxTime(); + } + + if (currentChildIndex) { + if (!(_currentMap.size())) { + retNode = _currentNode; + return retNode; + } + + _currentNode = _currentMap.begin()->second; + _currentMap.erase(_currentMap.begin()); + } + + if ((_currentNode->getDepth() < _maxDepth) && (Node::getNodeCount() < _maxNodes) && ((!maxTime) || (getTimerValue(3) < maxTime))) { + // Generate nodes + currentChildIndex = _currentNode->generateChildren(); + + if (currentChildIndex) { + Common::Array<Node *> vChildren = _currentNode->getChildren(); + + if (!vChildren.size() && !_currentMap.size()) { + currentChildIndex = 0; + retNode = _currentNode; + } + + for (Common::Array<Node *>::iterator i = vChildren.begin(); i != vChildren.end(); i++) { + IContainedObject *pTemp = (*i)->getContainedObject(); + currentT = pTemp->calcT(); + + if (currentT == SUCCESS) { + retNode = *i; + i = vChildren.end() - 1; + } else { + _currentMap.insert(fnpMMap::value_type(currentT, (*i))); + } + } + + if (!(_currentMap.size()) && (currentT != SUCCESS)) { + assert(_currentNode != NULL); + retNode = _currentNode; + } + } + } else { + retNode = _currentNode; + } +#endif + + return retNode; +} + +int Tree::IsBaseNode(Node *thisNode) { + return (thisNode == pBaseNode); +} + +} // End of namespace Scumm diff --git a/engines/scumm/he/moonbase/ai_tree.h b/engines/scumm/he/moonbase/ai_tree.h index cb3c8c5c55..1097665a7a 100644 --- a/engines/scumm/he/moonbase/ai_tree.h +++ b/engines/scumm/he/moonbase/ai_tree.h @@ -23,6 +23,7 @@ #ifndef SCUMM_HE_MOONBASE_AI_TREE_H #define SCUMM_HE_MOONBASE_AI_TREE_H +#include "common/hash-str.h" #include "scumm/he/moonbase/ai_node.h" namespace Scumm { @@ -36,14 +37,13 @@ class Tree { private: Node *pBaseNode; - int m_maxDepth; - int m_maxNodes; + int _maxDepth; + int _maxNodes; int currentChildIndex; - unsigned long m_startTime; - //fnpMMap m_currentMap; - Node *m_currentNode; + Common::StringMap _currentMap; + Node *_currentNode; public: Tree(); @@ -56,14 +56,11 @@ public: void duplicateTree(Node *sourceNode, Node *destNode); Node *getBaseNode() const { return pBaseNode; } - void setMaxDepth(int maxDepth) { m_maxDepth = maxDepth; } - int getMaxDepth() const { return m_maxDepth; } + void setMaxDepth(int maxDepth) { _maxDepth = maxDepth; } + int getMaxDepth() const { return _maxDepth; } - void setMaxNodes(int maxNodes) { m_maxNodes = maxNodes; } - int getMaxNodes() const { return m_maxNodes; } - - void setStartTime(unsigned long sTime) { m_startTime = sTime; } - unsigned long getStartTime() const { return m_startTime; } + void setMaxNodes(int maxNodes) { _maxNodes = maxNodes; } + int getMaxNodes() const { return _maxNodes; } Node *aStarSearch(); |