# tile_cmd.h

Go to the documentation of this file.

    00001 /* $Id: tile_cmd.h 18809 2010-01-15 16:41:15Z 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 };
    00063
    00068 typedef void DrawTileProc(TileInfo *ti);
    00069 typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
    00070 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
    00071
    00078 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
    00079
    00085 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
    00086
    00100 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
    00101
    00107 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
    00108 typedef bool ClickTileProc(TileIndex tile);
    00109 typedef void AnimateTileProc(TileIndex tile);
    00110 typedef void TileLoopProc(TileIndex tile);
    00111 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
    00112
    00114 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
    00115 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
    00116
    00132 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
    00133
    00137 struct TileTypeProcs {
    00138   DrawTileProc *draw_tile_proc;
    00139   GetSlopeZProc *get_slope_z_proc;
    00140   ClearTileProc *clear_tile_proc;
    00141   AddAcceptedCargoProc *add_accepted_cargo_proc;
    00142   GetTileDescProc *get_tile_desc_proc;
    00143   GetTileTrackStatusProc *get_tile_track_status_proc;
    00144   ClickTileProc *click_tile_proc;
    00145   AnimateTileProc *animate_tile_proc;
    00146   TileLoopProc *tile_loop_proc;
    00147   ChangeTileOwnerProc *change_tile_owner_proc;
    00148   AddProducedCargoProc *add_produced_cargo_proc;
    00149   VehicleEnterTileProc *vehicle_enter_tile_proc;
    00150   GetFoundationProc *get_foundation_proc;
    00151   TerraformTileProc *terraform_tile_proc;
    00152 };
    00153
    00154 extern const TileTypeProcs * const _tile_type_procs[16];
    00155
    00156 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
    00157 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
    00158 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
    00159 void GetTileDesc(TileIndex tile, TileDesc *td);
    00160
    00161 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
    00162 {
    00163   AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
    00164   if (proc == NULL) return;
    00165   uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
    00166   proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
    00167 }
    00168
    00169 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
    00170 {
    00171   AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
    00172   if (proc == NULL) return;
    00173   proc(tile, produced);
    00174 }
    00175
    00176 static inline void AnimateTile(TileIndex tile)
    00177 {
    00178   AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
    00179   assert(proc != NULL);
    00180   proc(tile);
    00181 }
    00182
    00183 static inline bool ClickTile(TileIndex tile)
    00184 {
    00185   ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
    00186   if (proc == NULL) return false;
    00187   return proc(tile);
    00188 }
    00189
    00190 #endif /* TILE_CMD_H */