OpenTTD Source: src/cargomonitor.h File Reference

OpenTTD Source 15.0-RC2

Typedefs | Functions | Variables
cargomonitor.h File Reference

Cargo transport monitoring declarations. More...

`#include "cargo_type.h"`
`#include "company_func.h"`
`#include "industry.h"`
`#include "town.h"`
`#include "core/overflowsafe_type.hpp"`

Go to the source code of this file.

## Typedefs
typedef uint32_t | CargoMonitorID
| Unique number for a company / cargo type / (town or industry).
typedef std::map< CargoMonitorID, OverflowSafeInt32 > | CargoMonitorMap
| Map type for storing and updating active cargo monitor numbers and their amounts.

## Functions
CargoMonitorID | EncodeCargoIndustryMonitor (CompanyID company, CargoType ctype, IndustryID ind)
| Encode a cargo monitor for pickup or delivery at an industry.
CargoMonitorID | EncodeCargoTownMonitor (CompanyID company, CargoType ctype, TownID town)
| Encode a cargo monitoring number for pickup or delivery at a town.
CompanyID | DecodeMonitorCompany (CargoMonitorID num)
| Extract the company from the cargo monitor.
CargoType | DecodeMonitorCargoType (CargoMonitorID num)
| Extract the cargo type from the cargo monitor.
bool | MonitorMonitorsIndustry (CargoMonitorID num)
| Does the cargo number monitor an industry or a town?
IndustryID | DecodeMonitorIndustry (CargoMonitorID num)
| Extract the industry number from the cargo monitor.
TownID | DecodeMonitorTown (CargoMonitorID num)
| Extract the town number from the cargo monitor.
void | ClearCargoPickupMonitoring (CompanyID company=INVALID_OWNER)
| Clear all pick-up cargo monitors.
void | ClearCargoDeliveryMonitoring (CompanyID company=INVALID_OWNER)
| Clear all delivery cargo monitors.
int32_t | GetDeliveryAmount (CargoMonitorID monitor, bool keep_monitoring)
| Get the amount of cargo delivered for the given cargo monitor since activation or last query.
int32_t | GetPickupAmount (CargoMonitorID monitor, bool keep_monitoring)
| Get the amount of cargo picked up for the given cargo monitor since activation or last query.
void | AddCargoDelivery (CargoType cargo_type, CompanyID company, uint32_t amount, Source src, const Station *st, IndustryID dest=IndustryID::Invalid())
| Cargo was delivered to its final destination, update the pickup and delivery maps.

## Variables
CargoMonitorMap | _cargo_pickups
| Map of monitored pick-ups to the amount since last query/activation.
CargoMonitorMap | _cargo_deliveries
| Map of monitored deliveries to the amount since last query/activation.
constexpr uint8_t | CCB_TOWN_IND_NUMBER_START = 0
| Start bit of the town or industry number.
constexpr uint8_t | CCB_TOWN_IND_NUMBER_LENGTH = 16
| Number of bits of the town or industry number.
constexpr uint8_t | CCB_IS_INDUSTRY_BIT = 16
| Bit indicating the town/industry number is an industry.
constexpr uint8_t | CCB_CARGO_TYPE_START = 19
| Start bit of the cargo type field.
constexpr uint8_t | CCB_CARGO_TYPE_LENGTH = 6
| Number of bits of the cargo type field.
constexpr uint8_t | CCB_COMPANY_START = 25
| Start bit of the company field.
constexpr uint8_t | CCB_COMPANY_LENGTH = 4
| Number of bits of the company field.

## Detailed Description

Cargo transport monitoring declarations.

Definition in file cargomonitor.h.

## Typedef Documentation

## ◆ CargoMonitorID

typedef uint32_t CargoMonitorID

Unique number for a company / cargo type / (town or industry).

Encoding is as follows:

- bits 0-15 town or industry number
- bit 16 is set if it is an industry number (else it is a town number).
- bits 19-23 Cargo type.
- bits 24-31 Company number. Type of the cargo monitor number.

Definition at line 29 of file cargomonitor.h.

## ◆ CargoMonitorMap

typedef std::map<CargoMonitorID, OverflowSafeInt32> CargoMonitorMap

Map type for storing and updating active cargo monitor numbers and their amounts.

Definition at line 32 of file cargomonitor.h.

## Function Documentation

## ◆ AddCargoDelivery()

void AddCargoDelivery | ( | CargoType | cargo_type,
|  | CompanyID | company,
|  | uint32_t | amount,
|  | Source | src,
|  | const Station * | st,
|  | IndustryID | dest
| ) |  |

Cargo was delivered to its final destination, update the pickup and delivery maps.

Parameters

  cargo_type | type of cargo.
  company | company delivering the cargo.
  amount | Amount of cargo delivered.
  src | source of cargo.
  st | station where the cargo is delivered to.
  dest | industry index where the cargo is delivered to.

