From f1b743e15a0f694fd800d2622b15d5285db8355c Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 30 Jun 2011 20:17:05 -0700 Subject: Fixed dice rolling to use the right range --- linden/indra/newview/floaterdice.cpp | 32 ++++++++++++-------------------- linden/indra/newview/floaterdice.h | 1 - 2 files changed, 12 insertions(+), 21 deletions(-) (limited to 'linden') diff --git a/linden/indra/newview/floaterdice.cpp b/linden/indra/newview/floaterdice.cpp index f16a6ca..203878c 100644 --- a/linden/indra/newview/floaterdice.cpp +++ b/linden/indra/newview/floaterdice.cpp @@ -37,7 +37,6 @@ #include "llchat.h" #include "llchatbar.h" -#include "llkeyboard.h" #include "llviewercontrol.h" @@ -75,13 +74,20 @@ void FloaterDice::onClickRoll(void* data) { S32 dice_total = 0; std::ostringstream rolls; - for (S32 i = 0; i < dice_count; ++i) + S32 i = 0; + do { - S32 roll = ll_rand(dice_sides); - dice_total += roll; - rolls << roll; - if (i < dice_count - 1) rolls << ", "; + // see the clamping rules for ll_rand + S32 roll = ll_rand(dice_sides+1); + if (roll > 0) + { + dice_total += roll; + rolls << roll; + if (i < dice_count - 1) rolls << ", "; + ++i; + } } + while (i < dice_count); std::string roll_text = llformat("/me rolled %dd%d for a total of %d", dice_count, dice_sides, dice_total); if (dice_count > 1) @@ -92,17 +98,3 @@ void FloaterDice::onClickRoll(void* data) } } } - -// virtual -BOOL FloaterDice::handleKeyHere(KEY key, MASK mask) -{ - BOOL handled = FALSE; - - if ((KEY_RETURN == key) && (mask == MASK_NONE)) - { - onClickRoll(this); - handled = TRUE; - } - - return handled; -} diff --git a/linden/indra/newview/floaterdice.h b/linden/indra/newview/floaterdice.h index 57a664b..5f36a80 100644 --- a/linden/indra/newview/floaterdice.h +++ b/linden/indra/newview/floaterdice.h @@ -44,7 +44,6 @@ public: private: static void onClickRoll(void* data); - virtual BOOL handleKeyHere(KEY key, MASK mask); }; #endif //floaterdice_h -- cgit v1.1