From 461fc1e268cb5db0394221f1b61383b453e6fc0a Mon Sep 17 00:00:00 2001 From: alberth Date: Tue, 18 Sep 2012 19:29:29 +0000 Subject: (svn r24531) -Fix: Max script chance was too big. --- src/script/api/script_base.cpp | 4 +++- src/script/api/script_base.hpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/script/api') diff --git a/src/script/api/script_base.cpp b/src/script/api/script_base.cpp index 5be6dd9a5..2472fe1c7 100644 --- a/src/script/api/script_base.cpp +++ b/src/script/api/script_base.cpp @@ -11,6 +11,7 @@ #include "../../stdafx.h" #include "script_base.hpp" +#include "script_error.hpp" #include "../../network/network.h" #include "../../core/random_func.hpp" @@ -42,7 +43,8 @@ /* static */ bool ScriptBase::Chance(uint out, uint max) { - return (uint16)Rand() <= (uint16)((65536 * out) / max); + EnforcePrecondition(false, out <= max); + return (uint16)Rand() <= (uint16)((65535 * out) / max); } /* static */ bool ScriptBase::ChanceItem(int unused_param, uint out, uint max) diff --git a/src/script/api/script_base.hpp b/src/script/api/script_base.hpp index 9384cbf80..a01325820 100644 --- a/src/script/api/script_base.hpp +++ b/src/script/api/script_base.hpp @@ -59,6 +59,7 @@ public: * After all, it is a random function. * @param out How many times it should return true. * @param max Out of this many times. + * @pre \a out is at most equal to \a max. * @return True if the chance worked out. */ static bool Chance(uint out, uint max); -- cgit v1.2.3-70-g09d2