OpenTTD GameScript API 20241220-master-g59680867c3
Public Types | Static Public Member Functions
GSSubsidy Class Reference

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

#include <script_subsidy.hpp>

Inheritance diagram for GSSubsidy:

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.
 
static bool IsAwarded (SubsidyID subsidy_id)
 Checks whether this subsidy is already awarded to some company.
 
static bool Create (CargoID cargo_type, SubsidyParticipantType from_type, int from_id, SubsidyParticipantType to_type, int to_id)
 Create a new subsidy.
 
static GSCompany::CompanyID GetAwardedTo (SubsidyID subsidy_id)
 Get the company index of the company this subsidy is awarded to.
 
static GSDate::Date GetExpireDate (SubsidyID subsidy_id)
 Get the economy-date this subsidy expires.
 
static CargoID GetCargoType (SubsidyID subsidy_id)
 Get the cargo type that has to be transported in order to be awarded this subsidy.
 
static SubsidyParticipantType GetSourceType (SubsidyID subsidy_id)
 Returns the type of source of subsidy.
 
static int GetSourceIndex (SubsidyID subsidy_id)
 Return the source IndustryID/TownID the subsidy is for.
 
static SubsidyParticipantType GetDestinationType (SubsidyID subsidy_id)
 Returns the type of destination of subsidy.
 
static int GetDestinationIndex (SubsidyID subsidy_id)
 Return the destination IndustryID/TownID the subsidy is for.
 

Detailed Description

Class that handles all subsidy related functions.

Member Enumeration Documentation

◆ 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

◆ Create()

static bool GSSubsidy::Create ( CargoID  cargo_type,
SubsidyParticipantType  from_type,
int  from_id,
SubsidyParticipantType  to_type,
int  to_id 
)
static

Create a new subsidy.

Parameters
cargo_typeThe type of cargo to cary for the subsidy.
from_typeThe type of the subsidy on the 'from' side.
from_idThe ID of the 'from' side.
to_typeThe type of the subsidy on the 'to' side.
to_idThe ID of the 'to' side.
Returns
True if the action succeeded.
Precondition
GSCompanyMode::IsDeity().
GSCargo::IsValidCargo(cargo_type)
from_type == SPT_INDUSTRY || from_type == SPT_TOWN.
to_type == SPT_INDUSTRY || to_type == SPT_TOWN.
(from_type == SPT_INDUSTRY && GSIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && GSTown::IsValidTown(from_id))
(to_type == SPT_INDUSTRY && GSIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && GSTown::IsValidTown(to_id))

◆ GetAwardedTo()

static GSCompany::CompanyID GSSubsidy::GetAwardedTo ( SubsidyID  subsidy_id)
static

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

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsAwarded(subsidy_id).
Returns
The companyindex of the company this subsidy is awarded to.

◆ GetCargoType()

static CargoID GSSubsidy::GetCargoType ( SubsidyID  subsidy_id)
static

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

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsValidSubsidy(subsidy_id).
Returns
The cargo type to transport.

◆ GetDestinationIndex()

static int GSSubsidy::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_idthe SubsidyID to check.
    Precondition
    IsValidSubsidy(subsidy_id).
    Returns
    One of TownID/IndustryID.

◆ GetDestinationType()

static SubsidyParticipantType GSSubsidy::GetDestinationType ( SubsidyID  subsidy_id)
static

Returns the type of destination of subsidy.

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsValidSubsidy(subsidy_id).
Returns
Type of destination of subsidy.

◆ GetExpireDate()

static GSDate::Date GSSubsidy::GetExpireDate ( SubsidyID  subsidy_id)
static

Get the economy-date this subsidy expires.

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

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsValidSubsidy(subsidy_id).
Returns
The last valid economy-date of this subsidy.
Note
The return value of this function will change if the subsidy is awarded.
See also
GSEconomyTime

◆ GetSourceIndex()

static int GSSubsidy::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_idThe SubsidyID to check.
    Precondition
    IsValidSubsidy(subsidy_id).
    Returns
    One of TownID/IndustryID.

◆ GetSourceType()

static SubsidyParticipantType GSSubsidy::GetSourceType ( SubsidyID  subsidy_id)
static

Returns the type of source of subsidy.

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsValidSubsidy(subsidy_id).
Returns
Type of source of subsidy.

◆ IsAwarded()

static bool GSSubsidy::IsAwarded ( SubsidyID  subsidy_id)
static

Checks whether this subsidy is already awarded to some company.

Parameters
subsidy_idThe SubsidyID to check.
Precondition
IsValidSubsidy(subsidy).
Returns
True if and only if this subsidy is already awarded.

◆ IsValidSubsidy()

static bool GSSubsidy::IsValidSubsidy ( SubsidyID  subsidy_id)
static

Check whether this is a valid SubsidyID.

Parameters
subsidy_idThe SubsidyID to check.
Returns
True if and only if this subsidy is still valid.