/* $Id$ */
/** @file random.cpp handles the random functions of the AIBase class */
#include "../ai_base.hpp"
#if defined(RANDOM_DEBUG)
uint32 AIBase::DoRandom(int line, const char *file)
#else
uint32 AIBase::Random()
#endif
{
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
* but we pick InteractiveRandomRange if we are a network_server or network-client. */
if (_networking) return InteractiveRandom();
#if defined(RANDOM_DEBUG)
return ::DoRandom(line, file);
#else
return ::Random();
#endif
}
#if defined(RANDOM_DEBUG)
uint AIBase::DoRandomRange(uint max, int line, const char *file)
#else
uint AIBase::RandomRange(uint max)
#endif
{
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over)
* but we pick InteractiveRandomRange if we are a network_server or network-client. */
if (_networking) return InteractiveRandomRange(max);
#if defined(RANDOM_DEBUG)
return ::DoRandomRange(max, line, file);
#else
return ::RandomRange(max);
#endif
}
bool AIBase::Chance(uint out, uint max)
{
return (uint16)this->Random() <= (uint16)((65536 * out) / max);
}