Files
@ r28520:f9aebe299cae
Branch filter:
Location: cpp/openttd-patchpack/source/src/newgrf_cargo.cpp - annotation
r28520:f9aebe299cae
3.5 KiB
text/x-c
Codechange: MacOS already has MIN/MAX macros defined
This is caused because we use PreCompile Headers, and one of them
includes a system headers which defines MIN/MAX.
This is caused because we use PreCompile Headers, and one of them
includes a system headers which defines MIN/MAX.
r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r6365:410001496130 r6383:09891b2cc6e4 r6365:410001496130 r6365:410001496130 r21383:942c32fb8b0e r21383:942c32fb8b0e r19738:837a139219f0 r19726:fb3262da438d r24069:49625df81342 r24069:49625df81342 r27737:728d55b97775 r6365:410001496130 r24069:49625df81342 r27737:728d55b97775 r19726:fb3262da438d r6383:09891b2cc6e4 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r27737:728d55b97775 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r24069:49625df81342 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r27737:728d55b97775 r24069:49625df81342 r6365:410001496130 r21299:8973364c4b52 r6365:410001496130 r6365:410001496130 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r19738:837a139219f0 r6365:410001496130 r6365:410001496130 r19726:fb3262da438d r21299:8973364c4b52 r23607:36c15679007d r6365:410001496130 r11985:d8202dea2203 r6365:410001496130 r6365:410001496130 r6365:410001496130 r27737:728d55b97775 r6365:410001496130 r19726:fb3262da438d r21299:8973364c4b52 r6365:410001496130 r6460:74b53af67ae0 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r19046:7fa5045a9a14 r28422:76582babb47f r19046:7fa5045a9a14 r27737:728d55b97775 r6460:74b53af67ae0 r19049:47de46c9ad63 r24633:c06360c1c210 r28422:76582babb47f r24633:c06360c1c210 r24633:c06360c1c210 r19049:47de46c9ad63 r19049:47de46c9ad63 r19049:47de46c9ad63 r28026:b046b2f1f539 r19049:47de46c9ad63 r19049:47de46c9ad63 r23520:20bbc807b0eb r19049:47de46c9ad63 r7717:a88200b1847a r19046:7fa5045a9a14 r7717:a88200b1847a r28422:76582babb47f r6460:74b53af67ae0 | /*
* 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 newgrf_cargo.cpp Implementation of NewGRF cargoes. */
#include "stdafx.h"
#include "debug.h"
#include "newgrf_spritegroup.h"
#include "safeguards.h"
/** Resolver of cargo. */
struct CargoResolverObject : public ResolverObject {
const CargoSpec *cargospec;
CargoResolverObject(const CargoSpec *cs, CallbackID callback = CBID_NO_CALLBACK, uint32_t callback_param1 = 0, uint32_t callback_param2 = 0);
GrfSpecFeature GetFeature() const override;
uint32_t GetDebugID() const override;
};
GrfSpecFeature CargoResolverObject::GetFeature() const
{
return GSF_CARGOES;
}
uint32_t CargoResolverObject::GetDebugID() const
{
return this->cargospec->label;
}
/**
* Constructor of the cargo resolver.
* @param cs Cargo being resolved.
* @param callback Callback ID.
* @param callback_param1 First parameter (var 10) of the callback.
* @param callback_param2 Second parameter (var 18) of the callback.
*/
CargoResolverObject::CargoResolverObject(const CargoSpec *cs, CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
: ResolverObject(cs->grffile, callback, callback_param1, callback_param2), cargospec(cs)
{
this->root_spritegroup = cs->group;
}
/**
* Get the custom sprite for the given cargo type.
* @param cs Cargo being queried.
* @return Custom sprite to draw, or \c 0 if not available.
*/
SpriteID GetCustomCargoSprite(const CargoSpec *cs)
{
CargoResolverObject object(cs);
const SpriteGroup *group = object.Resolve();
if (group == nullptr) return 0;
return group->GetResult();
}
uint16_t GetCargoCallback(CallbackID callback, uint32_t param1, uint32_t param2, const CargoSpec *cs)
{
CargoResolverObject object(cs, callback, param1, param2);
return object.ResolveCallback();
}
/**
* Translate a GRF-local cargo slot/bitnum into a CargoID.
* @param cargo GRF-local cargo slot/bitnum.
* @param grffile Originating GRF file.
* @param usebit Defines the meaning of \a cargo for GRF version < 7.
* If true, then \a cargo is a bitnum. If false, then \a cargo is a cargoslot.
* For GRF version >= 7 \a cargo is always a translated cargo bit.
* @return CargoID or INVALID_CARGO if the cargo is not available.
*/
CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
{
/* Pre-version 7 uses the 'climate dependent' ID in callbacks and properties, i.e. cargo is the cargo ID */
if (grffile->grf_version < 7 && !usebit) {
if (cargo >= CargoSpec::GetArraySize() || !CargoSpec::Get(cargo)->IsValid()) return INVALID_CARGO;
return cargo;
}
/* Other cases use (possibly translated) cargobits */
if (!grffile->cargo_list.empty()) {
/* ...and the cargo is in bounds, then get the cargo ID for
* the label */
if (cargo < grffile->cargo_list.size()) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
} else {
/* Else the cargo value is a 'climate independent' 'bitnum' */
return GetCargoIDByBitnum(cargo);
}
return INVALID_CARGO;
}
|