/* * Programmer: Cameron Taylor, a.k.a. Shanyr * Date: 3 May 2005 * Notes: Put do_dice in where you think it fits; don't forget the DO_FUN * entry; you may need to add an #include or two for is_number() and * atoi(). * 'dice' will roll two six-sided dice. 'dice' followed by a number * will restrict the number to 1-10 and roll that number of six-sided * dice. 'dice' followed by two numbers will restrict the first number * to 1-10 and the second number to 2-20 and roll (first number) dice * of (second number) sides. The values of all dice rolled are listed, * and the total. * If you have a 'snippets' help file, I would appreciate an entry * similar to: Dice code by Cameron Taylor. */ /* * This function allows a character to roll 1 or more dice. * Programmer: Cameron Taylor */ void do_dice( CHAR_DATA *ch, char *argument ) { const int MAX_DICE = 10; const int MAX_SIDES = 20; int number=2, sides=6; int total = 0; int dice[10]; char buf1[MAX_STRING_LENGTH]; char buf2[MAX_STRING_LENGTH]; char arg1 [MAX_INPUT_LENGTH]; char arg2 [MAX_INPUT_LENGTH]; int i; argument = one_argument( argument, arg1 ); argument = one_argument( argument, arg2 ); if(STR_HASDATA(arg1)) { if(is_number(arg1)) number = atoi(arg1); number = number > MAX_DICE ? MAX_DICE : (number < 1 ? 1 : number); if(STR_HASDATA(arg2)) { if(is_number(arg2)) sides = atoi(arg2); sides = sides > MAX_SIDES ? MAX_SIDES : (sides < 2 ? 2 : sides); } } for(i=0; i