maybe_random2()


Questions, Explanations, Howtos

Jk

Swamp Slogger

Posts: 165

Joined: Thursday, 23rd December 2010, 03:28

Post Wednesday, 16th March 2011, 21:08

maybe_random2()

I'm trying to understand fight.cc, and all the to_hit functionality is calling this function. It's clearly not just random between a minimum and a maximum. Can anyone explain how maybe_random2() works (or direct me to where it is in the code)?

For instance:
  Code:
your_to_hit += maybe_random2(you.skills[wpn_skill] + 1, random_factor);
User avatar

Dungeon Master

Posts: 4031

Joined: Thursday, 16th December 2010, 20:37

Location: France

Post Wednesday, 16th March 2011, 21:39

Re: maybe_random2()

it's defined in random.cc. random_factor is a boolean. If it's true, the function returns the result of random2, else it returns the mean. random2(x) returns a random number between 0 and x - 1.
maybe_random2 is used because the to_hit functions can either return a randomized result (when called for actual fight) or a mean value for the interface to report the average player to_hit (although this functionality is currently disabled).
<+Grunt> You dereference an invalid pointer! Ouch! That really hurt! The game dies...

For this message the author galehar has received thanks:
Jk

Return to Coding

Who is online

Users browsing this forum: No registered users and 17 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.