# tile_cmd.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 TILE_CMD_H
    00013 #define TILE_CMD_H
    00014
    00015 #include "slope_type.h"
    00016 #include "tile_type.h"
    00017 #include "command_type.h"
    00018 #include "vehicle_type.h"
    00019 #include "cargo_type.h"
    00020 #include "strings_type.h"
    00021 #include "date_type.h"
    00022 #include "company_type.h"
    00023 #include "direction_type.h"
    00024 #include "track_type.h"
    00025 #include "transport_type.h"
    00026 #include "tile_map.h"
    00027
    00029 enum VehicleEnterTileStatus {
    00030   VETS_ENTERED_STATION  = 1,
    00031   VETS_ENTERED_WORMHOLE = 2,
    00032   VETS_CANNOT_ENTER     = 3,
    00033
    00039   VETS_STATION_ID_OFFSET = 8,
    00040   VETS_STATION_MASK      = 0xFFFF << VETS_STATION_ID_OFFSET,
    00041
    00043   VETSB_CONTINUE         = 0,
    00044   VETSB_ENTERED_STATION  = 1 << VETS_ENTERED_STATION,
    00045   VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE,
    00046   VETSB_CANNOT_ENTER     = 1 << VETS_CANNOT_ENTER,
    00047 };
    00048 DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus);
    00049
    00051 struct TileInfo {
    00052   uint x;
    00053   uint y;
    00054   Slope tileh;
    00055   TileIndex tile;
    00056   uint z;
    00057 };
    00058
    00060 struct TileDesc {
    00061   StringID str;
    00062   Owner owner[4];
    00063   StringID owner_type[4];
    00064   Date build_date;
    00065   StringID station_class;
    00066   StringID station_name;
    00067   const char *grf;
    00068   uint64 dparam[2];
    00069 };
    00070
    00075 typedef void DrawTileProc(TileInfo *ti);
    00076 typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y);
    00077 typedef CommandCost ClearTileProc(TileIndex tile, DoCommandFlag flags);
    00078
    00085 typedef void AddAcceptedCargoProc(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted);
    00086
    00092 typedef void GetTileDescProc(TileIndex tile, TileDesc *td);
    00093
    00107 typedef TrackStatus GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side);
    00108
    00114 typedef void AddProducedCargoProc(TileIndex tile, CargoArray &produced);
    00115 typedef bool ClickTileProc(TileIndex tile);
    00116 typedef void AnimateTileProc(TileIndex tile);
    00117 typedef void TileLoopProc(TileIndex tile);
    00118 typedef void ChangeTileOwnerProc(TileIndex tile, Owner old_owner, Owner new_owner);
    00119
    00121 typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y);
    00122 typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh);
    00123
    00139 typedef CommandCost TerraformTileProc(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new);
    00140
    00144 struct TileTypeProcs {
    00145   DrawTileProc *draw_tile_proc;
    00146   GetSlopeZProc *get_slope_z_proc;
    00147   ClearTileProc *clear_tile_proc;
    00148   AddAcceptedCargoProc *add_accepted_cargo_proc;
    00149   GetTileDescProc *get_tile_desc_proc;
    00150   GetTileTrackStatusProc *get_tile_track_status_proc;
    00151   ClickTileProc *click_tile_proc;
    00152   AnimateTileProc *animate_tile_proc;
    00153   TileLoopProc *tile_loop_proc;
    00154   ChangeTileOwnerProc *change_tile_owner_proc;
    00155   AddProducedCargoProc *add_produced_cargo_proc;
    00156   VehicleEnterTileProc *vehicle_enter_tile_proc;
    00157   GetFoundationProc *get_foundation_proc;
    00158   TerraformTileProc *terraform_tile_proc;
    00159 };
    00160
    00161 extern const TileTypeProcs * const _tile_type_procs[16];
    00162
    00163 TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR);
    00164 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y);
    00165 void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner);
    00166 void GetTileDesc(TileIndex tile, TileDesc *td);
    00167
    00168 static inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
    00169 {
    00170   AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc;
    00171   if (proc == NULL) return;
    00172   uint32 dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != NULL' checks
    00173   proc(tile, acceptance, always_accepted == NULL ? &dummy : always_accepted);
    00174 }
    00175
    00176 static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
    00177 {
    00178   AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;
    00179   if (proc == NULL) return;
    00180   proc(tile, produced);
    00181 }
    00182
    00183 static inline void AnimateTile(TileIndex tile)
    00184 {
    00185   AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
    00186   assert(proc != NULL);
    00187   proc(tile);
    00188 }
    00189
    00190 static inline bool ClickTile(TileIndex tile)
    00191 {
    00192   ClickTileProc *proc = _tile_type_procs[GetTileType(tile)]->click_tile_proc;
    00193   if (proc == NULL) return false;
    00194   return proc(tile);
    00195 }
    00196
    00197 #endif /* TILE_CMD_H */