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
00024 enum RailTypeFlags {
00025 RTF_CATENARY = 0,
00026 RTF_NO_LEVEL_CROSSING = 1,
00027
00028 RTFB_NONE = 0,
00029 RTFB_CATENARY = 1 << RTF_CATENARY,
00030 RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING,
00031 };
00032 DECLARE_ENUM_AS_BIT_SET(RailTypeFlags)
00033
00034 struct SpriteGroup;
00035
00037 enum RailTypeSpriteGroup {
00038 RTSG_CURSORS,
00039 RTSG_OVERLAY,
00040 RTSG_GROUND,
00041 RTSG_TUNNEL,
00042 RTSG_WIRES,
00043 RTSG_PYLONS,
00044 RTSG_BRIDGE,
00045 RTSG_CROSSING,
00046 RTSG_DEPOT,
00047 RTSG_FENCES,
00048 RTSG_END,
00049 };
00050
00055 enum RailTrackOffset {
00056 RTO_X,
00057 RTO_Y,
00058 RTO_N,
00059 RTO_S,
00060 RTO_E,
00061 RTO_W,
00062 RTO_SLOPE_NE,
00063 RTO_SLOPE_SE,
00064 RTO_SLOPE_SW,
00065 RTO_SLOPE_NW,
00066 RTO_CROSSING_XY,
00067 RTO_JUNCTION_SW,
00068 RTO_JUNCTION_NE,
00069 RTO_JUNCTION_SE,
00070 RTO_JUNCTION_NW,
00071 RTO_JUNCTION_NSEW,
00072 };
00073
00077 enum RailTrackBridgeOffset {
00078 RTBO_X,
00079 RTBO_Y,
00080 RTBO_SLOPE,
00081 };
00082
00087 enum RailFenceOffset {
00088 RFO_FLAT_X,
00089 RFO_FLAT_Y,
00090 RFO_FLAT_VERT,
00091 RFO_FLAT_HORZ,
00092 RFO_SLOPE_SW,
00093 RFO_SLOPE_SE,
00094 RFO_SLOPE_NE,
00095 RFO_SLOPE_NW,
00096 };
00097
00101 struct RailtypeInfo {
00106 struct {
00107 SpriteID track_y;
00108 SpriteID track_ns;
00109 SpriteID ground;
00110 SpriteID single_x;
00111 SpriteID single_y;
00112 SpriteID single_n;
00113 SpriteID single_s;
00114 SpriteID single_e;
00115 SpriteID single_w;
00116 SpriteID single_sloped;
00117 SpriteID crossing;
00118 SpriteID tunnel;
00119 } base_sprites;
00120
00125 struct {
00126 SpriteID build_ns_rail;
00127 SpriteID build_x_rail;
00128 SpriteID build_ew_rail;
00129 SpriteID build_y_rail;
00130 SpriteID auto_rail;
00131 SpriteID build_depot;
00132 SpriteID build_tunnel;
00133 SpriteID convert_rail;
00134 } gui_sprites;
00135
00136 struct {
00137 CursorID rail_ns;
00138 CursorID rail_swne;
00139 CursorID rail_ew;
00140 CursorID rail_nwse;
00141 CursorID autorail;
00142 CursorID depot;
00143 CursorID tunnel;
00144 CursorID convert;
00145 } cursor;
00146
00147 struct {
00148 StringID toolbar_caption;
00149 StringID menu_text;
00150 StringID build_caption;
00151 StringID replace_text;
00152 StringID new_loco;
00153 } strings;
00154
00156 SpriteID snow_offset;
00157
00159 RailTypes powered_railtypes;
00160
00162 RailTypes compatible_railtypes;
00163
00172 SpriteID total_offset;
00173
00177 SpriteID bridge_offset;
00178
00182 byte custom_ground_offset;
00183
00187 byte curve_speed;
00188
00192 RailTypeFlags flags;
00193
00197 uint16 cost_multiplier;
00198
00202 uint8 acceleration_type;
00203
00207 uint16 max_speed;
00208
00212 RailTypeLabel label;
00213
00217 byte map_colour;
00218
00222 const SpriteGroup *group[RTSG_END];
00223
00224 inline bool UsesOverlay() const
00225 {
00226 return this->group[RTSG_GROUND] != NULL;
00227 }
00228 };
00229
00230
00236 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
00237 {
00238 extern RailtypeInfo _railtypes[RAILTYPE_END];
00239 assert(railtype < RAILTYPE_END);
00240 return &_railtypes[railtype];
00241 }
00242
00251 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
00252 {
00253 return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
00254 }
00255
00264 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
00265 {
00266 return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
00267 }
00268
00274 static inline bool RailNoLevelCrossings(RailType rt)
00275 {
00276 return HasBit(GetRailTypeInfo(rt)->flags, RTF_NO_LEVEL_CROSSING);
00277 }
00278
00284 static inline Money RailBuildCost(RailType railtype)
00285 {
00286 assert(railtype < RAILTYPE_END);
00287 return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3;
00288 }
00289
00295 static inline Money RailClearCost(RailType railtype)
00296 {
00297
00298
00299
00300
00301
00302 assert(railtype < RAILTYPE_END);
00303 return max(_price[PR_CLEAR_RAIL], -RailBuildCost(railtype) * 3 / 4);
00304 }
00305
00312 static inline Money RailConvertCost(RailType from, RailType to)
00313 {
00314
00315
00316
00317
00318 if (HasPowerOnRail(from, to)) {
00319 Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
00320 if (cost != 0) return cost;
00321 }
00322
00323
00324
00325
00326
00327 if (HasPowerOnRail(to, from)) {
00328 Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
00329 if (cost != 0) return cost;
00330 }
00331
00332
00333 return RailBuildCost(to) + RailClearCost(from);
00334 }
00335
00336 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
00337 int TicksToLeaveDepot(const Train *v);
00338
00339 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
00340
00341
00348 bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
00349
00355 bool ValParamRailtype(const RailType rail);
00356
00364 RailType GetBestRailtype(const CompanyID company);
00365
00371 RailTypes GetCompanyRailtypes(const CompanyID c);
00372
00378 RailType GetRailTypeByLabel(RailTypeLabel label);
00379
00383 void ResetRailTypes();
00384
00388 void InitRailTypes();
00389
00393 RailType AllocateRailType(RailTypeLabel label);
00394
00395 #endif