engine.h

Go to the documentation of this file.
00001 /* $Id: engine.h 12209 2008-02-21 19:09:10Z peter1138 $ */
00002 
00005 #ifndef ENGINE_H
00006 #define ENGINE_H
00007 
00008 #include "rail_type.h"
00009 #include "cargo_type.h"
00010 #include "vehicle_type.h"
00011 #include "gfx_type.h"
00012 #include "date_type.h"
00013 #include "sound_type.h"
00014 #include "player_type.h"
00015 #include "strings_type.h"
00016 
00017 enum RailVehicleTypes {
00018   RAILVEH_SINGLEHEAD,  
00019   RAILVEH_MULTIHEAD,   
00020   RAILVEH_WAGON,       
00021 };
00022 
00023 enum EngineClass {
00024   EC_STEAM,
00025   EC_DIESEL,
00026   EC_ELECTRIC,
00027   EC_MONORAIL,
00028   EC_MAGLEV,
00029 };
00030 
00031 struct RailVehicleInfo {
00032   byte image_index;
00033   RailVehicleTypes railveh_type;
00034   byte base_cost;
00035   RailTypeByte railtype;
00036   uint16 max_speed;
00037   uint16 power;
00038   uint16 weight;
00039   byte running_cost;
00040   byte running_cost_class;
00041   EngineClass engclass;           
00042   byte capacity;
00043   CargoID cargo_type;
00044   byte ai_rank;
00045   byte ai_passenger_only; 
00046   uint16 pow_wag_power;
00047   byte pow_wag_weight;
00048   byte visual_effect; // NOTE: this is not 100% implemented yet, at the moment it is only used as a 'fallback' value
00049                       //       for when the 'powered wagon' callback fails. But it should really also determine what
00050                       //       kind of visual effect to generate for a vehicle (default, steam, diesel, electric).
00051                       //       Same goes for the callback result, which atm is only used to check if a wagon is powered.
00052   byte shorten_factor;   
00053   byte tractive_effort;  
00054   byte user_def_data;    
00055 };
00056 
00057 struct ShipVehicleInfo {
00058   byte image_index;
00059   byte base_cost;
00060   uint16 max_speed;
00061   CargoID cargo_type;
00062   uint16 capacity;
00063   byte running_cost;
00064   SoundFxByte sfx;
00065   bool refittable;
00066 };
00067 
00068 /* AircraftVehicleInfo subtypes, bitmask type.
00069  * If bit 0 is 0 then it is a helicopter, otherwise it is a plane
00070  * in which case bit 1 tells us whether it's a big(fast) plane or not */
00071 enum {
00072   AIR_HELI = 0,
00073   AIR_CTOL = 1, 
00074   AIR_FAST = 2
00075 };
00076 
00077 struct AircraftVehicleInfo {
00078   byte image_index;
00079   byte base_cost;
00080   byte running_cost;
00081   byte subtype;
00082   SoundFxByte sfx;
00083   byte acceleration;
00084   uint16 max_speed;
00085   byte mail_capacity;
00086   uint16 passenger_capacity;
00087 };
00088 
00089 struct RoadVehicleInfo {
00090   byte image_index;
00091   byte base_cost;
00092   byte running_cost;
00093   byte running_cost_class;
00094   SoundFxByte sfx;
00095   byte max_speed;
00096   byte capacity;
00097   CargoID cargo_type;
00098 };
00099 
00103 struct EngineInfo {
00104   Date base_intro;
00105   Year lifelength;
00106   Year base_life;
00107   byte unk2;         
00108   byte load_amount;
00109   byte climates;
00110   uint32 refit_mask;
00111   byte refit_cost;
00112   byte misc_flags;
00113   byte callbackmask;
00114   int8 retire_early;  
00115   StringID string_id; 
00116 };
00117 
00118 struct Engine {
00119   char *name;         
00120   Date intro_date;
00121   Date age;
00122   uint16 reliability;
00123   uint16 reliability_spd_dec;
00124   uint16 reliability_start, reliability_max, reliability_final;
00125   uint16 duration_phase_1, duration_phase_2, duration_phase_3;
00126   byte lifelength;
00127   byte flags;
00128   uint8 preview_player_rank;
00129   byte preview_wait;
00130   byte player_avail;
00131   VehicleType type; 
00132 };
00133 
00137 enum {
00138   EF_RAIL_TILTS = 0, 
00139   EF_ROAD_TRAM  = 0, 
00140   EF_USES_2CC   = 1, 
00141   EF_RAIL_IS_MU = 2, 
00142 };
00143 
00147 enum {
00148   ENGINE_AVAILABLE         = 1, 
00149   ENGINE_EXCLUSIVE_PREVIEW = 2, 
00150   ENGINE_OFFER_WINDOW_OPEN = 4, 
00151 };
00152 
00153 enum {
00154   NUM_VEHICLE_TYPES = 6
00155 };
00156 
00157 static const EngineID INVALID_ENGINE = 0xFFFF;
00158 
00159 
00160 void SetupEngines();
00161 void StartupEngines();
00162 
00163 
00164 void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
00165 void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
00166 void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal);
00167 void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
00168 
00169 void LoadCustomEngineNames();
00170 void DeleteCustomEngineNames();
00171 
00172 bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player);
00173 CargoID GetEngineCargoType(EngineID engine);
00174 
00175 enum {
00176   NUM_NORMAL_RAIL_ENGINES = 54,
00177   NUM_MONORAIL_ENGINES    = 30,
00178   NUM_MAGLEV_ENGINES      = 32,
00179   NUM_TRAIN_ENGINES       = NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES + NUM_MAGLEV_ENGINES,
00180   NUM_ROAD_ENGINES        = 88,
00181   NUM_SHIP_ENGINES        = 11,
00182   NUM_AIRCRAFT_ENGINES    = 41,
00183   TOTAL_NUM_ENGINES       = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES + NUM_AIRCRAFT_ENGINES,
00184   AIRCRAFT_ENGINES_INDEX  = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES,
00185   SHIP_ENGINES_INDEX      = NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES,
00186   ROAD_ENGINES_INDEX      = NUM_TRAIN_ENGINES,
00187 };
00188 
00189 static inline EngineID GetFirstEngineOfType(VehicleType type)
00190 {
00191   const EngineID start[] = {0, ROAD_ENGINES_INDEX, SHIP_ENGINES_INDEX, AIRCRAFT_ENGINES_INDEX};
00192 
00193   return start[type];
00194 }
00195 
00196 static inline EngineID GetLastEngineOfType(VehicleType type)
00197 {
00198   const EngineID end[] = {
00199     NUM_TRAIN_ENGINES,
00200     ROAD_ENGINES_INDEX + NUM_ROAD_ENGINES,
00201     SHIP_ENGINES_INDEX + NUM_SHIP_ENGINES,
00202     AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES};
00203 
00204   return end[type];
00205 }
00206 
00207 extern Engine _engines[TOTAL_NUM_ENGINES];
00208 #define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
00209 #define FOR_ALL_ENGINEIDS_OF_TYPE(e, type) for (e = GetFirstEngineOfType(type); e != GetLastEngineOfType(type); e++)
00210 
00211 
00212 static inline Engine* GetEngine(EngineID i)
00213 {
00214   assert(i < lengthof(_engines));
00215   return &_engines[i];
00216 }
00217 
00218 static inline bool IsEngineIndex(uint index)
00219 {
00220   return index < TOTAL_NUM_ENGINES;
00221 }
00222 
00223 /* Access Vehicle Data */
00224 extern const EngineInfo _orig_engine_info[TOTAL_NUM_ENGINES];
00225 extern const RailVehicleInfo _orig_rail_vehicle_info[NUM_TRAIN_ENGINES];
00226 extern const ShipVehicleInfo _orig_ship_vehicle_info[NUM_SHIP_ENGINES];
00227 extern const AircraftVehicleInfo _orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
00228 extern const RoadVehicleInfo _orig_road_vehicle_info[NUM_ROAD_ENGINES];
00229 
00230 extern EngineInfo _engine_info[TOTAL_NUM_ENGINES];
00231 extern RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
00232 extern ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
00233 extern AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
00234 extern RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
00235 
00236 static inline const EngineInfo *EngInfo(EngineID e)
00237 {
00238   assert(e < lengthof(_engine_info));
00239   return &_engine_info[e];
00240 }
00241 
00242 static inline const RailVehicleInfo* RailVehInfo(EngineID e)
00243 {
00244   assert(e < lengthof(_rail_vehicle_info));
00245   return &_rail_vehicle_info[e];
00246 }
00247 
00248 static inline const ShipVehicleInfo* ShipVehInfo(EngineID e)
00249 {
00250   assert(e >= SHIP_ENGINES_INDEX && e < SHIP_ENGINES_INDEX + lengthof(_ship_vehicle_info));
00251   return &_ship_vehicle_info[e - SHIP_ENGINES_INDEX];
00252 }
00253 
00254 static inline const AircraftVehicleInfo* AircraftVehInfo(EngineID e)
00255 {
00256   assert(e >= AIRCRAFT_ENGINES_INDEX && e < AIRCRAFT_ENGINES_INDEX + lengthof(_aircraft_vehicle_info));
00257   return &_aircraft_vehicle_info[e - AIRCRAFT_ENGINES_INDEX];
00258 }
00259 
00260 static inline const RoadVehicleInfo* RoadVehInfo(EngineID e)
00261 {
00262   assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info));
00263   return &_road_vehicle_info[e - ROAD_ENGINES_INDEX];
00264 }
00265 
00266 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */
00267 void EngList_Create(EngineList *el);            
00268 void EngList_Destroy(EngineList *el);           
00269 uint EngList_Count(const EngineList *el);       
00270 void EngList_Add(EngineList *el, EngineID eid); 
00271 EngineID* EngList_Items(EngineList *el);        
00272 void EngList_RemoveAll(EngineList *el);         
00273 typedef int CDECL EngList_SortTypeFunction(const void*, const void*); 
00274 void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); 
00275 void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); 
00276 
00277 #endif /* ENGINE_H */

Generated on Mon Sep 22 20:34:15 2008 for openttd by  doxygen 1.5.6