OpenTTD GameScript API  20241120-master-g6d3adc6169
Public Types | Static Public Member Functions
GSCompany Class Reference

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

Inheritance diagram for GSCompany:

Public Types

enum  Quarter {
  CURRENT_QUARTER ,
  EARLIEST_QUARTER
}
 The range of possible quarters to get company information of. More...
 
enum  CompanyID {
  COMPANY_FIRST ,
  COMPANY_LAST ,
  COMPANY_INVALID ,
  COMPANY_SELF ,
  COMPANY_SPECTATOR
}
 Different constants related to CompanyID. More...
 
enum  Gender {
  GENDER_MALE ,
  GENDER_FEMALE ,
  GENDER_INVALID
}
 Possible genders for company presidents. More...
 
enum  LiveryScheme {
  LS_DEFAULT ,
  LS_STEAM ,
  LS_DIESEL ,
  LS_ELECTRIC ,
  LS_MONORAIL ,
  LS_MAGLEV ,
  LS_DMU ,
  LS_EMU ,
  LS_PASSENGER_WAGON_STEAM ,
  LS_PASSENGER_WAGON_DIESEL ,
  LS_PASSENGER_WAGON_ELECTRIC ,
  LS_PASSENGER_WAGON_MONORAIL ,
  LS_PASSENGER_WAGON_MAGLEV ,
  LS_FREIGHT_WAGON ,
  LS_BUS ,
  LS_TRUCK ,
  LS_PASSENGER_SHIP ,
  LS_FREIGHT_SHIP ,
  LS_HELICOPTER ,
  LS_SMALL_PLANE ,
  LS_LARGE_PLANE ,
  LS_PASSENGER_TRAM ,
  LS_FREIGHT_TRAM ,
  LS_INVALID
}
 List of different livery schemes. More...
 
enum  Colours {
  COLOUR_DARK_BLUE ,
  COLOUR_PALE_GREEN ,
  COLOUR_PINK ,
  COLOUR_YELLOW ,
  COLOUR_RED ,
  COLOUR_LIGHT_BLUE ,
  COLOUR_GREEN ,
  COLOUR_DARK_GREEN ,
  COLOUR_BLUE ,
  COLOUR_CREAM ,
  COLOUR_MAUVE ,
  COLOUR_PURPLE ,
  COLOUR_ORANGE ,
  COLOUR_BROWN ,
  COLOUR_GREY ,
  COLOUR_WHITE ,
  COLOUR_INVALID = ::INVALID_COLOUR
}
 List of colours.
 
enum  ExpensesType : int {
  EXPENSES_CONSTRUCTION ,
  EXPENSES_NEW_VEHICLES ,
  EXPENSES_TRAIN_RUN ,
  EXPENSES_ROADVEH_RUN ,
  EXPENSES_AIRCRAFT_RUN ,
  EXPENSES_SHIP_RUN ,
  EXPENSES_PROPERTY ,
  EXPENSES_TRAIN_INC ,
  EXPENSES_ROADVEH_INC ,
  EXPENSES_AIRCRAFT_INC ,
  EXPENSES_SHIP_INC ,
  EXPENSES_LOAN_INT ,
  EXPENSES_OTHER ,
  EXPENSES_INVALID
}
 Types of expenses. More...
 

Static Public Member Functions

static CompanyID ResolveCompanyID (CompanyID company)
 Resolved the given company index to the correct index for the company. More...
 
static bool IsMine (CompanyID company)
 Check if a CompanyID is your CompanyID, to ease up checks. More...
 
static bool SetName (Text *name)
 Set the name of your company. More...
 
static string GetName (CompanyID company)
 Get the name of the given company. More...
 
static bool SetPresidentName (Text *name)
 Set the name of your president. More...
 
static string GetPresidentName (CompanyID company)
 Get the name of the president of the given company. More...
 
static bool SetPresidentGender (Gender gender)
 Set the gender of the president of your company. More...
 
