File indexing completed on 2024-05-12 05:39:26
0001 #include "allsamenode.h" 0002 0003 AllSameNode::AllSameNode() : m_diceResult(new DiceResult()) 0004 { 0005 m_result= m_diceResult; 0006 } 0007 0008 void AllSameNode::run(ExecutionNode* previous) 0009 { 0010 m_previousNode= previous; 0011 if(nullptr != previous) 0012 { 0013 DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult()); 0014 if(nullptr != previous_result) 0015 { 0016 m_result->setPrevious(previous_result); 0017 bool allSame= true; 0018 int i= 0; 0019 qint64 previousValue= 0; 0020 if(previous_result->getResultList().size() < 2) 0021 { 0022 m_errors.insert(Dice::ERROR_CODE::ENDLESS_LOOP_ERROR, 0023 QStringLiteral("T operator must operate on more than 1 die")); 0024 return; 0025 } 0026 for(auto& die : previous_result->getResultList()) 0027 { 0028 if(i == 0) 0029 previousValue= die->getValue(); 0030 Die* tmpdie= new Die(*die); 0031 m_diceResult->insertResult(tmpdie); 0032 die->displayed(); 0033 if(previousValue != die->getValue()) 0034 allSame= false; 0035 ++i; 0036 } 0037 0038 while(allSame) 0039 { 0040 QList<Die*> list= m_diceResult->getResultList(); 0041 qint64 pValue= 0; 0042 int i= 0; 0043 for(auto& die : list) 0044 { 0045 die->roll(true); 0046 if(i == 0) 0047 pValue= die->getValue(); 0048 if(pValue != die->getValue()) 0049 allSame= false; 0050 ++i; 0051 } 0052 } 0053 } 0054 } 0055 if(nullptr != m_nextNode) 0056 { 0057 m_nextNode->run(this); 0058 } 0059 } 0060 0061 QString AllSameNode::toString(bool withLabel) const 0062 { 0063 if(withLabel) 0064 { 0065 return QString("%1 [label=\"AllSameNode\"]").arg(m_id); 0066 } 0067 else 0068 { 0069 return m_id; 0070 } 0071 } 0072 0073 qint64 AllSameNode::getPriority() const 0074 { 0075 qint64 priority= 0; 0076 if(nullptr != m_nextNode) 0077 { 0078 priority= m_nextNode->getPriority(); 0079 } 0080 return priority; 0081 } 0082 0083 ExecutionNode* AllSameNode::getCopy() const 0084 { 0085 return new AllSameNode(); 0086 }