2007-03-23 20:55:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 21:21:05 +01:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 16:11:33 +01:00
|
|
|
/** @file newgrf_cargo.cpp Implementation of NewGRF cargoes. */
|
|
|
|
|
2007-03-23 20:55:45 +00:00
|
|
|
#include "stdafx.h"
|
2007-03-26 09:43:14 +01:00
|
|
|
#include "debug.h"
|
2007-03-23 20:55:45 +00:00
|
|
|
#include "newgrf_spritegroup.h"
|
|
|
|
|
|
|
|
static uint32 CargoGetRandomBits(const ResolverObject *object)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32 CargoGetTriggers(const ResolverObject *object)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CargoSetTriggers(const ResolverObject *object, int triggers)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-08 17:23:30 +00:00
|
|
|
static uint32 CargoGetVariable(const ResolverObject *object, byte variable, uint32 parameter, bool *available)
|
2007-03-23 20:55:45 +00:00
|
|
|
{
|
2010-11-15 16:43:46 +00:00
|
|
|
DEBUG(grf, 1, "Unhandled cargo variable 0x%X", variable);
|
2007-03-26 09:43:14 +01:00
|
|
|
|
2007-03-23 20:55:45 +00:00
|
|
|
*available = false;
|
2009-02-18 09:14:41 +00:00
|
|
|
return UINT_MAX;
|
2007-03-23 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 13:13:42 +01:00
|
|
|
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const RealSpriteGroup *group)
|
2007-03-23 20:55:45 +00:00
|
|
|
{
|
2007-05-20 10:17:42 +01:00
|
|
|
/* Cargo action 2s should always have only 1 "loaded" state, but some
|
|
|
|
* times things don't follow the spec... */
|
2009-05-23 13:13:42 +01:00
|
|
|
if (group->num_loaded > 0) return group->loaded[0];
|
|
|
|
if (group->num_loading > 0) return group->loading[0];
|
2007-03-23 20:55:45 +00:00
|
|
|
|
2007-05-20 10:17:42 +01:00
|
|
|
return NULL;
|
2007-03-23 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
|
|
|
|
{
|
|
|
|
res->GetRandomBits = &CargoGetRandomBits;
|
|
|
|
res->GetTriggers = &CargoGetTriggers;
|
|
|
|
res->SetTriggers = &CargoSetTriggers;
|
|
|
|
res->GetVariable = &CargoGetVariable;
|
|
|
|
res->ResolveReal = &CargoResolveReal;
|
|
|
|
|
|
|
|
res->u.cargo.cs = cs;
|
|
|
|
|
2007-07-25 20:06:29 +01:00
|
|
|
res->callback = CBID_NO_CALLBACK;
|
2007-03-23 20:55:45 +00:00
|
|
|
res->callback_param1 = 0;
|
|
|
|
res->callback_param2 = 0;
|
2011-07-04 21:31:57 +01:00
|
|
|
res->ResetState();
|
|
|
|
|
2008-07-30 19:23:12 +01:00
|
|
|
res->grffile = cs->grffile;
|
2007-03-23 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SpriteID GetCustomCargoSprite(const CargoSpec *cs)
|
|
|
|
{
|
|
|
|
const SpriteGroup *group;
|
|
|
|
ResolverObject object;
|
|
|
|
|
|
|
|
NewCargoResolver(&object, cs);
|
|
|
|
|
2009-05-23 16:25:52 +01:00
|
|
|
group = SpriteGroup::Resolve(cs->group, &object);
|
2009-05-23 13:13:42 +01:00
|
|
|
if (group == NULL) return 0;
|
2007-03-23 20:55:45 +00:00
|
|
|
|
2009-05-23 13:13:42 +01:00
|
|
|
return group->GetResult();
|
2007-03-23 20:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-25 20:06:29 +01:00
|
|
|
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
|
2007-03-23 20:55:45 +00:00
|
|
|
{
|
|
|
|
ResolverObject object;
|
|
|
|
const SpriteGroup *group;
|
|
|
|
|
|
|
|
NewCargoResolver(&object, cs);
|
|
|
|
object.callback = callback;
|
|
|
|
object.callback_param1 = param1;
|
|
|
|
object.callback_param2 = param2;
|
|
|
|
|
2009-05-23 16:25:52 +01:00
|
|
|
group = SpriteGroup::Resolve(cs->group, &object);
|
2009-05-23 13:13:42 +01:00
|
|
|
if (group == NULL) return CALLBACK_FAILED;
|
2007-03-23 20:55:45 +00:00
|
|
|
|
2009-05-23 13:13:42 +01:00
|
|
|
return group->GetCallbackResult();
|
2007-03-23 20:55:45 +00:00
|
|
|
}
|
2007-04-13 20:32:18 +01:00
|
|
|
|
2012-02-07 22:46:26 +00:00
|
|
|
/**
|
|
|
|
* 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 CT_INVALID if the cargo is not available.
|
|
|
|
*/
|
2007-10-13 03:23:11 +01:00
|
|
|
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
|
2007-04-13 20:32:18 +01:00
|
|
|
{
|
2012-02-08 18:11:49 +00:00
|
|
|
/* 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) return cargo;
|
|
|
|
|
|
|
|
/* Other cases use (possibly translated) cargobits */
|
|
|
|
|
2012-05-25 21:57:36 +01:00
|
|
|
if (grffile->cargo_list.Length() > 0) {
|
2012-02-08 18:11:49 +00:00
|
|
|
/* ...and the cargo is in bounds, then get the cargo ID for
|
|
|
|
* the label */
|
2012-05-25 21:57:36 +01:00
|
|
|
if (cargo < grffile->cargo_list.Length()) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
|
2012-02-08 18:11:49 +00:00
|
|
|
} else {
|
2007-10-13 03:23:11 +01:00
|
|
|
/* Else the cargo value is a 'climate independent' 'bitnum' */
|
2012-02-07 22:46:26 +00:00
|
|
|
return GetCargoIDByBitnum(cargo);
|
2007-10-13 03:23:11 +01:00
|
|
|
}
|
|
|
|
return CT_INVALID;
|
2007-04-13 20:32:18 +01:00
|
|
|
}
|