(svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
--- a/src/ai/api/ai_base.cpp Fri Mar 16 10:00:17 2007 +0000
+++ b/src/ai/api/ai_base.cpp Fri Mar 16 10:14:14 2007 +0000
@@ -4,39 +4,23 @@
#include "ai_base.hpp"
-#if defined(RANDOM_DEBUG)
-uint32 AIBase::DoRandom(int line, const char *file)
-#else
-uint32 AIBase::Random()
-#endif
+uint32 AIBase::Rand()
{
/* 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
+uint AIBase::RandRange(uint max)
{
/* 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);
+ return (uint16)this->Rand() <= (uint16)((65536 * out) / max);
}
--- a/src/ai/api/ai_base.hpp Fri Mar 16 10:00:17 2007 +0000
+++ b/src/ai/api/ai_base.hpp Fri Mar 16 10:14:14 2007 +0000
@@ -7,28 +7,31 @@
#include "ai_object.hpp"
+/**
+ * Implementation of some basic function
+ *
+ * @note The random functions are not called Random and RandomRange, because
+ * when including them the RANDOM_DEBUG stuff messes with their names.
+ * However, because in MP we cannot use Random because that will cause
+ * desyncs (AIs are ran locally, not on all clients). This means that
+ * we use InteractiveRandom in MP, thus the whole random debugging is
+ * pointless for the AIs. Therefor the random functions are called
+ * differently.
+ */
class AIBase : public AIObject {
public:
/**
* Get a random value.
* @return A random value between 0 and MAX(uint32)
*/
-#if defined(RANDOM_DEBUG)
- uint32 DoRandom(int line, const char *file);
-#else
- uint32 Random();
-#endif
+ uint32 Rand();
/**
* Get a random value in a range.
* @param max The maximum value it will return.
* @return A random value between 0 .. max.
*/
-#if defined(RANDOM_DEBUG)
- uint DoRandomRange(uint max, int line, const char *file);
-#else
- uint RandomRange(uint max);
-#endif
+ uint RandRange(uint max);
/**
* Take a chance of 'out' out of 'max'.
@@ -44,9 +47,9 @@
DefSQClass <AIBase> SQAIBase("AIBase");
SQAIBase.PreRegister(engine);
SQAIBase.AddConstructor(engine);
- SQAIBase.DefSQFunction(engine, &AIBase::Random, "Random");
- SQAIBase.DefSQFunction(engine, &AIBase::RandomRange, "RandomRange");
- SQAIBase.DefSQFunction(engine, &AIBase::Chance, "Chance");
+ SQAIBase.DefSQFunction(engine, &AIBase::Rand, "Rand");
+ SQAIBase.DefSQFunction(engine, &AIBase::RandRange, "RandRange");
+ SQAIBase.DefSQFunction(engine, &AIBase::Chance, "Chance");
SQAIBase.PostRegister(engine);
}
#endif /* SQUIRREL_CLASS */