Changeset - r19600:6978d1dfdf82
[Not reviewed]
master
0 2 0
alberth - 12 years ago 2012-09-18 19:29:29
alberth@openttd.org
(svn r24531) -Fix: Max script chance was too big.
2 files changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_base.cpp
Show inline comments
 
@@ -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)
src/script/api/script_base.hpp
Show inline comments
 
@@ -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);
0 comments (0 inline, 0 general)