static Gender GetPresidentGender (CompanyID company)
 Get the gender of the president of the given company. More...
 
static bool SetLoanAmount (Money loan)
 Sets the amount to loan. More...
 
static bool SetMinimumLoanAmount (Money loan)
 Sets the minimum amount to loan, i.e. More...
 
static Money GetLoanAmount ()
 Gets the amount your company have loaned. More...
 
static Money GetMaxLoanAmount ()
 Gets the maximum amount your company can loan. More...
 
static bool SetMaxLoanAmountForCompany (CompanyID company, Money amount)
 Sets the max amount of money company can loan. More...
 
static bool ResetMaxLoanAmountForCompany (CompanyID company)
 Makes the max amount of money company can loan follow the global max loan setting. More...
 
static Money GetLoanInterval ()
 Gets the interval/loan step. More...
 
static Money GetBankBalance (CompanyID company)
 Gets the bank balance. More...
 
static bool ChangeBankBalance (CompanyID company, Money delta, ExpensesType expenses_type, TileIndex tile)
 Changes the bank balance by a delta value. More...
 
static Money GetQuarterlyIncome (CompanyID company, int quarter)
 Get the income of the company in the given economy-quarter. More...
 
static Money GetQuarterlyExpenses (CompanyID company, int quarter)
 Get the expenses of the company in the given economy-quarter. More...
 
static int GetQuarterlyCargoDelivered (CompanyID company, int quarter)
 Get the amount of cargo delivered by the given company in the given economy-quarter. More...
 
static int GetQuarterlyPerformanceRating (CompanyID company, int quarter)
 Get the performance rating of the given company in the given economy-quarter. More...
 
static Money GetQuarterlyCompanyValue (CompanyID company, int quarter)
 Get the value of the company in the given economy-quarter. More...
 
static bool BuildCompanyHQ (TileIndex tile)
 Build your company's HQ on the given tile. More...
 
static TileIndex GetCompanyHQ (CompanyID company)
 Return the location of a company's HQ. More...
 
static bool SetAutoRenewStatus (bool autorenew)
 Set whether autorenew is enabled for your company. More...
 
static bool GetAutoRenewStatus (CompanyID company)
 Return whether autorenew is enabled for a company. More...
 
static bool SetAutoRenewMonths (int months)
 Set the number of months before/after max age to autorenew an engine for your company. More...
 
static int GetAutoRenewMonths (CompanyID company)
 Return the number of months before/after max age to autorenew an engine for a company. More...
 
static bool SetAutoRenewMoney (Money money)
 Set the minimum money needed to autorenew an engine for your company. More...
 
static Money GetAutoRenewMoney (CompanyID company)
 Return the minimum money needed to autorenew an engine for a company. More...
 
static bool SetPrimaryLiveryColour (LiveryScheme scheme, Colours colour)
 Set primary colour for your company. More...
 
static bool SetSecondaryLiveryColour (LiveryScheme scheme, Colours colour)
 Set secondary colour for your company. More...
 
static GSCompany::Colours GetPrimaryLiveryColour (LiveryScheme scheme)
 Get primary colour of a livery for your company. More...
 
static GSCompany::Colours GetSecondaryLiveryColour (LiveryScheme scheme)
 Get secondary colour of a livery for your company. More...
 

Detailed Description

Class that handles all company related functions.

Member Enumeration Documentation

◆ CompanyID

Different constants related to CompanyID.

Enumerator
COMPANY_FIRST 

The first available company.

COMPANY_LAST 

The last available company.

COMPANY_INVALID 

An invalid company.

COMPANY_SELF 

Constant that gets resolved to the correct company index for your company.

COMPANY_SPECTATOR 

Constant indicating that player is spectating (gets resolved to COMPANY_INVALID)

◆ ExpensesType

Types of expenses.

Enumerator
EXPENSES_CONSTRUCTION 

Construction costs.

EXPENSES_NEW_VEHICLES 

