00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef NEWGRF_STATION_H
00013 #define NEWGRF_STATION_H
00014
00015 #include "newgrf_animation_type.h"
00016 #include "newgrf_callbacks.h"
00017 #include "newgrf_class.h"
00018 #include "newgrf_commons.h"
00019 #include "cargo_type.h"
00020 #include "station_type.h"
00021 #include "rail_type.h"
00022 #include "newgrf_spritegroup.h"
00023 #include "newgrf_town.h"
00024
00026 struct StationScopeResolver : public ScopeResolver {
00027 TileIndex tile;
00028 struct BaseStation *st;
00029 const struct StationSpec *statspec;
00030 CargoID cargo_type;
00031 Axis axis;
00032
00033 StationScopeResolver(ResolverObject &ro, const StationSpec *statspec, BaseStation *st, TileIndex tile);
00034
00035 uint32 GetRandomBits() const;
00036 uint32 GetTriggers() const;
00037 void SetTriggers(int triggers) const;
00038
00039 uint32 GetVariable(byte variable, uint32 parameter, bool *available) const;
00040 };
00041
00043 struct StationResolverObject : public ResolverObject {
00044 StationScopeResolver station_scope;
00045 TownScopeResolver *town_scope;
00046
00047 StationResolverObject(const StationSpec *statspec, BaseStation *st, TileIndex tile,
00048 CallbackID callback = CBID_NO_CALLBACK, uint32 callback_param1 = 0, uint32 callback_param2 = 0);
00049 ~StationResolverObject();
00050
00051 TownScopeResolver *GetTown();
00052
00053 ScopeResolver *GetScope(VarSpriteGroupScope scope = VSG_SCOPE_SELF, byte relative = 0)
00054 {
00055 switch (scope) {
00056 case VSG_SCOPE_SELF:
00057 return &this->station_scope;
00058
00059 case VSG_SCOPE_PARENT: {
00060 TownScopeResolver *tsr = this->GetTown();
00061 if (tsr != NULL) return tsr;
00062
00063 }
00064
00065 default:
00066 return ResolverObject::GetScope(scope, relative);
00067 }
00068 }
00069
00070 const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const;
00071 };
00072
00073 enum StationClassID {
00074 STAT_CLASS_BEGIN = 0,
00075 STAT_CLASS_DFLT = 0,
00076 STAT_CLASS_WAYP,
00077 STAT_CLASS_MAX = 256,
00078 };
00079 typedef SimpleTinyEnumT<StationClassID, byte> StationClassIDByte;
00080 template <> struct EnumPropsT<StationClassID> : MakeEnumPropsT<StationClassID, byte, STAT_CLASS_BEGIN, STAT_CLASS_MAX, STAT_CLASS_MAX, 8> {};
00081
00083 DECLARE_POSTFIX_INCREMENT(StationClassID)
00084
00085 enum StationSpecFlags {
00086 SSF_SEPARATE_GROUND,
00087 SSF_DIV_BY_STATION_SIZE,
00088 SSF_CB141_RANDOM_BITS,
00089 SSF_CUSTOM_FOUNDATIONS,
00090 SSF_EXTENDED_FOUNDATIONS,
00091 };
00092
00094 enum StationRandomTrigger {
00095 SRT_NEW_CARGO,
00096 SRT_CARGO_TAKEN,
00097 SRT_TRAIN_ARRIVES,
00098 SRT_TRAIN_DEPARTS,
00099 SRT_TRAIN_LOADS,
00100 SRT_PATH_RESERVATION,
00101 };
00102
00103
00104
00105 typedef byte *StationLayout;
00106
00108 struct StationSpec {
00115 GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
00116 StationClassID cls_id;
00117 StringID name;
00118
00123 byte disallowed_platforms;
00128 byte disallowed_lengths;
00129
00138 uint tiles;
00139 NewGRFSpriteLayout *renderdata;
00140
00145 uint16 cargo_threshold;
00146
00147 uint32 cargo_triggers;
00148
00149 byte callback_mask;
00150
00151 byte flags;
00152
00153 byte pylons;
00154 byte wires;
00155 byte blocked;
00156
00157 AnimationInfo animation;
00158
00159 byte lengths;
00160 byte *platforms;
00161 StationLayout **layouts;
00162 bool copied_layouts;
00163 };
00164
00166 typedef NewGRFClass<StationSpec, StationClassID, STAT_CLASS_MAX> StationClass;
00167
00168 const StationSpec *GetStationSpec(TileIndex t);
00169
00170
00171 uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, int y, bool centred);
00172
00173 SpriteID GetCustomStationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint32 var10 = 0);
00174 SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, BaseStation *st, TileIndex tile, uint layout, uint edge_info);
00175 uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, BaseStation *st, TileIndex tile);
00176 CommandCost PerformStationTileSlopeCheck(TileIndex north_tile, TileIndex cur_tile, const StationSpec *statspec, Axis axis, byte plat_len, byte numtracks);
00177
00178
00179 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
00180
00181
00182 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
00183
00184
00185 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station);
00186
00187 void AnimateStationTile(TileIndex tile);
00188 void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = CT_INVALID);
00189 void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigger trigger, CargoID cargo_type = CT_INVALID);
00190 void StationUpdateCachedTriggers(BaseStation *st);
00191
00192 #endif