OpenTTD AI API 20241220-master-g59680867c3
Static Public Member Functions
AIBase Class Reference

Class that handles some basic functions. More...

#include <script_base.hpp>

Inheritance diagram for AIBase:

Static Public Member Functions

static int Rand ()
 Get a random value.
 
static int RandItem (int unused_param)
 Get a random value.
 
static int RandRange (int max)
 Get a random value in a range.
 
static int RandRangeItem (int unused_param, int max)
 Get a random value in a range.
 
static bool Chance (int out, int max)
 Returns approximately 'out' times true when called 'max' times.
 
static bool ChanceItem (int unused_param, int out, int max)
 Returns approximately 'out' times true when called 'max' times.
 

Detailed Description

Class that handles some basic functions.

Note
The random functions are not called Random and RandomRange, because RANDOM_DEBUG does some tricky stuff, which messes with those names.

Member Function Documentation

◆ Chance()

static bool AIBase::Chance ( int  out,
int  max 
)
static

Returns approximately 'out' times true when called 'max' times.

After all, it is a random function.

Parameters
outHow many times it should return true. The value will be clamped to 0 .. MAX(int).
maxOut of this many times. The value will be clamped to 0 .. MAX(int).
Precondition
out is at most equal to max.
Returns
True if the chance worked out.

◆ ChanceItem()

static bool AIBase::ChanceItem ( int  unused_param,
int  out,
int  max 
)
static

Returns approximately 'out' times true when called 'max' times.

After all, it is a random function.

Parameters
unused_paramThis parameter is not used, but is needed to work with lists.
outHow many times it should return true. The value will be clamped to 0 .. MAX(int).
maxOut of this many times. The value will be clamped to 0 .. MAX(int).
Precondition
out is at most equal to max.
Returns
True if the chance worked out.

◆ Rand()

static int AIBase::Rand ( )
static

Get a random value.

Returns
A random value between 0 and MAX(int).

◆ RandItem()

static int AIBase::RandItem ( int  unused_param)
static

Get a random value.

Parameters
unused_paramThis parameter is not used, but is needed to work with lists.
Returns
A random value between 0 and MAX(int).

◆ RandRange()

static int AIBase::RandRange ( int  max)
static

Get a random value in a range.

Parameters
maxThe first number this function will never return (the maximum it returns is max - 1). The value will be clamped to 0 .. MAX(int).
Returns
A random value between 0 .. max - 1.

◆ RandRangeItem()

static int AIBase::RandRangeItem ( int  unused_param,
int  max 
)
static

Get a random value in a range.

Parameters
unused_paramThis parameter is not used, but is needed to work with lists.
maxThe first number this function will never return (the maximum it returns is max - 1). The value will be clamped to 0 .. MAX(int).
Returns
A random value between 0 .. max - 1.