src/ai/api/ai_base.cpp
author truebrain
Sat, 23 Feb 2008 16:21:10 +0000
branchnoai
changeset 9746 e4ab7ea8d897
parent 9737 ee408edf3851
child 9814 be51ea0adc29
permissions -rw-r--r--
(svn r12226) [NoAI] -Fix: remove the dep for AIStationList_Vehicle on AIStationList, as Squirrel doesn't like it
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"
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9660
diff changeset
     6
#include "../../network/network.h"
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     7
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
     8
/* static */ uint32 AIBase::Rand()
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     9
{
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    10
	/* 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
    11
	 *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9723
diff changeset
    12
	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
    13
	return ::Random();
9360
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
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
    16
/* static */ uint AIBase::RandRange(uint max)
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    17
{
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    18
	/* 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
    19
	 *   but we pick InteractiveRandomRange if we are a network_server or network-client. */
9736
183b38e0a480 (svn r12215) [NoAI] -Codechange: added '::' if a function comes from non-AI-API functions (was inconsistant till now)
truebrain
parents: 9723
diff changeset
    20
	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
    21
	return ::RandomRange(max);
9360
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
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
    24
/* 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
    25
{
9737
ee408edf3851 (svn r12216) [NoAI] -Codechange: made most functions 'static', which removes the need to create an instance to get, for example, engine information, and therefor heavily simplifying AI creation (Morloth)
truebrain
parents: 9736
diff changeset
    26
	return (uint16)Rand() <= (uint16)((65536 * out) / max);
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    27
}