Files
@ r28537:045dd8e45363
Branch filter:
Location: cpp/openttd-patchpack/source/src/cargo_type.h - annotation
r28537:045dd8e45363
4.2 KiB
text/x-c
Codechange: prevent out-of-bound read (even if the result is never used) (#11853)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r18668:b656d614c4fd r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r12642:9f166415b666 r12642:9f166415b666 r13874:a3b7b89e1abf r13874:a3b7b89e1abf r13874:a3b7b89e1abf r13874:a3b7b89e1abf r13874:a3b7b89e1abf r8119:8fdb3a371896 r8119:8fdb3a371896 r10260:88d82a40120c r22867:9bff1c966805 r10259:a52ae130587e r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r10259:a52ae130587e r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r10259:a52ae130587e r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r10259:a52ae130587e r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r8119:8fdb3a371896 r13874:a3b7b89e1abf r8119:8fdb3a371896 r8119:8fdb3a371896 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28422:76582babb47f r28422:76582babb47f r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r28423:a991b75e9b00 r23042:322861acac4e r27420:b37b70eb3169 r28422:76582babb47f r28422:76582babb47f r23042:322861acac4e r27737:728d55b97775 r22867:9bff1c966805 r22945:4ef2e91b5537 r22867:9bff1c966805 r12253:9cc92893e2d0 r27424:6a028979ce01 r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r27424:6a028979ce01 r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r18961:b2e758c9533f r27424:6a028979ce01 r18961:b2e758c9533f r27424:6a028979ce01 r18961:b2e758c9533f r12253:9cc92893e2d0 r8119:8fdb3a371896 r12642:9f166415b666 r12648:24c912bd53f6 r27106:2d95beb51290 r27106:2d95beb51290 r27106:2d95beb51290 r27106:2d95beb51290 r12642:9f166415b666 r12642:9f166415b666 r27737:728d55b97775 r12642:9f166415b666 r12642:9f166415b666 r10260:88d82a40120c | /*
* 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/>.
*/
/** @file cargo_type.h Types related to cargoes... */
#ifndef CARGO_TYPE_H
#define CARGO_TYPE_H
#include "core/enum_type.hpp"
/**
* Cargo slots to indicate a cargo type within a game.
* Numbers are re-used between different climates.
* @see CargoTypes
*/
typedef byte CargoID;
/** Available types of cargo */
enum CargoType {
/* Temperate */
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,
/* Arctic */
CT_WHEAT = 6,
CT_HILLY_UNUSED = 8,
CT_PAPER = 9,
CT_GOLD = 10,
CT_FOOD = 11,
/* Tropic */
CT_RUBBER = 1,
CT_FRUIT = 4,
CT_MAIZE = 6,
CT_COPPER_ORE = 8,
CT_WATER = 9,
CT_DIAMONDS = 10,
/* Toyland */
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,
CT_INVALID = 0xFF, ///< Invalid cargo type.
};
static const CargoID NUM_ORIGINAL_CARGO = 12; ///< Original number of cargo types.
static const CargoID NUM_CARGO = 64; ///< Maximum number of cargo types in a game.
/* CARGO_AUTO_REFIT and CARGO_NO_REFIT are stored in save-games for refit-orders, so should not be changed. */
static const CargoID CARGO_AUTO_REFIT = 0xFD; ///< Automatically choose cargo type when doing auto refitting.
static const CargoID CARGO_NO_REFIT = 0xFE; ///< Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-renew).
static const CargoID INVALID_CARGO = UINT8_MAX;
/**
* Special cargo filter criteria.
* These are used by user interface code only and must not be assigned to any entity. Not all values are valid for every UI filter.
*/
namespace CargoFilterCriteria {
static constexpr CargoID CF_ANY = NUM_CARGO; ///< Show all items independent of carried cargo (i.e. no filtering)
static constexpr CargoID CF_NONE = NUM_CARGO + 1; ///< Show only items which do not carry cargo (e.g. train engines)
static constexpr CargoID CF_ENGINES = NUM_CARGO + 2; ///< Show only engines (for rail vehicles only)
static constexpr CargoID CF_FREIGHT = NUM_CARGO + 3; ///< Show only vehicles which carry any freight (non-passenger) cargo
};
/** Test whether cargo type is not CT_INVALID */
inline bool IsValidCargoType(CargoType t) { return t != CT_INVALID; }
/** Test whether cargo type is not INVALID_CARGO */
inline bool IsValidCargoID(CargoID t) { return t != INVALID_CARGO; }
typedef uint64_t CargoTypes;
static const CargoTypes ALL_CARGOTYPES = (CargoTypes)UINT64_MAX;
/** Class for storing amounts of cargo */
struct CargoArray : std::array<uint, NUM_CARGO> {
/**
* Get the sum of all cargo amounts.
* @return The sum.
*/
template <typename T>
inline const T GetSum() const
{
return std::reduce(this->begin(), this->end(), T{});
}
/**
* Get the amount of cargos that have an amount.
* @return The amount.
*/
inline uint GetCount() const
{
return std::count_if(this->begin(), this->end(), [](uint amount) { return amount != 0; });
}
};
/** Types of cargo source and destination */
enum class SourceType : byte {
Industry, ///< Source/destination is an industry
Town, ///< Source/destination is a town
Headquarters, ///< Source/destination are company headquarters
};
typedef uint16_t SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE)
static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source
#endif /* CARGO_TYPE_H */
|