# AICargo Class Reference

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

`#include <ai_cargo.hpp>`

Inheritance diagram for AICargo:

## Public Types
enum | CargoClass { CC_PASSENGERS = 1 << 0, CC_MAIL = 1 << 1, CC_EXPRESS = 1 << 2, CC_ARMOURED = 1 << 3, CC_BULK = 1 << 4, CC_PIECE_GOODS = 1 << 5, CC_LIQUID = 1 << 6, CC_REFRIGERATED = 1 << 7, CC_HAZARDOUS = 1 << 8, CC_COVERED = 1 << 9 }
| The classes of cargo (from newgrf_cargo.h). More...
enum | TownEffect { TE_NONE = 0, TE_PASSENGERS = 1, TE_MAIL = 2, TE_GOODS = 3, TE_WATER = 4, TE_FOOD = 5 }
| The effects a cargo can have on a town. More...
## Static Public Member Functions
static const char * | GetClassName ()
| Get the name of this class to identify it towards squirrel.
static bool | IsValidCargo (CargoID cargo_type)
| Checks whether the given cargo type is valid.
static char * | GetCargoLabel (CargoID cargo_type)
| Gets the string representation of the cargo label.
static bool | IsFreight (CargoID cargo_type)
| Checks whether the give cargo is a freight or not.
static bool | HasCargoClass (CargoID cargo_type, CargoClass cargo_class)
| Check if this cargo is in the requested cargo class.
static TownEffect | GetTownEffect (CargoID cargo_type)
| Get the effect this cargo has on a town.
static Money | GetCargoIncome (CargoID cargo_type, uint32 distance, uint32 days_in_transit)
| Get the income for transporting a piece of cargo over the given distance within the specified time.

## Detailed Description

Class that handles all cargo related functions.

Definition at line 20 of file ai_cargo.hpp.

## Member Enumeration Documentation

enum AICargo::CargoClass

The classes of cargo (from newgrf_cargo.h).

Enumerator:

  CC_PASSENGERS | Passengers. Cargos of this class appear at bus stops. Cargos not of this class appear at truck stops.
  CC_MAIL | Mail.
  CC_EXPRESS | Express cargo (Goods, Food, Candy, but also possible for passengers).
  CC_ARMOURED | Armoured cargo (Valuables, Gold, Diamonds).
  CC_BULK | Bulk cargo (Coal, Grain etc., Ores, Fruit).
  CC_PIECE_GOODS | Piece goods (Livestock, Wood, Steel, Paper).
  CC_LIQUID | Liquids (Oil, Water, Rubber).
  CC_REFRIGERATED | Refrigerated cargo (Food, Fruit).
  CC_HAZARDOUS | Hazardous cargo (Nuclear Fuel, Explosives, etc.).
  CC_COVERED | Covered/Sheltered Freight (Transporation in Box Vans, Silo Wagons, etc.).

Definition at line 28 of file ai_cargo.hpp.

enum AICargo::TownEffect

The effects a cargo can have on a town.

Enumerator:

  TE_NONE | This cargo has no effect on a town.
  TE_PASSENGERS | This cargo supplies passengers to a town.
  TE_MAIL | This cargo supplies mail to a town.
  TE_GOODS | This cargo supplies goods to a town.
  TE_WATER | This cargo supplies water to a town.
  TE_FOOD | This cargo supplies food to a town.

Definition at line 44 of file ai_cargo.hpp.

## Member Function Documentation

Money AICargo::GetCargoIncome | ( | CargoID | cargo_type,
|  | uint32 | distance,
|  | uint32 | days_in_transit |
| ) |  |  | `[static]`

Get the income for transporting a piece of cargo over the given distance within the specified time.

Parameters:

  | cargo_type | The cargo to transport.

Precondition:
  AICargo::IsValidCargo(cargo_type).

Parameters:

  | distance | The distance the cargo travels from begin to end.
  | days_in_transit | Amount of (game) days the cargo is in transit. The max value of this variable is 637. Any value higher returns the same as 637 would.

