rubidium@9380: /* $Id$ */ rubidium@9380: truebrain@9829: /** @file ai_town.hpp Everything to query towns. */ rubidium@9380: rubidium@9380: #ifndef AI_TOWN_HPP rubidium@9380: #define AI_TOWN_HPP rubidium@9380: rubidium@9380: #include "ai_object.hpp" rubidium@10859: #include "ai_company.hpp" rubidium@9380: truelight@9448: /** truelight@9448: * Class that handles all town related functions. truelight@9448: */ rubidium@9380: class AITown : public AIObject { rubidium@9380: public: truelight@9529: static const char *GetClassName() { return "AITown"; } truelight@9529: truelight@9529: /** rubidium@10859: * Actions that one can perform on a town. rubidium@10859: */ rubidium@10859: enum TownAction { truebrain@10865: /* Values are important, as they represent the internal state of the game. */ truebrain@10865: rubidium@10859: /** rubidium@10859: * The cargo ratings temporary gains 25% of rating (in rubidium@10859: * absolute percentage, so 10% becomes 35%, with a max of 99%) rubidium@10859: * for all stations within 10 tiles. rubidium@10859: */ rubidium@10859: TOWN_ACTION_ADVERTISE_SMALL = 0, rubidium@10859: rubidium@10859: /** rubidium@10859: * The cargo ratings temporary gains 44% of rating (in rubidium@10859: * absolute percentage, so 10% becomes 54%, with a max of 99%) rubidium@10859: * for all stations within 15 tiles. rubidium@10859: */ rubidium@10859: TOWN_ACTION_ADVERTISE_MEDIUM = 1, rubidium@10859: rubidium@10859: /** rubidium@10859: * The cargo ratings temporary gains 63% of rating (in rubidium@10859: * absolute percentage, so 10% becomes 73%, with a max of 99%) rubidium@10859: * for all stations within 20 tiles. rubidium@10859: */ rubidium@10859: TOWN_ACTION_ADVERTISE_LARGE = 2, rubidium@10859: rubidium@10859: /** rubidium@10859: * Rebuild the roads of this town for 6 months. rubidium@10859: */ rubidium@10859: TOWN_ACTION_ROAD_REBUILD = 3, rubidium@10859: rubidium@10859: /** rubidium@10859: * Build a statue in this town. rubidium@10859: */ rubidium@10859: TOWN_ACTION_BUILD_STATUE = 4, rubidium@10859: rubidium@10859: /** rubidium@10859: * Fund the creation of extra buildings for 3 months. rubidium@10859: */ rubidium@10859: TOWN_ACTION_FUND_BUILDINGS = 5, rubidium@10859: rubidium@10859: /** rubidium@10859: * Buy exclusive rights for this town for 12 months. rubidium@10859: */ rubidium@10859: TOWN_ACTION_BUY_RIGHTS = 6, rubidium@10859: rubidium@10859: /** rubidium@10859: * Bribe the town in order to get a higher rating. rubidium@10859: */ rubidium@10859: TOWN_ACTION_BRIBE = 7, rubidium@10859: }; rubidium@10859: rubidium@10859: /** rubidium@10869: * Different ratings one could have in a town. rubidium@10869: */ rubidium@10869: enum TownRating { rubidium@10869: TOWN_RATING_NONE, ///< The company got no rating in the town. rubidium@10869: TOWN_RATING_APPALLING, ///< The company got an appalling rating in the town . rubidium@10869: TOWN_RATING_VERY_POOR, ///< The company got an very poor rating in the town. rubidium@10869: TOWN_RATING_POOR, ///< The company got an poor rating in the town. rubidium@10869: TOWN_RATING_MEDIOCRE, ///< The company got an mediocre rating in the town. rubidium@10869: TOWN_RATING_GOOD, ///< The company got an good rating in the town. rubidium@10869: TOWN_RATING_VERY_GOOD, ///< The company got an very good rating in the town. rubidium@10869: TOWN_RATING_EXCELLENT, ///< The company got an excellent rating in the town. rubidium@10869: TOWN_RATING_OUTSTANDING, ///< The company got an outstanding rating in the town. rubidium@10869: INVALID_TOWN_RATING = -1, ///< The town rating for invalid towns/companies. rubidium@10869: }; rubidium@10869: rubidium@10869: /** truelight@9448: * Gets the maximum town index; there are no valid towns with a higher index. truebrain@9838: * @return The maximum town index. truebrain@9838: * @post Return value is always non-negative. rubidium@9380: */ truebrain@9737: static TownID GetMaxTownID(); rubidium@9380: rubidium@9380: /** truelight@9448: * Gets the number of towns. This is different than GetMaxTownID() truelight@9448: * because of the way OpenTTD works internally. truebrain@9838: * @return The number of towns. truebrain@9838: * @post Return value is always non-negative. rubidium@9380: */ truebrain@9737: static int32 GetTownCount(); rubidium@9380: rubidium@9380: /** truelight@9448: * Checks whether the given town index is valid. truebrain@9838: * @param town_id The index to check. truebrain@9838: * @return True if and only if the town is valid. rubidium@9380: */ rubidium@9497: static bool IsValidTown(TownID town_id); rubidium@9380: rubidium@9380: /** truelight@9448: * Get the name of the town. truebrain@9838: * @param town_id The town to get the name of. truebrain@9838: * @pre IsValidTown(town_id). truebrain@9838: * @return The name of the town. rubidium@9380: */ truelight@9582: static char *GetName(TownID town_id); rubidium@9380: rubidium@9380: /** truelight@9448: * Gets the number of inhabitants in the town. glx@10840: * @param town_id The town to get the population of. truebrain@9838: * @pre IsValidTown(town_id). truebrain@9838: * @return The number of inhabitants. truebrain@9838: * @post Return value is always non-negative. rubidium@9380: */ truelight@9582: static int32 GetPopulation(TownID town_id); rubidium@9380: rubidium@9380: /** glx@10840: * Gets the number of houses in the town. glx@10840: * @param town_id The town to get the number of houses of. glx@10840: * @pre IsValidTown(town_id). glx@10840: * @return The number of houses. glx@10840: * @post Return value is always non-negative. glx@10840: */ truebrain@10844: static int32 GetHouseCount(TownID town_id); glx@10840: glx@10840: /** truelight@9448: * Gets the location of the town. truebrain@10841: * @param town_id The town to get the location of. truebrain@9838: * @pre IsValidTown(town_id). truebrain@9838: * @return The location of the town. rubidium@9380: */ truelight@9582: static TileIndex GetLocation(TownID town_id); truebrain@9814: truebrain@9814: /** glx@10840: * Get the total last month's production of the given cargo at a town. glx@10840: * @param town_id The index of the town. glx@10840: * @param cargo_id The index of the cargo. glx@10840: * @pre IsValidTown(town_id). glx@10840: * @pre AICargo::IsValidCargo(cargo_id). glx@10840: * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL. glx@10840: * @return The last month's production of the given cargo for this town. glx@10840: * @post Return value is always non-negative. glx@10840: */ glx@10840: static int32 GetLastMonthProduction(TownID town_id, CargoID cargo_id); glx@10840: glx@10840: /** glx@10840: * Get the total amount of cargo transported from a town last month. glx@10840: * @param town_id The index of the industry. glx@10840: * @param cargo_id The index of the cargo. glx@10840: * @pre IsValidTown(town_id). glx@10840: * @pre AICargo::IsValidCargo(cargo_id). glx@10840: * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL. glx@10840: * @return The amount of given cargo transported from this town last month. glx@10840: * @post Return value is always non-negative. glx@10840: */ glx@10840: static int32 GetLastMonthTransported(TownID town_id, CargoID cargo_id); glx@10840: glx@10840: /** glx@10840: * Get the maximum production of the given cargo at a town. glx@10840: * @param town_id The index of the town. glx@10840: * @param cargo_id The index of the cargo. glx@10840: * @pre IsValidTown(town_id). glx@10840: * @pre AICargo::IsValidCargo(cargo_id). glx@10840: * @pre AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL. glx@10840: * @return The maximum production of the given cargo for this town. glx@10840: * @post Return value is always non-negative. glx@10840: */ glx@10840: static int32 GetMaxProduction(TownID town_id, CargoID cargo_id); glx@10840: glx@10840: /** truebrain@9814: * Get the manhattan distance from the tile to the AITown::GetLocation() truebrain@9814: * of the town. truebrain@9814: * @param town_id The town to get the distance to. truebrain@9814: * @param tile The tile to get the distance to. truebrain@9838: * @pre IsValidTown(town_id). truebrain@9814: * @return The distance between town and tile. truebrain@9814: */ truebrain@9814: static int32 GetDistanceManhattanToTile(TownID town_id, TileIndex tile); truebrain@9814: truebrain@9814: /** truebrain@9814: * Get the square distance from the tile to the AITown::GetLocation() truebrain@9814: * of the town. truebrain@9814: * @param town_id The town to get the distance to. truebrain@9814: * @param tile The tile to get the distance to. truebrain@9838: * @pre IsValidTown(town_id). truebrain@9814: * @return The distance between town and tile. truebrain@9814: */ truebrain@9814: static int32 GetDistanceSquareToTile(TownID town_id, TileIndex tile); truebrain@10360: truebrain@10360: /** truebrain@10360: * Find out if this tile is within the rating influence of a town. truebrain@10361: * Stations on this tile influence the rating of the town. truebrain@10360: * @param town_id The town to check. truebrain@10360: * @param tile The tile to check. rubidium@10859: * @pre IsValidTown(town_id). truebrain@10360: * @return True if the tile is within the rating influence of the town. truebrain@10360: */ truebrain@10361: static bool IsWithinTownInfluence(TownID town_id, TileIndex tile); rubidium@10859: rubidium@10859: /** rubidium@10859: * Find out if this town has a statue for the current player. rubidium@10859: * @param town_id The town to check. rubidium@10859: * @pre IsValidTown(town_id). rubidium@10859: * @return True if the town has a statue. rubidium@10859: */ rubidium@10859: static bool HasStatue(TownID town_id); rubidium@10859: rubidium@10859: /** rubidium@10859: * Find out how long the town is undergoing road reconstructions. rubidium@10859: * @param town_id The town to check. rubidium@10859: * @pre IsValidTown(town_id). rubidium@10859: * @return The number of months the road reworks are still going to take. rubidium@10859: * The value 0 means that there are currently no road reworks. rubidium@10859: */ rubidium@10859: static int GetRoadReworkDuration(TownID town_id); rubidium@10859: rubidium@10859: /** rubidium@10859: * Find out which company currently has the exclusive rights of this town. rubidium@10859: * @param town_id The town to check. rubidium@10859: * @pre IsValidTown(town_id). rubidium@10859: * @return The company that has the exclusive rights. The value rubidium@10859: * AICompany::INVALID_COMPANY means that there are currently no rubidium@10859: * exclusive rights given out to anyone. rubidium@10859: */ rubidium@10859: static AICompany::CompanyID GetExclusiveRightsPlayer(TownID town_id); rubidium@10859: rubidium@10859: /** rubidium@10859: * Find out how long the town is under influence of the exclusive rights. rubidium@10859: * @param town_id The town to check. rubidium@10859: * @pre IsValidTown(town_id). rubidium@10859: * @return The number of months the exclusive rights hold. rubidium@10859: * The value 0 means that there are currently no exclusive rights rubidium@10859: * given out to anyone. rubidium@10859: */ rubidium@10859: static int32 GetExclusiveRightsDuration(TownID town_id); rubidium@10859: rubidium@10859: /** rubidium@10859: * Find out if an action can currently be performed on the town. rubidium@10859: * @param town_id The town to perform the action on. truebrain@10865: * @param town_action The action to perform on the town. rubidium@10859: * @pre IsValidTown(town_id). rubidium@10859: * @return True if and only if the action can performed. rubidium@10859: */ truebrain@10865: static bool IsActionAvailable(TownID town_id, TownAction town_action); rubidium@10859: rubidium@10859: /** rubidium@10859: * Perform a town action on this town. rubidium@10859: * @param town_id The town to perform the action on. truebrain@10865: * @param town_action The action to perform on the town. rubidium@10859: * @pre IsValidTown(town_id). truebrain@10865: * @pre IsActionAvailable(town_id, town_action). rubidium@10859: * @return True if the action succeeded. rubidium@10859: */ truebrain@10865: static bool PerformTownAction(TownID town_id, TownAction town_action); rubidium@10869: rubidium@10869: /** rubidium@10869: * Get the rating of a company within a town. rubidium@10869: * @param town_id The town to get the rating for. rubidium@10869: * @param company_id The company to get the rating for. rubidium@10869: * @pre IsValidTown(town_id). rubidium@10869: * @pre AICompany.ResolveCompanyID(company) != AICompany::INVALID_COMPANY. rubidium@10869: * @return The rating as shown to humans. rubidium@10869: */ rubidium@10869: static TownRating GetRating(TownID town_id, AICompany::CompanyID company_id); rubidium@9380: }; rubidium@9380: rubidium@9380: #endif /* AI_TOWN_HPP */