OpenTTD Source: src/newgrf/newgrf_internal_vehicle.h Source File

OpenTTD Source 15.0-RC2

newgrf_internal_vehicle.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NEWGRF_INTERNAL_VEHICLE_H
11#define NEWGRF_INTERNAL_VEHICLE_H
12
13#include "../newgrf.h"
14#include "../engine_base.h"
15#include "../vehicle_func.h"
16#include "newgrf_internal.h"
17
19 struct GRFTempEngineData {
21 enum Refittability : uint8_t {
22 UNSET = 0,
23 EMPTY,
24 NONEMPTY,
25 };
26
27 CargoClasses cargo_allowed;
28 CargoClasses cargo_allowed_required;
29 CargoClasses cargo_disallowed;
30 std::vector<RailTypeLabel> railtypelabels;
31 uint8_t roadtramtype;
32 const GRFFile *defaultcargo_grf;
33 Refittability refittability;
34 uint8_t rv_max_speed;
35 CargoTypes ctt_include_mask;
36 CargoTypes ctt_exclude_mask;
37
42 void UpdateRefittability(bool non_empty)
43 {
44 if (non_empty) {
45 this->refittability = NONEMPTY;
46 } else if (this->refittability == UNSET) {
47 this->refittability = EMPTY;
48 }
49 }
50};
51
52extern TypedIndexContainer<std::vector<GRFTempEngineData>, EngineID> _gted;
53
54 Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access = false);
55void ConvertTTDBasePrice(uint32_t base_pointer, std::string_view error_location, Price *index);
56
63template <VehicleType T>
64 static inline bool IsValidNewGRFImageIndex(uint8_t image_index)
65{
66 return image_index == CUSTOM_VEHICLE_SPRITENUM || IsValidImageIndex<T>(image_index);
67}
68
69 ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteReader &buf);
70
71#endif /* NEWGRF_INTERNAL_VEHICLE_H */
ByteReader
Class to read from a NewGRF file.
Definition newgrf_bytereader.h:18
Engine
Definition engine_base.h:38
EnumBitSet< CargoClass, uint16_t >
TypedIndexContainer
A sort-of mixin that implements 'at(pos)' and 'operator[](pos)' only for a specific type.
Definition convertible_through_base.hpp:38
Price
Price
Enumeration of all base prices for use with Prices.
Definition economy_type.h:95
newgrf_internal.h
NewGRF internal processing state.
ChangeInfoResult
ChangeInfoResult
Possible return values for the GrfChangeInfoHandler functions.
Definition newgrf_internal.h:20
ConvertTTDBasePrice
void ConvertTTDBasePrice(uint32_t base_pointer, std::string_view error_location, Price *index)
Converts TTD(P) Base Price pointers into the enum used by OTTD See http://wiki.ttdpatch....
Definition newgrf.cpp:332
_gted
TypedIndexContainer< std::vector< GRFTempEngineData >, EngineID > _gted
Temporary engine data used during NewGRF loading.
Definition newgrf.cpp:78
CommonVehicleChangeInfo
ChangeInfoResult CommonVehicleChangeInfo(EngineInfo *ei, int prop, ByteReader &buf)
Define properties common to all vehicles.
Definition newgrf_act0.cpp:33
IsValidNewGRFImageIndex
static bool IsValidNewGRFImageIndex(uint8_t image_index)
Helper to check whether an image index is valid for a particular NewGRF vehicle.
Definition newgrf_internal_vehicle.h:64
GetNewEngine
Engine * GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access=false)
Returns the engine associated to a certain internal_id, resp.
Definition newgrf.cpp:214
EngineInfo
Information about a vehicle.
Definition engine_type.h:198
GRFFile
Dynamic data of a loaded NewGRF.
Definition newgrf.h:114
GRFTempEngineData
Temporary engine data used when loading only.
Definition newgrf_internal_vehicle.h:19
GRFTempEngineData::ctt_exclude_mask
CargoTypes ctt_exclude_mask
Cargo types always excluded from the refit mask.
Definition newgrf_internal_vehicle.h:36
GRFTempEngineData::Refittability
Refittability
Summary state of refittability properties.
Definition newgrf_internal_vehicle.h:21
GRFTempEngineData::UNSET
@ UNSET
No properties assigned. Default refit masks shall be activated.
Definition newgrf_internal_vehicle.h:22
GRFTempEngineData::EMPTY
@ EMPTY
GRF defined vehicle as not-refittable. The vehicle shall only carry the default cargo.
Definition newgrf_internal_vehicle.h:23
GRFTempEngineData::NONEMPTY
@ NONEMPTY
GRF defined the vehicle as refittable. If the refitmask is empty after translation (cargotypes not av...
Definition newgrf_internal_vehicle.h:24
GRFTempEngineData::refittability
Refittability refittability
Did the newgrf set any refittability property? If not, default refittability will be applied.
Definition newgrf_internal_vehicle.h:33
GRFTempEngineData::cargo_disallowed
CargoClasses cargo_disallowed
Bitmask of cargo classes that are disallowed as a refit.
Definition newgrf_internal_vehicle.h:29
GRFTempEngineData::ctt_include_mask
CargoTypes ctt_include_mask
Cargo types always included in the refit mask.
Definition newgrf_internal_vehicle.h:35
GRFTempEngineData::rv_max_speed
uint8_t rv_max_speed
Temporary storage of RV prop 15, maximum speed in mph/0.8.
Definition newgrf_internal_vehicle.h:34
GRFTempEngineData::cargo_allowed
CargoClasses cargo_allowed
Bitmask of cargo classes that are allowed as a refit.
Definition newgrf_internal_vehicle.h:27
GRFTempEngineData::UpdateRefittability
void UpdateRefittability(bool non_empty)
Update the summary refittability on setting a refittability property.
Definition newgrf_internal_vehicle.h:42
GRFTempEngineData::cargo_allowed_required
CargoClasses cargo_allowed_required
Bitmask of cargo classes that are required to be all present to allow a cargo as a refit.
Definition newgrf_internal_vehicle.h:28
GRFTempEngineData::defaultcargo_grf
const GRFFile * defaultcargo_grf
GRF defining the cargo translation table to use if the default cargo is the 'first refittable'.
Definition newgrf_internal_vehicle.h:32
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF >
CUSTOM_VEHICLE_SPRITENUM
@ CUSTOM_VEHICLE_SPRITENUM
Vehicle sprite from NewGRF.
Definition vehicle_func.h:28
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22