OpenTTD
Typedefs | Enumerations | 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"
#include <map>

Go to the source code of this file.

Typedefs

typedef uint32 CargoMonitorID
 Unique number for a company / cargo type / (town or industry). More...
 
typedef std::map< CargoMonitorID, OverflowSafeInt32CargoMonitorMap
 Map type for storing and updating active cargo monitor numbers and their amounts. More...
 

Enumerations

enum  CargoCompanyBits {
  CCB_TOWN_IND_NUMBER_START = 0, CCB_TOWN_IND_NUMBER_LENGTH = 16, CCB_IS_INDUSTRY_BIT = 16, CCB_IS_INDUSTRY_BIT_VALUE = 1ul << CCB_IS_INDUSTRY_BIT,
  CCB_CARGO_TYPE_START = 19, CCB_CARGO_TYPE_LENGTH = 5, CCB_COMPANY_START = 24, CCB_COMPANY_LENGTH = 8
}
 Constants for encoding and extracting cargo monitors. More...
 

Functions

static CargoMonitorID EncodeCargoIndustryMonitor (CompanyID company, CargoID ctype, IndustryID ind)
 Encode a cargo monitor for pickup or delivery at an industry. More...
 
static CargoMonitorID EncodeCargoTownMonitor (CompanyID company, CargoID ctype, TownID town)
 Encode a cargo monitoring number for pickup or delivery at a town. More...
 
static CompanyID DecodeMonitorCompany (CargoMonitorID num)
 Extract the company from the cargo monitor. More...
 
static CargoID DecodeMonitorCargoType (CargoMonitorID num)
 Extract the cargo type from the cargo monitor. More...
 
static bool MonitorMonitorsIndustry (CargoMonitorID num)
 Does the cargo number monitor an industry or a town? More...
 
static IndustryID DecodeMonitorIndustry (CargoMonitorID num)
 Extract the industry number from the cargo monitor. More...
 
static TownID DecodeMonitorTown (CargoMonitorID num)
 Extract the town number from the cargo monitor. More...
 
void ClearCargoPickupMonitoring (CompanyID company=INVALID_OWNER)
 Clear all pick-up cargo monitors. More...
 
void ClearCargoDeliveryMonitoring (CompanyID company=INVALID_OWNER)
 Clear all delivery cargo monitors. More...
 
int32 GetDeliveryAmount (CargoMonitorID monitor, bool keep_monitoring)
 Get the amount of cargo delivered for the given cargo monitor since activation or last query. More...
 
int32 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 amount, SourceType src_type, SourceID src, const Station *st)
 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

Cargo transport monitoring declarations.

Definition in file cargomonitor.h.

Typedef Documentation

◆ CargoMonitorID

typedef uint32 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 22 of file cargomonitor.h.

◆ CargoMonitorMap

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

Definition at line 35 of file cargomonitor.h.

Enumeration Type Documentation

◆ CargoCompanyBits

Constants for encoding and extracting cargo monitors.

Enumerator
CCB_TOWN_IND_NUMBER_START 

Start bit of the town or industry number.

CCB_TOWN_IND_NUMBER_LENGTH 

Number of bits of the town or industry number.

CCB_IS_INDUSTRY_BIT 

Bit indicating the town/industry number is an industry.

CCB_IS_INDUSTRY_BIT_VALUE 

Value of the CCB_IS_INDUSTRY_BIT bit.

CCB_CARGO_TYPE_START 

Start bit of the cargo type field.

CCB_CARGO_TYPE_LENGTH 

Number of bits of the cargo type field.

CCB_COMPANY_START 

Start bit of the company field.

CCB_COMPANY_LENGTH 

Number of bits of the company field.

Definition at line 42 of file cargomonitor.h.

Function Documentation

◆ AddCargoDelivery()

void AddCargoDelivery ( CargoID  cargo_type,
CompanyID  company,
uint32  amount,
SourceType  src_type,
SourceID  src,
const Station st 
)

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

Parameters
cargo_typetype of cargo.
companycompany delivering the cargo.
amountAmount of cargo delivered.
src_typetype of src.
srcindex of source.
ststation where the cargo is delivered to.

Definition at line 121 of file cargomonitor.cpp.

