summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2013-04-06 11:59:27 +0000
committerrubidium <rubidium@openttd.org>2013-04-06 11:59:27 +0000
commit70454b8d64ee2469859c9153b74f4d26b47c898c (patch)
treed83c3093e98597e211199f75f9a915b948cb816b /src
parente5a77f94bdc48051524b51f697bae5b09d222f1f (diff)
downloadopenttd-70454b8d64ee2469859c9153b74f4d26b47c898c.tar.xz
(svn r25148) -Fix [FS#5517]: [Script] XXBase::Chance function did not work for large values (>65535)
Diffstat (limited to 'src')
-rw-r--r--src/script/api/script_base.cpp2
-rw-r--r--src/script/api/script_base.hpp1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/script/api/script_base.cpp b/src/script/api/script_base.cpp
index 2472fe1c7..7fd5b2df9 100644
--- a/src/script/api/script_base.cpp
+++ b/src/script/api/script_base.cpp
@@ -44,7 +44,7 @@
/* static */ bool ScriptBase::Chance(uint out, uint 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)
diff --git a/src/script/api/script_base.hpp b/src/script/api/script_base.hpp
index a01325820..936dee77d 100644
--- a/src/script/api/script_base.hpp
+++ b/src/script/api/script_base.hpp
@@ -70,6 +70,7 @@ public:
* @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 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 ChanceItem(int unused_param, uint out, uint max);