2005-07-24 16:12:37 +02:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-03-31 02:06:17 +02:00
|
|
|
/** @file station_base.h Base classes/functions for stations. */
|
2007-04-04 03:35:16 +02:00
|
|
|
|
2008-03-31 02:06:17 +02:00
|
|
|
#ifndef STATION_BASE_H
|
|
|
|
#define STATION_BASE_H
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2008-03-28 17:33:28 +01:00
|
|
|
#include "station_type.h"
|
2007-02-16 10:38:43 +01:00
|
|
|
#include "airport.h"
|
2009-05-22 17:39:22 +02:00
|
|
|
#include "core/pool_type.hpp"
|
2007-06-22 13:58:59 +02:00
|
|
|
#include "cargopacket.h"
|
2007-12-21 23:50:51 +01:00
|
|
|
#include "cargo_type.h"
|
2008-01-07 15:02:26 +01:00
|
|
|
#include "town_type.h"
|
2008-03-31 08:42:26 +02:00
|
|
|
#include "strings_type.h"
|
|
|
|
#include "date_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2008-09-30 22:51:04 +02:00
|
|
|
#include "company_type.h"
|
2008-11-20 00:55:34 +01:00
|
|
|
#include "industry_type.h"
|
2008-03-31 08:42:26 +02:00
|
|
|
#include "core/geometry_type.hpp"
|
2008-05-07 15:10:15 +02:00
|
|
|
#include "viewport_type.h"
|
2009-06-24 19:39:54 +02:00
|
|
|
#include "station_map.h"
|
2007-04-20 10:00:30 +02:00
|
|
|
#include <list>
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-05-22 17:13:50 +02:00
|
|
|
typedef Pool<Station, StationID, 32, 64000> StationPool;
|
|
|
|
extern StationPool _station_pool;
|
2007-08-02 10:47:56 +02:00
|
|
|
|
2007-03-08 21:50:27 +01:00
|
|
|
static const byte INITIAL_STATION_RATING = 175;
|
2007-01-14 21:00:25 +01:00
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
struct GoodsEntry {
|
2007-08-26 15:55:36 +02:00
|
|
|
enum AcceptancePickup {
|
|
|
|
ACCEPTANCE,
|
|
|
|
PICKUP
|
|
|
|
};
|
|
|
|
|
2007-01-14 21:00:25 +01:00
|
|
|
GoodsEntry() :
|
2007-08-26 15:55:36 +02:00
|
|
|
acceptance_pickup(0),
|
2007-06-22 19:34:04 +02:00
|
|
|
days_since_pickup(255),
|
2007-03-08 21:50:27 +01:00
|
|
|
rating(INITIAL_STATION_RATING),
|
2007-01-14 21:00:25 +01:00
|
|
|
last_speed(0),
|
2007-06-22 13:58:59 +02:00
|
|
|
last_age(255)
|
2007-01-14 21:00:25 +01:00
|
|
|
{}
|
|
|
|
|
2007-08-26 15:55:36 +02:00
|
|
|
byte acceptance_pickup;
|
2004-08-09 19:04:08 +02:00
|
|
|
byte days_since_pickup;
|
|
|
|
byte rating;
|
|
|
|
byte last_speed;
|
|
|
|
byte last_age;
|
2007-06-22 13:58:59 +02:00
|
|
|
CargoList cargo; ///< The cargo packets of cargo waiting in this station
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
struct StationSpecList {
|
2006-04-19 09:17:00 +02:00
|
|
|
const StationSpec *spec;
|
2007-04-04 03:35:16 +02:00
|
|
|
uint32 grfid; ///< GRF ID of this custom station
|
|
|
|
uint8 localidx; ///< Station ID within GRF of station
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2006-04-19 09:17:00 +02:00
|
|
|
|
2007-01-15 00:02:12 +01: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 17:51:10 +01:00
|
|
|
bool PtInExtendedRect(int x, int y, int distance = 0) const;
|
2007-01-15 00:02:12 +01: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 21:44:13 +02:00
|
|
|
/** Base class for all station-ish types */
|
|
|
|
struct BaseStation {
|
2009-07-17 22:30:07 +02: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 21:44:13 +02: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 20:39:17 +02:00
|
|
|
uint8 num_specs; ///< Number of specs in the speclist
|
|
|
|
StationSpecList *speclist; ///< List of station specs of this station
|
2009-07-17 21:44:13 +02: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 20:39:17 +02:00
|
|
|
BaseStation(TileIndex tile) : xy(tile) { }
|
|
|
|
|
2009-07-17 22:30:07 +02:00
|
|
|
virtual ~BaseStation();
|
|
|
|
|
2009-07-17 21:44:13 +02: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 10:41:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the coordinated of the sign (as shown in the viewport).
|
|
|
|
*/
|
|
|
|
virtual void UpdateVirtCoord() = 0;
|
2009-07-17 21:44:13 +02: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 20:39:17 +02: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 17:42:03 +02:00
|
|
|
typedef SmallVector<Industry *, 2> IndustryVector;
|
|
|
|
|
2008-10-19 17:39:12 +02:00
|
|
|
/** Station data structure */
|
2009-07-18 20:39:17 +02:00
|
|
|
struct Station : StationPool::PoolItem<&_station_pool>, SpecializedStation<Station, false> {
|
2007-08-24 21:19:18 +02:00
|
|
|
public:
|
2008-03-31 02:06:17 +02:00
|
|
|
RoadStop *GetPrimaryRoadStop(RoadStopType type) const
|
2007-08-24 21:19:18 +02:00
|
|
|
{
|
2008-03-31 02:06:17 +02:00
|
|
|
return type == ROADSTOP_BUS ? bus_stops : truck_stops;
|
2007-08-24 21:19:18 +02:00
|
|
|
}
|
|
|
|
|
2009-05-22 22:18:45 +02:00
|
|
|
RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
|
2007-08-24 21:19:18 +02:00
|
|
|
|
|
|
|
const AirportFTAClass *Airport() const
|
|
|
|
{
|
2008-12-26 19:01:15 +01:00
|
|
|
if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
|
2007-08-24 21:19:18 +02:00
|
|
|
return GetAirport(airport_type);
|
|
|
|
}
|
2007-02-16 10:38:43 +01:00
|
|
|
|
2005-01-29 20:41:44 +01:00
|
|
|
RoadStop *bus_stops;
|
|
|
|
RoadStop *truck_stops;
|
2004-08-09 19:04:08 +02:00
|
|
|
TileIndex train_tile;
|
|
|
|
TileIndex airport_tile;
|
|
|
|
TileIndex dock_tile;
|
2008-11-20 00:55:34 +01:00
|
|
|
|
|
|
|
IndustryType indtype; ///< Industry type to get the name from
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2009-07-04 13:26:57 +02:00
|
|
|
StationHadVehicleOfTypeByte had_vehicle_of_type;
|
2004-09-10 21:02:27 +02:00
|
|
|
|
2004-08-09 19:04:08 +02:00
|
|
|
byte time_since_load;
|
|
|
|
byte time_since_unload;
|
|
|
|
byte airport_type;
|
|
|
|
|
2007-04-04 03:35:16 +02:00
|
|
|
/* trainstation width/height */
|
2004-08-09 19:04:08 +02:00
|
|
|
byte trainst_w, trainst_h;
|
|
|
|
|
2007-04-04 03:35:16 +02:00
|
|
|
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
|
2004-08-09 19:04:08 +02:00
|
|
|
|
2006-04-18 10:50:17 +02:00
|
|
|
byte last_vehicle_type;
|
2007-04-20 10:00:30 +02:00
|
|
|
std::list<Vehicle *> loading_vehicles;
|
2008-10-19 17:39:12 +02:00
|
|
|
GoodsEntry goods[NUM_CARGO]; ///< Goods at this station
|
2005-01-29 20:41:44 +01:00
|
|
|
|
2009-06-25 17:42:03 +02:00
|
|
|
IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
|
|
|
|
|
2007-01-15 00:02:12 +01:00
|
|
|
StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions
|
2007-01-14 20:18:50 +01:00
|
|
|
|
2008-12-26 19:01:15 +01:00
|
|
|
Station(TileIndex tile = INVALID_TILE);
|
2009-05-22 17:13:50 +02:00
|
|
|
~Station();
|
2007-01-14 20:18:50 +01:00
|
|
|
|
2009-07-04 13:26:57 +02:00
|
|
|
void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
|
2007-09-09 12:13:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the tiles of the station as dirty.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-06-08 11:35:39 +02:00
|
|
|
void MarkTilesDirty(bool cargo_change) const;
|
2009-06-26 01:49:59 +02:00
|
|
|
|
2009-07-07 18:43:58 +02:00
|
|
|
void UpdateVirtCoord();
|
|
|
|
|
2007-02-13 17:36:38 +01:00
|
|
|
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
|
|
|
|
uint GetPlatformLength(TileIndex tile) const;
|
2009-06-25 17:42:03 +02:00
|
|
|
void RecomputeIndustriesNear();
|
|
|
|
static void RecomputeIndustriesNearForAll();
|
|
|
|
|
2008-10-25 16:19:09 +02:00
|
|
|
uint GetCatchmentRadius() const;
|
2009-06-24 19:39:54 +02:00
|
|
|
|
2009-07-17 21:44:13 +02:00
|
|
|
/* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
|
2009-06-26 01:49:59 +02:00
|
|
|
{
|
|
|
|
return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
|
|
|
|
}
|
|
|
|
|
2009-07-17 21:44:13 +02:00
|
|
|
/* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
|
|
|
|
|
2009-06-26 01:49:59 +02: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 19:39:54 +02:00
|
|
|
static FORCEINLINE Station *GetByTile(TileIndex tile)
|
|
|
|
{
|
|
|
|
return Station::Get(GetStationIndex(tile));
|
|
|
|
}
|
2009-07-05 15:20:05 +02:00
|
|
|
|
|
|
|
static void PostDestructor(size_t index);
|
2004-08-09 19:04:08 +02:00
|
|
|
};
|
|
|
|
|
2009-05-22 16:23:36 +02: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 23:31:58 +01:00
|
|
|
|
2008-03-31 02:06:17 +02:00
|
|
|
#endif /* STATION_BASE_H */
|