truelight@9638: /* $Id$ */ truelight@9638: truebrain@9829: /** @file ai_station.hpp Everything to query and build stations. */ truelight@9638: truelight@9638: #ifndef AI_STATION_HPP truelight@9638: #define AI_STATION_HPP truelight@9638: truelight@9638: #include "ai_object.hpp" rubidium@9866: #include "ai_error.hpp" truebrain@10668: #include "ai_road.hpp" truelight@9638: truelight@9638: /** truelight@9638: * Class that handles all station related functions. truelight@9638: */ truelight@9638: class AIStation : public AIObject { truelight@9638: public: truebrain@9829: static const char *GetClassName() { return "AIStation"; } truebrain@9829: truelight@9638: /** truebrain@9873: * All station related error messages. rubidium@9866: */ rubidium@9866: enum ErrorMessages { rubidium@9866: /** Base for station related errors */ rubidium@9866: ERR_STATION_BASE = AIError::ERR_CAT_STATION << AIError::ERR_CAT_BIT_SIZE, rubidium@9866: rubidium@9866: /** The station size exceeds the station spread */ rubidium@10094: ERR_STATION_TOO_LARGE, // [STR_306C_STATION_TOO_SPREAD_OUT] rubidium@9866: rubidium@10094: /** The station is build too close to another station, airport or dock */ rubidium@10094: ERR_STATION_TOO_CLOSE_TO_ANOTHER_STATION, // [STR_300D_TOO_CLOSE_TO_ANOTHER_AIRPORT, STR_3009_TOO_CLOSE_TO_ANOTHER_STATION, STR_304C_TOO_CLOSE_TO_ANOTHER_DOCK] rubidium@10094: rubidium@10094: /** There are too many stations, airports and docks in the game */ rubidium@10094: ERR_STATION_TOO_MANY_STATIONS, // [STR_3008_TOO_MANY_STATIONS_LOADING, STR_TOO_MANY_TRUCK_STOPS, STR_TOO_MANY_BUS_STOPS] rubidium@10094: rubidium@10094: /** There are too many stations, airports of docks in a town */ rubidium@10094: ERR_STATION_TOO_MANY_STATIONS_IN_TOWN, // [STR_3007_TOO_MANY_STATIONS_LOADING] rubidium@9866: }; rubidium@9866: rubidium@9866: /** truelight@9670: * Type of stations known in the game. truelight@9670: */ truelight@9670: enum StationType { truebrain@10865: /* Values are important, as they represent the internal state of the game. */ truebrain@9838: STATION_ANY = 0x00, //!< All station types truebrain@9838: STATION_TRAIN = 0x01, //!< Train station truebrain@9838: STATION_TRUCK_STOP = 0x02, //!< Truck station truebrain@9838: STATION_BUS_STOP = 0x04, //!< Bus station truebrain@9838: STATION_AIRPORT = 0x08, //!< Airport truebrain@9838: STATION_DOCK = 0x10, //!< Dock truelight@9670: }; truelight@9670: truelight@9670: /** truelight@9638: * Checks whether the given station is valid and owned by you. truebrain@9838: * @param station_id The station to check. truebrain@9838: * @return True if and only if the station is valid. truelight@9638: */ truelight@9638: static bool IsValidStation(StationID station_id); truelight@9638: truelight@9638: /** truebrain@9838: * Get the StationID of a tile, if there is a station. truebrain@9838: * @param tile The tile to find the stationID of truelight@9666: * @return StationID of the station. truebrain@9838: * @post Use IsValidStation() to see if the station is valid. truelight@9666: */ truelight@9666: static StationID GetStationID(TileIndex tile); truelight@9666: truelight@9666: /** truelight@9696: * Get the name of a station. truebrain@9838: * @param station_id The station to get the name of. truelight@9696: * @pre IsValidStation(station_id). truebrain@9838: * @return The name of the station. truelight@9696: */ truelight@9696: static char *GetName(StationID station_id); truelight@9696: truelight@9696: /** truebrain@10381: * Set the name this station. truebrain@10644: * @param station_id The station to set the name of. truebrain@10381: * @param name The new name of the station. truebrain@10381: * @pre IsValidStation(station_id). truebrain@10381: * @pre 'name' must have at least one character. truebrain@10381: * @exception AIError::ERR_NAME_IS_NOT_UNIQUE truebrain@10381: * @return True if the name was changed. truebrain@10381: */ truebrain@10381: static bool SetName(StationID station_id, const char *name); truebrain@10381: truebrain@10381: /** truelight@9638: * Get the current location of a station. truebrain@9838: * @param station_id The station to get the location of. truelight@9638: * @pre IsValidStation(station_id). truebrain@9838: * @return The tile the station is currently on. truelight@9638: */ truelight@9638: static TileIndex GetLocation(StationID station_id); truelight@9638: truelight@9638: /** truelight@9638: * See how much cargo there is waiting on a station. truebrain@9838: * @param station_id The station to get the cargo-waiting of. truebrain@9838: * @param cargo_id The cargo to get the cargo-waiting of. truelight@9638: * @pre IsValidStation(station_id). truelight@9638: * @pre IsValidCargo(cargo_id). truebrain@9838: * @return The amount of units waiting at the station. truelight@9638: */ truelight@9638: static int32 GetCargoWaiting(StationID station_id, CargoID cargo_id); truelight@9648: truelight@9648: /** truelight@9648: * See how high the rating is of a cargo on a station. truebrain@9838: * @param station_id The station to get the cargo-rating of. truebrain@9838: * @param cargo_id The cargo to get the cargo-rating of. truelight@9648: * @pre IsValidStation(station_id). truelight@9648: * @pre IsValidCargo(cargo_id). truebrain@9838: * @return The rating in percent of the cargo on the station. truelight@9648: */ truelight@9648: static int32 GetCargoRating(StationID station_id, CargoID cargo_id); truelight@9670: truelight@9670: /** truelight@9670: * Get the coverage radius of this type of station. truebrain@10865: * @param station_type The type of station. truebrain@9838: * @return The radius in tiles. truelight@9670: */ truebrain@10863: static int32 GetCoverageRadius(AIStation::StationType station_type); truebrain@9814: truebrain@9814: /** truebrain@9814: * Get the manhattan distance from the tile to the AIStation::GetLocation() truebrain@9814: * of the station. truebrain@9814: * @param station_id The station to get the distance to. truebrain@9814: * @param tile The tile to get the distance to. truebrain@10668: * @pre IsValidStation(station_id). truebrain@9814: * @return The distance between station and tile. truebrain@9814: */ truebrain@9814: static int32 GetDistanceManhattanToTile(StationID station_id, TileIndex tile); truebrain@9814: truebrain@9814: /** truebrain@9814: * Get the square distance from the tile to the AIStation::GetLocation() truebrain@9814: * of the station. truebrain@9814: * @param station_id The station to get the distance to. truebrain@9814: * @param tile The tile to get the distance to. truebrain@10668: * @pre IsValidStation(station_id). truebrain@9814: * @return The distance between station and tile. truebrain@9814: */ truebrain@9814: static int32 GetDistanceSquareToTile(StationID station_id, TileIndex tile); truebrain@10360: truebrain@10360: /** truebrain@10360: * Find out if this station is within the rating influence of a town. truebrain@10361: * Stations within the radius influence the rating of the town. truebrain@10360: * @param station_id The station to check. truebrain@10360: * @param town_id The town to check. truebrain@10360: * @return True if the tile is within the rating influence of the town. truebrain@10360: */ truebrain@10361: static bool IsWithinTownInfluence(StationID station_id, TownID town_id); truebrain@10668: truebrain@10668: /** truebrain@10668: * Check if any part of the station contains a station of the type truebrain@10863: * StationType truebrain@10863: * @param station_id The station to look at. truebrain@10863: * @param station_type The StationType to look for. truebrain@10863: * @return True if the station has a station part of the type StationType. truebrain@10863: */ truebrain@10863: static bool HasStationType(StationID station_id, StationType station_type); truebrain@10863: truebrain@10863: /** truebrain@10863: * Check if any part of the station contains a station of the type truebrain@10668: * RoadType. truebrain@10669: * @param station_id The station to look at. truebrain@10668: * @param road_type The RoadType to look for. truebrain@10668: * @return True if the station has a station part of the type RoadType. truebrain@10668: */ truebrain@10668: static bool HasRoadType(StationID station_id, AIRoad::RoadType road_type); truelight@9638: }; truebrain@9838: truelight@9670: DECLARE_ENUM_AS_BIT_SET(AIStation::StationType); truelight@9638: truelight@9638: #endif /* AI_STATION_HPP */