|
|
/*
|
|
|
* 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 callback_param1 = 0, uint32 callback_param2 = 0);
|
|
|
|
|
|
const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override;
|
|
|
|
|
|
GrfSpecFeature GetFeature() const override;
|
|
|
uint32 GetDebugID() const override;
|
|
|
};
|
|
|
|
|
|
/* virtual */ const SpriteGroup *CargoResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
|
|
{
|
|
|
/* Cargo action 2s should always have only 1 "loaded" state, but some
|
|
|
* times things don't follow the spec... */
|
|
|
if (!group->loaded.empty()) return group->loaded[0];
|
|
|
if (!group->loading.empty()) return group->loading[0];
|
|
|
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
GrfSpecFeature CargoResolverObject::GetFeature() const
|
|
|
{
|
|
|
return GSF_CARGOES;
|
|
|
}
|
|
|
|
|
|
uint32 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 callback_param1, uint32 callback_param2)
|
|
|
: ResolverObject(cs->grffile, callback, callback_param1, callback_param2), cargospec(cs)
|
|
|
{
|
|
|
this->root_spritegroup = cs->group;
|
|
|
}
|
|
|
|
|
|
/**
|