New vehicles.

EXPENSES_TRAIN_RUN 

Running costs trains.

EXPENSES_ROADVEH_RUN 

Running costs road vehicles.

EXPENSES_AIRCRAFT_RUN 

Running costs aircraft.

EXPENSES_SHIP_RUN 

Running costs ships.

EXPENSES_PROPERTY 

Property costs.

EXPENSES_TRAIN_INC 

Revenue from trains.

EXPENSES_ROADVEH_INC 

Revenue from road vehicles.

EXPENSES_AIRCRAFT_INC 

Revenue from aircraft.

EXPENSES_SHIP_INC 

Revenue from ships.

EXPENSES_LOAN_INT 

Interest payments over the loan.

EXPENSES_OTHER 

Other expenses.

EXPENSES_INVALID 

Invalid expense type.

◆ Gender

Possible genders for company presidents.

Enumerator
GENDER_MALE 

A male person.

GENDER_FEMALE 

A female person.

GENDER_INVALID 

An invalid gender.

◆ LiveryScheme

List of different livery schemes.

Enumerator
LS_DEFAULT 

Default scheme.

LS_STEAM 

Steam engines.

LS_DIESEL 

Diesel engines.

LS_ELECTRIC 

Electric engines.

LS_MONORAIL 

Monorail engines.

LS_MAGLEV 

Maglev engines.

LS_DMU 

DMUs and their passenger wagons.

LS_EMU 

EMUs and their passenger wagons.

LS_PASSENGER_WAGON_STEAM 

Passenger wagons attached to steam engines.

LS_PASSENGER_WAGON_DIESEL 

Passenger wagons attached to diesel engines.

LS_PASSENGER_WAGON_ELECTRIC 

Passenger wagons attached to electric engines.

LS_PASSENGER_WAGON_MONORAIL 

Passenger wagons attached to monorail engines.

LS_PASSENGER_WAGON_MAGLEV 

Passenger wagons attached to maglev engines.

LS_FREIGHT_WAGON 

Freight wagons.

LS_BUS 

Buses.

LS_TRUCK 

Trucks.

LS_PASSENGER_SHIP 

Passenger ships.

LS_FREIGHT_SHIP 

Freight ships.

LS_HELICOPTER 

Helicopters.

LS_SMALL_PLANE 

Small aeroplanes.

LS_LARGE_PLANE 

Large aeroplanes.

LS_PASSENGER_TRAM 

Passenger trams.

LS_FREIGHT_TRAM 

Freight trams.

◆ Quarter

The range of possible quarters to get company information of.

Enumerator
CURRENT_QUARTER 

The current quarter.

EARLIEST_QUARTER 

The earliest quarter company information is available for.

Member Function Documentation

◆ BuildCompanyHQ()

static bool GSCompany::BuildCompanyHQ ( TileIndex  tile)
static

Build your company's HQ on the given tile.

Parameters
tileThe tile to build your HQ on, this tile is the most northern tile of your HQ.
Precondition
GSMap::IsValidTile(tile).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_FLAT_LAND_REQUIRED
Returns
True if the HQ could be build.
Note
An HQ can not be removed, only by water or rebuilding; If an HQ is build again, the old one is removed.

◆ ChangeBankBalance()

static bool GSCompany::ChangeBankBalance ( CompanyID  company,
Money  delta,
ExpensesType  expenses_type,
TileIndex  tile 
)
static

Changes the bank balance by a delta value.

This method does not affect the loan but instead allows a GS to give or take money from a company.

Parameters
companyThe company to change the bank balance of.
deltaAmount of money to give or take from the bank balance. A positive value adds money to the bank balance.
expenses_typeThe account in the finances window that will register the cost.
tileThe tile to show text effect on or GSMap::TILE_INVALID
Returns
True, if the bank balance was changed.
Precondition
GSCompanyMode::IsDeity().
ResolveCompanyID(company) != COMPANY_INVALID.
Note
You need to create your own news message to inform about costs/gifts that you create using this command.

