OpenTTD GameScript API: GSLeagueTable Class Reference

OpenTTD GameScript API 13.0-RC1

Public Types | Static Public Member Functions
GSLeagueTable Class Reference

Class that handles league table related functions. More...

Inheritance diagram for GSLeagueTable:

## Public Types
enum | LeagueTableID { LEAGUE_TABLE_INVALID }
| The league table IDs. More...
enum | LeagueTableElementID { LEAGUE_TABLE_ELEMENT_INVALID }
| The league table element IDs. More...
enum | LinkType : byte { LINK_NONE, LINK_TILE, LINK_INDUSTRY, LINK_TOWN, LINK_COMPANY, LINK_STORY_PAGE }
| The type of a link. More...

## Static Public Member Functions
static bool | IsValidLeagueTable (LeagueTableID table_id)
| Check whether this is a valid league table ID. More...
static bool | IsValidLeagueTableElement (LeagueTableElementID element_id)
| Check whether this is a valid league table element ID. More...
static LeagueTableID | New (Text *title, Text *header, Text *footer)
| Create a new league table. More...
static LeagueTableElementID | NewElement (LeagueTableID table, int64 rating, GSCompany::CompanyID company, Text *text, Text *score, LinkType link_type, LinkTargetID link_target)
| Create a new league table element. More...
static bool | UpdateElementData (LeagueTableElementID element, GSCompany::CompanyID company, Text *text, LinkType link_type, LinkTargetID link_target)
| Update the attributes of a league table element. More...
static bool | UpdateElementScore (LeagueTableElementID element, int64 rating, Text *score)
| Create a new league table element. More...
static bool | RemoveElement (LeagueTableElementID element)
| Remove a league table element. More...

## Detailed Description

Class that handles league table related functions.

To create a league table:

1. Create the league table
2. Create league table elements that will be shown in the table in the order of their rating (higher=better).

## Member Enumeration Documentation

## ◆ LeagueTableElementID

enum GSLeagueTable::LeagueTableElementID

The league table element IDs.

Enumerator
LEAGUE_TABLE_ELEMENT_INVALID | An invalid league table element id.

## ◆ LeagueTableID

enum GSLeagueTable::LeagueTableID

The league table IDs.

Enumerator
LEAGUE_TABLE_INVALID | An invalid league table id.

## ◆ LinkType

enum GSLeagueTable::LinkType : byte

The type of a link.

Enumerator
LINK_NONE | No link.
LINK_TILE | Link a tile.
LINK_INDUSTRY | Link an industry.
LINK_TOWN | Link a town.
LINK_COMPANY | Link a company.
LINK_STORY_PAGE | Link a story page.

## Member Function Documentation

## ◆ IsValidLeagueTable()

static bool GSLeagueTable::IsValidLeagueTable | ( | LeagueTableID | table_id | ) |
| static

Check whether this is a valid league table ID.

Parameters

  table_id | The LeagueTableID to check.

Returns
  true iff this league table is valid.

## ◆ IsValidLeagueTableElement()

static bool GSLeagueTable::IsValidLeagueTableElement | ( | LeagueTableElementID | element_id | ) |
| static

Check whether this is a valid league table element ID.

Parameters

  element_id | The LeagueTableElementID to check.

Returns
  true iff this league table element is valid.

## ◆ New()

static LeagueTableID GSLeagueTable::New | ( | Text * | title,
|  | Text * | header,
|  | Text * | footer
| ) |  |
| static

Create a new league table.

Parameters

  title | League table title (can be either a raw string, or GSText object).

Returns
  The new LeagueTableID, or LEAGUE_TABLE_INVALID if it failed.

Precondition
  No GSCompanyMode may be in scope.
  title != nullptr && len(title) != 0.

## ◆ NewElement()

static LeagueTableElementID GSLeagueTable::NewElement | ( | LeagueTableID | table,
|  | int64 | rating,
|  | GSCompany::CompanyID | company,
|  | Text * | text,
|  | Text * | score,
|  | LinkType | link_type,
|  | LinkTargetID | link_target
| ) |  |
| static

Create a new league table element.

Parameters

  table | Id of the league table this element belongs to.
  rating | Value that elements are ordered by.
  company | Company to show the color blob for or INVALID_COMPANY.
  text | Text of the element (can be either a raw string, or GSText object).
  score | String representation of the score associated with the element (can be either a raw string, or GSText object).
  link_type | Type of the referenced object.
  link_target | Id of the referenced object.

Returns
  The new LeagueTableElementID, or LEAGUE_TABLE_ELEMENT_INVALID if it failed.

Precondition
  No GSCompanyMode may be in scope.
  IsValidLeagueTable(table).
  text != nullptr && len(text) != 0.
  score != nullptr && len(score) != 0.
  IsValidLink(Link(link_type, link_target)).

## ◆ RemoveElement()

static bool GSLeagueTable::RemoveElement | ( | LeagueTableElementID | element | ) |
| static

Remove a league table element.

Parameters

  element | Id of the element to update

Returns
  True if the action succeeded.

Precondition
  No GSCompanyMode may be in scope.
  IsValidLeagueTableElement(element).

## ◆ UpdateElementData()

static bool GSLeagueTable::UpdateElementData | ( | LeagueTableElementID | element,
|  | GSCompany::CompanyID | company,
|  | Text * | text,
|  | LinkType | link_type,
|  | LinkTargetID | link_target
| ) |  |
| static

Update the attributes of a league table element.

Parameters

  element | Id of the element to update
  company | Company to show the color blob for or INVALID_COMPANY.
  text | Text of the element (can be either a raw string, or GSText object).
  link_type | Type of the referenced object.
  link_target | Id of the referenced object.

Returns
  True if the action succeeded.

Precondition
  No GSCompanyMode may be in scope.
  IsValidLeagueTableElement(element).
  text != nullptr && len(text) != 0.
  IsValidLink(Link(link_type, link_target)).

## ◆ UpdateElementScore()

static bool GSLeagueTable::UpdateElementScore | ( | LeagueTableElementID | element,
|  | int64 | rating,
|  | Text * | score
| ) |  |
| static

Create a new league table element.

Parameters

  element | Id of the element to update
  rating | Value that elements are ordered by.
  score | String representation of the score associated with the element (can be either a raw string, or GSText object).

Returns
  True if the action succeeded.

Precondition
  No GSCompanyMode may be in scope.
  IsValidLeagueTableElement(element).
  score != nullptr && len(score) != 0.