tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef STATION_H truelight@0: #define STATION_H truelight@0: tron@2154: #include "player.h" matthijs@5216: #include "oldpool.h" darkvater@405: #include "sprite.h" matthijs@1247: #include "tile.h" peter1138@2963: #include "newgrf_station.h" truelight@0: tron@5921: static const StationID INVALID_STATION = 0xFFFF; tron@5921: truelight@0: typedef struct GoodsEntry { tron@5921: GoodsEntry() : tron@5921: waiting_acceptance(0), tron@5921: days_since_pickup(0), tron@5921: rating(175), tron@5921: enroute_from(INVALID_STATION), celestar@5934: enroute_from_xy(INVALID_TILE), tron@5921: last_speed(0), tron@5921: last_age(255), tron@5921: feeder_profit(0) tron@5921: {} tron@5921: truelight@0: uint16 waiting_acceptance; truelight@0: byte days_since_pickup; truelight@0: byte rating; Darkvater@3347: StationID enroute_from; celestar@5934: TileIndex enroute_from_xy; truelight@0: byte enroute_time; truelight@0: byte last_speed; truelight@0: byte last_age; celestar@1935: int32 feeder_profit; truelight@0: } GoodsEntry; truelight@0: celestar@6087: /** A Stop for a Road Vehicle */ celestar@6087: struct RoadStop { celestar@6087: /** Types of RoadStops */ celestar@6087: enum Type { celestar@6087: BUS, ///< A standard stop for buses celestar@6087: TRUCK ///< A standard stop for trucks celestar@6087: }; celestar@5959: celestar@6088: static const int cDebugCtorLevel = 3; ///< Debug level on which Contructor / Destructor messages are printed celestar@6088: static const uint LIMIT = 16; ///< The maximum amount of roadstops that are allowed at a single station celestar@6087: celestar@6087: TileIndex xy; ///< Position on the map celestar@6087: RoadStopID index; ///< Global (i.e. pool-wide) index celestar@6087: byte status; ///< Current status of the Stop. Like which spot is taken. TODO - enumify this celestar@6087: byte num_vehicles; ///< Number of vehicles currently slotted to this stop celestar@6087: struct RoadStop *next; ///< Next stop of the given type at this station celestar@5959: tron@5967: RoadStop(TileIndex tile); celestar@5959: ~RoadStop(); celestar@5959: celestar@5959: void *operator new (size_t size); celestar@5959: void operator delete(void *rs); celestar@5959: celestar@5959: /* For loading games */ celestar@5959: void *operator new (size_t size, int index); celestar@5959: void operator delete(void *rs, int index); celestar@5959: celestar@6086: bool IsValid() const; celestar@6086: protected: tron@5964: static RoadStop *AllocateRaw(void); celestar@6087: }; celestar@1217: peter1138@3587: typedef struct StationSpecList { peter1138@3587: const StationSpec *spec; peter1138@3587: uint32 grfid; /// GRF ID of this custom station peter1138@3587: uint8 localidx; /// Station ID within GRF of station peter1138@3587: } StationSpecList; peter1138@3587: KUDr@5927: /** StationRect - used to track station spread out rectangle - cheaper than scanning whole map */ KUDr@5927: struct StationRect : public Rect { KUDr@5927: enum StationRectMode KUDr@5927: { KUDr@5927: ADD_TEST = 0, KUDr@5927: ADD_TRY, KUDr@5927: ADD_FORCE KUDr@5927: }; KUDr@5927: KUDr@5927: StationRect(); KUDr@5927: void MakeEmpty(); celestar@6161: bool PtInExtendedRect(int x, int y, int distance = 0) const; KUDr@5927: bool IsEmpty() const; KUDr@5927: bool BeforeAddTile(TileIndex tile, StationRectMode mode); KUDr@5927: bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode); KUDr@5927: bool AfterRemoveTile(Station *st, TileIndex tile); KUDr@5927: bool AfterRemoveRect(Station *st, TileIndex tile, int w, int h); KUDr@5927: KUDr@5927: static bool ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a); KUDr@5927: KUDr@5927: StationRect& operator = (Rect src); KUDr@5927: }; KUDr@5927: truelight@0: struct Station { tron@6127: public: tron@6127: RoadStop *GetPrimaryRoadStop(RoadStop::Type type) const tron@6127: { tron@6127: return type == RoadStop::BUS ? bus_stops : truck_stops; tron@6127: } tron@6127: truelight@0: TileIndex xy; celestar@1217: RoadStop *bus_stops; celestar@1217: RoadStop *truck_stops; truelight@0: TileIndex train_tile; truelight@0: TileIndex airport_tile; truelight@0: TileIndex dock_tile; truelight@0: Town *town; truelight@0: uint16 string_id; truelight@0: truelight@0: ViewportSign sign; truelight@0: truelight@0: uint16 had_vehicle_of_type; truelight@193: truelight@0: byte time_since_load; truelight@0: byte time_since_unload; truelight@0: byte delete_ctr; rubidium@5838: PlayerByte owner; truelight@0: byte facilities; truelight@0: byte airport_type; truelight@0: truelight@0: // trainstation width/height truelight@0: byte trainst_w, trainst_h; truelight@0: peter1138@3587: /** List of custom stations (StationSpecs) allocated to the station */ peter1138@3786: uint8 num_specs; peter1138@3587: StationSpecList *speclist; peter1138@3587: rubidium@4289: Date build_date; truelight@0: truelight@0: //uint16 airport_flags; darkvater@393: uint32 airport_flags; celestar@1551: StationID index; truelight@0: celestar@3580: byte last_vehicle_type; truelight@0: GoodsEntry goods[NUM_CARGO]; celestar@1217: peter1138@3687: uint16 random_bits; peter1138@3687: byte waiting_triggers; peter1138@3687: KUDr@5927: StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions KUDr@5916: KUDr@5927: static const int cDebugCtorLevel = 3; KUDr@5916: KUDr@5916: Station(TileIndex tile = 0); KUDr@5916: ~Station(); KUDr@5916: KUDr@5916: /* normal new/delete operators. Used when building/removing station */ KUDr@5916: void* operator new (size_t size); KUDr@5916: void operator delete(void *p); KUDr@5916: KUDr@5916: /* new/delete operators accepting station index. Used when loading station from savegame. */ KUDr@5916: void* operator new (size_t size, int st_idx); KUDr@5916: void operator delete(void *p, int st_idx); KUDr@5916: KUDr@5972: void AddFacility(byte new_facility_bit, TileIndex facil_xy); KUDr@5916: void MarkDirty() const; KUDr@5916: void MarkTilesDirty() const; KUDr@5916: bool TileBelongsToRailStation(TileIndex tile) const; celestar@6147: bool IsBuoy() const; KUDr@5916: KUDr@5916: protected: KUDr@5916: static Station *AllocateRaw(void); truelight@0: }; truelight@0: truelight@0: enum { rubidium@4344: FACIL_TRAIN = 0x01, rubidium@4344: FACIL_TRUCK_STOP = 0x02, rubidium@4344: FACIL_BUS_STOP = 0x04, rubidium@4344: FACIL_AIRPORT = 0x08, rubidium@4344: FACIL_DOCK = 0x10, truelight@0: }; truelight@0: truelight@0: enum { rubidium@4344: // HVOT_PENDING_DELETE = 1 << 0, // not needed anymore belugas@3554: HVOT_TRAIN = 1 << 1, belugas@3554: HVOT_BUS = 1 << 2, belugas@3554: HVOT_TRUCK = 1 << 3, celestar@1217: HVOT_AIRCRAFT = 1 << 4, belugas@3554: HVOT_SHIP = 1 << 5, matthijs@1751: /* This bit is used to mark stations. No, it does not belong here, but what matthijs@1751: * can we do? ;-) */ belugas@3554: HVOT_BUOY = 1 << 6 truelight@0: }; truelight@0: celestar@5852: typedef enum CatchmentAeras { celestar@5852: CA_NONE = 0, rubidium@4344: CA_BUS = 3, rubidium@4344: CA_TRUCK = 3, rubidium@4344: CA_AIR_OILPAD = 3, rubidium@4344: CA_TRAIN = 4, rubidium@4344: CA_AIR_HELIPORT = 4, rubidium@4344: CA_AIR_SMALL = 4, rubidium@4344: CA_AIR_LARGE = 5, rubidium@4344: CA_DOCK = 5, rubidium@4344: CA_AIR_METRO = 6, rubidium@4344: CA_AIR_INTER = 8, rubidium@4344: CA_AIR_COMMUTER = 4, rubidium@4344: CA_AIR_HELIDEPOT = 4, richk@4059: CA_AIR_INTERCON = 10, rubidium@4344: CA_AIR_HELISTATION = 4, celestar@5852: } CatchmentAera; Celestar@568: tron@2498: void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius); truelight@0: tron@2498: void ShowStationViewWindow(StationID station); tron@1093: void UpdateAllStationVirtCoord(void); truelight@0: celestar@3812: /* sorter stuff */ celestar@3812: void RebuildStationLists(void); celestar@3812: void ResortStationLists(void); celestar@3812: matthijs@5216: DECLARE_OLD_POOL(Station, Station, 6, 1000) truelight@1272: matthijs@5247: static inline StationID GetMaxStationIndex(void) truelight@4354: { truelight@4354: /* TODO - This isn't the real content of the function, but truelight@4354: * with the new pool-system this will be replaced with one that matthijs@5247: * _really_ returns the highest index. Now it just returns truelight@4354: * the next safe value we are sure about everything is below. truelight@4354: */ matthijs@5247: return GetStationPoolSize() - 1; matthijs@5247: } matthijs@5247: matthijs@5247: static inline uint GetNumStations(void) matthijs@5247: { truelight@4354: return GetStationPoolSize(); truelight@4354: } truelight@4354: truelight@4346: /** truelight@4346: * Check if a station really exists. truelight@4346: */ truelight@4346: static inline bool IsValidStation(const Station *st) truelight@4346: { truelight@4346: return st->xy != 0; truelight@4346: } truelight@4346: truelight@4352: static inline bool IsValidStationID(StationID index) truelight@4352: { truelight@4352: return index < GetStationPoolSize() && IsValidStation(GetStation(index)); truelight@4352: } truelight@4352: tron@4980: #define FOR_ALL_STATIONS_FROM(st, start) for (st = GetStation(start); st != NULL; st = (st->index + 1U < GetStationPoolSize()) ? GetStation(st->index + 1U) : NULL) if (IsValidStation(st)) truelight@1272: #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) truelight@919: truelight@1284: truelight@1284: /* Stuff for ROADSTOPS */ truelight@1284: matthijs@5216: DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) truelight@1284: celestar@6086: #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()) truelight@1284: #define FOR_ALL_ROADSTOPS(rs) FOR_ALL_ROADSTOPS_FROM(rs, 0) truelight@1284: truelight@1284: /* End of stuff for ROADSTOPS */ truelight@1284: truelight@1284: peter1138@3765: void AfterLoadStations(void); tron@1424: void GetProductionAroundTiles(AcceptedCargo produced, TileIndex tile, int w, int h, int rad); tron@1424: void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, int w, int h, int rad); Darkvater@2436: uint GetStationPlatforms(const Station *st, TileIndex tile); celestar@3928: uint GetPlatformLength(TileIndex tile, DiagDirection dir); darkvater@384: darkvater@384: peter1138@3763: const DrawTileSprites *GetStationTileLayout(byte gfx); tron@2520: void StationPickerDrawSprite(int x, int y, RailType railtype, int image); tron@2520: celestar@6087: RoadStop * GetRoadStopByTile(TileIndex tile, RoadStop::Type type); celestar@6087: uint GetNumRoadStops(const Station* st, RoadStop::Type type); truelight@1284: RoadStop * AllocateRoadStop( void ); celestar@3123: void ClearSlot(Vehicle *v); celestar@1217: tron@6135: void DeleteOilRig(TileIndex t); tron@6135: truelight@0: #endif /* STATION_H */