# station_base.h

Go to the documentation of this file.

    00001 /* $Id: station_base.h 18860 2010-01-18 14:32:47Z yexo $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef STATION_BASE_H
    00013 #define STATION_BASE_H
    00014
    00015 #include "base_station_base.h"
    00016 #include "airport.h"
    00017 #include "cargopacket.h"
    00018 #include "industry_type.h"
    00019
    00020 typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
    00021 extern StationPool _station_pool;
    00022
    00023 static const byte INITIAL_STATION_RATING = 175;
    00024
    00025 struct GoodsEntry {
    00026   enum AcceptancePickup {
    00027     ACCEPTANCE,
    00028     PICKUP
    00029   };
    00030
    00031   GoodsEntry() :
    00032     acceptance_pickup(0),
    00033     days_since_pickup(255),
    00034     rating(INITIAL_STATION_RATING),
    00035     last_speed(0),
    00036     last_age(255)
    00037   {}
    00038
    00039   byte acceptance_pickup;
    00040   byte days_since_pickup;
    00041   byte rating;
    00042   byte last_speed;
    00043   byte last_age;
    00044   StationCargoList cargo;
    00045 };
    00046
    00047
    00048 typedef SmallVector<Industry *, 2> IndustryVector;
    00049
    00051 struct Station : SpecializedStation<Station, false> {
    00052 public:
    00053   RoadStop *GetPrimaryRoadStop(RoadStopType type) const
    00054   {
    00055     return type == ROADSTOP_BUS ? bus_stops : truck_stops;
    00056   }
    00057
    00058   RoadStop *GetPrimaryRoadStop(const struct RoadVehicle *v) const;
    00059
    00060   const AirportFTAClass *Airport() const
    00061   {
    00062     if (airport_tile == INVALID_TILE) return GetAirport(AT_DUMMY);
    00063     return GetAirport(airport_type);
    00064   }
    00065
    00066   const AirportSpec *GetAirportSpec() const
    00067   {
    00068     if (airport_tile == INVALID_TILE) return &AirportSpec::dummy;
    00069     return AirportSpec::Get(this->airport_type);
    00070   }
    00071
    00072   RoadStop *bus_stops;
    00073   TileArea bus_station;
    00074   RoadStop *truck_stops;
    00075   TileArea truck_station;
    00076
    00077   TileIndex airport_tile;
    00078   TileIndex dock_tile;
    00079
    00080   IndustryType indtype;
    00081
    00082   StationHadVehicleOfTypeByte had_vehicle_of_type;
    00083
    00084   byte time_since_load;
    00085   byte time_since_unload;
    00086   byte airport_type;
    00087
    00088   uint64 airport_flags;
    00089
    00090   byte last_vehicle_type;
    00091   std::list<Vehicle *> loading_vehicles;
    00092   GoodsEntry goods[NUM_CARGO];
    00093   uint32 always_accepted;
    00094
    00095   IndustryVector industries_near;
    00096
    00097   Station(TileIndex tile = INVALID_TILE);
    00098   ~Station();
    00099
    00100   void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
    00101
    00107   void MarkTilesDirty(bool cargo_change) const;
    00108
    00109   void UpdateVirtCoord();
    00110
    00111   /* virtual */ uint GetPlatformLength(TileIndex tile, DiagDirection dir) const;
    00112   /* virtual */ uint GetPlatformLength(TileIndex tile) const;
    00113   void RecomputeIndustriesNear();
    00114   static void RecomputeIndustriesNearForAll();
    00115
    00116   uint GetCatchmentRadius() const;
    00117   Rect GetCatchmentRect() const;
    00118
    00119   /* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const
    00120   {
    00121     return IsRailStationTile(tile) && GetStationIndex(tile) == this->index;
    00122   }
    00123
    00124   FORCEINLINE bool TileBelongsToAirport(TileIndex tile) const
    00125   {
    00126     return IsAirportTile(tile) && GetStationIndex(tile) == this->index;
    00127   }
    00128
    00129   FORCEINLINE TileIndex GetHangarTile(uint hangar_num) const
    00130   {
    00131     assert(this->airport_tile != INVALID_TILE);
    00132     assert(hangar_num < this->GetAirportSpec()->nof_depots);
    00133     return this->airport_tile + ToTileIndexDiff(this->GetAirportSpec()->depot_table[hangar_num]);
    00134   }
    00135
    00136   /* virtual */ uint32 GetNewGRFVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) const;
    00137
    00138   /* virtual */ void GetTileArea(TileArea *ta, StationType type) const;
    00139 };
    00140
    00141 #define FOR_ALL_STATIONS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Station, var)
    00142
    00143 #endif /* STATION_BASE_H */