--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_base.cpp Thu Mar 15 22:46:22 2007 +0000
@@ -0,0 +1,42 @@
+/* $Id$ */
+
+/** @file ai_base.cpp handles the 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);
+}