src/ai/core/base/random.cpp
author truelight
Tue, 13 Mar 2007 18:36:29 +0000
branchnoai
changeset 9361 7bb2bd22b16e
parent 9360 c20d0a9e0a5c
child 9362 3aebc515446a
permissions -rw-r--r--
(svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
-Change: split AIBase into AIBase and AIController, where the last should be extended by the real AI
-Remove: removed the SP queue-code, as it is no longer needed with the new message system
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
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     3
/** @file random.cpp handles the random functions of the AIBase class */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     4
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     5
#include "../ai_base.hpp"
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     6
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     7
uint32 AIBase::Random()
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
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    15
uint32 AIBase::RandomRange(uint max)
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
{
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    25
	return this->Random() <= (uint16)((65536 * out) / max);
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    26
}