2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-03-31 01:06:17 +01:00
|
|
|
/** @file station_base.h Base classes/functions for stations. */
|
2007-04-04 02:35:16 +01:00
|
|
|
|
2008-03-31 01:06:17 +01:00
|
|
|
#ifndef STATION_BASE_H
|
|
|
|
#define STATION_BASE_H
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2008-03-28 16:33:28 +00:00
|
|
|
#include "station_type.h"
|
2007-02-16 09:38:43 +00:00
|
|
|
#include "airport.h"
|
2009-05-22 16:39:22 +01:00
|
|
|
#include "core/pool_type.hpp"
|
2007-06-22 12:58:59 +01:00
|
|
|
#include "cargopacket.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town_type.h"
|
2008-03-31 07:42:26 +01:00
|
|
|
#include "strings_type.h"
|
|
|
|
#include "date_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2008-09-30 21:51:04 +01:00
|
|
|
#include "company_type.h"
|
2008-11-19 23:55:34 +00:00
|
|
|
#include "industry_type.h"
|
2008-03-31 07:42:26 +01:00
|
|
|
#include "core/geometry_type.hpp"
|
2008-05-07 14:10:15 +01:00
|
|
|
#include "viewport_type.h"
|
2009-06-24 18:39:54 +01:00
|
|
|
#include "station_map.h"
|
2007-04-20 09:00:30 +01:00
|
|
|
#include <list>
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-05-22 16:13:50 +01:00
|
|
|
typedef Pool<Station, StationID, 32, 64000> StationPool;
|
|
|
|
extern StationPool _station_pool;
|
2007-08-02 09:47:56 +01:00
|
|
|
|
2007-03-08 20:50:27 +00:00
|
|
|
static const byte INITIAL_STATION_RATING = 175;
|
2007-01-14 20:00:25 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct GoodsEntry {
|
2007-08-26 14:55:36 +01:00
|
|
|
enum AcceptancePickup {
|
|
|
|
ACCEPTANCE,
|
|
|
|
PICKUP
|
|
|
|
};
|
|
|
|
|
2007-01-14 20:00:25 +00:00
|
|
|
GoodsEntry() :
|
2007-08-26 14:55:36 +01:00
|
|
|
acceptance_pickup(0),
|
2007-06-22 18:34:04 +01:00
|
|
|
days_since_pickup(255),
|
2007-03-08 20:50:27 +00:00
|
|
|
rating(INITIAL_STATION_RATING),
|
2007-01-14 20:00:25 +00:00
|
|
|
last_speed(0),
|
2007-06-22 12:58:59 +01:00
|
|
|
last_age(255)
|
2007-01-14 20:00:25 +00:00
|
|
|
{}
|
|
|
|
|
2007-08-26 14:55:36 +01:00
|
|
|
byte acceptance_pickup;
|
2004-08-09 18:04:08 +01:00
|
|
|
byte days_since_pickup;
|
|
|
|
byte rating;
|
|
|
|
byte last_speed;
|
|
|
|
byte last_age;
|
2007-06-22 12:58:59 +01:00
|
|
|
CargoList cargo; ///< The cargo packets of cargo waiting in this station
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct StationSpecList {
|
2006-04-19 08:17:00 +01:00
|
|
|
const StationSpec *spec;
|
2007-04-04 02:35:16 +01:00
|
|
|
uint32 grfid; ///< GRF ID of this custom station
|
|
|
|
uint8 localidx; ///< Station ID within GRF of station
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-04-19 08:17:00 +01:00
|
|
|
|
2007-01-14 23:02:12 +00:00
|
|
|
/** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */
|
|
|
|
struct StationRect : public Rect {
|
|
|
|
enum StationRectMode
|
|
|
|
{
|
|
|
|
ADD_TEST = 0,
|
|
|
|
ADD_TRY,
|
|
|
|
ADD_FORCE
|
|
|
|
};
|
|
|
|
|
|
|
|
StationRect();
|
|
|
|
void MakeEmpty();
|
2007-02-02 16:51:10 +00:00
|
|
|
bool PtInExtendedRect(int x, int y, int distance = 0) const;
|
2007-01-14 23:02:12 +00:00
|
|
|
bool IsEmpty() const;
|
|
|
|
bool BeforeAddTile(TileIndex tile, StationRectMode mode);
|
|
|
|
bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode);
|
|
|
|
bool AfterRemoveTile(Station *st, TileIndex tile);
|
|
|
|
bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h);
|
|
|
|
|
|
|
|
static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a);
|
|
|
|
|
|
|
|
StationRect& operator = (Rect src);
|
|
|
|
};
|
|
|
|
|
2009-07-17 20:44:13 +01:00
|
|
|
/** Base class for all station-ish types */
|
|
|
|
struct BaseStation {
|
2009-07-17 21:30:07 +01:00
|
|
|
TileIndex xy; ///< Base tile of the station
|
|
|
|
ViewportSign sign; ///< NOSAVE: Dimensions of sign
|
|
|
|
byte delete_ctr; ///< Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is deleted.
|
|
|
|
|
2009-07-17 20:44:13 +01:00
|
|
|
char *name; ///< Custom name
|
|
|
|
StringID string_id; ///< Default name (town area) of station
|
|
|
|
|
|
|
|
Town *town; ///< The town this station is associated with
|
|
|
|
OwnerByte owner; ///< The owner of this station
|
|
|
|
StationFacilityByte facilities; ///< The facilities that this station has
|
|
|
|
|
2009-07-18 19:39:17 +01:00
|
|
|
uint8 num_specs; ///< Number of specs in the speclist
|
|
|
|
StationSpecList *speclist; ///< List of station specs of this station
|
2009-07-17 20:44:13 +01:00
|
|
|
|
|
|
|
Date build_date; ///< Date of construction
|
|
|
|
|
|
|
|
uint16 random_bits; ///< Random bits assigned to this station
|
|
|
|
byte waiting_triggers; ///< Waiting triggers (NewGRF) for this station
|
|
|
|
uint8 cached_anim_triggers; ///< NOSAVE: Combined animation trigger bitmask, used to determine if trigger processing should happen.
|
|
|
|
|
2009-07-18 19:39:17 +01:00
|
|
|
BaseStation(TileIndex tile) : xy(tile) { }
|
|
|
|
|
2009-07-17 21:30:07 +01:00
|
|
|
virtual ~BaseStation();
|
|
|
|
|
2009-07-17 20:44:13 +01:00
|
|
|
/**
|
|
|
|
* Check whether a specific tile belongs to this station.
|
|
|
|
* @param tile the tile to check
|
|
|
|
* @return true if the tile belongs to this station
|
|
|
|
*/
|
|
|
|
virtual bool TileBelongsToRailStation(TileIndex tile) const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to get a NewGRF variable that isn't implemented by the base class.
|
|
|
|
* @param object the resolver object related to this query
|
|
|
|
* @param variable that is queried
|
|
|
|
* @param parameter parameter for that variable
|
|
|
|
* @param available will return false if ever the variable asked for does not exist
|
|
|
|
* @return the value stored in the corresponding variable
|
|
|
|
*/
|
|
|
|
virtual uint32 GetNewGRFVariable(const struct ResolverObject *object, byte variable, byte parameter, bool *available) const = 0;
|
2009-07-18 09:41:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the coordinated of the sign (as shown in the viewport).
|
|
|
|
*/
|
|
|
|
virtual void UpdateVirtCoord() = 0;
|
2009-07-17 20:44:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base station belonging to a specific tile.
|
|
|
|
* @param tile The tile to get the base station from.
|
|
|
|
* @return the station associated with that tile.
|
|
|
|
*/
|
|
|
|
static BaseStation *GetByTile(TileIndex tile);
|
|
|
|
};
|
|
|
|
|
2009-07-18 19:39:17 +01:00
|
|
|
/**
|
|
|
|
* Class defining several overloaded accessors so we don't
|
|
|
|
* have to cast base stations that often
|
|
|
|
*/
|
|
|
|
template <class T, bool Tis_waypoint>
|
|
|
|
struct SpecializedStation : public BaseStation {
|
|
|
|
static const StationFacility EXPECTED_FACIL = Tis_waypoint ? FACIL_WAYPOINT : FACIL_NONE; ///< Specialized type
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set station type correctly
|
|
|
|
* @param tile The base tile of the station.
|
|
|
|
*/
|
|
|
|
FORCEINLINE SpecializedStation<T, Tis_waypoint>(TileIndex tile) :
|
|
|
|
BaseStation(tile)
|
|
|
|
{
|
|
|
|
this->facilities = EXPECTED_FACIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for checking whether the given station is of this type.
|
|
|
|
* @param st the station to check.
|
|
|
|
* @return true if the station is the type we expect it to be.
|
|
|
|
*/
|
|
|
|
static FORCEINLINE bool IsExpected(const BaseStation *st)
|
|
|
|
{
|
|
|
|
return (st->facilities & FACIL_WAYPOINT) == EXPECTED_FACIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a BaseStation to SpecializedStation with type checking.
|
|
|
|
* @param st BaseStation pointer
|
|
|
|
* @return pointer to SpecializedStation
|
|
|
|
*/
|
|
|
|
static FORCEINLINE T *From(BaseStation *st)
|
|
|
|
{
|
|
|
|
assert(IsExpected(st));
|
|
|
|
return (T *)st;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a const BaseStation to const SpecializedStation with type checking.
|
|
|
|
* @param st BaseStation pointer
|
|
|
|
* @return pointer to SpecializedStation
|
|
|
|
*/
|
|
|
|
static FORCEINLINE const T *From(const BaseStation *st)
|
|
|
|
{
|
|
|
|
assert(IsExpected(st));
|
|
|
|
return (const T *)st;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-25 16:42:03 +01:00
|
|
|
typedef SmallVector<Industry *, 2> IndustryVector;
|
|
|
|
|
2008-10-19 16:39:12 +01:00
|
|
|
/** Station data structure */
|
2009-07-18 19:39:17 +01:00
|
|
|
struct Station : StationPool::PoolItem<&_station_pool>, SpecializedStation<Station, false> {
|
2007-08-24 20:19:18 +01:00
|
|
|
public:
|
2008-03-31 01:06:17 +01:00
|
|
|
RoadStop *GetPrimaryRoadStop(RoadStopType type) const
|
2007-08-24 20:19:18 +01:00
|
|
|
{
|
2008-03-31 01:06:17 +01:00
|
|
|
return type == ROADSTOP_BUS ? bus_stops : truck_stops;
|
2007-08-24 20:19:18 +01:00
|
|
|
}
|
|
|
|
|
2009-05-22 21:18:45 +01:00
|
|
|
RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
|
2007-08-24 20:19:18 +01:00
|
|
|
|
|
|
|
const AirportFTAClass *Airport() const
|
|
|
|
{
|
2008-12-26 18:01:15 +00:00
|
|
|
if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
|
2007-08-24 20:19:18 +01:00
|
|
|
return GetAirport(airport_type);
|
|
|
|
}
|
2007-02-16 09:38:43 +00:00
|
|
|
|
2005-01-29 19:41:44 +00:00
|
|
|
RoadStop *bus_stops;
|
|
|
|
RoadStop *truck_stops;
|
2004-08-09 18:04:08 +01:00
|
|
|
TileIndex train_tile;
|
|
|
|
TileIndex airport_tile;
|
|
|
|
TileIndex dock_tile;
|
2008-11-19 23:55:34 +00:00
|
|
|
|
|
|
|
IndustryType indtype; ///< Industry type to get the name from
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2009-07-04 12:26:57 +01:00
|
|
|
StationHadVehicleOfTypeByte had_vehicle_of_type;
|
2004-09-10 20:02:27 +01:00
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
byte time_since_load;
|
|
|
|
byte time_since_unload;
|
|
|
|
byte airport_type;
|
|
|
|
|
2007-04-04 02:35:16 +01:00
|
|
|
/* trainstation width/height */
|
2004-08-09 18:04:08 +01:00
|
|
|
byte trainst_w, trainst_h;
|
|
|
|
|
2007-04-04 02:35:16 +01:00
|
|
|
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
|
2004-08-09 18:04:08 +01:00
|
|
|
|
2006-04-18 09:50:17 +01:00
|
|
|
byte last_vehicle_type;
|
2007-04-20 09:00:30 +01:00
|
|
|
std::list<Vehicle *> loading_vehicles;
|
2008-10-19 16:39:12 +01:00
|
|
|
GoodsEntry goods[NUM_CARGO]; ///< Goods at this station
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2009-06-25 16:42:03 +01:00
|
|
|
IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
|
|
|
|
|
2007-01-14 23:02:12 +00:00
|
|
|
StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2008-12-26 18:01:15 +00:00
|
|
|
Station(TileIndex tile = INVALID_TILE);
|
2009-05-22 16:13:50 +01:00
|
|
|
~Station();
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2009-07-04 12:26:57 +01:00
|
|
|
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
|
2007-09-09 11:13:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the tiles of the station as dirty.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-06-08 10:35:39 +01:00
|
|
|
void MarkTilesDirty(bool cargo_change) const;
|
2009-06-26 00:49:59 +01:00
|
|
|
|
2009-07-07 17:43:58 +01:00
|
|
|
void UpdateVirtCoord();
|
|
|
|
|
2007-02-13 16:36:38 +00:00
|
|
|
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
|
|
|
|
uint GetPlatformLength(TileIndex tile) const;
|
2009-06-25 16:42:03 +01:00
|
|
|
void RecomputeIndustriesNear();
|
|
|
|
static void RecomputeIndustriesNearForAll();
|
|
|
|
|
2008-10-25 15:19:09 +01:00
|
|
|
uint GetCatchmentRadius() const;
|
2009-06-24 18:39:54 +01:00
|
|
|
|
2009-07-17 20:44:13 +01:00
|
|
|
/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
|
2009-06-26 00:49:59 +01:00
|
|
|
{
|
|
|
|
return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
|
|
|
|
}
|
|
|
|
|
2009-07-17 20:44:13 +01:00
|
|
|
/* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
|
|
|
|
|
2009-06-26 00:49:59 +01:00
|
|
|
/**
|
|
|
|
* Determines whether a station is a buoy only.
|
|
|
|
* @todo Ditch this encoding of buoys
|
|
|
|
*/
|
|
|
|
FORCEINLINE bool IsBuoy() const
|
|
|
|
{
|
|
|
|
return (this->had_vehicle_of_type & HVOT_BUOY) != 0;
|
|
|
|
}
|
|
|
|
|
2009-06-24 18:39:54 +01:00
|
|
|
static FORCEINLINE Station *GetByTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
return Station::Get(GetStationIndex(tile));
|
|
|
|
}
|
2009-07-05 14:20:05 +01:00
|
|
|
|
|
|
|
static void PostDestructor(size_t index);
|
2004-08-09 18:04:08 +01:00
|
|
|
};
|
|
|
|
|
2009-05-22 15:23:36 +01:00
|
|
|
#define FOR_ALL_STATIONS_FROM(var, start) FOR_ALL_ITEMS_FROM(Station, station_index, var, start)
|
|
|
|
#define FOR_ALL_STATIONS(var) FOR_ALL_STATIONS_FROM(var, 0)
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2008-03-31 01:06:17 +01:00
|
|
|
#endif /* STATION_BASE_H */
|