OpenTTD Source: src/cargomonitor.cpp File Reference

OpenTTD Source 14.1

Functions | Variables
cargomonitor.cpp File Reference
`#include "stdafx.h"`
`#include "cargomonitor.h"`
`#include "station_base.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
static void | ClearCargoMonitoring (CargoMonitorMap &cargo_monitor_map, CompanyID company=INVALID_OWNER)
| Helper method for ClearCargoPickupMonitoring and ClearCargoDeliveryMonitoring. More...
void | ClearCargoPickupMonitoring (CompanyID company)
| Clear all pick-up cargo monitors. More...
void | ClearCargoDeliveryMonitoring (CompanyID company)
| Clear all delivery cargo monitors. More...
static int32_t | GetAmount (CargoMonitorMap &monitor_map, CargoMonitorID monitor, bool keep_monitoring)
| Get and reset the amount associated with a cargo monitor. More...
int32_t | GetDeliveryAmount (CargoMonitorID monitor, bool keep_monitoring)
| Get the amount of cargo delivered for the given cargo monitor since activation or last query. More...
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. More...
void | AddCargoDelivery (CargoID cargo_type, CompanyID company, uint32_t amount, SourceType src_type, SourceID src, const Station *st, IndustryID dest)
| Cargo was delivered to its final destination, update the pickup and delivery maps. More...

## 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.

## Detailed Description

Implementation of the cargo transport monitoring.

Definition in file cargomonitor.cpp.

## Function Documentation

## ◆ AddCargoDelivery()

void AddCargoDelivery | ( | CargoID | cargo_type,
|  | CompanyID | company,
|  | uint32_t | amount,
|  | SourceType | src_type,
|  | SourceID | 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_type | type of src.
  src | index of source.
  st | station where the cargo is delivered to.
  dest | industry index where the cargo is delivered to.

Definition at line 119 of file cargomonitor.cpp.

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

Referenced by 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 CMDLChunkHandler::Load().

## ◆ ClearCargoMonitoring()

static void ClearCargoMonitoring | ( | CargoMonitorMap & | cargo_monitor_map,
|  | CompanyID | company = `INVALID_OWNER`
| ) |  |
| static

Helper method for ClearCargoPickupMonitoring and ClearCargoDeliveryMonitoring.

Clears all monitors that belong to the specified company or all if INVALID_OWNER is specified as company.

Parameters

  cargo_monitor_map | reference to the cargo monitor map to operate on.
  company | company to clear cargo monitors for or INVALID_OWNER if all cargo monitors should be cleared.

Definition at line 26 of file cargomonitor.cpp.

References DecodeMonitorCompany(), and INVALID_OWNER.

Referenced by ClearCargoDeliveryMonitoring(), and ClearCargoPickupMonitoring().

## ◆ 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 CMPUChunkHandler::Load().

## ◆ GetAmount()

static int32_t GetAmount | ( | CargoMonitorMap & | monitor_map,
|  | CargoMonitorID | monitor,
|  | bool | keep_monitoring
| ) |  |
| static

Get and reset the amount associated with a cargo monitor.

Parameters

  [in,out] | monitor_map | Monitoring map to search (and reset for the queried entry).
  | monitor | Cargo monitor to query/reset.
  | keep_monitoring | After returning from this call, continue monitoring.

Returns
  Amount collected since last query/activation for the monitored combination.

Definition at line 69 of file cargomonitor.cpp.

Referenced by GetDeliveryAmount(), and GetPickupAmount().

## ◆ 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 92 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 104 of file cargomonitor.cpp.

References _cargo_pickups, and GetAmount().