◆ GetAutoRenewMoney()

static Money GSCompany::GetAutoRenewMoney ( CompanyID  company)
static

Return the minimum money needed to autorenew an engine for a company.

Parameters
companyThe company to get the autorenew money of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The minimum required money for autorenew to work.

◆ GetAutoRenewMonths()

static int GSCompany::GetAutoRenewMonths ( CompanyID  company)
static

Return the number of months before/after max age to autorenew an engine for a company.

Parameters
companyThe company to get the autorenew months of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The number of calendar-months before/after max age of engine.
See also
GSCalendarTime

◆ GetAutoRenewStatus()

static bool GSCompany::GetAutoRenewStatus ( CompanyID  company)
static

Return whether autorenew is enabled for a company.

Parameters
companyThe company to get the autorenew status of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
True if autorenew is enabled.

◆ GetBankBalance()

static Money GSCompany::GetBankBalance ( CompanyID  company)
static

Gets the bank balance.

In other words, the amount of money the given company can spent. If infinite money is enabled, it returns INT32_MAX.

Parameters
companyThe company to get the bank balance of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The actual bank balance or INT32_MAX.

◆ GetCompanyHQ()

static TileIndex GSCompany::GetCompanyHQ ( CompanyID  company)
static

Return the location of a company's HQ.

Parameters
companyThe company the get the HQ of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The tile of the company's HQ, this tile is the most northern tile of that HQ, or GSMap::TILE_INVALID if there is no HQ yet.

◆ GetLoanAmount()

static Money GSCompany::GetLoanAmount ( )
static

Gets the amount your company have loaned.

Returns
The amount loaned money.
Postcondition
GetLoanInterval() is always a multiplier of the return value.

◆ GetLoanInterval()

static Money GSCompany::GetLoanInterval ( )
static

Gets the interval/loan step.

Returns
The loan step.
Postcondition
Return value is always positive.

◆ GetMaxLoanAmount()

static Money GSCompany::GetMaxLoanAmount ( )
static

Gets the maximum amount your company can loan.

In deity mode returns the global max loan.

Returns
The maximum amount your company can loan.
Postcondition
GetLoanInterval() is always a multiplier of the return value.

◆ GetName()

static string GSCompany::GetName ( CompanyID  company)
static

Get the name of the given company.

Parameters
companyThe company to get the name for.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The name of the given company.

◆ GetPresidentGender()

static Gender GSCompany::GetPresidentGender ( CompanyID  company)
static

Get the gender of the president of the given company.

Parameters
companyThe company to get the presidents gender off.
Returns
The gender of the president.

◆ GetPresidentName()

static string GSCompany::GetPresidentName ( CompanyID  company)
static

Get the name of the president of the given company.

Parameters
companyThe company to get the president's name for.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
Returns
The name of the president of the given company.

◆ GetPrimaryLiveryColour()

static GSCompany::Colours GSCompany::GetPrimaryLiveryColour ( LiveryScheme  scheme)
static

Get primary colour of a livery for your company.

Parameters
schemeLivery scheme to get.
Returns
Primary colour of livery.

◆ GetQuarterlyCargoDelivered()

static int GSCompany::GetQuarterlyCargoDelivered ( CompanyID  company,
int  quarter 
)
static

Get the amount of cargo delivered by the given company in the given economy-quarter.

Parameters
companyThe company to get the amount of delivered cargo of.
quarterThe economy-quarter to get the amount of delivered cargo of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
quarter <= EARLIEST_QUARTER.
Returns
The amount of cargo delivered by the given company in the given economy-quarter.
See also
GSEconomyTime

◆ GetQuarterlyCompanyValue()

static Money GSCompany::GetQuarterlyCompanyValue ( CompanyID  company,
int  quarter 
)
static

Get the value of the company in the given economy-quarter.

