(svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
parent
059e94e355
commit
02cdf01507
@ -1,91 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/** @file depot.h Header files for depots (not hangars) */
|
||||
|
||||
#ifndef DEPOT_H
|
||||
#define DEPOT_H
|
||||
|
||||
#include "direction_type.h"
|
||||
#include "depot_type.h"
|
||||
#include "oldpool.h"
|
||||
#include "road_map.h"
|
||||
#include "rail_map.h"
|
||||
#include "water_map.h"
|
||||
#include "station_map.h"
|
||||
|
||||
DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
|
||||
|
||||
struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
|
||||
TileIndex xy;
|
||||
TownID town_index;
|
||||
|
||||
Depot(TileIndex xy = 0) : xy(xy) {}
|
||||
~Depot();
|
||||
|
||||
inline bool IsValid() const { return this->xy != 0; }
|
||||
};
|
||||
|
||||
static inline bool IsValidDepotID(DepotID index)
|
||||
{
|
||||
return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
|
||||
}
|
||||
|
||||
void ShowDepotWindow(TileIndex tile, VehicleType type);
|
||||
|
||||
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (d->IsValid())
|
||||
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
|
||||
|
||||
/**
|
||||
* Check if a tile is a depot and it is a depot of the given type.
|
||||
*/
|
||||
static inline bool IsDepotTypeTile(TileIndex tile, TransportType type)
|
||||
{
|
||||
switch (type) {
|
||||
default: NOT_REACHED();
|
||||
case TRANSPORT_RAIL:
|
||||
return IsRailDepotTile(tile);
|
||||
|
||||
case TRANSPORT_ROAD:
|
||||
return IsRoadDepotTile(tile);
|
||||
|
||||
case TRANSPORT_WATER:
|
||||
return IsShipDepotTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given tile a tile with a depot on it?
|
||||
* @param tile the tile to check
|
||||
* @return true if and only if there is a depot on the tile.
|
||||
*/
|
||||
static inline bool IsDepotTile(TileIndex tile)
|
||||
{
|
||||
return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the slope of the tile is suitable to build a depot of given direction
|
||||
* @param direction The direction in which the depot's exit points
|
||||
* @param tileh The slope of the tile in question
|
||||
* @return true if the construction is possible
|
||||
|
||||
* This is checked by the ugly 0x4C >> direction magic, which does the following:
|
||||
* 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
|
||||
* So: for direction (only the significant bits are shown)<p>
|
||||
* 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
|
||||
* 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
|
||||
* 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
|
||||
* 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
|
||||
* So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
|
||||
*/
|
||||
static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
|
||||
{
|
||||
return ((0x4C >> direction) & tileh) != 0;
|
||||
}
|
||||
|
||||
Depot *GetDepotByTile(TileIndex tile);
|
||||
void InitializeDepots();
|
||||
|
||||
void DeleteDepotHighlightOfVehicle(const Vehicle *v);
|
||||
|
||||
#endif /* DEPOT_H */
|
@ -0,0 +1,35 @@
|
||||
/* $Id$ */
|
||||
|
||||
/** @file depot.h Base for all depots (except hangars) */
|
||||
|
||||
#ifndef DEPOT_BASE_H
|
||||
#define DEPOT_BASE_H
|
||||
|
||||
#include "tile_type.h"
|
||||
#include "depot_type.h"
|
||||
#include "oldpool.h"
|
||||
#include "town_type.h"
|
||||
|
||||
DECLARE_OLD_POOL(Depot, Depot, 3, 8000)
|
||||
|
||||
struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
|
||||
TileIndex xy;
|
||||
TownID town_index;
|
||||
|
||||
Depot(TileIndex xy = 0) : xy(xy) {}
|
||||
~Depot();
|
||||
|
||||
inline bool IsValid() const { return this->xy != 0; }
|
||||
};
|
||||
|
||||
static inline bool IsValidDepotID(DepotID index)
|
||||
{
|
||||
return index < GetDepotPoolSize() && GetDepot(index)->IsValid();
|
||||
}
|
||||
|
||||
Depot *GetDepotByTile(TileIndex tile);
|
||||
|
||||
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = GetDepot(start); d != NULL; d = (d->index + 1U < GetDepotPoolSize()) ? GetDepot(d->index + 1U) : NULL) if (d->IsValid())
|
||||
#define FOR_ALL_DEPOTS(d) FOR_ALL_DEPOTS_FROM(d, 0)
|
||||
|
||||
#endif /* DEPOT_BASE_H */
|
@ -0,0 +1,39 @@
|
||||
/* $Id$ */
|
||||
|
||||
/** @file depot_func.h Functions related to depots. */
|
||||
|
||||
#ifndef DEPOT_FUNC_H
|
||||
#define DEPOT_FUNC_H
|
||||
|
||||
#include "depot_type.h"
|
||||
#include "tile_type.h"
|
||||
#include "vehicle_type.h"
|
||||
#include "direction_type.h"
|
||||
#include "slope_type.h"
|
||||
|
||||
void ShowDepotWindow(TileIndex tile, VehicleType type);
|
||||
void InitializeDepots();
|
||||
|
||||
void DeleteDepotHighlightOfVehicle(const Vehicle *v);
|
||||
|
||||
/**
|
||||
* Find out if the slope of the tile is suitable to build a depot of given direction
|
||||
* @param direction The direction in which the depot's exit points
|
||||
* @param tileh The slope of the tile in question
|
||||
* @return true if the construction is possible
|
||||
|
||||
* This is checked by the ugly 0x4C >> direction magic, which does the following:
|
||||
* 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
|
||||
* So: for direction (only the significant bits are shown)<p>
|
||||
* 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
|
||||
* 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
|
||||
* 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
|
||||
* 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
|
||||
* So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
|
||||
*/
|
||||
static inline bool CanBuildDepotByTileh(DiagDirection direction, Slope tileh)
|
||||
{
|
||||
return ((0x4C >> direction) & tileh) != 0;
|
||||
}
|
||||
|
||||
#endif /* DEPOT_FUNC_H */
|
@ -0,0 +1,41 @@
|
||||
/* $Id$ */
|
||||
|
||||
/** @file depot_map.h Map related accessors for depots. */
|
||||
|
||||
#ifndef DEPOT_MAP_H
|
||||
#define DEPOT_MAP_H
|
||||
|
||||
#include "road_map.h"
|
||||
#include "rail_map.h"
|
||||
#include "water_map.h"
|
||||
#include "station_map.h"
|
||||
|
||||
/**
|
||||
* Check if a tile is a depot and it is a depot of the given type.
|
||||
*/
|
||||
static inline bool IsDepotTypeTile(TileIndex tile, TransportType type)
|
||||
{
|
||||
switch (type) {
|
||||
default: NOT_REACHED();
|
||||
case TRANSPORT_RAIL:
|
||||
return IsRailDepotTile(tile);
|
||||
|
||||
case TRANSPORT_ROAD:
|
||||
return IsRoadDepotTile(tile);
|
||||
|
||||
case TRANSPORT_WATER:
|
||||
return IsShipDepotTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the given tile a tile with a depot on it?
|
||||
* @param tile the tile to check
|
||||
* @return true if and only if there is a depot on the tile.
|
||||
*/
|
||||
static inline bool IsDepotTile(TileIndex tile)
|
||||
{
|
||||
return IsRailDepotTile(tile) || IsRoadDepotTile(tile) || IsShipDepotTile(tile) || IsHangarTile(tile);
|
||||
}
|
||||
|
||||
#endif /* DEPOT_MAP_H */
|
Loading…
Reference in New Issue