tron@2186: /* $Id$ */ tron@2186: rubidium@9281: /** @file station_base.h Base classes/functions for stations. */ belugas@6916: rubidium@9281: #ifndef STATION_BASE_H rubidium@9281: #define STATION_BASE_H truelight@0: rubidium@9265: #include "station_type.h" tron@6358: #include "airport.h" matthijs@5216: #include "oldpool.h" rubidium@7506: #include "cargopacket.h" rubidium@8615: #include "cargo_type.h" rubidium@8709: #include "town_type.h" rubidium@9283: #include "strings_type.h" rubidium@9283: #include "date_type.h" rubidium@9283: #include "vehicle_type.h" rubidium@9283: #include "player_type.h" rubidium@9283: #include "core/geometry_type.hpp" rubidium@10445: #include "viewport_type.h" rubidium@6996: #include truelight@0: rubidium@7873: DECLARE_OLD_POOL(Station, Station, 6, 1000) rubidium@7873: DECLARE_OLD_POOL(RoadStop, RoadStop, 5, 2000) rubidium@7873: truelight@6587: static const byte INITIAL_STATION_RATING = 175; tron@5921: rubidium@6574: struct GoodsEntry { rubidium@7970: enum AcceptancePickup { rubidium@7970: ACCEPTANCE, rubidium@7970: PICKUP rubidium@7970: }; rubidium@7970: tron@5921: GoodsEntry() : rubidium@7970: acceptance_pickup(0), rubidium@7509: days_since_pickup(255), truelight@6587: rating(INITIAL_STATION_RATING), tron@5921: last_speed(0), rubidium@7506: last_age(255) tron@5921: {} tron@5921: rubidium@7970: byte acceptance_pickup; truelight@0: byte days_since_pickup; truelight@0: byte rating; truelight@0: byte last_speed; truelight@0: byte last_age; rubidium@7506: CargoList cargo; ///< The cargo packets of cargo waiting in this station rubidium@6574: }; truelight@0: celestar@6087: /** A Stop for a Road Vehicle */ rubidium@7873: struct RoadStop : PoolItem { truelight@7900: static const int cDebugCtorLevel = 5; ///< 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 rubidium@6316: static const uint MAX_BAY_COUNT = 2; ///< The maximum number of loading bays celestar@6087: celestar@6087: TileIndex xy; ///< Position on the map rubidium@6316: byte status; ///< Current status of the Stop. Like which spot is taken. Access using *Bay and *Busy functions. 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: rubidium@7873: RoadStop(TileIndex tile = 0); rubidium@7873: virtual ~RoadStop(); celestar@5959: rubidium@7992: /** rubidium@7992: * Determines whether a road stop exists rubidium@7992: * @return true if and only is the road stop exists rubidium@7992: */ rubidium@7992: inline bool IsValid() const { return this->xy != 0; } rubidium@6316: rubidium@6316: /* For accessing status */ rubidium@6316: bool HasFreeBay() const; rubidium@6338: bool IsFreeBay(uint nr) const; rubidium@6316: uint AllocateBay(); rubidium@6338: void AllocateDriveThroughBay(uint nr); rubidium@6316: void FreeBay(uint nr); rubidium@6316: bool IsEntranceBusy() const; rubidium@6316: void SetEntranceBusy(bool busy); rubidium@7965: rubidium@7965: RoadStop *GetNextRoadStop(const Vehicle *v) const; celestar@6087: }; celestar@1217: rubidium@6574: struct StationSpecList { peter1138@3587: const StationSpec *spec; belugas@6916: uint32 grfid; ///< GRF ID of this custom station belugas@6916: uint8 localidx; ///< Station ID within GRF of station rubidium@6574: }; 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: rubidium@7873: struct Station : PoolItem { rubidium@7965: public: rubidium@9281: RoadStop *GetPrimaryRoadStop(RoadStopType type) const rubidium@7965: { rubidium@9281: return type == ROADSTOP_BUS ? bus_stops : truck_stops; rubidium@7965: } tron@6127: rubidium@7965: RoadStop *GetPrimaryRoadStop(const Vehicle *v) const; rubidium@7965: rubidium@7965: const AirportFTAClass *Airport() const rubidium@7965: { rubidium@7965: if (airport_tile == 0) return GetAirport(AT_DUMMY); rubidium@7965: return GetAirport(airport_type); rubidium@7965: } tron@6358: 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; peter1138@8754: StringID string_id; ///< Default name (town area) of station peter1138@8754: char *name; ///< Custom name 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: belugas@6916: /* 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: belugas@6916: uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 truelight@0: celestar@3580: byte last_vehicle_type; rubidium@6996: std::list loading_vehicles; truelight@0: GoodsEntry goods[NUM_CARGO]; celestar@1217: peter1138@3687: uint16 random_bits; peter1138@3687: byte waiting_triggers; peter1138@10266: uint8 cached_anim_triggers; ///< Combined animation trigger bitmask, used to determine if trigger processing should happen. peter1138@3687: KUDr@5927: StationRect rect; ///< Station spread out rectangle (not saved) maintained by StationRect_xxx() functions KUDr@5916: truelight@7900: static const int cDebugCtorLevel = 5; KUDr@5916: KUDr@5916: Station(TileIndex tile = 0); rubidium@7873: virtual ~Station(); rubidium@7872: KUDr@5972: void AddFacility(byte new_facility_bit, TileIndex facil_xy); rubidium@8041: rubidium@8041: /** rubidium@8041: * Mark the sign of a station dirty for repaint. rubidium@8041: * rubidium@8041: * @ingroup dirty rubidium@8041: */ KUDr@5916: void MarkDirty() const; rubidium@8041: rubidium@8041: /** rubidium@8041: * Marks the tiles of the station as dirty. rubidium@8041: * rubidium@8041: * @ingroup dirty rubidium@8041: */ peter1138@7319: void MarkTilesDirty(bool cargo_change) const; KUDr@5916: bool TileBelongsToRailStation(TileIndex tile) const; celestar@6324: uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; celestar@6324: uint GetPlatformLength(TileIndex tile) const; celestar@6147: bool IsBuoy() const; rubidium@7992: rubidium@7992: /** rubidium@7992: * Determines whether a station exists rubidium@7992: * @return true if and only is the station exists rubidium@7992: */ rubidium@7992: inline bool IsValid() const { return this->xy != 0; } truelight@0: }; truelight@0: rubidium@6573: static inline StationID GetMaxStationIndex() 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: rubidium@6573: static inline uint GetNumStations() matthijs@5247: { truelight@4354: return GetStationPoolSize(); truelight@4354: } truelight@4354: celestar@6322: static inline bool IsValidStationID(StationID index) truelight@4346: { celestar@6322: return index < GetStationPoolSize() && GetStation(index)->IsValid(); truelight@4346: } truelight@4346: celestar@6322: #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()) truelight@1272: #define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0) truelight@919: truelight@1284: truelight@1284: /* Stuff for ROADSTOPS */ 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: rubidium@9281: #endif /* STATION_BASE_H */