tile_cmd.h

Go to the documentation of this file.
00001 /* $Id: tile_cmd.h 19551 2010-04-03 19:48:01Z 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 TILE_CMD_H
00013 #define TILE_CMD_H
00014 
00015 #include "command_type.h"
00016 #include "vehicle_type.h"
00017 #include "cargo_type.h"
00018 #include "track_type.h"
00019 #include "tile_map.h"
00020 
00022 enum VehicleEnterTileStatus {
00023   VETS_ENTERED_STATION  = 1, 
00024   VETS_ENTERED_WORMHOLE = 2, 
00025   VETS_CANNOT_ENTER     = 3, 
00026 
00032   VETS_STATION_ID_OFFSET = 8,
00033   VETS_STATION_MASK      = 0xFFFF << VETS_STATION_ID_OFFSET,
00034 
00036   VETSB_CONTINUE         = 0,                          
00037   VETSB_ENTERED_STATION  = 1 << VETS_ENTERED_STATION,  
00038   VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE, 
00039   VETSB_CANNOT_ENTER     = 1 << VETS_CANNOT_ENTER,     
00040 };
00041 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus);
00042 
00044 struct TileInfo {
00045   uint x;         
00046   uint y;         
00047   Slope tileh;    
00048   TileIndex tile; 
00049   uint z;         
00050 };
00051 
00053 struct TileDesc {
00054   StringID str;           
00055   Owner owner[4];         
00056   StringID owner_type[4]; 
00057   Date build_date;        
00058   StringID station_class; 
00059   StringID station_name;  
00060   const char *grf;        
00061   uint64 dparam[2];       
00062   uint16 rail_speed;      
00063 };
00064 
00069 typedef void DrawTileProc(TileInfo *ti);
00070 typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
00071 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
00072 
00079 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
00080 
00086 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
00087 
00101 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
00102 
00108 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
00109 typedef bool ClickTileProc(TileIndex tile);
00110 typedef void AnimateTileProc(TileIndex tile);
00111 typedef void TileLoopProc(TileIndex tile);
00112 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
00113 
00115 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
00116 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
00117 
00133 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
00134 
00138 struct TileTypeProcs {
00139   DrawTileProc *draw_tile_proc;                  
00140   GetSlopeZProc *get_slope_z_proc;
00141   ClearTileProc *clear_tile_proc;
00142   AddAcceptedCargoProc *add_accepted_cargo_proc; 
00143   GetTileDescProc *get_tile_desc_proc;           
00144   GetTileTrackStatusProc *get_tile_track_status_proc; 
00145   ClickTileProc *click_tile_proc;                
00146   AnimateTileProc *animate_tile_proc;
00147   TileLoopProc *tile_loop_proc;
00148   ChangeTileOwnerProc *change_tile_owner_proc;
00149   AddProducedCargoProc *add_produced_cargo_proc; 
00150   VehicleEnterTileProc *vehicle_enter_tile_proc; 
00151   GetFoundationProc *get_foundation_proc;
00152   TerraformTileProc *terraform_tile_proc;        
00153 };
00154 
00155 extern const TileTypeProcs * const _tile_type_procs[16];
00156 
00157 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
00158 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
00159 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
00160 void GetTileDesc(TileIndex tile, TileDesc *td);
00161 
00162 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
00163 {
00164   AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
00165   if (proc == NULL) return;
00166   uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
00167   proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
00168 }
00169 
00170 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
00171 {
00172   AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
00173   if (proc == NULL) return;
00174   proc(tile, produced);
00175 }
00176 
00177 static inline void AnimateTile(TileIndex tile)
00178 {
00179   AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
00180   assert(proc != NULL);
00181   proc(tile);
00182 }
00183 
00184 static inline bool ClickTile(TileIndex tile)
00185 {
00186   ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
00187   if (proc == NULL) return false;
00188   return proc(tile);
00189 }
00190 
00191 #endif /* TILE_CMD_H */

Generated on Sun Nov 14 14:41:58 2010 for OpenTTD by  doxygen 1.6.1