File indexing completed on 2024-05-12 05:39:26
0001 /*************************************************************************** 0002 * Copyright (C) 2014 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * This file is part of DiceParser * 0006 * * 0007 * DiceParser is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU General Public License as published by * 0009 * the Free Software Foundation; either version 2 of the License, or * 0010 * (at your option) any later version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0015 * GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License * 0018 * along with this program; if not, write to the * 0019 * Free Software Foundation, Inc., * 0020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0021 ***************************************************************************/ 0022 #include "bind.h" 0023 0024 BindNode::BindNode() : m_diceResult(new DiceResult()) 0025 { 0026 m_result= m_diceResult; 0027 } 0028 void BindNode::run(ExecutionNode* previous) 0029 { 0030 m_previousNode= previous; 0031 if(nullptr == m_previousNode) 0032 return; 0033 0034 m_result->setPrevious(previous->getResult()); 0035 for(auto start : *m_startList) 0036 { 0037 ExecutionNode* last= getLatestNode(start); 0038 if(nullptr != last) 0039 { 0040 auto tmpResult= last->getResult(); 0041 while(nullptr != tmpResult) 0042 { 0043 DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); 0044 if(nullptr != dice) 0045 { 0046 m_diceResult->setHomogeneous(false); 0047 for(auto& die : dice->getResultList()) 0048 { 0049 if(!die->hasBeenDisplayed()) 0050 { 0051 Die* tmpdie= new Die(*die); 0052 die->displayed(); 0053 m_diceResult->getResultList().append(tmpdie); 0054 } 0055 } 0056 } 0057 tmpResult= tmpResult->getPrevious(); 0058 } 0059 } 0060 } 0061 0062 if(nullptr != m_nextNode) 0063 { 0064 m_nextNode->run(this); 0065 } 0066 } 0067 ExecutionNode* BindNode::getLatestNode(ExecutionNode* node) 0068 { 0069 ExecutionNode* next= node; 0070 while(nullptr != next->getNextNode() && (next->getNextNode() != this)) 0071 { 0072 next= next->getNextNode(); 0073 } 0074 return next; 0075 } 0076 QString BindNode::toString(bool withLabel) const 0077 { 0078 if(withLabel) 0079 { 0080 return QString("%1 [label=\"Bind Node\"]").arg(m_id); 0081 } 0082 else 0083 { 0084 return m_id; 0085 } 0086 } 0087 qint64 BindNode::getPriority() const 0088 { 0089 qint64 priority= 0; 0090 if(nullptr != m_previousNode) 0091 { 0092 priority= m_previousNode->getPriority(); 0093 } 0094 return priority; 0095 } 0096 ExecutionNode* BindNode::getCopy() const 0097 { 0098 BindNode* node= new BindNode(); 0099 if(nullptr != m_nextNode) 0100 { 0101 node->setNextNode(m_nextNode->getCopy()); 0102 } 0103 return node; 0104 } 0105 0106 std::vector<ExecutionNode*>* BindNode::getStartList() const 0107 { 0108 return m_startList; 0109 } 0110 0111 void BindNode::setStartList(std::vector<ExecutionNode*>* startList) 0112 { 0113 m_startList= startList; 0114 }