author | rubidium |
Sat, 14 Apr 2007 20:38:10 +0000 | |
branch | noai |
changeset 9594 | 5009a30f320a |
parent 9440 | 0986434f3af8 |
child 9660 | d0a430e8310b |
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 |
|
9440
0986434f3af8
(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.
rubidium
parents:
9430
diff
changeset
|
7 |
uint32 AIBase::Rand() |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
8 |
{ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
9 |
/* 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
|
10 |
* 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
|
11 |
if (_networking) return InteractiveRandom(); |
9361
7bb2bd22b16e
(svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
9360
diff
changeset
|
12 |
return ::Random(); |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
13 |
} |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
14 |
|
9440
0986434f3af8
(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.
rubidium
parents:
9430
diff
changeset
|
15 |
uint AIBase::RandRange(uint max) |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
16 |
{ |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
17 |
/* 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
|
18 |
* 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
|
19 |
if (_networking) return InteractiveRandomRange(max); |
9361
7bb2bd22b16e
(svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents:
9360
diff
changeset
|
20 |
return ::RandomRange(max); |
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 |
|
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
23 |
bool AIBase::Chance(uint out, uint max) |
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
24 |
{ |
9440
0986434f3af8
(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.
rubidium
parents:
9430
diff
changeset
|
25 |
return (uint16)this->Rand() <= (uint16)((65536 * out) / max); |
9360
c20d0a9e0a5c
(svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff
changeset
|
26 |
} |