# rail.h

Go to the documentation of this file.

    00001 /* $Id: rail.h 12386 2008-03-19 20:50:19Z smatz $ */
    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 "tile_cmd.h"
    00015
    00018 struct RailtypeInfo {
    00021   struct {
    00022     SpriteID track_y;
    00023     SpriteID track_ns;
    00024     SpriteID ground;
    00025     SpriteID single_y;
    00026     SpriteID single_x;
    00027     SpriteID single_n;
    00028     SpriteID single_s;
    00029     SpriteID single_e;
    00030     SpriteID single_w;
    00031     SpriteID crossing;
    00032     SpriteID tunnel;
    00033   } base_sprites;
    00034
    00037   struct {
    00038     SpriteID build_ns_rail;
    00039     SpriteID build_x_rail;
    00040     SpriteID build_ew_rail;
    00041     SpriteID build_y_rail;
    00042     SpriteID auto_rail;
    00043     SpriteID build_depot;
    00044     SpriteID build_tunnel;
    00045     SpriteID convert_rail;
    00046   } gui_sprites;
    00047
    00048   struct {
    00049     CursorID rail_ns;
    00050     CursorID rail_swne;
    00051     CursorID rail_ew;
    00052     CursorID rail_nwse;
    00053     CursorID autorail;
    00054     CursorID depot;
    00055     CursorID tunnel;
    00056     CursorID convert;
    00057   } cursor;
    00058
    00059   struct {
    00060     StringID toolbar_caption;
    00061   } strings;
    00062
    00064   SpriteID snow_offset;
    00065
    00067   RailTypes powered_railtypes;
    00068
    00070   RailTypes compatible_railtypes;
    00071
    00080   SpriteID total_offset;
    00081
    00085   SpriteID bridge_offset;
    00086
    00090   byte custom_ground_offset;
    00091
    00095   byte curve_speed;
    00096 };
    00097
    00098
    00104 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
    00105 {
    00106   extern RailtypeInfo _railtypes[RAILTYPE_END];
    00107   assert(railtype < RAILTYPE_END);
    00108   return &_railtypes[railtype];
    00109 }
    00110
    00119 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
    00120 {
    00121   return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
    00122 }
    00123
    00132 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
    00133 {
    00134   return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
    00135 }
    00136
    00137
    00138 extern int _railtype_cost_multiplier[RAILTYPE_END];
    00139 extern const int _default_railtype_cost_multiplier[RAILTYPE_END];
    00140
    00146 static inline Money RailBuildCost(RailType railtype)
    00147 {
    00148   assert(railtype < RAILTYPE_END);
    00149   return (_price.build_rail * _railtype_cost_multiplier[railtype]) >> 3;
    00150 }
    00151
    00158 static inline Money RailConvertCost(RailType from, RailType to)
    00159 {
    00160   /* rail -> el. rail
    00161    * calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail)
    00162    * (the price of workers to get to place is that 1/4)
    00163    */
    00164   if (HasPowerOnRail(from, to)) {
    00165     return ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
    00166   }
    00167
    00168   /* el. rail -> rail
    00169    * calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail)
    00170    * (the price of workers is 1 / 4 + price of copper sold to a recycle center)
    00171    */
    00172   if (HasPowerOnRail(to, from)) {
    00173     return (RailBuildCost(from) - RailBuildCost(to)) >> 2;
    00174   }
    00175
    00176   /* make the price the same as remove + build new type */
    00177   return RailBuildCost(to) + _price.remove_rail;
    00178 }
    00179
    00180 void *UpdateTrainPowerProc(Vehicle *v, void *data);
    00181 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
    00182 void DrawDefaultWaypointSprite(int x, int y, RailType railtype);
    00183 void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
    00184 int TicksToLeaveDepot(const Vehicle *v);
    00185
    00191 void DrawCatenary(const TileInfo *ti);
    00192 void DrawCatenaryOnTunnel(const TileInfo *ti);
    00193
    00194 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
    00195
    00196 int32 SettingsDisableElrail(int32 p1);
    00197
    00204 bool HasRailtypeAvail(const PlayerID p, const RailType railtype);
    00205
    00211 bool ValParamRailtype(const RailType rail);
    00212
    00220 RailType GetBestRailtype(const PlayerID p);
    00221
    00227 RailTypes GetPlayerRailtypes(const PlayerID p);
    00228
    00229 #endif /* RAIL_H */