src/ai/api/ai_base.cpp
author truelight
Sat, 14 Jul 2007 23:49:31 +0000
branchnoai
changeset 9660 d0a430e8310b
parent 9440 0986434f3af8
child 9723 eee46cb39750
permissions -rw-r--r--
(svn r10569) [NoAI] -Add: added AIListRandomize as Valuator for all lists to attach a random value to all items
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
9660
d0a430e8310b (svn r10569) [NoAI] -Add: added AIListRandomize as Valuator for all lists to attach a random value to all items
truelight
parents: 9440
diff changeset
     7
/* static */ 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
9660
d0a430e8310b (svn r10569) [NoAI] -Add: added AIListRandomize as Valuator for all lists to attach a random value to all items
truelight
parents: 9440
diff changeset
    15
/* static */ 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
9660
d0a430e8310b (svn r10569) [NoAI] -Add: added AIListRandomize as Valuator for all lists to attach a random value to all items
truelight
parents: 9440
diff changeset
    23
/* static */ bool AIBase::Chance(uint out, uint max)
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    24
{
9660
d0a430e8310b (svn r10569) [NoAI] -Add: added AIListRandomize as Valuator for all lists to attach a random value to all items
truelight
parents: 9440
diff changeset
    25
	return (uint16)AIBase::Rand() <= (uint16)((65536 * out) / max);
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    26
}