1
0
Fork 0

(svn r25148) -Fix [FS#5517]: [Script] XXBase::Chance function did not work for large values (>65535)

release/1.4
rubidium 2013-04-06 11:59:27 +00:00
parent e5a77f94bd
commit 70454b8d64
2 changed files with 2 additions and 1 deletions

View File

@ -44,7 +44,7 @@
/* static */ bool ScriptBase::Chance(uint out, uint max) /* static */ bool ScriptBase::Chance(uint out, uint max)
{ {
EnforcePrecondition(false, out <= max); EnforcePrecondition(false, out <= max);
return (uint16)Rand() <= (uint16)((65535 * out) / max); return ScriptBase::RandRange(max) < out;
} }
/* static */ bool ScriptBase::ChanceItem(int unused_param, uint out, uint max) /* static */ bool ScriptBase::ChanceItem(int unused_param, uint out, uint max)

View File

@ -70,6 +70,7 @@ public:
* @param unused_param This parameter is not used, but is needed to work with lists. * @param unused_param This parameter is not used, but is needed to work with lists.
* @param out How many times it should return true. * @param out How many times it should return true.
* @param max Out of this many times. * @param max Out of this many times.
* @pre \a out is at most equal to \a max.
* @return True if the chance worked out. * @return True if the chance worked out.
*/ */
static bool ChanceItem(int unused_param, uint out, uint max); static bool ChanceItem(int unused_param, uint out, uint max);