newgrf_airport.h

Go to the documentation of this file.
00001 /* $Id$ */
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 NEWGRF_AIRPORT_H
00013 #define NEWGRF_AIRPORT_H
00014 
00015 #include "airport.h"
00016 #include "date_type.h"
00017 #include "map_type.h"
00018 #include "newgrf_class.h"
00019 #include "newgrf_commons.h"
00020 #include "gfx_type.h"
00021 #include "tilearea_type.h"
00022 
00024 typedef byte StationGfx;
00025 
00027 struct AirportTileTable {
00028   TileIndexDiffC ti; 
00029   StationGfx gfx;    
00030 };
00031 
00033 class AirportTileTableIterator : public TileIterator {
00034 private:
00035   const AirportTileTable *att; 
00036   TileIndex base_tile;         
00037 
00038 public:
00044   AirportTileTableIterator(const AirportTileTable *att, TileIndex base_tile) : TileIterator(base_tile + ToTileIndexDiff(att->ti)), att(att), base_tile(base_tile)
00045   {
00046   }
00047 
00048   inline TileIterator& operator ++()
00049   {
00050     this->att++;
00051     if (this->att->ti.x == -0x80) {
00052       this->tile = INVALID_TILE;
00053     } else {
00054       this->tile = this->base_tile + ToTileIndexDiff(this->att->ti);
00055     }
00056     return *this;
00057   }
00058 
00060   StationGfx GetStationGfx() const
00061   {
00062     return this->att->gfx;
00063   }
00064 
00065   virtual AirportTileTableIterator *Clone() const
00066   {
00067     return new AirportTileTableIterator(*this);
00068   }
00069 };
00070 
00072 enum AirportClassID {
00073   APC_BEGIN     = 0,  
00074   APC_SMALL     = 0,  
00075   APC_LARGE,          
00076   APC_HUB,            
00077   APC_HELIPORT,       
00078   APC_MAX       = 16, 
00079 };
00080 
00082 DECLARE_POSTFIX_INCREMENT(AirportClassID)
00083 
00084 
00085 enum TTDPAirportType {
00086   ATP_TTDP_SMALL,    
00087   ATP_TTDP_LARGE,    
00088   ATP_TTDP_HELIPORT, 
00089   ATP_TTDP_OILRIG,   
00090 };
00091 
00093 struct HangarTileTable {
00094   TileIndexDiffC ti; 
00095   Direction dir;     
00096   byte hangar_num;   
00097 };
00098 
00102 struct AirportSpec {
00103   const struct AirportFTAClass *fsm;     
00104   const AirportTileTable * const *table; 
00105   Direction *rotation;                   
00106   byte num_table;                        
00107   const HangarTileTable *depot_table;    
00108   byte nof_depots;                       
00109   byte size_x;                           
00110   byte size_y;                           
00111   byte noise_level;                      
00112   byte catchment;                        
00113   Year min_year;                         
00114   Year max_year;                         
00115   StringID name;                         
00116   TTDPAirportType ttd_airport_type;      
00117   AirportClassID cls_id;                 
00118   SpriteID preview_sprite;               
00119   uint16 maintenance_cost;               
00120   /* Newgrf data */
00121   bool enabled;                          
00122   struct GRFFileProps grf_prop;          
00123 
00124   static const AirportSpec *Get(byte type);
00125   static AirportSpec *GetWithoutOverride(byte type);
00126 
00127   bool IsAvailable() const;
00128 
00129   static void ResetAirports();
00130 
00132   byte GetIndex() const
00133   {
00134     assert(this >= specs && this < endof(specs));
00135     return (byte)(this - specs);
00136   }
00137 
00138   static AirportSpec dummy; 
00139 
00140 private:
00141   static AirportSpec specs[NUM_AIRPORTS]; 
00142 };
00143 
00145 typedef NewGRFClass<AirportSpec, AirportClassID, APC_MAX> AirportClass;
00146 
00147 void BindAirportSpecs();
00148 
00149 StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback);
00150 
00151 #endif /* NEWGRF_AIRPORT_H */