OpenTTD GameScript API: GSCargoMonitor Class Reference

OpenTTD GameScript API 15.1

Static Public Member Functions
GSCargoMonitor Class Reference

Class that handles all cargo movement monitoring related functions. More...

`#include <script_cargomonitor.hpp>`

Inheritance diagram for GSCargoMonitor:

## Static Public Member Functions
static int | GetTownDeliveryAmount (GSCompany::CompanyID company, CargoType cargo, TownID town_id, bool keep_monitoring)
| Get the amount of cargo delivered to a town by a company since the last query, and update the monitoring state.
static int | GetIndustryDeliveryAmount (GSCompany::CompanyID company, CargoType cargo, IndustryID industry_id, bool keep_monitoring)
| Get the amount of cargo delivered to an industry by a company since the last query, and update the monitoring state.
static int | GetTownPickupAmount (GSCompany::CompanyID company, CargoType cargo, TownID town_id, bool keep_monitoring)
| Get the amount of cargo picked up (and delivered) from a town by a company since the last query, and update the monitoring state.
static int | GetIndustryPickupAmount (GSCompany::CompanyID company, CargoType cargo, IndustryID industry_id, bool keep_monitoring)
| Get the amount of cargo picked up (and delivered) from an industry by a company since the last query, and update the monitoring state.
static void | StopAllMonitoring ()
| Stop monitoring everything.

## Detailed Description

Class that handles all cargo movement monitoring related functions.

To get an understanding of what users are transporting, this class provides cargo pick-up and delivery monitoring functions. It works as follows:

- Select a company, a cargo-type, and an industry that gets the cargo triplet.
- Perform a call to GetIndustryDeliveryAmount, setting 'keep_monitoring' to `true`. The return value is not important, but from this moment the program accumulates all deliveries by the given company to the given industry of the given cargo type.
- Some time later, perform another call to GetIndustryDeliveryAmount. It returns the accumulated amount of cargo that the company has delivered. The call causes the collected amount to be reset. On the next call you will thus always get the delivered amount since the previous call.
- When monitoring the deliveries is not interesting any more, set 'keep_monitoring' to `false`. The collecting process that happens between calls is stopped.

In the same way you can monitor town deliveries, and you can monitor pick-up from towns and industries. The latter get added at the moment the cargo is delivered. This prevents users from getting credit for picking up cargo without delivering it.

The active monitors are saved and loaded. Upon bankruptcy or company takeover, the cargo monitors are automatically stopped for that company. You can reset to the empty state with StopAllMonitoring.

## Member Function Documentation

## ◆ GetIndustryDeliveryAmount()

static int GSCargoMonitor::GetIndustryDeliveryAmount | ( | GSCompany::CompanyID | company,
|  | CargoType | cargo,
|  | IndustryID | industry_id,
|  | bool | keep_monitoring
| ) |  |
| static

Get the amount of cargo delivered to an industry by a company since the last query, and update the monitoring state.

Parameters

  company | Company to query.
  cargo | Cargo type to query.
  industry_id | Industry to query.
  keep_monitoring | If `true`, the given combination continues to be monitored for the next call. If `false`, monitoring ends.

Returns
  Amount of delivered cargo of the given cargo type to the given industry by the given company since the last call, or `-1` if a parameter is out-of-bound.

## ◆ GetIndustryPickupAmount()

static int GSCargoMonitor::GetIndustryPickupAmount | ( | GSCompany::CompanyID | company,
|  | CargoType | cargo,
|  | IndustryID | industry_id,
|  | bool | keep_monitoring
| ) |  |
| static

Get the amount of cargo picked up (and delivered) from an industry by a company since the last query, and update the monitoring state.

Parameters

  company | Company to query.
  cargo | Cargo type to query.
  industry_id | Industry to query.
  keep_monitoring | If `true`, the given combination continues to be monitored for the next call. If `false`, monitoring ends.

Returns
  Amount of picked up cargo of the given cargo type to the given industry by the given company since the last call, or `-1` if a parameter is out-of-bound.

Note
  Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.

## ◆ GetTownDeliveryAmount()

static int GSCargoMonitor::GetTownDeliveryAmount | ( | GSCompany::CompanyID | company,
|  | CargoType | cargo,
|  | TownID | town_id,
|  | bool | keep_monitoring
| ) |  |
| static

Get the amount of cargo delivered to a town by a company since the last query, and update the monitoring state.

Parameters

  company | Company to query.
  cargo | Cargo type to query.
  town_id | Town to query.
  keep_monitoring | If `true`, the given combination continues to be monitored for the next call. If `false`, monitoring ends.

Returns
  Amount of delivered cargo of the given cargo type to the given town by the given company since the last call, or `-1` if a parameter is out-of-bound.

## ◆ GetTownPickupAmount()

static int GSCargoMonitor::GetTownPickupAmount | ( | GSCompany::CompanyID | company,
|  | CargoType | cargo,
|  | TownID | town_id,
|  | bool | keep_monitoring
| ) |  |
| static

Get the amount of cargo picked up (and delivered) from a town by a company since the last query, and update the monitoring state.

Parameters

  company | Company to query.
  cargo | Cargo type to query.
  town_id | Town to query.
  keep_monitoring | If `true`, the given combination continues to be monitored for the next call. If `false`, monitoring ends.

Returns
  Amount of picked up cargo of the given cargo type to the given town by the given company since the last call, or `-1` if a parameter is out-of-bound.

Note
  Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.