Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "debug.h"
00014 #include "newgrf_spritegroup.h"
00015
00017 struct CargoResolverObject : public ResolverObject {
00018 CargoResolverObject(const CargoSpec *cs, CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
00019
00020 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
00021 };
00022
00023 const SpriteGroup *CargoResolverObject::ResolveReal(const RealSpriteGroup *group) const
00024 {
00025
00026
00027 if (group->num_loaded > 0) return group->loaded[0];
00028 if (group->num_loading > 0) return group->loading[0];
00029
00030 return NULL;
00031 }
00032
00040 CargoResolverObject::CargoResolverObject(const CargoSpec *cs, CallbackID callback, uint32 callback_param1, uint32 callback_param2)
00041 : ResolverObject(cs->grffile, callback, callback_param1, callback_param2)
00042 {
00043 this->root_spritegroup = cs->group;
00044 }
00045
00051 SpriteID GetCustomCargoSprite(const CargoSpec *cs)
00052 {
00053 CargoResolverObject object(cs);
00054 const SpriteGroup *group = object.Resolve();
00055 if (group == NULL) return 0;
00056
00057 return group->GetResult();
00058 }
00059
00060
00061 uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs)
00062 {
00063 CargoResolverObject object(cs, callback, param1, param2);
00064 return object.ResolveCallback();
00065 }
00066
00076 CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
00077 {
00078
00079 if (grffile->grf_version < 7 && !usebit) return cargo;
00080
00081
00082
00083 if (grffile->cargo_list.Length() > 0) {
00084
00085
00086 if (cargo < grffile->cargo_list.Length()) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
00087 } else {
00088
00089 return GetCargoIDByBitnum(cargo);
00090 }
00091 return CT_INVALID;
00092 }