src/ai/api/base/random.cpp
author truelight
Thu, 15 Mar 2007 22:28:14 +0000
branchnoai
changeset 9427 ef0c109c5661
parent 9371 src/ai/core/base/random.cpp@cfa43f975d01
permissions -rw-r--r--
(svn r9230) [NoAI] -Change: moved ai/core/ai.* to ai/
-Change: moved ai/squirrel/* to ai/
-Change: renamed ai/core to ai/api
/* $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);
}