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 #include "date_type.h"
00023
00025 enum RailTypeFlags {
00026 RTF_CATENARY = 0,
00027 RTF_NO_LEVEL_CROSSING = 1,
00028
00029 RTFB_NONE = 0,
00030 RTFB_CATENARY = 1 << RTF_CATENARY,
00031 RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING,
00032 };
00033 DECLARE_ENUM_AS_BIT_SET(RailTypeFlags)
00034
00035 struct SpriteGroup;
00036
00038 enum RailTypeSpriteGroup {
00039 RTSG_CURSORS,
00040 RTSG_OVERLAY,
00041 RTSG_GROUND,
00042 RTSG_TUNNEL,
00043 RTSG_WIRES,
00044 RTSG_PYLONS,
00045 RTSG_BRIDGE,
00046 RTSG_CROSSING,
00047 RTSG_DEPOT,
00048 RTSG_FENCES,
00049 RTSG_END,
00050 };
00051
00056 enum RailTrackOffset {
00057 RTO_X,
00058 RTO_Y,
00059 RTO_N,
00060 RTO_S,
00061 RTO_E,
00062 RTO_W,
00063 RTO_SLOPE_NE,
00064 RTO_SLOPE_SE,
00065 RTO_SLOPE_SW,
00066 RTO_SLOPE_NW,
00067 RTO_CROSSING_XY,
00068 RTO_JUNCTION_SW,
00069 RTO_JUNCTION_NE,
00070 RTO_JUNCTION_SE,
00071 RTO_JUNCTION_NW,
00072 RTO_JUNCTION_NSEW,
00073 };
00074
00078 enum RailTrackBridgeOffset {
00079 RTBO_X,
00080 RTBO_Y,
00081 RTBO_SLOPE,
00082 };
00083
00088 enum RailFenceOffset {
00089 RFO_FLAT_X,
00090 RFO_FLAT_Y,
00091 RFO_FLAT_VERT,
00092 RFO_FLAT_HORZ,
00093 RFO_SLOPE_SW,
00094 RFO_SLOPE_SE,
00095 RFO_SLOPE_NE,
00096 RFO_SLOPE_NW,
00097 };
00098
00102 struct RailtypeInfo {
00107 struct {
00108 SpriteID track_y;
00109 SpriteID track_ns;
00110 SpriteID ground;
00111 SpriteID single_x;
00112 SpriteID single_y;
00113 SpriteID single_n;
00114 SpriteID single_s;
00115 SpriteID single_e;
00116 SpriteID single_w;
00117 SpriteID single_sloped;
00118 SpriteID crossing;
00119 SpriteID tunnel;
00120 } base_sprites;
00121
00126 struct {
00127 SpriteID build_ns_rail;
00128 SpriteID build_x_rail;
00129 SpriteID build_ew_rail;
00130 SpriteID build_y_rail;
00131 SpriteID auto_rail;
00132 SpriteID build_depot;
00133 SpriteID build_tunnel;
00134 SpriteID convert_rail;
00135 } gui_sprites;
00136
00137 struct {
00138 CursorID rail_ns;
00139 CursorID rail_swne;
00140 CursorID rail_ew;
00141 CursorID rail_nwse;
00142 CursorID autorail;
00143 CursorID depot;
00144 CursorID tunnel;
00145 CursorID convert;
00146 } cursor;
00147
00148 struct {
00149 StringID name;
00150 StringID toolbar_caption;
00151 StringID menu_text;
00152 StringID build_caption;
00153 StringID replace_text;
00154 StringID new_loco;
00155 } strings;
00156
00158 SpriteID snow_offset;
00159
00161 RailTypes powered_railtypes;
00162
00164 RailTypes compatible_railtypes;
00165
00169 SpriteID bridge_offset;
00170
00174 byte fallback_railtype;
00175
00179 byte curve_speed;
00180
00184 RailTypeFlags flags;
00185
00189 uint16 cost_multiplier;
00190
00194 uint16 maintenance_multiplier;
00195
00199 uint8 acceleration_type;
00200
00204 uint16 max_speed;
00205
00209 RailTypeLabel label;
00210
00214 byte map_colour;
00215
00223 Date introduction_date;
00224
00229 RailTypes introduction_required_railtypes;
00230
00234 RailTypes introduces_railtypes;
00235
00239 byte sorting_order;
00240
00244 const GRFFile *grffile[RTSG_END];
00245
00249 const SpriteGroup *group[RTSG_END];
00250
00251 inline bool UsesOverlay() const
00252 {
00253 return this->group[RTSG_GROUND] != NULL;
00254 }
00255
00263 inline uint GetRailtypeSpriteOffset() const
00264 {
00265 return 82 * this->fallback_railtype;
00266 }
00267 };
00268
00269
00275 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
00276 {
00277 extern RailtypeInfo _railtypes[RAILTYPE_END];
00278 assert(railtype < RAILTYPE_END);
00279 return &_railtypes[railtype];
00280 }
00281
00290 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
00291 {
00292 return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
00293 }
00294
00303 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
00304 {
00305 return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
00306 }
00307
00313 static inline bool RailNoLevelCrossings(RailType rt)
00314 {
00315 return HasBit(GetRailTypeInfo(rt)->flags, RTF_NO_LEVEL_CROSSING);
00316 }
00317
00323 static inline Money RailBuildCost(RailType railtype)
00324 {
00325 assert(railtype < RAILTYPE_END);
00326 return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3;
00327 }
00328
00334 static inline Money RailClearCost(RailType railtype)
00335 {
00336
00337
00338
00339
00340
00341 assert(railtype < RAILTYPE_END);
00342 return max(_price[PR_CLEAR_RAIL], -RailBuildCost(railtype) * 3 / 4);
00343 }
00344
00351 static inline Money RailConvertCost(RailType from, RailType to)
00352 {
00353
00354
00355 Money rebuildcost = RailBuildCost(to) + RailClearCost(from);
00356
00357
00358
00359
00360
00361 if (HasPowerOnRail(from, to) || HasPowerOnRail(to, from)) {
00362 Money upgradecost = RailBuildCost(to) / 8 + max((Money)0, RailBuildCost(to) - RailBuildCost(from));
00363 return min(upgradecost, rebuildcost);
00364 }
00365
00366
00367
00368 return rebuildcost;
00369 }
00370
00377 static inline Money RailMaintenanceCost(RailType railtype, uint32 num)
00378 {
00379 assert(railtype < RAILTYPE_END);
00380 return (_price[PR_INFRASTRUCTURE_RAIL] * GetRailTypeInfo(railtype)->maintenance_multiplier * num * (1 + IntSqrt(num))) >> 11;
00381 }
00382
00388 static inline Money SignalMaintenanceCost(uint32 num)
00389 {
00390 return (_price[PR_INFRASTRUCTURE_RAIL] * 15 * num * (1 + IntSqrt(num))) >> 8;
00391 }
00392
00393 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
00394 int TicksToLeaveDepot(const Train *v);
00395
00396 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
00397
00398
00399 bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
00400 bool ValParamRailtype(const RailType rail);
00401
00402 RailTypes AddDateIntroducedRailTypes(RailTypes current, Date date);
00403
00404 RailType GetBestRailtype(const CompanyID company);
00405 RailTypes GetCompanyRailtypes(const CompanyID c);
00406
00407 RailType GetRailTypeByLabel(RailTypeLabel label);
00408
00409 void ResetRailTypes();
00410 void InitRailTypes();
00411 RailType AllocateRailType(RailTypeLabel label);
00412
00413 #endif