src/ai/api/base/random.cpp
branchnoai
changeset 9427 ef0c109c5661
parent 9371 cfa43f975d01
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/base/random.cpp	Thu Mar 15 22:28:14 2007 +0000
@@ -0,0 +1,42 @@
+/* $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);
+}