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 int 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 uint16 road_speed;
00067 };
00068
00073 typedef void DrawTileProc(TileInfo *ti);
00074 typedef int GetSlopeZProc(TileIndex tile, uint x, uint y);
00075 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
00076
00083 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
00084
00090 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
00091
00105 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
00106
00112 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
00113 typedef bool ClickTileProc(TileIndex tile);
00114 typedef void AnimateTileProc(TileIndex tile);
00115 typedef void TileLoopProc(TileIndex tile);
00116 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
00117
00119 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
00120 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
00121
00137 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new);
00138
00143 struct TileTypeProcs {
00144 DrawTileProc *draw_tile_proc;
00145 GetSlopeZProc *get_slope_z_proc;
00146 ClearTileProc *clear_tile_proc;
00147 AddAcceptedCargoProc *add_accepted_cargo_proc;
00148 GetTileDescProc *get_tile_desc_proc;
00149 GetTileTrackStatusProc *get_tile_track_status_proc;
00150 ClickTileProc *click_tile_proc;
00151 AnimateTileProc *animate_tile_proc;
00152 TileLoopProc *tile_loop_proc;
00153 ChangeTileOwnerProc *change_tile_owner_proc;
00154 AddProducedCargoProc *add_produced_cargo_proc;
00155 VehicleEnterTileProc *vehicle_enter_tile_proc;
00156 GetFoundationProc *get_foundation_proc;
00157 TerraformTileProc *terraform_tile_proc;
00158 };
00159
00160 extern const TileTypeProcs * const _tile_type_procs[16];
00161
00162 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
00163 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
00164 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
00165 void GetTileDesc(TileIndex tile, TileDesc *td);
00166
00167 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
00168 {
00169 AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
00170 if (proc == NULL) return;
00171 uint32 dummy = 0;
00172 proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
00173 }
00174
00175 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
00176 {
00177 AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
00178 if (proc == NULL) return;
00179 proc(tile, produced);
00180 }
00181
00182 static inline void AnimateTile(TileIndex tile)
00183 {
00184 AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
00185 assert(proc != NULL);
00186 proc(tile);
00187 }
00188
00189 static inline bool ClickTile(TileIndex tile)
00190 {
00191 ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
00192 if (proc == NULL) return false;
00193 return proc(tile);
00194 }
00195
00196 #endif