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-06-25 16:42:03 +01:00
|
|
|
typedef SmallVector<Industry *, 2> IndustryVector;
|
|
|
|
|
2008-10-19 16:39:12 +01:00
|
|
|
/** Station data structure */
|
2009-05-22 16:13:50 +01:00
|
|
|
struct Station : StationPool::PoolItem<&_station_pool> {
|
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
|
|
|
|
2004-08-09 18:04:08 +01:00
|
|
|
TileIndex xy;
|
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;
|
|
|
|
Town *town;
|
2008-11-19 23:55:34 +00:00
|
|
|
|
|
|
|
/* Place to get a name from, in order of importance: */
|
2008-01-12 19:58:06 +00:00
|
|
|
char *name; ///< Custom name
|
2008-11-19 23:55:34 +00:00
|
|
|
IndustryType indtype; ///< Industry type to get the name from
|
|
|
|
StringID string_id; ///< Default name (town area) of station
|
2004-08-09 18:04:08 +01:00
|
|
|
|
|
|
|
ViewportSign sign;
|
|
|
|
|
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 delete_ctr;
|
2008-09-30 21:39:50 +01:00
|
|
|
OwnerByte owner;
|
2009-07-04 12:26:57 +01:00
|
|
|
StationFacilityByte facilities;
|
2004-08-09 18:04:08 +01:00
|
|
|
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;
|
|
|
|
|
2006-04-19 08:17:00 +01:00
|
|
|
/** List of custom stations (StationSpecs) allocated to the station */
|
2006-05-08 14:35:25 +01:00
|
|
|
uint8 num_specs;
|
2006-04-19 08:17:00 +01:00
|
|
|
StationSpecList *speclist;
|
|
|
|
|
2008-10-19 16:39:12 +01:00
|
|
|
Date build_date; ///< Date of construction
|
2004-08-09 18:04:08 +01:00
|
|
|
|
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()
|
|
|
|
|
2006-04-28 21:48:45 +01:00
|
|
|
uint16 random_bits;
|
|
|
|
byte waiting_triggers;
|
2008-04-20 00:19:12 +01:00
|
|
|
uint8 cached_anim_triggers; ///< Combined animation trigger bitmask, used to determine if trigger processing should happen.
|
2006-04-28 21:48:45 +01:00
|
|
|
|
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-06-26 00:49:59 +01:00
|
|
|
FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
|
|
|
|
{
|
|
|
|
return IsRailwayStationTile(tile) && GetStationIndex(tile) == this->index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 */
|