Returns:
  The amount of money that would be earned by this trip.

Definition at line 58 of file ai_cargo.cpp.

References Clamp(), and IsValidCargo().

char * AICargo::GetCargoLabel | ( | CargoID | cargo_type | ) | `[static]`

Gets the string representation of the cargo label.

Parameters:

  | cargo_type | The cargo to get the string representation of.

Precondition:
  AICargo::IsValidCargo(cargo_type).

Returns:
  The cargo label.

Note:
  Never use this to check if it is a certain cargo. NewGRF can redefine all of the names.

Definition at line 23 of file ai_cargo.cpp.

References GB(), CargoSpec::Get(), IsValidCargo(), and CargoSpec::label.

static const char* AICargo::GetClassName | ( |  | ) | `[inline, static]`

Get the name of this class to identify it towards squirrel.

Definition at line 23 of file ai_cargo.hpp.

AICargo::TownEffect AICargo::GetTownEffect | ( | CargoID | cargo_type | ) | `[static]`

Get the effect this cargo has on a town.

Parameters:

  | cargo_type | The cargo to check on.

Precondition:
  AICargo::IsValidCargo(cargo_type).

Returns:
  The effect this cargo has on a town, or TE_NONE if it has no effect.

Definition at line 51 of file ai_cargo.cpp.

References CargoSpec::Get(), IsValidCargo(), and TE_NONE.

Referenced by AITown::GetLastMonthProduction(), AITown::GetLastMonthTransported(), and AITown::GetLastMonthTransportedPercentage().

bool AICargo::HasCargoClass | ( | CargoID | cargo_type,
|  | CargoClass | cargo_class |
| ) |  |  | `[static]`

Check if this cargo is in the requested cargo class.

Parameters:

  | cargo_type | The cargo to check on.

Precondition:
  AICargo::IsValidCargo(cargo_type).

Parameters:

  | cargo_class | The class to check for.

Returns:
  True if and only if the cargo is in the cargo class.

Definition at line 45 of file ai_cargo.cpp.

References IsCargoInClass(), and IsValidCargo().

Referenced by AIEngine::CanPullCargo(), and AIRoad::GetRoadVehicleTypeForCargo().

bool AICargo::IsFreight | ( | CargoID | cargo_type | ) | `[static]`

Checks whether the give cargo is a freight or not.

This defines whether the "freight train weight multiplier" will apply to trains transporting this cargo.

Parameters:

  | cargo_type | The cargo to check on.

Precondition:
  AICargo::IsValidCargo(cargo_type).

Returns:
  True if and only if the cargo is freight.

Definition at line 38 of file ai_cargo.cpp.

References CargoSpec::Get(), CargoSpec::is_freight, and IsValidCargo().

bool AICargo::IsValidCargo | ( | CargoID | cargo_type | ) | `[static]`

Checks whether the given cargo type is valid.

Parameters:

  | cargo_type | The cargo to check.

Returns:
  True if and only if the cargo type is valid.

Definition at line 18 of file ai_cargo.cpp.

References CargoSpec::Get(), and NUM_CARGO.

Referenced by AIEngine::CanPullCargo(), AIEngine::CanRefitCargo(), AIVehicle::GetCapacity(), GetCargoIncome(), GetCargoLabel(), AIVehicle::GetCargoLoad(), AIStation::GetCargoRating(), AIStation::GetCargoWaiting(), AITown::GetLastMonthProduction(), AIIndustry::GetLastMonthProduction(), AITown::GetLastMonthTransported(), AIIndustry::GetLastMonthTransported(), AITown::GetLastMonthTransportedPercentage(), AIIndustry::GetLastMonthTransportedPercentage(), AIVehicle::GetRefitCapacity(), AIIndustry::GetStockpiledCargo(), GetTownEffect(), HasCargoClass(), AIIndustry::IsCargoAccepted(), IsFreight(), and AIVehicle::RefitVehicle().

The documentation for this class was generated from the following files:

- src/ai/api/ai_cargo.hpp
- src/ai/api/ai_cargo.cpp