tile_cmd.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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
00043
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 StringID airport_class;
00061 StringID airport_name;
00062 StringID airport_tile_name;
00063 const char *grf;
00064 uint64 dparam[2];
00065 uint16 rail_speed;
00066 };
00067
00072 typedef void DrawTileProc(TileInfo *ti);
00073 typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
00074 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
00075
00082 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
00083
00089 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
00090
00104 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
00105
00111 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
00112 typedef bool ClickTileProc(TileIndex tile);
00113 typedef void AnimateTileProc(TileIndex tile);
00114 typedef void TileLoopProc(TileIndex tile);
00115 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
00116
00118 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
00119 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
00120
00136 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
00137
00142 struct TileTypeProcs {
00143 DrawTileProc *draw_tile_proc;
00144 GetSlopeZProc *get_slope_z_proc;
00145 ClearTileProc *clear_tile_proc;
00146 AddAcceptedCargoProc *add_accepted_cargo_proc;
00147 GetTileDescProc *get_tile_desc_proc;
00148 GetTileTrackStatusProc *get_tile_track_status_proc;
00149 ClickTileProc *click_tile_proc;
00150 AnimateTileProc *animate_tile_proc;
00151 TileLoopProc *tile_loop_proc;
00152 ChangeTileOwnerProc *change_tile_owner_proc;
00153 AddProducedCargoProc *add_produced_cargo_proc;
00154 VehicleEnterTileProc *vehicle_enter_tile_proc;
00155 GetFoundationProc *get_foundation_proc;
00156 TerraformTileProc *terraform_tile_proc;
00157 };
00158
00159 extern const TileTypeProcs * const _tile_type_procs[16];
00160
00161 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
00162 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
00163 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
00164 void GetTileDesc(TileIndex tile, TileDesc *td);
00165
00166 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
00167 {
00168 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
00169 if (proc == NULL) return;
00170 uint32 dummy = 0;
00171 proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
00172 }
00173
00174 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
00175 {
00176 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
00177 if (proc == NULL) return;
00178 proc(tile, produced);
00179 }
00180
00181 static inline void AnimateTile(TileIndex tile)
00182 {
00183 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
00184 assert(proc != NULL);
00185 proc(tile);
00186 }
00187
00188 static inline bool ClickTile(TileIndex tile)
00189 {
00190 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
00191 if (proc == NULL) return false;
00192 return proc(tile);
00193 }
00194
00195 #endif