References _cargo_deliveries, _cargo_pickups, SmallVector< T, S >::Begin(), EncodeCargoIndustryMonitor(), EncodeCargoTownMonitor(), SmallVector< T, S >::End(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Station::industries_near, INVALID_SOURCE, ST_INDUSTRY, ST_TOWN, and BaseStation::town.

◆ ClearCargoDeliveryMonitoring()

void ClearCargoDeliveryMonitoring ( CompanyID  company)

Clear all delivery cargo monitors.

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

Definition at line 60 of file cargomonitor.cpp.

References _cargo_deliveries, and ClearCargoMonitoring().

Referenced by InitializeEconomy(), and LoadDelivery().

◆ ClearCargoPickupMonitoring()

void ClearCargoPickupMonitoring ( CompanyID  company)

Clear all pick-up cargo monitors.

Parameters
companyclear 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 50 of file cargomonitor.cpp.

References _cargo_pickups, and ClearCargoMonitoring().

Referenced by InitializeEconomy(), and LoadPickup().

◆ DecodeMonitorCargoType()

static CargoID DecodeMonitorCargoType ( CargoMonitorID  num)
inlinestatic

Extract the cargo type from the cargo monitor.

Parameters
numCargo monitoring number to decode.
Returns
The extracted cargo type.

Definition at line 106 of file cargomonitor.h.

References CCB_CARGO_TYPE_LENGTH, CCB_CARGO_TYPE_START, and GB().

◆ DecodeMonitorCompany()

static CompanyID DecodeMonitorCompany ( CargoMonitorID  num)
inlinestatic

Extract the company from the cargo monitor.

Parameters
numCargo monitoring number to decode.
Returns
The extracted company id.

Definition at line 96 of file cargomonitor.h.

References CCB_COMPANY_LENGTH, CCB_COMPANY_START, and GB().

Referenced by ClearCargoMonitoring().

◆ DecodeMonitorIndustry()

static IndustryID DecodeMonitorIndustry ( CargoMonitorID  num)
inlinestatic

Extract the industry number from the cargo monitor.

Parameters
numCargo monitoring number to decode.
Returns
The extracted industry id, or #INVALID_INDUSTRY if the number does not monitor an industry.

Definition at line 126 of file cargomonitor.h.

References MonitorMonitorsIndustry().

◆ DecodeMonitorTown()

static TownID DecodeMonitorTown ( CargoMonitorID  num)
inlinestatic

Extract the town number from the cargo monitor.

Parameters
numCargo monitoring number to decode.
Returns
The extracted town id, or #INVALID_TOWN if the number does not monitor a town.

Definition at line 137 of file cargomonitor.h.

References MonitorMonitorsIndustry().

◆ EncodeCargoIndustryMonitor()

static CargoMonitorID EncodeCargoIndustryMonitor ( CompanyID  company,
CargoID  ctype,
IndustryID  ind 
)
inlinestatic

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

Parameters
companyCompany performing the transport.
ctypeCargo type being transported.
indIndustry providing or accepting the cargo.
Returns
The encoded cargo/company/industry number.

Definition at line 61 of file cargomonitor.h.

Referenced by AddCargoDelivery().

◆ EncodeCargoTownMonitor()

static CargoMonitorID EncodeCargoTownMonitor ( CompanyID  company,
CargoID  ctype,
TownID  town 
)
inlinestatic

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

Parameters
companyCompany performing the transport.
ctypeCargo type being transported.
townTown providing or accepting the cargo.
Returns
The encoded cargo/company/town number.

Definition at line 80 of file cargomonitor.h.

Referenced by AddCargoDelivery().

◆ GetDeliveryAmount()

int32 GetDeliveryAmount ( CargoMonitorID  monitor,
bool  keep_monitoring 
)

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

Parameters
monitorCargo monitor to query.
keep_monitoringAfter returning from this call, continue monitoring.
Returns
Amount of delivered cargo for the monitored combination.

Definition at line 95 of file cargomonitor.cpp.

References _cargo_deliveries, and GetAmount().

◆ GetPickupAmount()

int32 GetPickupAmount ( CargoMonitorID  monitor,
bool  keep_monitoring 
)

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

Parameters
monitorMonitoring number to query.
keep_monitoringAfter 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 107 of file cargomonitor.cpp.

References _cargo_pickups, and GetAmount().

◆ MonitorMonitorsIndustry()

static bool MonitorMonitorsIndustry ( CargoMonitorID  num)
inlinestatic

Does the cargo number monitor an industry or a town?

Parameters
numCargo monitoring number to decode.
Returns
true if monitoring an industry, false if monitoring a town.

Definition at line 116 of file cargomonitor.h.

References CCB_IS_INDUSTRY_BIT, and HasBit().

Referenced by DecodeMonitorIndustry(), and DecodeMonitorTown().