Changeset - r20170:7706d53b2679
[Not reviewed]
master
0 2 0
rubidium - 11 years ago 2013-04-06 11:59:27
rubidium@openttd.org
(svn r25148) -Fix [FS#5517]: [Script] XXBase::Chance function did not work for large values (>65535)
2 files changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_base.cpp
Show inline comments
 
@@ -41,13 +41,13 @@
 
	return ScriptBase::RandRange(max);
 
}
 

	
 
/* 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)
 
{
 
	return ScriptBase::Chance(out, max);
 
}
src/script/api/script_base.hpp
Show inline comments
 
@@ -67,12 +67,13 @@ public:
 
	/**
 
	 * Returns approximately 'out' times true when called 'max' times.
 
	 *   After all, it is a random function.
 
	 * @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);
 
};
 

	
 
#endif /* SCRIPT_BASE_HPP */
0 comments (0 inline, 0 general)