tron@2186: /* $Id$ */ tron@2186: celestar@9908: /** @file station.h */ celestar@9908: truelight@0: #ifndef STATION_H truelight@0: #define STATION_H truelight@0: tron@6358: #include "airport.h" 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" celestar@9910: #include truelight@0: tron@5921: static const StationID INVALID_STATION = 0xFFFF; celestar@9895: static const byte INITIAL_STATION_RATING = 175; tron@5921: celestar@9895: struct GoodsEntry { tron@5921: GoodsEntry() : tron@5921: waiting_acceptance(0), richk@6524: unload_pending(0), tron@5921: days_since_pickup(0), celestar@9895: rating(INITIAL_STATION_RATING), 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; richk@6524: uint16 unload_pending; ///< records how much cargo is awaiting transfer during gradual loading to allow correct fee calc 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; celestar@9895: }; 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 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 celestar@6087: RoadStopID index; ///< Global (i.e. pool-wide) index 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: 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; 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); celestar@6086: protected: celestar@9895: static RoadStop *AllocateRaw(); celestar@6087: }; celestar@1217: celestar@9895: struct StationSpecList { peter1138@3587: const StationSpec *spec; celestar@9908: uint32 grfid; ///< GRF ID of this custom station celestar@9908: uint8 localidx; ///< Station ID within GRF of station celestar@9895: }; 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: tron@6358: const AirportFTAClass *Airport() const tron@6358: { celestar@9908: if (airport_tile == 0) return GetAirport(AT_DUMMY); tron@6358: return GetAirport(airport_type); tron@6358: } 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; 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: celestar@9908: /* 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: celestar@9908: uint64 airport_flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 celestar@1551: StationID index; truelight@0: celestar@3580: byte last_vehicle_type; celestar@9910: std::list loading_vehicles; 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@6324: uint GetPlatformLength(TileIndex tile, DiagDirection dir) const; celestar@6324: uint GetPlatformLength(TileIndex tile) const; celestar@6147: bool IsBuoy() const; celestar@6322: bool IsValid() const; KUDr@5916: KUDr@5916: protected: celestar@9895: static Station *AllocateRaw(); 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@9895: enum CatchmentArea { celestar@5852: CA_NONE = 0, rubidium@4344: CA_BUS = 3, rubidium@4344: CA_TRUCK = 3, rubidium@4344: CA_TRAIN = 4, tron@6367: CA_DOCK = 5 celestar@9895: }; Celestar@568: tron@2498: void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius); truelight@0: tron@2498: void ShowStationViewWindow(StationID station); celestar@9895: void UpdateAllStationVirtCoord(); truelight@0: celestar@3812: /* sorter stuff */ celestar@9895: void RebuildStationLists(); celestar@9895: void ResortStationLists(); celestar@3812: matthijs@5216: DECLARE_OLD_POOL(Station, Station, 6, 1000) truelight@1272: celestar@9895: 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: celestar@9895: 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: 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: celestar@9895: void AfterLoadStations(); 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@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); celestar@9895: RoadStop * AllocateRoadStop(); celestar@3123: void ClearSlot(Vehicle *v); celestar@1217: tron@6135: void DeleteOilRig(TileIndex t); tron@6135: truelight@0: #endif /* STATION_H */