Definition at line 117 of file cargomonitor.cpp.

References _cargo_deliveries, _cargo_pickups, EncodeCargoIndustryMonitor(), EncodeCargoTownMonitor(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Station::industries_near, Industry, BaseStation::town, Town, and Source::type.

Referenced by DeliverGoods(), and DeliverGoodsToIndustry().

## ◆ ClearCargoDeliveryMonitoring()

void ClearCargoDeliveryMonitoring | ( | CompanyID | company | ) |

Clear all delivery cargo monitors.

Parameters

  company | clear all delivery monitors for this company or if INVALID_OWNER is passed, all delivery monitors are cleared regardless of company.

Definition at line 57 of file cargomonitor.cpp.

References _cargo_deliveries, and ClearCargoMonitoring().

Referenced by ChangeOwnershipOfCompanyItems(), InitializeEconomy(), and CMDLChunkHandler::Load().

## ◆ ClearCargoPickupMonitoring()

void ClearCargoPickupMonitoring | ( | CompanyID | company | ) |

Clear all pick-up cargo monitors.

Parameters

  company | clear all pick-up monitors for this company or if INVALID_OWNER is passed, all pick-up monitors are cleared regardless of company.

Definition at line 47 of file cargomonitor.cpp.

References _cargo_pickups, and ClearCargoMonitoring().

Referenced by ChangeOwnershipOfCompanyItems(), InitializeEconomy(), and CMPUChunkHandler::Load().

## ◆ DecodeMonitorCargoType()

CargoType DecodeMonitorCargoType | ( | CargoMonitorID | num | ) |
| inline

Extract the cargo type from the cargo monitor.

Parameters

  num | Cargo monitoring number to decode.

Returns
  The extracted cargo type.

Definition at line 105 of file cargomonitor.h.

References CCB_CARGO_TYPE_LENGTH, CCB_CARGO_TYPE_START, and GB().

## ◆ DecodeMonitorCompany()

CompanyID DecodeMonitorCompany | ( | CargoMonitorID | num | ) |
| inline

Extract the company from the cargo monitor.

Parameters

  num | Cargo monitoring number to decode.

Returns
  The extracted company id.

Definition at line 95 of file cargomonitor.h.

References CCB_COMPANY_LENGTH, CCB_COMPANY_START, and GB().

Referenced by ClearCargoMonitoring().

## ◆ DecodeMonitorIndustry()

IndustryID DecodeMonitorIndustry | ( | CargoMonitorID | num | ) |
| inline

Extract the industry number from the cargo monitor.

Parameters

  num | Cargo monitoring number to decode.

Returns
  The extracted industry id, or IndustryID::Invalid() if the number does not monitor an industry.

Definition at line 125 of file cargomonitor.h.

References CCB_TOWN_IND_NUMBER_LENGTH, CCB_TOWN_IND_NUMBER_START, GB(), and MonitorMonitorsIndustry().

## ◆ DecodeMonitorTown()

TownID DecodeMonitorTown | ( | CargoMonitorID | num | ) |
| inline

Extract the town number from the cargo monitor.

Parameters

  num | Cargo monitoring number to decode.

Returns
  The extracted town id, or TownID::Invalid() if the number does not monitor a town.

Definition at line 136 of file cargomonitor.h.

References CCB_TOWN_IND_NUMBER_LENGTH, CCB_TOWN_IND_NUMBER_START, GB(), and MonitorMonitorsIndustry().

## ◆ EncodeCargoIndustryMonitor()

CargoMonitorID EncodeCargoIndustryMonitor | ( | CompanyID | company,
|  | CargoType | ctype,
|  | IndustryID | ind
| ) |  |
| inline

Encode a cargo monitor for pickup or delivery at an industry.

Parameters

  company | Company performing the transport.
  ctype | Cargo type being transported.
  ind | Industry providing or accepting the cargo.

Returns
  The encoded cargo/company/industry number.

Definition at line 58 of file cargomonitor.h.

References CCB_CARGO_TYPE_LENGTH, CCB_CARGO_TYPE_START, CCB_COMPANY_LENGTH, CCB_COMPANY_START, CCB_IS_INDUSTRY_BIT, CCB_TOWN_IND_NUMBER_LENGTH, CCB_TOWN_IND_NUMBER_START, SB(), and SetBit().

Referenced by AddCargoDelivery().

## ◆ EncodeCargoTownMonitor()

CargoMonitorID EncodeCargoTownMonitor | ( | CompanyID | company,
|  | CargoType | ctype,
|  | TownID | town
| ) |  |
| inline

Encode a cargo monitoring number for pickup or delivery at a town.

Parameters

  company | Company performing the transport.
  ctype | Cargo type being transported.
  town | Town providing or accepting the cargo.

Returns
  The encoded cargo/company/town number.

Definition at line 78 of file cargomonitor.h.

References CCB_CARGO_TYPE_LENGTH, CCB_CARGO_TYPE_START, CCB_COMPANY_LENGTH, CCB_COMPANY_START, CCB_TOWN_IND_NUMBER_LENGTH, CCB_TOWN_IND_NUMBER_START, SB(), and BaseStation::town.

Referenced by AddCargoDelivery().

## ◆ GetDeliveryAmount()

int32_t GetDeliveryAmount | ( | CargoMonitorID | monitor,
|  | bool | keep_monitoring
| ) |  |

Get the amount of cargo delivered for the given cargo monitor since activation or last query.

Parameters

  monitor | Cargo monitor to query.
  keep_monitoring | After returning from this call, continue monitoring.

Returns
  Amount of delivered cargo for the monitored combination.

Definition at line 91 of file cargomonitor.cpp.

References _cargo_deliveries, and GetAmount().

## ◆ GetPickupAmount()

int32_t GetPickupAmount | ( | CargoMonitorID | monitor,
|  | bool | keep_monitoring
| ) |  |

Get the amount of cargo picked up for the given cargo monitor since activation or last query.

Parameters

  monitor | Monitoring number to query.
  keep_monitoring | After returning from this call, continue monitoring.

Returns
  Amount of picked up cargo for the monitored combination.

Note
  Cargo pick up is counted on final delivery, to prevent users getting credit for picking up cargo without delivering it.

Definition at line 103 of file cargomonitor.cpp.

References _cargo_pickups, and GetAmount().

## ◆ MonitorMonitorsIndustry()

bool MonitorMonitorsIndustry | ( | CargoMonitorID | num | ) |
| inline

Does the cargo number monitor an industry or a town?

Parameters

  num | Cargo monitoring number to decode.

Returns
  true if monitoring an industry, false if monitoring a town.

Definition at line 115 of file cargomonitor.h.

References CCB_IS_INDUSTRY_BIT, and HasBit().

Referenced by DecodeMonitorIndustry(), and DecodeMonitorTown().

## Variable Documentation

## ◆ _cargo_deliveries

CargoMonitorMap _cargo_deliveries
| extern

Map of monitored deliveries to the amount since last query/activation.

Definition at line 17 of file cargomonitor.cpp.

Referenced by AddCargoDelivery(), ClearCargoDeliveryMonitoring(), GetDeliveryAmount(), CMDLChunkHandler::Load(), and CMDLChunkHandler::Save().

## ◆ _cargo_pickups

CargoMonitorMap _cargo_pickups
| extern

Map of monitored pick-ups to the amount since last query/activation.

Definition at line 16 of file cargomonitor.cpp.

Referenced by AddCargoDelivery(), ClearCargoPickupMonitoring(), GetPickupAmount(), CMPUChunkHandler::Load(), and CMPUChunkHandler::Save().

## ◆ CCB_CARGO_TYPE_LENGTH

constexpr uint8_t CCB_CARGO_TYPE_LENGTH = 6
| constexpr

Number of bits of the cargo type field.

Definition at line 43 of file cargomonitor.h.

Referenced by DecodeMonitorCargoType(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().

## ◆ CCB_CARGO_TYPE_START

constexpr uint8_t CCB_CARGO_TYPE_START = 19
| constexpr

Start bit of the cargo type field.

Definition at line 42 of file cargomonitor.h.

Referenced by DecodeMonitorCargoType(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().

## ◆ CCB_COMPANY_LENGTH

constexpr uint8_t CCB_COMPANY_LENGTH = 4
| constexpr

Number of bits of the company field.

Definition at line 45 of file cargomonitor.h.

Referenced by DecodeMonitorCompany(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().

## ◆ CCB_COMPANY_START

constexpr uint8_t CCB_COMPANY_START = 25
| constexpr

Start bit of the company field.

Definition at line 44 of file cargomonitor.h.

Referenced by DecodeMonitorCompany(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().

## ◆ CCB_IS_INDUSTRY_BIT

constexpr uint8_t CCB_IS_INDUSTRY_BIT = 16
| constexpr

Bit indicating the town/industry number is an industry.

Definition at line 41 of file cargomonitor.h.

Referenced by EncodeCargoIndustryMonitor(), and MonitorMonitorsIndustry().

## ◆ CCB_TOWN_IND_NUMBER_LENGTH

constexpr uint8_t CCB_TOWN_IND_NUMBER_LENGTH = 16
| constexpr

Number of bits of the town or industry number.

Definition at line 40 of file cargomonitor.h.

Referenced by DecodeMonitorIndustry(), DecodeMonitorTown(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().

## ◆ CCB_TOWN_IND_NUMBER_START

constexpr uint8_t CCB_TOWN_IND_NUMBER_START = 0
| constexpr

Start bit of the town or industry number.

Definition at line 39 of file cargomonitor.h.

Referenced by DecodeMonitorIndustry(), DecodeMonitorTown(), EncodeCargoIndustryMonitor(), and EncodeCargoTownMonitor().