OpenTTD AI API: AISubsidy Class Reference

OpenTTD AI API 13.0-beta1

Public Types | Static Public Member Functions
AISubsidy Class Reference

Class that handles all subsidy related functions. More...

Inheritance diagram for AISubsidy:

## Public Types
enum | SubsidyParticipantType { out, SPT_INDUSTRY, SPT_TOWN, SPT_INVALID }
| Enumeration for source and destination of a subsidy. More...

## Static Public Member Functions
static bool | IsValidSubsidy (SubsidyID subsidy_id)
| Check whether this is a valid SubsidyID. More...
static bool | IsAwarded (SubsidyID subsidy_id)
| Checks whether this subsidy is already awarded to some company. More...
static AICompany::CompanyID | GetAwardedTo (SubsidyID subsidy_id)
| Get the company index of the company this subsidy is awarded to. More...
static AIDate::Date | GetExpireDate (SubsidyID subsidy_id)
| Get the date this subsidy expires. More...
static CargoID | GetCargoType (SubsidyID subsidy_id)
| Get the cargo type that has to be transported in order to be awarded this subsidy. More...
static SubsidyParticipantType | GetSourceType (SubsidyID subsidy_id)
| Returns the type of source of subsidy. More...
static int32 | GetSourceIndex (SubsidyID subsidy_id)
| Return the source IndustryID/TownID the subsidy is for. More...
static SubsidyParticipantType | GetDestinationType (SubsidyID subsidy_id)
| Returns the type of destination of subsidy. More...
static int32 | GetDestinationIndex (SubsidyID subsidy_id)
| Return the destination IndustryID/TownID the subsidy is for. More...

## Detailed Description

Class that handles all subsidy related functions.

## Member Enumeration Documentation

## ◆ SubsidyParticipantType

enum AISubsidy::SubsidyParticipantType

Enumeration for source and destination of a subsidy.

Note
  The list of values may grow in future.

Enumerator
SPT_INDUSTRY | Subsidy participant is an industry.
SPT_TOWN | Subsidy participant is a town.
SPT_INVALID | Invalid/unknown participant type.

## Member Function Documentation

## ◆ GetAwardedTo()

static AICompany::CompanyID AISubsidy::GetAwardedTo | ( | SubsidyID | subsidy_id | ) |
| static

Get the company index of the company this subsidy is awarded to.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsAwarded(subsidy_id).

Returns
  The companyindex of the company this subsidy is awarded to.

## ◆ GetCargoType()

static CargoID AISubsidy::GetCargoType | ( | SubsidyID | subsidy_id | ) |
| static

Get the cargo type that has to be transported in order to be awarded this subsidy.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsValidSubsidy(subsidy_id).

Returns
  The cargo type to transport.

## ◆ GetDestinationIndex()

static int32 AISubsidy::GetDestinationIndex | ( | SubsidyID | subsidy_id | ) |
| static

Return the destination IndustryID/TownID the subsidy is for.

- GetDestinationType(subsidy_id) == SPT_INDUSTRY -> return the IndustryID.
- GetDestinationType(subsidy_id) == SPT_TOWN -> return the TownID.
  Parameters

    subsidy_id | the SubsidyID to check.

  Precondition
    IsValidSubsidy(subsidy_id).
  Returns
    One of TownID/IndustryID.

## ◆ GetDestinationType()

static SubsidyParticipantType AISubsidy::GetDestinationType | ( | SubsidyID | subsidy_id | ) |
| static

Returns the type of destination of subsidy.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsValidSubsidy(subsidy_id).

Returns
  Type of destination of subsidy.

## ◆ GetExpireDate()

static AIDate::Date AISubsidy::GetExpireDate | ( | SubsidyID | subsidy_id | ) |
| static

Get the date this subsidy expires.

In case the subsidy is already awarded, return the date the subsidy expires, else, return the date the offer expires.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsValidSubsidy(subsidy_id).

Returns
  The last valid date of this subsidy.

Note
  The return value of this function will change if the subsidy is awarded.

## ◆ GetSourceIndex()

static int32 AISubsidy::GetSourceIndex | ( | SubsidyID | subsidy_id | ) |
| static

Return the source IndustryID/TownID the subsidy is for.

- GetSourceType(subsidy_id) == SPT_INDUSTRY -> return the IndustryID.
- GetSourceType(subsidy_id) == SPT_TOWN -> return the TownID.
  Parameters

    subsidy_id | The SubsidyID to check.

  Precondition
    IsValidSubsidy(subsidy_id).
  Returns
    One of TownID/IndustryID.

## ◆ GetSourceType()

static SubsidyParticipantType AISubsidy::GetSourceType | ( | SubsidyID | subsidy_id | ) |
| static

Returns the type of source of subsidy.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsValidSubsidy(subsidy_id).

Returns
  Type of source of subsidy.

## ◆ IsAwarded()

static bool AISubsidy::IsAwarded | ( | SubsidyID | subsidy_id | ) |
| static

Checks whether this subsidy is already awarded to some company.

Parameters

  subsidy_id | The SubsidyID to check.

Precondition
  IsValidSubsidy(subsidy).

Returns
  True if and only if this subsidy is already awarded.

## ◆ IsValidSubsidy()

static bool AISubsidy::IsValidSubsidy | ( | SubsidyID | subsidy_id | ) |
| static

Check whether this is a valid SubsidyID.

Parameters

  subsidy_id | The SubsidyID to check.

Returns
  True if and only if this subsidy is still valid.