newgrf_station.h

Go to the documentation of this file.
00001 /* $Id: newgrf_station.h 26085 2013-11-24 14:41:19Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
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   /* virtual */ uint32 GetRandomBits() const;
00036   /* virtual */ uint32 GetTriggers() const;
00037   /* virtual */ void SetTriggers(int triggers) const;
00038 
00039   /* virtual */ 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   /* virtual */ 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         /* FALL-THROUGH */
00063       }
00064 
00065       default:
00066         return ResolverObject::GetScope(scope, relative);
00067     }
00068   }
00069 
00070   /* virtual */ 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 /* Station layout for given dimensions - it is a two-dimensional array
00104  * where index is computed as (x * platforms) + platform. */
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 /* Evaluate a tile's position within a station, and return the result a bitstuffed format. */
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 /* Allocate a StationSpec to a Station. This is called once per build operation. */
00179 int AllocateSpecToStation(const StationSpec *statspec, BaseStation *st, bool exec);
00180 
00181 /* Deallocate a StationSpec from a Station. Called when removing a single station tile. */
00182 void DeallocateSpecFromStation(BaseStation *st, byte specindex);
00183 
00184 /* Draw representation of a station tile for GUI purposes. */
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 /* NEWGRF_STATION_H */