2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/** @file station.h */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef STATION_H
|
|
|
|
#define STATION_H
|
|
|
|
|
2007-02-16 09:38:43 +00:00
|
|
|
#include "airport.h"
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2004-11-14 16:42:08 +00:00
|
|
|
#include "sprite.h"
|
2005-01-31 11:23:10 +00:00
|
|
|
#include "tile.h"
|
2007-05-24 08:52:28 +00:00
|
|
|
#include "road.h"
|
2006-02-03 15:51:00 +00:00
|
|
|
#include "newgrf_station.h"
|
2007-06-22 11:58:59 +00:00
|
|
|
#include "cargopacket.h"
|
2007-04-20 08:00:30 +00:00
|
|
|
#include <list>
|
2007-11-15 22:20:33 +00:00
|
|
|
#include <set>
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-08-02 08:47:56 +00:00
|
|
|
struct Station;
|
|
|
|
struct RoadStop;
|
|
|
|
|
|
|
|
DECLARE_OLD_POOL(Station, Station, 6, 1000)
|
|
|
|
DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
|
|
|
|
|
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 13:55:36 +00:00
|
|
|
enum AcceptancePickup {
|
|
|
|
ACCEPTANCE,
|
|
|
|
PICKUP
|
|
|
|
};
|
|
|
|
|
2007-01-14 20:00:25 +00:00
|
|
|
GoodsEntry() :
|
2007-08-26 13:55:36 +00:00
|
|
|
acceptance_pickup(0),
|
2007-06-22 17:34:04 +00: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 11:58:59 +00:00
|
|
|
last_age(255)
|
2007-01-14 20:00:25 +00:00
|
|
|
{}
|
|
|
|
|
2007-08-26 13:55:36 +00:00
|
|
|
byte acceptance_pickup;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte days_since_pickup;
|
|
|
|
byte rating;
|
|
|
|
byte last_speed;
|
|
|
|
byte last_age;
|
2007-06-22 11:58:59 +00:00
|
|
|
CargoList cargo; ///< The cargo packets of cargo waiting in this station
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-25 10:06:58 +00:00
|
|
|
/** A Stop for a Road Vehicle */
|
2007-08-02 08:47:56 +00:00
|
|
|
struct RoadStop : PoolItem<RoadStop, RoadStopID, &_RoadStop_pool> {
|
2007-01-25 10:06:58 +00:00
|
|
|
/** Types of RoadStops */
|
|
|
|
enum Type {
|
|
|
|
BUS, ///< A standard stop for buses
|
|
|
|
TRUCK ///< A standard stop for trucks
|
|
|
|
};
|
2007-01-17 11:15:51 +00:00
|
|
|
|
2007-08-03 23:19:29 +00:00
|
|
|
static const int cDebugCtorLevel = 5; ///< Debug level on which Contructor / Destructor messages are printed
|
2007-01-25 11:11:43 +00:00
|
|
|
static const uint LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station
|
2007-02-13 00:25:42 +00:00
|
|
|
static const uint MAX_BAY_COUNT = 2; ///< The maximum number of loading bays
|
2007-01-25 10:06:58 +00:00
|
|
|
|
|
|
|
TileIndex xy; ///< Position on the map
|
2007-02-13 00:25:42 +00:00
|
|
|
byte status; ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions.
|
2007-01-25 10:06:58 +00:00
|
|
|
byte num_vehicles; ///< Number of vehicles currently slotted to this stop
|
|
|
|
struct RoadStop *next; ///< Next stop of the given type at this station
|
2007-01-17 11:15:51 +00:00
|
|
|
|
2007-08-02 08:47:56 +00:00
|
|
|
RoadStop(TileIndex tile = 0);
|
|
|
|
virtual ~RoadStop();
|
2007-01-17 11:15:51 +00:00
|
|
|
|
2007-08-30 20:40:33 +00:00
|
|
|
/**
|
|
|
|
* Determines whether a road stop exists
|
|
|
|
* @return true if and only is the road stop exists
|
|
|
|
*/
|
|
|
|
inline bool IsValid() const { return this->xy != 0; }
|
2007-02-13 00:25:42 +00:00
|
|
|
|
|
|
|
/* For accessing status */
|
|
|
|
bool HasFreeBay() const;
|
2007-02-14 16:37:16 +00:00
|
|
|
bool IsFreeBay(uint nr) const;
|
2007-02-13 00:25:42 +00:00
|
|
|
uint AllocateBay();
|
2007-02-14 16:37:16 +00:00
|
|
|
void AllocateDriveThroughBay(uint nr);
|
2007-02-13 00:25:42 +00:00
|
|
|
void FreeBay(uint nr);
|
|
|
|
bool IsEntranceBusy() const;
|
|
|
|
void SetEntranceBusy(bool busy);
|
2007-08-24 19:19:18 +00:00
|
|
|
|
|
|
|
RoadStop *GetNextRoadStop(const Vehicle *v) const;
|
2007-01-25 10:06:58 +00:00
|
|
|
};
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
struct StationSpecList {
|
2006-04-19 07:17:00 +00:00
|
|
|
const StationSpec *spec;
|
2007-04-04 01:35:16 +00: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 07:17:00 +00: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);
|
|
|
|
};
|
|
|
|
|
2007-08-02 08:47:56 +00:00
|
|
|
struct Station : PoolItem<Station, StationID, &_Station_pool> {
|
2007-08-24 19:19:18 +00:00
|
|
|
public:
|
|
|
|
RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const
|
|
|
|
{
|
|
|
|
return type == RoadStop::BUS ? bus_stops : truck_stops;
|
|
|
|
}
|
|
|
|
|
|
|
|
RoadStop *GetPrimaryRoadStop(const Vehicle *v) const;
|
|
|
|
|
|
|
|
const AirportFTAClass *Airport() const
|
|
|
|
{
|
|
|
|
if (airport_tile == 0) return GetAirport(AT_DUMMY);
|
|
|
|
return GetAirport(airport_type);
|
|
|
|
}
|
2007-02-16 09:38:43 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex xy;
|
2005-01-29 19:41:44 +00:00
|
|
|
RoadStop *bus_stops;
|
|
|
|
RoadStop *truck_stops;
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex train_tile;
|
|
|
|
TileIndex airport_tile;
|
|
|
|
TileIndex dock_tile;
|
|
|
|
Town *town;
|
|
|
|
uint16 string_id;
|
|
|
|
|
|
|
|
ViewportSign sign;
|
|
|
|
|
|
|
|
uint16 had_vehicle_of_type;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
byte time_since_load;
|
|
|
|
byte time_since_unload;
|
|
|
|
byte delete_ctr;
|
2007-01-10 18:56:51 +00:00
|
|
|
PlayerByte owner;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte facilities;
|
|
|
|
byte airport_type;
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* trainstation width/height */
|
2004-08-09 17:04:08 +00:00
|
|
|
byte trainst_w, trainst_h;
|
|
|
|
|
2006-04-19 07:17:00 +00:00
|
|
|
/** List of custom stations (StationSpecs) allocated to the station */
|
2006-05-08 13:35:25 +00:00
|
|
|
uint8 num_specs;
|
2006-04-19 07:17:00 +00:00
|
|
|
StationSpecList *speclist;
|
|
|
|
|
2006-08-15 16:55:40 +00:00
|
|
|
Date build_date;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-18 08:50:17 +00:00
|
|
|
byte last_vehicle_type;
|
2007-04-20 08:00:30 +00:00
|
|
|
std::list<Vehicle *> loading_vehicles;
|
2004-08-09 17:04:08 +00:00
|
|
|
GoodsEntry goods[NUM_CARGO];
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2006-04-28 20:48:45 +00:00
|
|
|
uint16 random_bits;
|
|
|
|
byte waiting_triggers;
|
|
|
|
|
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
|
|
|
|
2007-08-03 23:19:29 +00:00
|
|
|
static const int cDebugCtorLevel = 5;
|
2007-01-14 19:18:50 +00:00
|
|
|
|
|
|
|
Station(TileIndex tile = 0);
|
2007-08-02 08:47:56 +00:00
|
|
|
virtual ~Station();
|
2007-01-14 19:18:50 +00:00
|
|
|
|
2007-01-18 09:34:44 +00:00
|
|
|
void AddFacility(byte new_facility_bit, TileIndex facil_xy);
|
2007-09-09 10:13:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the sign of a station dirty for repaint.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-01-14 19:18:50 +00:00
|
|
|
void MarkDirty() const;
|
2007-09-09 10:13:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the tiles of the station as dirty.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2007-06-08 09:35:39 +00:00
|
|
|
void MarkTilesDirty(bool cargo_change) const;
|
2007-01-14 19:18:50 +00:00
|
|
|
bool TileBelongsToRailStation(TileIndex tile) const;
|
2007-02-13 16:36:38 +00:00
|
|
|
uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
|
|
|
|
uint GetPlatformLength(TileIndex tile) const;
|
2007-02-01 16:48:38 +00:00
|
|
|
bool IsBuoy() const;
|
2007-08-30 20:40:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether a station exists
|
|
|
|
* @return true if and only is the station exists
|
|
|
|
*/
|
|
|
|
inline bool IsValid() const { return this->xy != 0; }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-07-16 23:55:22 +00:00
|
|
|
enum StationType {
|
|
|
|
STATION_RAIL,
|
|
|
|
STATION_AIRPORT,
|
|
|
|
STATION_TRUCK,
|
|
|
|
STATION_BUS,
|
|
|
|
STATION_OILRIG,
|
|
|
|
STATION_DOCK,
|
|
|
|
STATION_BUOY
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
enum {
|
2006-08-22 14:38:37 +00:00
|
|
|
FACIL_TRAIN = 0x01,
|
|
|
|
FACIL_TRUCK_STOP = 0x02,
|
|
|
|
FACIL_BUS_STOP = 0x04,
|
|
|
|
FACIL_AIRPORT = 0x08,
|
|
|
|
FACIL_DOCK = 0x10,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2006-08-22 14:38:37 +00:00
|
|
|
// HVOT_PENDING_DELETE = 1 << 0, // not needed anymore
|
2006-04-15 03:08:14 +00:00
|
|
|
HVOT_TRAIN = 1 << 1,
|
|
|
|
HVOT_BUS = 1 << 2,
|
|
|
|
HVOT_TRUCK = 1 << 3,
|
2005-01-29 19:41:44 +00:00
|
|
|
HVOT_AIRCRAFT = 1 << 4,
|
2006-04-15 03:08:14 +00:00
|
|
|
HVOT_SHIP = 1 << 5,
|
2005-05-02 22:13:20 +00:00
|
|
|
/* This bit is used to mark stations. No, it does not belong here, but what
|
|
|
|
* can we do? ;-) */
|
2006-04-15 03:08:14 +00:00
|
|
|
HVOT_BUOY = 1 << 6
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum CatchmentArea {
|
2007-01-11 11:05:01 +00:00
|
|
|
CA_NONE = 0,
|
2006-08-22 14:38:37 +00:00
|
|
|
CA_BUS = 3,
|
|
|
|
CA_TRUCK = 3,
|
|
|
|
CA_TRAIN = 4,
|
2007-08-31 12:45:21 +00:00
|
|
|
CA_DOCK = 5,
|
|
|
|
|
|
|
|
MAX_CATCHMENT = 10, ///< Airports have a catchment up to this number.
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2004-12-08 15:46:13 +00:00
|
|
|
|
2005-10-07 07:35:15 +00:00
|
|
|
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-15 22:20:33 +00:00
|
|
|
/** A set of stations (\c const \c Station* ) */
|
|
|
|
typedef std::set<Station*> StationSet;
|
|
|
|
|
|
|
|
StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h);
|
|
|
|
|
2005-10-07 07:35:15 +00:00
|
|
|
void ShowStationViewWindow(StationID station);
|
2007-03-07 11:47:46 +00:00
|
|
|
void UpdateAllStationVirtCoord();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline StationID GetMaxStationIndex()
|
2006-08-22 20:41:26 +00:00
|
|
|
{
|
|
|
|
/* TODO - This isn't the real content of the function, but
|
|
|
|
* with the new pool-system this will be replaced with one that
|
2006-12-05 13:58:20 +00:00
|
|
|
* _really_ returns the highest index. Now it just returns
|
2006-08-22 20:41:26 +00:00
|
|
|
* the next safe value we are sure about everything is below.
|
|
|
|
*/
|
2006-12-05 13:58:20 +00:00
|
|
|
return GetStationPoolSize() - 1;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline uint GetNumStations()
|
2006-12-05 13:58:20 +00:00
|
|
|
{
|
2006-08-22 20:41:26 +00:00
|
|
|
return GetStationPoolSize();
|
|
|
|
}
|
|
|
|
|
2006-08-22 18:15:17 +00:00
|
|
|
static inline bool IsValidStationID(StationID index)
|
|
|
|
{
|
2007-02-13 15:42:52 +00:00
|
|
|
return index < GetStationPoolSize() && GetStation(index)->IsValid();
|
2006-08-22 18:15:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 15:42:52 +00:00
|
|
|
#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (st->IsValid())
|
2005-02-03 17:22:35 +00:00
|
|
|
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2005-02-04 15:31:30 +00:00
|
|
|
|
|
|
|
/* Stuff for ROADSTOPS */
|
|
|
|
|
2007-01-25 08:58:09 +00:00
|
|
|
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1U < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1U) : NULL) if (rs->IsValid())
|
2005-02-04 15:31:30 +00:00
|
|
|
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
|
|
|
|
|
|
|
|
/* End of stuff for ROADSTOPS */
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void AfterLoadStations();
|
2005-03-05 18:44:26 +00:00
|
|
|
void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad);
|
|
|
|
void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad);
|
2004-11-14 01:25:05 +00:00
|
|
|
|
|
|
|
|
2007-07-16 23:55:22 +00:00
|
|
|
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
|
|
|
|
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
|
2005-10-16 09:13:04 +00:00
|
|
|
|
2007-01-25 10:06:58 +00:00
|
|
|
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type);
|
|
|
|
uint GetNumRoadStops(const Station* st, RoadStop::Type type);
|
2007-03-07 11:47:46 +00:00
|
|
|
RoadStop * AllocateRoadStop();
|
2006-03-02 08:55:12 +00:00
|
|
|
void ClearSlot(Vehicle *v);
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2007-01-31 10:50:12 +00:00
|
|
|
void DeleteOilRig(TileIndex t);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* STATION_H */
|