Re: [CODE] Oedit limits

From: George (greerga@CIRCLEMUD.ORG)
Date: 04/13/98


On Mon, 13 Apr 1998, Del (Panther) wrote:

>George wrote:
>> I 'solved' that problem by limiting the dice size in the dice() function.
>> So if you go over the limit, the damage becomes 1. :)
>>
>> A 1000000d20 weapon may cause your MUD to checkpoint crash unless you have
>> a fast machine.
>>
>
>Can you show how you did this? or give some idea please?

Um, ok, sure.  The easiest way is:

/* simulates dice roll */
int dice(int number, int size)
{
  int sum = 0;

-  if (size <= 0 || number <= 0)
-    return 0;
+  if (size <= 0 || number <= 0 || size > 99 || number > 99)
+    return 0;

  while (number-- > 0)
    sum += ((circle_random() % size) + 1);

  return sum;
}

Thinking takes less time than posting though. :)

--
George Greer  -  Me@Null.net   | Genius may have its limitations, but stupidity
http://www.van.ml.org/~greerga | is not thus handicapped. -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST