Translations update
[openttd/fttd.git] / src / newgrf_cargo.cpp
bloba0e518ee11c172c88a99dcb06c3d47ac30da1595
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file newgrf_cargo.cpp Implementation of NewGRF cargoes. */
12 #include "stdafx.h"
13 #include "debug.h"
14 #include "newgrf_spritegroup.h"
16 /** Resolver of cargo. */
17 struct CargoResolverObject : public ResolverObject {
18 /**
19 * Constructor of the cargo resolver.
20 * @param cs Cargo being resolved.
21 * @param callback Callback ID.
22 * @param param1 First parameter (var 10) of the callback.
23 * @param param2 Second parameter (var 18) of the callback.
25 CargoResolverObject (const CargoSpec *cs, CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0)
26 : ResolverObject (cs->grffile, callback, param1, param2)
30 /* virtual */ const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
33 /* virtual */ const SpriteGroup *CargoResolverObject::ResolveReal(const RealSpriteGroup *group) const
35 /* Cargo action 2s should always have only 1 "loaded" state, but some
36 * times things don't follow the spec... */
37 if (group->num_loaded > 0) return group->loaded[0];
38 if (group->num_loading > 0) return group->loading[0];
40 return NULL;
43 static inline const SpriteGroup *CargoResolve (const CargoSpec *cs,
44 CallbackID callback = CBID_NO_CALLBACK, uint32 param1 = 0, uint32 param2 = 0)
46 CargoResolverObject object (cs, callback, param1, param2);
47 return SpriteGroup::Resolve (cs->group, object);
50 /**
51 * Get the custom sprite for the given cargo type.
52 * @param cs Cargo being queried.
53 * @return Custom sprite to draw, or \c 0 if not available.
55 SpriteID GetCustomCargoSprite(const CargoSpec *cs)
57 const SpriteGroup *group = CargoResolve (cs);
58 if (group == NULL) return 0;
60 return group->GetResult();
64 uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
66 return SpriteGroup::CallbackResult (CargoResolve (cs, callback, param1, param2));
69 /**
70 * Translate a GRF-local cargo slot/bitnum into a CargoID.
71 * @param cargo GRF-local cargo slot/bitnum.
72 * @param grffile Originating GRF file.
73 * @param usebit Defines the meaning of \a cargo for GRF version < 7.
74 * If true, then \a cargo is a bitnum. If false, then \a cargo is a cargoslot.
75 * For GRF version >= 7 \a cargo is always a translated cargo bit.
76 * @return CargoID or CT_INVALID if the cargo is not available.
78 CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
80 /* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */
81 if (grffile->grf_version < 7 && !usebit) return cargo;
83 /* Other cases use (possibly translated) cargobits */
85 if (grffile->cargo_list.Length() > 0) {
86 /* ...and the cargo is in bounds, then get the cargo ID for
87 * the label */
88 if (cargo < grffile->cargo_list.Length()) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
89 } else {
90 /* Else the cargo value is a 'climate independent' 'bitnum' */
91 return GetCargoIDByBitnum(cargo);
93 return CT_INVALID;