2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef STATION_H
|
|
|
|
#define STATION_H
|
|
|
|
|
2005-07-21 19:36:43 +00:00
|
|
|
#include "player.h"
|
2005-02-03 17:22:35 +00:00
|
|
|
#include "pool.h"
|
2004-11-14 16:42:08 +00:00
|
|
|
#include "sprite.h"
|
2005-01-31 11:23:10 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
2006-02-03 15:51:00 +00:00
|
|
|
#include "newgrf_station.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
typedef struct GoodsEntry {
|
|
|
|
uint16 waiting_acceptance;
|
|
|
|
byte days_since_pickup;
|
|
|
|
byte rating;
|
2005-02-02 16:16:43 +00:00
|
|
|
uint16 enroute_from;
|
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;
|
2004-08-09 17:04:08 +00:00
|
|
|
} GoodsEntry;
|
|
|
|
|
2005-01-29 19:41:44 +00:00
|
|
|
typedef enum RoadStopType {
|
|
|
|
RS_BUS,
|
|
|
|
RS_TRUCK
|
|
|
|
} RoadStopType;
|
|
|
|
|
2005-02-02 16:16:43 +00:00
|
|
|
enum {
|
|
|
|
INVALID_STATION = 0xFFFF,
|
|
|
|
INVALID_SLOT = 0xFFFF,
|
|
|
|
NUM_SLOTS = 2,
|
|
|
|
ROAD_STOP_LIMIT = 8,
|
|
|
|
};
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2005-03-25 10:40:58 +00:00
|
|
|
typedef uint16 StationID;
|
|
|
|
|
2005-01-29 19:41:44 +00:00
|
|
|
typedef struct RoadStop {
|
|
|
|
TileIndex xy;
|
|
|
|
bool used;
|
|
|
|
byte status;
|
|
|
|
uint32 index;
|
|
|
|
uint16 slot[NUM_SLOTS];
|
2005-03-25 10:40:58 +00:00
|
|
|
StationID station;
|
2005-01-29 19:41:44 +00:00
|
|
|
uint8 type;
|
|
|
|
struct RoadStop *next;
|
|
|
|
struct RoadStop *prev;
|
|
|
|
} RoadStop;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
struct Station {
|
|
|
|
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;
|
2005-09-30 20:37:25 +00:00
|
|
|
PlayerID owner;
|
2004-08-09 17:04:08 +00:00
|
|
|
byte facilities;
|
|
|
|
byte airport_type;
|
|
|
|
|
|
|
|
// trainstation width/height
|
|
|
|
byte trainst_w, trainst_h;
|
|
|
|
|
2004-11-14 11:04:59 +00:00
|
|
|
byte class_id; // custom graphics station class
|
|
|
|
byte stat_id; // custom graphics station id in the @class_id class
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 build_date;
|
|
|
|
|
|
|
|
//uint16 airport_flags;
|
2004-11-14 11:04:59 +00:00
|
|
|
uint32 airport_flags;
|
2005-03-25 10:40:58 +00:00
|
|
|
StationID index;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
VehicleID last_vehicle;
|
|
|
|
GoodsEntry goods[NUM_CARGO];
|
2005-01-29 19:41:44 +00:00
|
|
|
|
|
|
|
/* Stuff that is no longer used, but needed for conversion */
|
|
|
|
TileIndex bus_tile_obsolete;
|
|
|
|
TileIndex lorry_tile_obsolete;
|
|
|
|
|
|
|
|
byte truck_stop_status_obsolete;
|
|
|
|
byte bus_stop_status_obsolete;
|
|
|
|
byte blocked_months_obsolete;
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FACIL_TRAIN = 1,
|
|
|
|
FACIL_TRUCK_STOP = 2,
|
|
|
|
FACIL_BUS_STOP = 4,
|
|
|
|
FACIL_AIRPORT = 8,
|
|
|
|
FACIL_DOCK = 0x10,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
// HVOT_PENDING_DELETE = 1<<0, // not needed anymore
|
|
|
|
HVOT_TRAIN = 1<<1,
|
|
|
|
HVOT_BUS = 1 << 2,
|
|
|
|
HVOT_TRUCK = 1 << 3,
|
2005-01-29 19:41:44 +00:00
|
|
|
HVOT_AIRCRAFT = 1 << 4,
|
2004-08-09 17:04:08 +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? ;-) */
|
2004-08-09 17:04:08 +00:00
|
|
|
HVOT_BUOY = 1 << 6
|
|
|
|
};
|
|
|
|
|
2004-12-08 15:46:13 +00:00
|
|
|
enum {
|
|
|
|
CA_BUS = 3,
|
|
|
|
CA_TRUCK = 3,
|
|
|
|
CA_AIR_OILPAD = 3,
|
|
|
|
CA_TRAIN = 4,
|
|
|
|
CA_AIR_HELIPORT = 4,
|
|
|
|
CA_AIR_SMALL = 4,
|
|
|
|
CA_AIR_LARGE = 5,
|
|
|
|
CA_DOCK = 5,
|
2005-01-06 18:45:28 +00:00
|
|
|
CA_AIR_METRO = 6,
|
2004-12-08 15:46:13 +00:00
|
|
|
CA_AIR_INTER = 8,
|
2005-01-06 18:45:28 +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-01-15 19:06:22 +00:00
|
|
|
TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st);
|
2004-08-15 13:21:18 +00:00
|
|
|
|
2005-10-07 07:35:15 +00:00
|
|
|
void ShowStationViewWindow(StationID station);
|
2005-01-22 20:23:18 +00:00
|
|
|
void UpdateAllStationVirtCoord(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
VARDEF SortStruct *_station_sort;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-03 17:22:35 +00:00
|
|
|
extern MemoryPool _station_pool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pointer to the station with index 'index'
|
|
|
|
*/
|
2005-03-25 10:40:58 +00:00
|
|
|
static inline Station *GetStation(StationID index)
|
2005-01-06 22:31:58 +00:00
|
|
|
{
|
2005-02-03 17:22:35 +00:00
|
|
|
return (Station*)GetItemFromPool(&_station_pool, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current size of the StationPool
|
|
|
|
*/
|
|
|
|
static inline uint16 GetStationPoolSize(void)
|
|
|
|
{
|
|
|
|
return _station_pool.total_items;
|
2005-01-06 22:31:58 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-04-22 05:41:09 +00:00
|
|
|
static inline bool IsStationIndex(uint index)
|
|
|
|
{
|
|
|
|
return index < GetStationPoolSize();
|
|
|
|
}
|
|
|
|
|
2005-02-03 17:22:35 +00:00
|
|
|
#define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1 < GetStationPoolSize()) ? GetStation(st->index + 1) : NULL)
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
extern MemoryPool _roadstop_pool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pointer to the roadstop with index 'index'
|
|
|
|
*/
|
|
|
|
static inline RoadStop *GetRoadStop(uint index)
|
|
|
|
{
|
|
|
|
return (RoadStop*)GetItemFromPool(&_roadstop_pool, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current size of the RoadStoptPool
|
|
|
|
*/
|
|
|
|
static inline uint16 GetRoadStopPoolSize(void)
|
|
|
|
{
|
|
|
|
return _roadstop_pool.total_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FOR_ALL_ROADSTOPS_FROM(rs, start) for (rs = GetRoadStop(start); rs != NULL; rs = (rs->index + 1 < GetRoadStopPoolSize()) ? GetRoadStop(rs->index + 1) : NULL)
|
|
|
|
#define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0)
|
|
|
|
|
|
|
|
/* End of stuff for ROADSTOPS */
|
|
|
|
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
VARDEF bool _station_sort_dirty[MAX_PLAYERS];
|
|
|
|
VARDEF bool _global_station_sort_dirty;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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);
|
2005-09-18 20:56:44 +00:00
|
|
|
uint GetStationPlatforms(const Station *st, TileIndex tile);
|
2004-11-14 01:25:05 +00:00
|
|
|
|
|
|
|
|
2005-10-16 09:13:04 +00:00
|
|
|
void StationPickerDrawSprite(int x, int y, RailType railtype, int image);
|
|
|
|
|
2005-01-29 19:41:44 +00:00
|
|
|
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
|
2005-02-13 21:51:47 +00:00
|
|
|
static inline int GetRoadStopType(TileIndex tile)
|
|
|
|
{
|
2005-07-13 18:04:01 +00:00
|
|
|
return (_m[tile].m5 < 0x47) ? RS_TRUCK : RS_BUS;
|
2005-02-13 21:51:47 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 19:41:44 +00:00
|
|
|
RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type);
|
2005-02-04 15:31:30 +00:00
|
|
|
RoadStop * AllocateRoadStop( void );
|
2005-04-11 20:54:25 +00:00
|
|
|
void ClearSlot(Vehicle *v, RoadStop *rs);
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static inline bool IsTrainStationTile(TileIndex tile)
|
|
|
|
{
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0, 8);
|
2005-01-31 11:23:10 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 10:31:26 +00:00
|
|
|
static inline bool IsCompatibleTrainStationTile(TileIndex tile, TileIndex ref)
|
|
|
|
{
|
|
|
|
assert(IsTrainStationTile(ref));
|
|
|
|
return
|
|
|
|
IsTrainStationTile(tile) &&
|
2005-11-14 08:09:57 +00:00
|
|
|
GB(_m[tile].m3, 0, 4) == GB(_m[ref].m3, 0, 4) && // same rail type?
|
|
|
|
GB(_m[tile].m5, 0, 1) == GB(_m[ref].m5, 0, 1); // same direction?
|
2005-04-12 10:31:26 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 22:13:20 +00:00
|
|
|
static inline bool IsRoadStationTile(TileIndex tile) {
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_STATION) && IS_BYTE_INSIDE(_m[tile].m5, 0x43, 0x4B);
|
2005-01-31 11:23:10 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
/**
|
|
|
|
* Check if a station really exists.
|
|
|
|
*/
|
2005-05-02 16:02:24 +00:00
|
|
|
static inline bool IsValidStation(const Station *st)
|
2005-02-06 22:36:08 +00:00
|
|
|
{
|
2005-05-02 16:02:24 +00:00
|
|
|
return st->xy != 0; /* XXX: Replace by INVALID_TILE someday */
|
2005-02-06 22:36:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 22:13:20 +00:00
|
|
|
static inline bool IsBuoy(const Station* st)
|
|
|
|
{
|
|
|
|
return st->had_vehicle_of_type & HVOT_BUOY; /* XXX: We should really ditch this ugly coding and switch to something sane... */
|
|
|
|
}
|
|
|
|
|
2005-10-22 06:39:32 +00:00
|
|
|
static inline bool IsBuoyTile(TileIndex tile)
|
|
|
|
{
|
2005-07-13 18:04:01 +00:00
|
|
|
return IsTileType(tile, MP_STATION) && _m[tile].m5 == 0x52;
|
2005-05-02 22:13:20 +00:00
|
|
|
}
|
|
|
|
|
2005-01-31 11:23:10 +00:00
|
|
|
/* Get's the direction the station exit points towards. Ie, returns 0 for a
|
|
|
|
* station with the exit NE. */
|
2005-06-24 12:38:35 +00:00
|
|
|
static inline byte GetRoadStationDir(TileIndex tile)
|
|
|
|
{
|
2005-01-31 11:23:10 +00:00
|
|
|
assert(IsRoadStationTile(tile));
|
2005-07-13 18:04:01 +00:00
|
|
|
return (_m[tile].m5 - 0x43) & 3;
|
2005-01-31 11:23:10 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* STATION_H */
|