Parameters
companyThe company to get the value of.
quarterThe economy-quarter to get the value of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
quarter <= EARLIEST_QUARTER.
Returns
The value of the company in the given economy-quarter.
See also
GSEconomyTime

◆ GetQuarterlyExpenses()

static Money GSCompany::GetQuarterlyExpenses ( CompanyID  company,
int  quarter 
)
static

Get the expenses of the company in the given economy-quarter.

Note that this function only considers recurring expenses from vehicle running cost, maintenance and interests; it does not include one-time expenses from construction and buying stuff.

Parameters
companyThe company to get the quarterly expenses of.
quarterThe economy-quarter to get the expenses of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
quarter <= EARLIEST_QUARTER.
Returns
The expenses of the company in the given economy-quarter.
See also
GSEconomyTime

◆ GetQuarterlyIncome()

static Money GSCompany::GetQuarterlyIncome ( CompanyID  company,
int  quarter 
)
static

Get the income of the company in the given economy-quarter.

Note that this function only considers recurring income from vehicles; it does not include one-time income from selling stuff.

Parameters
companyThe company to get the quarterly income of.
quarterThe economy-quarter to get the income of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
quarter <= EARLIEST_QUARTER.
Returns
The gross income of the company in the given economy-quarter.
See also
GSEconomyTime

◆ GetQuarterlyPerformanceRating()

static int GSCompany::GetQuarterlyPerformanceRating ( CompanyID  company,
int  quarter 
)
static

Get the performance rating of the given company in the given economy-quarter.

Parameters
companyThe company to get the performance rating of.
quarterThe economy-quarter to get the performance rating of.
Precondition
ResolveCompanyID(company) != COMPANY_INVALID.
quarter <= EARLIEST_QUARTER.
quarter != CURRENT_QUARTER.
Note
The performance rating is calculated after every economy-quarter, so the value for CURRENT_QUARTER is undefined.
Returns
The performance rating of the given company in the given economy-quarter.
See also
GSEconomyTime

◆ GetSecondaryLiveryColour()

static GSCompany::Colours GSCompany::GetSecondaryLiveryColour ( LiveryScheme  scheme)
static

Get secondary colour of a livery for your company.

Parameters
schemeLivery scheme to get.
Returns
Secondary colour of livery.

◆ IsMine()

static bool GSCompany::IsMine ( CompanyID  company)
static

Check if a CompanyID is your CompanyID, to ease up checks.

Parameters
companyThe company index to check.
Precondition
GSCompanyMode::IsValid().
Returns
True if and only if this company is your CompanyID.

◆ ResetMaxLoanAmountForCompany()

static bool GSCompany::ResetMaxLoanAmountForCompany ( CompanyID  company)
static

Makes the max amount of money company can loan follow the global max loan setting.

Parameters
companyThe company ID.
Returns
True, if the max loan was reset.
Precondition
GSCompanyMode::IsDeity().
amount >= 0 && amount <= MAX_LOAN_LIMIT.
ResolveCompanyID(company) != COMPANY_INVALID.
Note
You need to create your own news message to inform about max loan change.

◆ ResolveCompanyID()

static CompanyID GSCompany::ResolveCompanyID ( CompanyID  company)
static

Resolved the given company index to the correct index for the company.

If the company index was COMPANY_SELF it will be resolved to the index of your company. If the company with the given index does not exist it will return COMPANY_INVALID.

Parameters
companyThe company index to resolve.
Returns
The resolved company index.

◆ SetAutoRenewMoney()

static bool GSCompany::SetAutoRenewMoney ( Money  money)
static

Set the minimum money needed to autorenew an engine for your company.

Parameters
moneyThe new minimum required money for autorenew to work.
Precondition
GSCompanyMode::IsValid().
Returns
True if autorenew money has been modified.
Precondition
money >= 0
money < 2**32

◆ SetAutoRenewMonths()

static bool GSCompany::SetAutoRenewMonths ( int  months)
static

Set the number of months before/after max age to autorenew an engine for your company.

