2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-15 21:56:00 +00:00
|
|
|
/** @file cargo_type.h Types related to cargoes... */
|
2007-12-21 22:50:51 +00:00
|
|
|
|
|
|
|
#ifndef CARGO_TYPE_H
|
|
|
|
#define CARGO_TYPE_H
|
|
|
|
|
2009-08-07 22:23:34 +00:00
|
|
|
#include "core/enum_type.hpp"
|
|
|
|
|
2009-12-05 21:39:28 +00:00
|
|
|
/**
|
|
|
|
* Cargo slots to indicate a cargo type within a game.
|
|
|
|
* Numbers are re-used between different climates.
|
|
|
|
* @see CargoTypes
|
|
|
|
*/
|
2007-12-21 22:50:51 +00:00
|
|
|
typedef byte CargoID;
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
/** Available types of cargo */
|
2018-05-21 21:08:39 +00:00
|
|
|
enum CargoType {
|
2008-10-19 09:51:19 +00:00
|
|
|
/* Temperate */
|
2007-12-21 22:50:51 +00:00
|
|
|
CT_PASSENGERS = 0,
|
|
|
|
CT_COAL = 1,
|
|
|
|
CT_MAIL = 2,
|
|
|
|
CT_OIL = 3,
|
|
|
|
CT_LIVESTOCK = 4,
|
|
|
|
CT_GOODS = 5,
|
|
|
|
CT_GRAIN = 6,
|
|
|
|
CT_WOOD = 7,
|
|
|
|
CT_IRON_ORE = 8,
|
|
|
|
CT_STEEL = 9,
|
|
|
|
CT_VALUABLES = 10,
|
|
|
|
|
2008-10-19 09:51:19 +00:00
|
|
|
/* Arctic */
|
2007-12-21 22:50:51 +00:00
|
|
|
CT_WHEAT = 6,
|
|
|
|
CT_HILLY_UNUSED = 8,
|
|
|
|
CT_PAPER = 9,
|
|
|
|
CT_GOLD = 10,
|
|
|
|
CT_FOOD = 11,
|
|
|
|
|
2008-10-19 09:51:19 +00:00
|
|
|
/* Tropic */
|
2007-12-21 22:50:51 +00:00
|
|
|
CT_RUBBER = 1,
|
|
|
|
CT_FRUIT = 4,
|
|
|
|
CT_MAIZE = 6,
|
|
|
|
CT_COPPER_ORE = 8,
|
|
|
|
CT_WATER = 9,
|
|
|
|
CT_DIAMONDS = 10,
|
|
|
|
|
2008-10-19 09:51:19 +00:00
|
|
|
/* Toyland */
|
2007-12-21 22:50:51 +00:00
|
|
|
CT_SUGAR = 1,
|
|
|
|
CT_TOYS = 3,
|
|
|
|
CT_BATTERIES = 4,
|
|
|
|
CT_CANDY = 5,
|
|
|
|
CT_TOFFEE = 6,
|
|
|
|
CT_COLA = 7,
|
|
|
|
CT_COTTON_CANDY = 8,
|
|
|
|
CT_BUBBLES = 9,
|
|
|
|
CT_PLASTIC = 10,
|
|
|
|
CT_FIZZY_DRINKS = 11,
|
|
|
|
|
2018-06-26 12:32:58 +00:00
|
|
|
NUM_CARGO = 64, ///< Maximal number of cargo types in a game.
|
2007-12-21 22:50:51 +00:00
|
|
|
|
2011-11-04 00:38:51 +00:00
|
|
|
CT_AUTO_REFIT = 0xFD, ///< Automatically choose cargo type when doing auto refitting.
|
2009-12-05 21:39:28 +00:00
|
|
|
CT_NO_REFIT = 0xFE, ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
|
|
|
|
CT_INVALID = 0xFF, ///< Invalid cargo type.
|
2007-12-21 22:50:51 +00:00
|
|
|
};
|
|
|
|
|
2018-07-26 21:09:35 +00:00
|
|
|
/** Test whether cargo type is not CT_INVALID */
|
|
|
|
inline bool IsCargoTypeValid(CargoType t) { return t != CT_INVALID; }
|
|
|
|
/** Test whether cargo type is not CT_INVALID */
|
|
|
|
inline bool IsCargoIDValid(CargoID t) { return t != CT_INVALID; }
|
|
|
|
|
2018-06-26 12:32:58 +00:00
|
|
|
typedef uint64 CargoTypes;
|
2018-05-21 21:08:39 +00:00
|
|
|
|
2018-07-02 20:47:55 +00:00
|
|
|
static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
|
2018-05-21 21:08:39 +00:00
|
|
|
|
2009-06-27 21:06:58 +00:00
|
|
|
/** Class for storing amounts of cargo */
|
|
|
|
struct CargoArray {
|
|
|
|
private:
|
2009-12-05 21:39:28 +00:00
|
|
|
uint amount[NUM_CARGO]; ///< Amount of each type of cargo.
|
2009-06-27 21:06:58 +00:00
|
|
|
|
|
|
|
public:
|
2009-12-05 21:39:28 +00:00
|
|
|
/** Default constructor. */
|
2011-12-20 17:57:56 +00:00
|
|
|
inline CargoArray()
|
2009-06-27 21:06:58 +00:00
|
|
|
{
|
|
|
|
this->Clear();
|
|
|
|
}
|
|
|
|
|
2009-12-05 21:39:28 +00:00
|
|
|
/** Reset all entries. */
|
2011-12-20 17:57:56 +00:00
|
|
|
inline void Clear()
|
2009-06-27 21:06:58 +00:00
|
|
|
{
|
|
|
|
memset(this->amount, 0, sizeof(this->amount));
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Read/write access to an amount of a specific cargo type.
|
2009-12-05 21:39:28 +00:00
|
|
|
* @param cargo Cargo type to access.
|
|
|
|
*/
|
2011-12-20 17:57:56 +00:00
|
|
|
inline uint &operator[](CargoID cargo)
|
2009-06-27 21:06:58 +00:00
|
|
|
{
|
|
|
|
return this->amount[cargo];
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Read-only access to an amount of a specific cargo type.
|
2009-12-05 21:39:28 +00:00
|
|
|
* @param cargo Cargo type to access.
|
|
|
|
*/
|
2011-12-20 17:57:56 +00:00
|
|
|
inline const uint &operator[](CargoID cargo) const
|
2009-06-27 21:06:58 +00:00
|
|
|
{
|
|
|
|
return this->amount[cargo];
|
|
|
|
}
|
2012-01-20 20:18:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the sum of all cargo amounts.
|
|
|
|
* @return The sum.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
inline const T GetSum() const
|
|
|
|
{
|
|
|
|
T ret = 0;
|
|
|
|
for (size_t i = 0; i < lengthof(this->amount); i++) {
|
|
|
|
ret += this->amount[i];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the amount of cargos that have an amount.
|
|
|
|
* @return The amount.
|
|
|
|
*/
|
|
|
|
inline byte GetCount() const
|
|
|
|
{
|
|
|
|
byte count = 0;
|
|
|
|
for (size_t i = 0; i < lengthof(this->amount); i++) {
|
|
|
|
if (this->amount[i] != 0) count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2009-06-27 21:06:58 +00:00
|
|
|
};
|
2007-12-21 22:50:51 +00:00
|
|
|
|
2009-08-07 22:23:34 +00:00
|
|
|
|
2009-08-08 16:42:55 +00:00
|
|
|
/** Types of cargo source and destination */
|
2019-04-22 08:28:09 +00:00
|
|
|
enum SourceType : byte {
|
2009-08-08 16:42:55 +00:00
|
|
|
ST_INDUSTRY, ///< Source/destination is an industry
|
|
|
|
ST_TOWN, ///< Source/destination is a town
|
|
|
|
ST_HEADQUARTERS, ///< Source/destination are company headquarters
|
2009-08-07 22:23:34 +00:00
|
|
|
};
|
|
|
|
|
2009-08-08 16:42:55 +00:00
|
|
|
typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
|
2009-08-07 22:23:34 +00:00
|
|
|
static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
|
|
|
|
|
2008-10-19 15:39:12 +00:00
|
|
|
#endif /* CARGO_TYPE_H */
|