org.guifications.plugins: 928229936b9893eb62902716ccb743215c476c79

grim at guifications.org grim at guifications.org
Mon Nov 19 01:15:05 CST 2007


-----------------------------------------------------------------
Revision: 928229936b9893eb62902716ccb743215c476c79
Ancestor: 8274eb3fcb71be37c1b30eafdda48088cb14a15a
Author: grim at guifications.org
Date: 2007-11-19T07:14:35
Branch: org.guifications.plugins

Modified files:
        dice/dice.c

ChangeLog: 

Multiplication and division are working now.  Although there are some corner cases yet.

For example, 'd6+d10+10+2d5: (2) (10) (5 2 4 3 5 1 2 4 4 2) = 44' is wrong, the 10 gets considered the number of dice, not a separate bonus.
Also, something like '2d6-d2' won't subtract.


-----------------------------------------------------------------
This revision's diffstat output:
 dice.c |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
-------------- next part --------------
============================================================
--- dice/dice.c	8cf0ba6c0e6353c44b45faac04c796b17f52b6a6
+++ dice/dice.c	48c27063a9894d4c595660416d39fdd12cf02c94
@@ -76,7 +76,8 @@ dice_notation_roll_helper(const gchar *d
 static gchar *
 dice_notation_roll_helper(const gchar *dn, gint *value) {
 	GString *str = g_string_new("");
-	gchar *ret = NULL;
+	gchar *ret = NULL, *ms = NULL;
+	gchar op = '\0';
 	gint dice = 0, sides = 0, i = 0, t = 0, v = 0;
 	gdouble multiplier = 1.0;
 
@@ -127,19 +128,20 @@ dice_notation_roll_helper(const gchar *d
 		purple_debug_info("dice", "looking for the next operator: %s\n", dn);
 	}
 
+	purple_debug_info("dice", "next operator: %s\n", dn);
+
 	/* check if we're multiplying or dividing this block */
 	if(*dn == 'x' || *dn == '/') {
-		gchar op;
-
-		v = atof(dn);
-
 		op = *dn;
 		dn++;
 
-		multiplier = v;
+		multiplier = v = atof(dn);
 
+		ms = g_strdup_printf("%d", (gint)multiplier);
+
 		/* move past our multiplier */
 		for(t = v; t > 0; t /= 10) {
+			purple_debug_info("dice", "moving past the multiplier: %s\n", dn);
 			dn++;
 		}
 
@@ -155,14 +157,22 @@ dice_notation_roll_helper(const gchar *d
 		t = rand() % sides + 1;
 		v = ROUND(t * multiplier);
 
-		g_string_append_printf(str, "%s%d", (i > 0) ? " " : "", v);
+		g_string_append_printf(str, "%s%d", (i > 0) ? " " : "", t);
 		
 		purple_debug_info("dice", "die %d: %d(%d)\n", i, v, t);
 
 		*value += v;
 	}
+
 	g_string_append_printf(str, ")");
 
+	/* if we have a multiplier, we need to output it as well */
+	if(multiplier != 1.0)
+		g_string_append_printf(str, "%c(%s)", op, ms);
+
+	/* free our string of the multiplier */
+	g_free(ms);
+
 	purple_debug_info("dice", "value=%d;str=%s\n", *value, str->str);
 
 	/* we have more in our string, recurse! */


More information about the Plugins-commits mailing list