Parameters
monthsThe number of calendar-months before/after max age of engine. The value will be clamped to MIN(int) .. MAX(int).
Precondition
GSCompanyMode::IsValid().
Returns
True if autorenew months has been modified.
See also
GSCalendarTime

◆ SetAutoRenewStatus()

static bool GSCompany::SetAutoRenewStatus ( bool  autorenew)
static

Set whether autorenew is enabled for your company.

Parameters
autorenewThe new autorenew status.
Precondition
GSCompanyMode::IsValid().
Returns
True if autorenew status has been modified.

◆ SetLoanAmount()

static bool GSCompany::SetLoanAmount ( Money  loan)
static

Sets the amount to loan.

Parameters
loanThe amount to loan (multiplier of GetLoanInterval()).
Precondition
'loan' must be non-negative.
GetLoanInterval() must be a multiplier of 'loan'.
'loan' must be below GetMaxLoanAmount().
'loan' - GetLoanAmount() + GetBankBalance() must be non-negative.
GSCompanyMode::IsValid().
Returns
True if the loan could be set to your requested amount.

◆ SetMaxLoanAmountForCompany()

static bool GSCompany::SetMaxLoanAmountForCompany ( CompanyID  company,
Money  amount 
)
static

Sets the max amount of money company can loan.

Parameters
companyThe company ID.
amountMax loan amount. Will be rounded down to a multiple of GetLoanInterval().
Returns
True, if the max loan was changed.
Precondition
GSCompanyMode::IsDeity().
amount >= 0.
ResolveCompanyID(company) != COMPANY_INVALID.
Note
You need to create your own news message to inform about max loan change.
Max loan value set with this method is not affected by inflation.

◆ SetMinimumLoanAmount()

static bool GSCompany::SetMinimumLoanAmount ( Money  loan)
static

Sets the minimum amount to loan, i.e.

the given amount of loan rounded up.

Parameters
loanThe amount to loan (any positive number).
Precondition
'loan' must be non-negative.
'loan' must be below GetMaxLoanAmount().
GSCompanyMode::IsValid().
Returns
True if we could allocate a minimum of 'loan' loan.

◆ SetName()

static bool GSCompany::SetName ( Text *  name)
static

Set the name of your company.

Parameters
nameThe new name of the company (can be either a raw string, or a GSText object).
Precondition
name != null && len(name) != 0.
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_NAME_IS_NOT_UNIQUE
Returns
True if the name was changed.

◆ SetPresidentGender()

static bool GSCompany::SetPresidentGender ( Gender  gender)
static

Set the gender of the president of your company.

Parameters
genderThe new gender for your president.
Precondition
GetPresidentGender(GSCompany.COMPANY_SELF) != gender.
GSCompanyMode::IsValid().
Returns
True if the gender was changed.
Note
When successful a random face will be created.

◆ SetPresidentName()

static bool GSCompany::SetPresidentName ( Text *  name)
static

Set the name of your president.

Parameters
nameThe new name of the president (can be either a raw string, or a GSText object).
Precondition
name != null && len(name) != 0.
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_NAME_IS_NOT_UNIQUE
Returns
True if the name was changed.

◆ SetPrimaryLiveryColour()

static bool GSCompany::SetPrimaryLiveryColour ( LiveryScheme  scheme,
Colours  colour 
)
static

Set primary colour for your company.

Parameters
schemeLivery scheme to set.
colourColour to set.
Precondition
GSCompanyMode::IsValid().
Returns
False if unable to set primary colour of the livery scheme (e.g. colour in use).

◆ SetSecondaryLiveryColour()

static bool GSCompany::SetSecondaryLiveryColour ( LiveryScheme  scheme,
Colours  colour 
)
static

Set secondary colour for your company.

Parameters
schemeLivery scheme to set.
colourColour to set.
Precondition
GSCompanyMode::IsValid().
Returns
False if unable to set secondary colour of the livery scheme.