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-04-20 08:00:30 +00:00
|
|
|
#include <list>
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 20:00:25 +00:00
|
|
|
static const StationID INVALID_STATION = 0xFFFF;
|
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-01-14 20:00:25 +00:00
|
|
|
GoodsEntry() :
|
|
|
|
waiting_acceptance(0),
|
2007-03-02 18:49:11 +00:00
|
|
|
unload_pending(0),
|
2007-01-14 20:00:25 +00:00
|
|
|
days_since_pickup(0),
|
2007-03-08 20:50:27 +00:00
|
|
|
rating(INITIAL_STATION_RATING),
|
2007-01-14 20:00:25 +00:00
|
|
|
enroute_from(INVALID_STATION),
|
2007-01-15 14:42:24 +00:00
|
|
|
enroute_from_xy(INVALID_TILE),
|
2007-01-14 20:00:25 +00:00
|
|
|
last_speed(0),
|
|
|
|
last_age(255),
|
|
|
|
feeder_profit(0)
|
|
|
|
{}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 waiting_acceptance;
|
2007-03-02 18:49:11 +00:00
|
|
|
uint16 unload_pending; ///< records how much cargo is awaiting transfer during gradual loading to allow correct fee calc
|
2004-08-09 17:04:08 +00:00
|
|
|
byte days_since_pickup;
|
|
|
|
byte rating;
|
2006-03-26 22:55:27 +00:00
|
|
|
StationID enroute_from;
|
2007-01-15 14:42:24 +00:00
|
|
|
TileIndex enroute_from_xy;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte enroute_time;
|
|
|
|
byte last_speed;
|
|
|
|
byte last_age;
|
2005-06-15 16:58:15 +00:00
|
|
|
int32 feeder_profit;
|
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 */
|
|
|
|
struct RoadStop {
|
|
|
|
/** 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-01-25 11:11:43 +00:00
|
|
|
static const int cDebugCtorLevel = 3; ///< Debug level on which Contructor / Destructor messages are printed
|
|
|
|
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
|
|
|
|
RoadStopID index; ///< Global (i.e. pool-wide) index
|
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-01-17 21:14:17 +00:00
|
|
|
RoadStop(TileIndex tile);
|
2007-01-17 11:15:51 +00:00
|
|
|
~RoadStop();
|
|
|
|
|
|
|
|
void *operator new (size_t size);
|
|
|
|
void operator delete(void *rs);
|
|
|
|
|
|
|
|
/* For loading games */
|
|
|
|
void *operator new (size_t size, int index);
|
|
|
|
void operator delete(void *rs, int index);
|
|
|
|
|
2007-01-25 08:58:09 +00:00
|
|
|
bool IsValid() const;
|
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-01-25 08:58:09 +00:00
|
|
|
protected:
|
2007-03-07 11:47:46 +00:00
|
|
|
static RoadStop *AllocateRaw();
|
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);
|
|
|
|
};
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
struct Station {
|
2007-01-31 04:34:56 +00:00
|
|
|
public:
|
|
|
|
RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const
|
|
|
|
{
|
|
|
|
return type == RoadStop::BUS ? bus_stops : truck_stops;
|
|
|
|
}
|
|
|
|
|
2007-02-16 09:38:43 +00:00
|
|
|
const AirportFTAClass *Airport() const
|
|
|
|
{
|
2007-03-29 13:52:34 +00:00
|
|
|
if (airport_tile == 0) return GetAirport(AT_DUMMY);
|
2007-02-16 09:38:43 +00:00
|
|
|
return GetAirport(airport_type);
|
|
|
|
}
|
|
|
|
|
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
|
2005-03-25 10:40:58 +00:00
|
|
|
StationID index;
|
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-01-14 23:02:12 +00:00
|
|
|
static const int cDebugCtorLevel = 3;
|
2007-01-14 19:18:50 +00:00
|
|
|
|
|
|
|
Station(TileIndex tile = 0);
|
|
|
|
~Station();
|
|
|
|
|
|
|
|
/* normal new/delete operators. Used when building/removing station */
|
|
|
|
void* operator new (size_t size);
|
|
|
|
void operator delete(void *p);
|
|
|
|
|
|
|
|
/* new/delete operators accepting station index. Used when loading station from savegame. */
|
|
|
|
void* operator new (size_t size, int st_idx);
|
|
|
|
void operator delete(void *p, int st_idx);
|
|
|
|
|
2007-01-18 09:34:44 +00:00
|
|
|
void AddFacility(byte new_facility_bit, TileIndex facil_xy);
|
2007-01-14 19:18:50 +00:00
|
|
|
void MarkDirty() const;
|
|
|
|
void MarkTilesDirty() const;
|
|
|
|
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-02-13 15:42:52 +00:00
|
|
|
bool IsValid() const;
|
2007-01-14 19:18:50 +00:00
|
|
|
|
|
|
|
protected:
|
2007-03-07 11:47:46 +00:00
|
|
|
static Station *AllocateRaw();
|
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-02-17 07:45:18 +00:00
|
|
|
CA_DOCK = 5
|
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
|
|
|
|
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
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
/* sorter stuff */
|
2007-03-07 11:47:46 +00:00
|
|
|
void RebuildStationLists();
|
|
|
|
void ResortStationLists();
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2006-12-03 17:27:43 +00:00
|
|
|
DECLARE_OLD_POOL(Station, Station, 6, 1000)
|
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 */
|
|
|
|
|
2006-12-03 17:27:43 +00:00
|
|
|
DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000)
|
2005-02-04 15:31:30 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2006-05-06 20:33:22 +00:00
|
|
|
const DrawTileSprites *GetStationTileLayout(byte gfx);
|
2007-05-24 08:52:28 +00:00
|
|
|
void StationPickerDrawSprite(int x, int y, 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 */
|