diff options
| author | 2019-01-13 16:26:52 +0100 | |
|---|---|---|
| committer | 2019-01-13 16:30:03 +0100 | |
| commit | 663e4d49fdd2f8f8ca27c771a52cc0aa09357289 (patch) | |
| tree | f60039a46d3c89b1027e82053ee1d65299783340 /die.cpp | |
| parent | 0134061fa7e86118feac8080d5e7caf42877079e (diff) | |
| download | OneRoll-663e4d49fdd2f8f8ca27c771a52cc0aa09357289.tar.gz OneRoll-663e4d49fdd2f8f8ca27c771a52cc0aa09357289.zip | |
clang format.
Diffstat (limited to 'die.cpp')
| -rw-r--r-- | die.cpp | 136 |
1 files changed, 70 insertions, 66 deletions
@@ -1,24 +1,24 @@ /*************************************************************************** -* Copyright (C) 2014 by Renaud Guezennec * -* http://www.rolisteam.org/contact * -* * -* This file is part of DiceParser * -* * -* DiceParser 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., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ + * Copyright (C) 2014 by Renaud Guezennec * + * http://www.rolisteam.org/contact * + * * + * This file is part of DiceParser * + * * + * DiceParser 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #include "die.h" @@ -27,29 +27,34 @@ #include <chrono> Die::Die() - : m_hasValue(false),m_displayStatus(false),m_highlighted(true),m_base(1),m_color(""),m_op(Die::PLUS)//,m_mt(m_randomDevice) + : m_hasValue(false) + , m_displayStatus(false) + , m_highlighted(true) + , m_base(1) + , m_color("") + , m_op(Die::PLUS) //,m_mt(m_randomDevice) { - auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); - m_rng = std::mt19937(quintptr(this)+seed); + auto seed= std::chrono::high_resolution_clock::now().time_since_epoch().count(); + m_rng= std::mt19937(quintptr(this) + seed); } Die::Die(const Die& die) { - m_value = die.m_value; - m_rollResult = die.m_rollResult; - m_selected = die.m_selected; - m_hasValue = die.m_hasValue; - m_displayStatus = die.m_displayStatus; - m_maxValue = die.m_maxValue; - m_highlighted = die.m_highlighted; - m_base = die.m_base; - m_color = die.getColor(); - m_op = die.getOp(); + m_value= die.m_value; + m_rollResult= die.m_rollResult; + m_selected= die.m_selected; + m_hasValue= die.m_hasValue; + m_displayStatus= die.m_displayStatus; + m_maxValue= die.m_maxValue; + m_highlighted= die.m_highlighted; + m_base= die.m_base; + m_color= die.getColor(); + m_op= die.getOp(); } void Die::setValue(qint64 r) { - m_value = r; - m_hasValue = true; + m_value= r; + m_hasValue= true; } void Die::insertRollValue(qint64 r) @@ -59,10 +64,9 @@ void Die::insertRollValue(qint64 r) void Die::setSelected(bool b) { - m_selected = b; + m_selected= b; } - bool Die::isSelected() const { return m_selected; @@ -75,42 +79,42 @@ qint64 Die::getValue() const } else { - qint64 value=0; - int i = 0; + qint64 value= 0; + int i= 0; for(qint64 tmp : m_rollResult) { - if(i>0) + if(i > 0) { switch(m_op) { case PLUS: - value+=tmp; + value+= tmp; break; case MULTIPLICATION: - value*=tmp; + value*= tmp; break; case MINUS: - value-=tmp; + value-= tmp; break; case INTEGER_DIVIDE: case DIVIDE: - if(tmp!=0) + if(tmp != 0) { - value/=tmp; + value/= tmp; } else { - //error(); + // error(); } break; case POW: - value=static_cast<qint64>(std::pow(value,tmp)); + value= static_cast<qint64>(std::pow(value, tmp)); break; } } else { - value=tmp; + value= tmp; } ++i; } @@ -123,23 +127,22 @@ QList<qint64> Die::getListValue() const } bool Die::hasChildrenValue() { - return m_rollResult.size()>1?true:false; + return m_rollResult.size() > 1 ? true : false; } void Die::replaceLastValue(qint64 value) { m_rollResult.removeLast(); - insertRollValue(value); + insertRollValue(value); } void Die::roll(bool adding) { - if(m_maxValue!=0) + if(m_maxValue != 0) { - //quint64 value=(qrand()%m_faces)+m_base; - - std::uniform_int_distribution<qint64> dist(m_base,m_maxValue); - qint64 value = dist(m_rng); - if((adding)||(m_rollResult.isEmpty())) + // quint64 value=(qrand()%m_faces)+m_base; + std::uniform_int_distribution<qint64> dist(m_base, m_maxValue); + qint64 value= dist(m_rng); + if((adding) || (m_rollResult.isEmpty())) { insertRollValue(value); } @@ -152,7 +155,7 @@ void Die::roll(bool adding) quint64 Die::getFaces() const { - return abs(m_maxValue-m_base)+1; + return abs(m_maxValue - m_base) + 1; } qint64 Die::getLastRolledValue() { @@ -169,11 +172,12 @@ bool Die::hasBeenDisplayed() const } void Die::displayed() { - m_displayStatus = true; + m_displayStatus= true; } + void Die::setHighlighted(bool a) { - m_highlighted = a; + m_highlighted= a; } bool Die::isHighlighted() const @@ -182,7 +186,7 @@ bool Die::isHighlighted() const } void Die::setBase(qint64 base) { - m_base = base; + m_base= base; } qint64 Die::getBase() { @@ -193,9 +197,9 @@ QString Die::getColor() const return m_color; } -void Die::setColor(const QString &color) +void Die::setColor(const QString& color) { - m_color = color; + m_color= color; } qint64 Die::getMaxValue() const @@ -203,9 +207,9 @@ qint64 Die::getMaxValue() const return m_maxValue; } -void Die::setMaxValue(const qint64 &maxValue) +void Die::setMaxValue(const qint64& maxValue) { - m_maxValue = maxValue; + m_maxValue= maxValue; } Die::ArithmeticOperator Die::getOp() const @@ -213,7 +217,7 @@ Die::ArithmeticOperator Die::getOp() const return m_op; } -void Die::setOp(const Die::ArithmeticOperator &op) +void Die::setOp(const Die::ArithmeticOperator& op) { - m_op = op; + m_op= op; } |