5 #ifndef AI_BASE_HPP |
5 #ifndef AI_BASE_HPP |
6 #define AI_BASE_HPP |
6 #define AI_BASE_HPP |
7 |
7 |
8 #include "ai_object.hpp" |
8 #include "ai_object.hpp" |
9 |
9 |
|
10 /** |
|
11 * Implementation of some basic function |
|
12 * |
|
13 * @note The random functions are not called Random and RandomRange, because |
|
14 * when including them the RANDOM_DEBUG stuff messes with their names. |
|
15 * However, because in MP we cannot use Random because that will cause |
|
16 * desyncs (AIs are ran locally, not on all clients). This means that |
|
17 * we use InteractiveRandom in MP, thus the whole random debugging is |
|
18 * pointless for the AIs. Therefor the random functions are called |
|
19 * differently. |
|
20 */ |
10 class AIBase : public AIObject { |
21 class AIBase : public AIObject { |
11 public: |
22 public: |
12 /** |
23 /** |
13 * Get a random value. |
24 * Get a random value. |
14 * @return A random value between 0 and MAX(uint32) |
25 * @return A random value between 0 and MAX(uint32) |
15 */ |
26 */ |
16 #if defined(RANDOM_DEBUG) |
27 uint32 Rand(); |
17 uint32 DoRandom(int line, const char *file); |
|
18 #else |
|
19 uint32 Random(); |
|
20 #endif |
|
21 |
28 |
22 /** |
29 /** |
23 * Get a random value in a range. |
30 * Get a random value in a range. |
24 * @param max The maximum value it will return. |
31 * @param max The maximum value it will return. |
25 * @return A random value between 0 .. max. |
32 * @return A random value between 0 .. max. |
26 */ |
33 */ |
27 #if defined(RANDOM_DEBUG) |
34 uint RandRange(uint max); |
28 uint DoRandomRange(uint max, int line, const char *file); |
|
29 #else |
|
30 uint RandomRange(uint max); |
|
31 #endif |
|
32 |
35 |
33 /** |
36 /** |
34 * Take a chance of 'out' out of 'max'. |
37 * Take a chance of 'out' out of 'max'. |
35 * @param out How many times is should return true. |
38 * @param out How many times is should return true. |
36 * @param max What the max value of 'out' can be. |
39 * @param max What the max value of 'out' can be. |
42 #ifdef DEFINE_SQUIRREL_CLASS |
45 #ifdef DEFINE_SQUIRREL_CLASS |
43 void SQAIBaseRegister(Squirrel *engine) { |
46 void SQAIBaseRegister(Squirrel *engine) { |
44 DefSQClass <AIBase> SQAIBase("AIBase"); |
47 DefSQClass <AIBase> SQAIBase("AIBase"); |
45 SQAIBase.PreRegister(engine); |
48 SQAIBase.PreRegister(engine); |
46 SQAIBase.AddConstructor(engine); |
49 SQAIBase.AddConstructor(engine); |
47 SQAIBase.DefSQFunction(engine, &AIBase::Random, "Random"); |
50 SQAIBase.DefSQFunction(engine, &AIBase::Rand, "Rand"); |
48 SQAIBase.DefSQFunction(engine, &AIBase::RandomRange, "RandomRange"); |
51 SQAIBase.DefSQFunction(engine, &AIBase::RandRange, "RandRange"); |
49 SQAIBase.DefSQFunction(engine, &AIBase::Chance, "Chance"); |
52 SQAIBase.DefSQFunction(engine, &AIBase::Chance, "Chance"); |
50 SQAIBase.PostRegister(engine); |
53 SQAIBase.PostRegister(engine); |
51 } |
54 } |
52 #endif /* SQUIRREL_CLASS */ |
55 #endif /* SQUIRREL_CLASS */ |
53 |
56 |
54 #endif /* AI_BASE_HPP */ |
57 #endif /* AI_BASE_HPP */ |