author | rubidium |
Thu, 15 Mar 2007 22:46:22 +0000 | |
branch | noai |
changeset 9430 | 9e0a193b2bec |
parent 9427 | src/ai/api/base/random.cpp@ef0c109c5661 |
child 9440 | 0986434f3af8 |
permissions | -rw-r--r-- |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
2 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
3 |
/** @file ai_base.cpp handles the functions of the AIBase class */ |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
4 |
|
9430
9e0a193b2bec
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
rubidium
parents:
9427
diff
changeset
|
5 |
#include "ai_base.hpp" |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
6 |
|
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
7 |
#if defined(RANDOM_DEBUG) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
8 |
uint32 AIBase::DoRandom(int line, const char *file) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
9 |
#else |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
10 |
uint32 AIBase::Random() |
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
11 |
#endif |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
12 |
{ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
13 |
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over) |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
14 |
* but we pick InteractiveRandomRange if we are a network_server or network-client. */ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
15 |
if (_networking) return InteractiveRandom(); |
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
16 |
#if defined(RANDOM_DEBUG) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
17 |
return ::DoRandom(line, file); |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
18 |
#else |
9361
7bb2bd22b16e
(svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
9360
diff
changeset
|
19 |
return ::Random(); |
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
20 |
#endif |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
21 |
} |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
22 |
|
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
23 |
#if defined(RANDOM_DEBUG) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
24 |
uint AIBase::DoRandomRange(uint max, int line, const char *file) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
25 |
#else |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
26 |
uint AIBase::RandomRange(uint max) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
27 |
#endif |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
28 |
{ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
29 |
/* We pick RandomRange if we are in SP (so when saved, we do the same over and over) |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
30 |
* but we pick InteractiveRandomRange if we are a network_server or network-client. */ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
31 |
if (_networking) return InteractiveRandomRange(max); |
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
32 |
#if defined(RANDOM_DEBUG) |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
33 |
return ::DoRandomRange(max, line, file); |
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
34 |
#else |
9361
7bb2bd22b16e
(svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
9360
diff
changeset
|
35 |
return ::RandomRange(max); |
9362
3aebc515446a
(svn r9145) [NoAI] -Fix: allow compiling with RANDOM_DEBUG enabled (tnx Rubidium)
truelight
parents:
9361
diff
changeset
|
36 |
#endif |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
37 |
} |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
38 |
|
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
39 |
bool AIBase::Chance(uint out, uint max) |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
40 |
{ |
9371
cfa43f975d01
(svn r9158) [NoAI] -Fix: a 1 in 2 chance wasn't a 1 in two, but a 1 in 2 * 65536...
rubidium
parents:
9362
diff
changeset
|
41 |
return (uint16)this->Random() <= (uint16)((65536 * out) / max); |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
42 |
} |