diff options
Diffstat (limited to 'engines/scumm')
-rw-r--r-- | engines/scumm/he/moonbase/ai_node.cpp | 153 | ||||
-rw-r--r-- | engines/scumm/he/moonbase/ai_node.h | 49 | ||||
-rw-r--r-- | engines/scumm/module.mk | 1 |
3 files changed, 177 insertions, 26 deletions
diff --git a/engines/scumm/he/moonbase/ai_node.cpp b/engines/scumm/he/moonbase/ai_node.cpp new file mode 100644 index 0000000000..083a156a31 --- /dev/null +++ b/engines/scumm/he/moonbase/ai_node.cpp @@ -0,0 +1,153 @@ +/* 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_node.h" + +namespace Scumm { + +IContainedObject::IContainedObject(IContainedObject &sourceContainedObject) { + _objID = sourceContainedObject.getObjID(); + _valueG = sourceContainedObject.getG(); +} + +int Node::_nodeCount = 0; + +Node::Node() { + _parent = NULL; + _depth = 0; + _nodeCount++; + _contents = NULL; +} + +Node::Node(Node *sourceNode) { + _parent = NULL; + _children = sourceNode->getChildren(); + + _depth = sourceNode->getDepth(); + + _contents = sourceNode->getContainedObject()->duplicate(); +} + +Node::~Node() { + if (_contents != NULL) { + delete _contents; + _contents = NULL; + } + + _nodeCount--; +} + +int Node::generateChildren() { + int numChildren = _contents->numChildrenToGen(); + + int numChildrenGenerated = numChildren; + int errorCode = -1; + static int i = 0; + + while (i < numChildren) { + Node *tempNode = new Node; + _children.push_back(tempNode); + tempNode->setParent(this); + tempNode->setDepth(_depth + 1); + + int completionFlag; + + IContainedObject *thisContObj = _contents->createChildObj(i, completionFlag); + assert(!(thisContObj != NULL && completionFlag == 0)); + + if (!completionFlag) { + _children.pop_back(); + delete tempNode; + return 0; + } + + i++; + + if (thisContObj != NULL) { + tempNode->setContainedObject(thisContObj); + } else { + _children.pop_back(); + delete tempNode; + numChildrenGenerated--; + } + } + + i = 0; + + if (numChildrenGenerated > 0) + return numChildrenGenerated; + + return errorCode; +} + + +int Node::generateNextChild() { + int numChildren = _contents->numChildrenToGen(); + + static int i = 0; + + Node *tempNode = new Node; + _children.push_back(tempNode); + tempNode->setParent(this); + tempNode->setDepth(_depth + 1); + + int compFlag; + IContainedObject *thisContObj = _contents->createChildObj(i, compFlag); + + if (thisContObj != NULL) { + tempNode->setContainedObject(thisContObj); + } else { + _children.pop_back(); + delete tempNode; + } + + ++i; + + if (i > numChildren) + i = 0; + + return i; +} + +Node *Node::popChild() { + Node *temp; + + temp = _children.back(); + _children.pop_back(); + return temp; +} + +Node *Node::getFirstStep() { + Node *currentNode = this; + + if (currentNode->getParent() == NULL) + return currentNode; + + while (currentNode->getParent()->getParent() != NULL) + currentNode = currentNode->getParent(); + + assert(currentNode->getDepth() == 1); + + return currentNode; +} + +} // End of namespace Scumm diff --git a/engines/scumm/he/moonbase/ai_node.h b/engines/scumm/he/moonbase/ai_node.h index 87b6b96ebb..00800c2129 100644 --- a/engines/scumm/he/moonbase/ai_node.h +++ b/engines/scumm/he/moonbase/ai_node.h @@ -32,27 +32,26 @@ const float FAILURE = 1e20; class IContainedObject { private: - int objID; - float valueG; + int _objID; + float _valueG; protected: - virtual float getG() const { return valueG; } + virtual float getG() const { return _valueG; } virtual float calcH() { return 0; } - public: - IContainedObject() { valueG = 0; } - IContainedObject(float inG) { valueG = inG; } + IContainedObject() { _valueG = 0; } + IContainedObject(float inG) { _valueG = inG; } IContainedObject(IContainedObject &sourceContainedObject); virtual ~IContainedObject() {} virtual IContainedObject *duplicate() = 0; - void setValueG(float inG) { valueG = inG; } - float getValueG() { return valueG; } + void setValueG(float inG) { _valueG = inG; } + float getValueG() { return _valueG; } - int getObjID() const { return objID; } - void setObjID(int inputObjID) { objID = inputObjID; } + int getObjID() const { return _objID; } + void setObjID(int inputObjID) { _objID = inputObjID; } virtual int numChildrenToGen() = 0; virtual IContainedObject *createChildObj(int index, int &completionFlag) = 0; @@ -65,40 +64,38 @@ public: class Node { private: - Node *pParent; - Common::List<Node *> vpChildren; + Node *_parent; + Common::List<Node *> _children; - int m_depth; - static int m_nodeCount; + int _depth; + static int _nodeCount; - IContainedObject *pContents; + IContainedObject *_contents; public: Node(); Node(Node *sourceNode); ~Node(); - void setParent(Node *parentPtr) { pParent = parentPtr; } - Node *getParent() const { return pParent; } + void setParent(Node *parentPtr) { _parent = parentPtr; } + Node *getParent() const { return _parent; } - void setDepth(int depth) { m_depth = depth; } - int getDepth() const { return m_depth; } + void setDepth(int depth) { _depth = depth; } + int getDepth() const { return _depth; } - static int getNodeCount() { return m_nodeCount; } + static int getNodeCount() { return _nodeCount; } - void setContainedObject(IContainedObject *pValue) { pContents = pValue; } - IContainedObject *getContainedObject() { return pContents; } + void setContainedObject(IContainedObject *value) { _contents = value; } + IContainedObject *getContainedObject() { return _contents; } - Common::List<Node *> getChildren() const { return vpChildren; } + Common::List<Node *> getChildren() const { return _children; } int generateChildren(); int generateNextChild(); Node *popChild(); - float getObjectT() { return pContents->calcT(); } + float getObjectT() { return _contents->calcT(); } Node *getFirstStep(); - - void printPath(); }; } // End of namespace Scumm diff --git a/engines/scumm/module.mk b/engines/scumm/module.mk index 582411f179..28153f51f9 100644 --- a/engines/scumm/module.mk +++ b/engines/scumm/module.mk @@ -140,6 +140,7 @@ MODULE_OBJS += \ he/logic/puttrace.o \ he/logic/soccer.o \ he/moonbase/ai_defenseunit.o \ + he/moonbase/ai_node.o \ he/moonbase/ai_types.o \ he/moonbase/ai_weapon.o \ he/moonbase/moonbase.o \ |