rail.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef RAIL_H
00013 #define RAIL_H
00014
00015 #include "rail_type.h"
00016 #include "track_type.h"
00017 #include "gfx_type.h"
00018 #include "core/bitmath_func.hpp"
00019 #include "economy_func.h"
00020 #include "slope_type.h"
00021 #include "strings_type.h"
00022
00023 enum RailTypeFlag {
00024 RTF_CATENARY = 0,
00025 };
00026
00027 enum RailTypeFlags {
00028 RTFB_NONE = 0,
00029 RTFB_CATENARY = 1 << RTF_CATENARY,
00030 };
00031 DECLARE_ENUM_AS_BIT_SET(RailTypeFlags);
00032
00036 enum RailFenceOffset {
00037 RFO_FLAT_X,
00038 RFO_FLAT_Y,
00039 RFO_FLAT_VERT,
00040 RFO_FLAT_HORZ,
00041 RFO_SLOPE_SW,
00042 RFO_SLOPE_SE,
00043 RFO_SLOPE_NE,
00044 RFO_SLOPE_NW,
00045 };
00046
00049 struct RailtypeInfo {
00052 struct {
00053 SpriteID track_y;
00054 SpriteID track_ns;
00055 SpriteID ground;
00056 SpriteID single_x;
00057 SpriteID single_y;
00058 SpriteID single_n;
00059 SpriteID single_s;
00060 SpriteID single_e;
00061 SpriteID single_w;
00062 SpriteID single_sloped;
00063 SpriteID crossing;
00064 SpriteID tunnel;
00065 } base_sprites;
00066
00069 struct {
00070 SpriteID build_ns_rail;
00071 SpriteID build_x_rail;
00072 SpriteID build_ew_rail;
00073 SpriteID build_y_rail;
00074 SpriteID auto_rail;
00075 SpriteID build_depot;
00076 SpriteID build_tunnel;
00077 SpriteID convert_rail;
00078 } gui_sprites;
00079
00080 struct {
00081 CursorID rail_ns;
00082 CursorID rail_swne;
00083 CursorID rail_ew;
00084 CursorID rail_nwse;
00085 CursorID autorail;
00086 CursorID depot;
00087 CursorID tunnel;
00088 CursorID convert;
00089 } cursor;
00090
00091 struct {
00092 StringID toolbar_caption;
00093 StringID menu_text;
00094 StringID build_caption;
00095 StringID replace_text;
00096 StringID new_loco;
00097 } strings;
00098
00100 SpriteID snow_offset;
00101
00103 RailTypes powered_railtypes;
00104
00106 RailTypes compatible_railtypes;
00107
00116 SpriteID total_offset;
00117
00121 SpriteID bridge_offset;
00122
00126 byte custom_ground_offset;
00127
00131 byte curve_speed;
00132
00136 RailTypeFlags flags;
00137
00141 uint8 cost_multiplier;
00142
00146 uint8 acceleration_type;
00147
00151 uint16 max_speed;
00152
00156 RailTypeLabel label;
00157 };
00158
00159
00165 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
00166 {
00167 extern RailtypeInfo _railtypes[RAILTYPE_END];
00168 assert(railtype < RAILTYPE_END);
00169 return &_railtypes[railtype];
00170 }
00171
00180 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
00181 {
00182 return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
00183 }
00184
00193 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
00194 {
00195 return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
00196 }
00197
00203 static inline Money RailBuildCost(RailType railtype)
00204 {
00205 assert(railtype < RAILTYPE_END);
00206 return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3;
00207 }
00208
00215 static inline Money RailConvertCost(RailType from, RailType to)
00216 {
00217
00218
00219
00220
00221 if (HasPowerOnRail(from, to)) {
00222 Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
00223 if (cost != 0) return cost;
00224 }
00225
00226
00227
00228
00229
00230 if (HasPowerOnRail(to, from)) {
00231 Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
00232 if (cost != 0) return cost;
00233 }
00234
00235
00236 return RailBuildCost(to) + _price[PR_CLEAR_RAIL];
00237 }
00238
00239 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
00240 Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
00241 int TicksToLeaveDepot(const Train *v);
00242
00243 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
00244
00245
00252 bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
00253
00259 bool ValParamRailtype(const RailType rail);
00260
00268 RailType GetBestRailtype(const CompanyID company);
00269
00275 RailTypes GetCompanyRailtypes(const CompanyID c);
00276
00282 RailType GetRailTypeByLabel(RailTypeLabel label);
00283
00287 void ResetRailTypes();
00288
00292 RailType AllocateRailType(RailTypeLabel label);
00293
00294 #endif