OpenTTD AI API  20240328-master-gca53e134be
Static Public Member Functions
AIBase Class Reference

Class that handles some basic functions. More...

Inheritance diagram for AIBase:

Static Public Member Functions

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

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 ( SQInteger  out,
SQInteger  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(uint32_t).
maxOut of this many times. The value will be clamped to 0 .. MAX(uint32_t).
Precondition
out is at most equal to max.
Returns
True if the chance worked out.

◆ ChanceItem()

static bool AIBase::ChanceItem ( SQInteger  unused_param,
SQInteger  out,
SQInteger  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(uint32_t).
maxOut of this many times. The value will be clamped to 0 .. MAX(uint32_t).
Precondition
out is at most equal to max.
Returns
True if the chance worked out.

◆ Rand()

static SQInteger AIBase::Rand ( )
static

Get a random value.

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

◆ RandItem()

static SQInteger AIBase::RandItem ( SQInteger  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(uint32_t).

◆ RandRange()

static SQInteger AIBase::RandRange ( SQInteger  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(uint32_t).
Returns
A random value between 0 .. max - 1.

◆ RandRangeItem()

static SQInteger AIBase::RandRangeItem ( SQInteger  unused_param,
SQInteger  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(uint32_t).
Returns
A random value between 0 .. max - 1.