# rail.h

Go to the documentation of this file.

    00001 /* $Id: rail.h 15417 2009-02-08 18:11:06Z peter1138 $ */
    00002
    00005 #ifndef RAIL_H
    00006 #define RAIL_H
    00007
    00008 #include "rail_type.h"
    00009 #include "track_type.h"
    00010 #include "vehicle_type.h"
    00011 #include "gfx_type.h"
    00012 #include "core/bitmath_func.hpp"
    00013 #include "economy_func.h"
    00014 #include "slope_type.h"
    00015
    00016 enum RailTypeFlag {
    00017   RTF_CATENARY = 0,
    00018 };
    00019
    00020 enum RailTypeFlags {
    00021   RTFB_NONE     = 0,
    00022   RTFB_CATENARY = 1 << RTF_CATENARY,
    00023 };
    00024 DECLARE_ENUM_AS_BIT_SET(RailTypeFlags);
    00025
    00029 enum RailFenceOffset {
    00030   RFO_FLAT_X,
    00031   RFO_FLAT_Y,
    00032   RFO_FLAT_VERT,
    00033   RFO_FLAT_HORZ,
    00034   RFO_SLOPE_SW,
    00035   RFO_SLOPE_SE,
    00036   RFO_SLOPE_NE,
    00037   RFO_SLOPE_NW,
    00038 };
    00039
    00042 struct RailtypeInfo {
    00045   struct {
    00046     SpriteID track_y;
    00047     SpriteID track_ns;
    00048     SpriteID ground;
    00049     SpriteID single_y;
    00050     SpriteID single_x;
    00051     SpriteID single_n;
    00052     SpriteID single_s;
    00053     SpriteID single_e;
    00054     SpriteID single_w;
    00055     SpriteID single_sloped;
    00056     SpriteID crossing;
    00057     SpriteID tunnel;
    00058   } base_sprites;
    00059
    00062   struct {
    00063     SpriteID build_ns_rail;
    00064     SpriteID build_x_rail;
    00065     SpriteID build_ew_rail;
    00066     SpriteID build_y_rail;
    00067     SpriteID auto_rail;
    00068     SpriteID build_depot;
    00069     SpriteID build_tunnel;
    00070     SpriteID convert_rail;
    00071   } gui_sprites;
    00072
    00073   struct {
    00074     CursorID rail_ns;
    00075     CursorID rail_swne;
    00076     CursorID rail_ew;
    00077     CursorID rail_nwse;
    00078     CursorID autorail;
    00079     CursorID depot;
    00080     CursorID tunnel;
    00081     CursorID convert;
    00082   } cursor;
    00083
    00084   struct {
    00085     StringID toolbar_caption;
    00086     StringID menu_text;
    00087     StringID build_caption;
    00088     StringID replace_text;
    00089     StringID new_loco;
    00090   } strings;
    00091
    00093   SpriteID snow_offset;
    00094
    00096   RailTypes powered_railtypes;
    00097
    00099   RailTypes compatible_railtypes;
    00100
    00109   SpriteID total_offset;
    00110
    00114   SpriteID bridge_offset;
    00115
    00119   byte custom_ground_offset;
    00120
    00124   byte curve_speed;
    00125
    00129   RailTypeFlags flags;
    00130
    00134   uint8 cost_multiplier;
    00135
    00139   RailTypeLabel label;
    00140 };
    00141
    00142
    00148 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
    00149 {
    00150   extern RailtypeInfo _railtypes[RAILTYPE_END];
    00151   assert(railtype < RAILTYPE_END);
    00152   return &_railtypes[railtype];
    00153 }
    00154
    00163 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
    00164 {
    00165   return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
    00166 }
    00167
    00176 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
    00177 {
    00178   return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
    00179 }
    00180
    00186 static inline Money RailBuildCost(RailType railtype)
    00187 {
    00188   assert(railtype < RAILTYPE_END);
    00189   return (_price.build_rail * GetRailTypeInfo(railtype)->cost_multiplier) >> 3;
    00190 }
    00191
    00198 static inline Money RailConvertCost(RailType from, RailType to)
    00199 {
    00200   /* rail -> el. rail
    00201    * calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail)
    00202    * (the price of workers to get to place is that 1/4)
    00203    */
    00204   if (HasPowerOnRail(from, to)) {
    00205     Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
    00206     if (cost != 0) return cost;
    00207   }
    00208
    00209   /* el. rail -> rail
    00210    * calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail)
    00211    * (the price of workers is 1 / 4 + price of copper sold to a recycle center)
    00212    */
    00213   if (HasPowerOnRail(to, from)) {
    00214     Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
    00215     if (cost != 0) return cost;
    00216   }
    00217
    00218   /* make the price the same as remove + build new type */
    00219   return RailBuildCost(to) + _price.remove_rail;
    00220 }
    00221
    00222 Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data);
    00223 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
    00224 void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
    00225 Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
    00226 int TicksToLeaveDepot(const Vehicle *v);
    00227
    00228 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
    00229
    00230
    00237 bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
    00238
    00244 bool ValParamRailtype(const RailType rail);
    00245
    00253 RailType GetBestRailtype(const CompanyID company);
    00254
    00260 RailTypes GetCompanyRailtypes(const CompanyID c);
    00261
    00267 RailType GetRailTypeByLabel(RailTypeLabel label);
    00268
    00272 void ResetRailTypes();
    00273
    00274 #endif /* RAIL_H */