rail.h

Go to the documentation of this file.
00001 /* $Id: rail.h 18809 2010-01-15 16:41:15Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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   RailTypeLabel label;
00152 };
00153 
00154 
00160 static inline const RailtypeInfo *GetRailTypeInfo(RailType railtype)
00161 {
00162   extern RailtypeInfo _railtypes[RAILTYPE_END];
00163   assert(railtype < RAILTYPE_END);
00164   return &_railtypes[railtype];
00165 }
00166 
00175 static inline bool IsCompatibleRail(RailType enginetype, RailType tiletype)
00176 {
00177   return HasBit(GetRailTypeInfo(enginetype)->compatible_railtypes, tiletype);
00178 }
00179 
00188 static inline bool HasPowerOnRail(RailType enginetype, RailType tiletype)
00189 {
00190   return HasBit(GetRailTypeInfo(enginetype)->powered_railtypes, tiletype);
00191 }
00192 
00198 static inline Money RailBuildCost(RailType railtype)
00199 {
00200   assert(railtype < RAILTYPE_END);
00201   return (_price[PR_BUILD_RAIL] * GetRailTypeInfo(railtype)->cost_multiplier) >> 3;
00202 }
00203 
00210 static inline Money RailConvertCost(RailType from, RailType to)
00211 {
00212   /* rail -> el. rail
00213    * calculate the price as 5 / 4 of (cost build el. rail) - (cost build rail)
00214    * (the price of workers to get to place is that 1/4)
00215    */
00216   if (HasPowerOnRail(from, to)) {
00217     Money cost = ((RailBuildCost(to) - RailBuildCost(from)) * 5) >> 2;
00218     if (cost != 0) return cost;
00219   }
00220 
00221   /* el. rail -> rail
00222    * calculate the price as 1 / 4 of (cost build el. rail) - (cost build rail)
00223    * (the price of workers is 1 / 4 + price of copper sold to a recycle center)
00224    */
00225   if (HasPowerOnRail(to, from)) {
00226     Money cost = (RailBuildCost(from) - RailBuildCost(to)) >> 2;
00227     if (cost != 0) return cost;
00228   }
00229 
00230   /* make the price the same as remove + build new type */
00231   return RailBuildCost(to) + _price[PR_CLEAR_RAIL];
00232 }
00233 
00234 void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
00235 Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
00236 int TicksToLeaveDepot(const Train *v);
00237 
00238 Foundation GetRailFoundation(Slope tileh, TrackBits bits);
00239 
00240 
00247 bool HasRailtypeAvail(const CompanyID company, const RailType railtype);
00248 
00254 bool ValParamRailtype(const RailType rail);
00255 
00263 RailType GetBestRailtype(const CompanyID company);
00264 
00270 RailTypes GetCompanyRailtypes(const CompanyID c);
00271 
00277 RailType GetRailTypeByLabel(RailTypeLabel label);
00278 
00282 void ResetRailTypes();
00283 
00284 #endif /* RAIL_H */

Generated on Wed Jan 20 23:38:38 2010 for OpenTTD by  doxygen 1.5.6