File indexing completed on 2024-05-12 05:39:29
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 "uniquenode.h" 0023 0024 UniqueNode::UniqueNode() : m_diceResult(new DiceResult()) 0025 { 0026 m_result= m_diceResult; 0027 } 0028 void UniqueNode::run(ExecutionNode* previous) 0029 { 0030 m_previousNode= previous; 0031 if(nullptr != previous) 0032 { 0033 m_result->setPrevious(previous->getResult()); 0034 Result* tmpResult= previous->getResult(); 0035 if(nullptr != tmpResult) 0036 { 0037 DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult); 0038 if(nullptr != dice) 0039 { 0040 auto const& resultList= dice->getResultList(); 0041 std::vector<qint64> formerValues; 0042 formerValues.reserve(resultList.size()); 0043 for(auto& oldDie : resultList) 0044 { 0045 auto value= oldDie->getValue(); 0046 auto it= std::find(formerValues.begin(), formerValues.end(), value); 0047 0048 if(it == formerValues.end()) 0049 { 0050 auto die= new Die(*oldDie); 0051 m_diceResult->insertResult(die); 0052 formerValues.push_back(value); 0053 } 0054 oldDie->displayed(); 0055 } 0056 } 0057 } 0058 } 0059 if(nullptr != m_nextNode) 0060 { 0061 m_nextNode->run(this); 0062 } 0063 } 0064 0065 QString UniqueNode::toString(bool withLabel) const 0066 { 0067 if(withLabel) 0068 { 0069 return QString("%1 [label=\"UniqueNode Node\"]").arg(m_id); 0070 } 0071 else 0072 { 0073 return m_id; 0074 } 0075 } 0076 qint64 UniqueNode::getPriority() const 0077 { 0078 qint64 priority= 0; 0079 if(nullptr != m_nextNode) 0080 { 0081 priority= m_nextNode->getPriority(); 0082 } 0083 return priority; 0084 } 0085 ExecutionNode* UniqueNode::getCopy() const 0086 { 0087 UniqueNode* node= new UniqueNode(); 0088 if(nullptr != m_nextNode) 0089 { 0090 node->setNextNode(m_nextNode->getCopy()); 0091 } 0092 return node; 0093 }