AITown Class Reference

Class that handles all town related functions. More...

#include <ai_town.hpp>

Inheritance diagram for AITown:

AIObject SimpleCountedObject

Public Types

enum  TownAction {
  TOWN_ACTION_ADVERTISE_SMALL = 0, TOWN_ACTION_ADVERTISE_MEDIUM = 1, TOWN_ACTION_ADVERTISE_LARGE = 2, TOWN_ACTION_ROAD_REBUILD = 3,
  TOWN_ACTION_BUILD_STATUE = 4, TOWN_ACTION_FUND_BUILDINGS = 5, TOWN_ACTION_BUY_RIGHTS = 6, TOWN_ACTION_BRIBE = 7
}
 Actions that one can perform on a town. More...
enum  TownRating {
  TOWN_RATING_NONE, TOWN_RATING_APPALLING, TOWN_RATING_VERY_POOR, TOWN_RATING_POOR,
  TOWN_RATING_MEDIOCRE, TOWN_RATING_GOOD, TOWN_RATING_VERY_GOOD, TOWN_RATING_EXCELLENT,
  TOWN_RATING_OUTSTANDING, TOWN_RATING_INVALID = -1
}
 Different ratings one could have in a town. More...
enum  RoadLayout {
  ROAD_LAYOUT_ORIGINAL, ROAD_LAYOUT_BETTER_ROADS, ROAD_LAYOUT_2x2, ROAD_LAYOUT_3x3,
  ROAD_LAYOUT_INVALID = -1
}
 Possible layouts for the roads in a town. More...

Static Public Member Functions

static const char * GetClassName ()
static int32 GetTownCount ()
 Gets the number of towns.
static bool IsValidTown (TownID town_id)
 Checks whether the given town index is valid.
static char * GetName (TownID town_id)
 Get the name of the town.
static int32 GetPopulation (TownID town_id)
 Gets the number of inhabitants in the town.
static int32 GetHouseCount (TownID town_id)
 Gets the number of houses in the town.
static TileIndex GetLocation (TownID town_id)
 Gets the location of the town.
static int32 GetLastMonthProduction (TownID town_id, CargoID cargo_id)
 Get the total last month's production of the given cargo at a town.
static int32 GetLastMonthTransported (TownID town_id, CargoID cargo_id)
 Get the total amount of cargo transported from a town last month.
static int32 GetMaxProduction (TownID town_id, CargoID cargo_id)
 Get the maximum production of the given cargo at a town.
static int32 GetDistanceManhattanToTile (TownID town_id, TileIndex tile)
 Get the manhattan distance from the tile to the AITown::GetLocation() of the town.
static int32 GetDistanceSquareToTile (TownID town_id, TileIndex tile)
 Get the square distance from the tile to the AITown::GetLocation() of the town.
static bool IsWithinTownInfluence (TownID town_id, TileIndex tile)
 Find out if this tile is within the rating influence of a town.
static bool HasStatue (TownID town_id)
 Find out if this town has a statue for the current company.
static int GetRoadReworkDuration (TownID town_id)
 Find out how long the town is undergoing road reconstructions.
static AICompany::CompanyID GetExclusiveRightsCompany (TownID town_id)
 Find out which company currently has the exclusive rights of this town.
static int32 GetExclusiveRightsDuration (TownID town_id)
 Find out how long the town is under influence of the exclusive rights.
static bool IsActionAvailable (TownID town_id, TownAction town_action)
 Find out if an action can currently be performed on the town.
static bool PerformTownAction (TownID town_id, TownAction town_action)
 Perform a town action on this town.
static TownRating GetRating (TownID town_id, AICompany::CompanyID company_id)
 Get the rating of a company within a town.
static int GetAllowedNoise (TownID town_id)
 Get the maximum level of noise that still can be added by airports before the town start to refuse building a new airport.
static RoadLayout GetRoadLayout (TownID town_id)
 Get the road layout for a town.

Detailed Description

Class that handles all town related functions.

Definition at line 14 of file ai_town.hpp.


Member Enumeration Documentation

Actions that one can perform on a town.

Enumerator:
TOWN_ACTION_ADVERTISE_SMALL  The cargo ratings temporary gains 25% of rating (in absolute percentage, so 10% becomes 35%, with a max of 99%) for all stations within 10 tiles.
TOWN_ACTION_ADVERTISE_MEDIUM  The cargo ratings temporary gains 44% of rating (in absolute percentage, so 10% becomes 54%, with a max of 99%) for all stations within 15 tiles.
TOWN_ACTION_ADVERTISE_LARGE  The cargo ratings temporary gains 63% of rating (in absolute percentage, so 10% becomes 73%, with a max of 99%) for all stations within 20 tiles.
TOWN_ACTION_ROAD_REBUILD  Rebuild the roads of this town for 6 months.
TOWN_ACTION_BUILD_STATUE  Build a statue in this town.
TOWN_ACTION_FUND_BUILDINGS  Fund the creation of extra buildings for 3 months.
TOWN_ACTION_BUY_RIGHTS  Buy exclusive rights for this town for 12 months.
TOWN_ACTION_BRIBE  Bribe the town in order to get a higher rating.

Definition at line 21 of file ai_town.hpp.

Different ratings one could have in a town.

Enumerator:
TOWN_RATING_NONE  The company got no rating in the town.
TOWN_RATING_APPALLING  The company got an appalling rating in the town .
TOWN_RATING_VERY_POOR  The company got an very poor rating in the town.
TOWN_RATING_POOR  The company got an poor rating in the town.
TOWN_RATING_MEDIOCRE  The company got an mediocre rating in the town.
TOWN_RATING_GOOD  The company got an good rating in the town.
TOWN_RATING_VERY_GOOD  The company got an very good rating in the town.
TOWN_RATING_EXCELLENT  The company got an excellent rating in the town.
TOWN_RATING_OUTSTANDING  The company got an outstanding rating in the town.
TOWN_RATING_INVALID  The town rating for invalid towns/companies.

Definition at line 74 of file ai_town.hpp.

Possible layouts for the roads in a town.

Enumerator:
ROAD_LAYOUT_ORIGINAL  Original algorithm (min. 1 distance between roads).
ROAD_LAYOUT_BETTER_ROADS  Extended original algorithm (min. 2 distance between roads).
ROAD_LAYOUT_2x2  Geometric 2x2 grid algorithm.
ROAD_LAYOUT_3x3  Geometric 3x3 grid algorithm.
ROAD_LAYOUT_INVALID  The layout for invalid towns.

Definition at line 90 of file ai_town.hpp.


Member Function Documentation

int32 AITown::GetTownCount (  )  [static]

Gets the number of towns.

Returns:
The number of towns.
Postcondition:
Return value is always non-negative.

Definition at line 17 of file ai_town.cpp.

bool AITown::IsValidTown ( TownID  town_id  )  [static]

Checks whether the given town index is valid.

Parameters:
town_id The index to check.
Returns:
True if and only if the town is valid.

Definition at line 22 of file ai_town.cpp.

References IsValidTownID().

Referenced by GetAllowedNoise(), GetExclusiveRightsCompany(), GetExclusiveRightsDuration(), GetHouseCount(), GetLastMonthProduction(), GetLastMonthTransported(), GetLocation(), GetMaxProduction(), GetName(), GetPopulation(), GetRating(), GetRoadLayout(), GetRoadReworkDuration(), HasStatue(), IsActionAvailable(), IsWithinTownInfluence(), and PerformTownAction().

char * AITown::GetName ( TownID  town_id  )  [static]

Get the name of the town.

Parameters:
town_id The town to get the name of.
Precondition:
IsValidTown(town_id).
Returns:
The name of the town.

Definition at line 27 of file ai_town.cpp.

References IsValidTown().

int32 AITown::GetPopulation ( TownID  town_id  )  [static]

Gets the number of inhabitants in the town.

Parameters:
town_id The town to get the population of.
Precondition:
IsValidTown(town_id).
Returns:
The number of inhabitants.
Postcondition:
Return value is always non-negative.

Definition at line 39 of file ai_town.cpp.

References IsValidTown().

int32 AITown::GetHouseCount ( TownID  town_id  )  [static]

Gets the number of houses in the town.

Parameters:
town_id The town to get the number of houses of.
Precondition:
IsValidTown(town_id).
Returns:
The number of houses.
Postcondition:
Return value is always non-negative.

Definition at line 46 of file ai_town.cpp.

References IsValidTown().

TileIndex AITown::GetLocation ( TownID  town_id  )  [static]

Gets the location of the town.

Parameters:
town_id The town to get the location of.
Precondition:
IsValidTown(town_id).
Returns:
The location of the town.

Definition at line 53 of file ai_town.cpp.

References INVALID_TILE, and IsValidTown().

Referenced by GetDistanceManhattanToTile(), and GetDistanceSquareToTile().

int32 AITown::GetLastMonthProduction ( TownID  town_id,
CargoID  cargo_id 
) [static]

Get the total last month's production of the given cargo at a town.

Parameters:
town_id The index of the town.
cargo_id The index of the cargo.
Precondition:
IsValidTown(town_id).

AICargo::IsValidCargo(cargo_id).

AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.

Returns:
The last month's production of the given cargo for this town.
Postcondition:
Return value is always non-negative.

Definition at line 60 of file ai_town.cpp.

References AICargo::GetTownEffect(), AICargo::IsValidCargo(), IsValidTown(), AICargo::TE_MAIL, and AICargo::TE_PASSENGERS.

int32 AITown::GetLastMonthTransported ( TownID  town_id,
CargoID  cargo_id 
) [static]

Get the total amount of cargo transported from a town last month.

Parameters:
town_id The index of the industry.
cargo_id The index of the cargo.
Precondition:
IsValidTown(town_id).

AICargo::IsValidCargo(cargo_id).

AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.

Returns:
The amount of given cargo transported from this town last month.
Postcondition:
Return value is always non-negative.

Definition at line 74 of file ai_town.cpp.

References AICargo::GetTownEffect(), AICargo::IsValidCargo(), IsValidTown(), AICargo::TE_MAIL, and AICargo::TE_PASSENGERS.

int32 AITown::GetMaxProduction ( TownID  town_id,
CargoID  cargo_id 
) [static]

Get the maximum production of the given cargo at a town.

Parameters:
town_id The index of the town.
cargo_id The index of the cargo.
Precondition:
IsValidTown(town_id).

AICargo::IsValidCargo(cargo_id).

AICargo::GetTownEffect(cargo_id) == TE_PASSENGERS || AICargo::GetTownEffect(cargo_id) == TE_MAIL.

Returns:
The maximum production of the given cargo for this town.
Postcondition:
Return value is always non-negative.

Definition at line 88 of file ai_town.cpp.

References AICargo::GetTownEffect(), AICargo::IsValidCargo(), IsValidTown(), AICargo::TE_MAIL, and AICargo::TE_PASSENGERS.

int32 AITown::GetDistanceManhattanToTile ( TownID  town_id,
TileIndex  tile 
) [static]

Get the manhattan distance from the tile to the AITown::GetLocation() of the town.

Parameters:
town_id The town to get the distance to.
tile The tile to get the distance to.
Precondition:
IsValidTown(town_id).
Returns:
The distance between town and tile.

Definition at line 102 of file ai_town.cpp.

References AIMap::DistanceManhattan(), and GetLocation().

int32 AITown::GetDistanceSquareToTile ( TownID  town_id,
TileIndex  tile 
) [static]

Get the square distance from the tile to the AITown::GetLocation() of the town.

Parameters:
town_id The town to get the distance to.
tile The tile to get the distance to.
Precondition:
IsValidTown(town_id).
Returns:
The distance between town and tile.

Definition at line 107 of file ai_town.cpp.

References AIMap::DistanceSquare(), and GetLocation().

Referenced by IsWithinTownInfluence().

bool AITown::IsWithinTownInfluence ( TownID  town_id,
TileIndex  tile 
) [static]

Find out if this tile is within the rating influence of a town.

Stations on this tile influence the rating of the town.

Parameters:
town_id The town to check.
tile The tile to check.
Precondition:
IsValidTown(town_id).
Returns:
True if the tile is within the rating influence of the town.

Definition at line 112 of file ai_town.cpp.

References GetDistanceSquareToTile(), and IsValidTown().

Referenced by AITile::IsWithinTownInfluence(), and AIStation::IsWithinTownInfluence().

bool AITown::HasStatue ( TownID  town_id  )  [static]

Find out if this town has a statue for the current company.

Parameters:
town_id The town to check.
Precondition:
IsValidTown(town_id).
Returns:
True if the town has a statue.

Definition at line 120 of file ai_town.cpp.

References HasBit(), and IsValidTown().

int AITown::GetRoadReworkDuration ( TownID  town_id  )  [static]

Find out how long the town is undergoing road reconstructions.

Parameters:
town_id The town to check.
Precondition:
IsValidTown(town_id).
Returns:
The number of months the road reworks are still going to take. The value 0 means that there are currently no road reworks.

Definition at line 127 of file ai_town.cpp.

References IsValidTown().

AICompany::CompanyID AITown::GetExclusiveRightsCompany ( TownID  town_id  )  [static]

Find out which company currently has the exclusive rights of this town.

Parameters:
town_id The town to check.
Precondition:
IsValidTown(town_id).
Returns:
The company that has the exclusive rights. The value AICompany::COMPANY_INVALID means that there are currently no exclusive rights given out to anyone.

Definition at line 134 of file ai_town.cpp.

References AICompany::COMPANY_INVALID, and IsValidTown().

int32 AITown::GetExclusiveRightsDuration ( TownID  town_id  )  [static]

Find out how long the town is under influence of the exclusive rights.

Parameters:
town_id The town to check.
Precondition:
IsValidTown(town_id).
Returns:
The number of months the exclusive rights hold. The value 0 means that there are currently no exclusive rights given out to anyone.

Definition at line 141 of file ai_town.cpp.

References IsValidTown().

bool AITown::IsActionAvailable ( TownID  town_id,
TownAction  town_action 
) [static]

Find out if an action can currently be performed on the town.

Parameters:
town_id The town to perform the action on.
town_action The action to perform on the town.
Precondition:
IsValidTown(town_id).
Returns:
True if and only if the action can performed.

Definition at line 148 of file ai_town.cpp.

References GetMaskOfTownActions(), HasBit(), and IsValidTown().

Referenced by PerformTownAction().

bool AITown::PerformTownAction ( TownID  town_id,
TownAction  town_action 
) [static]

Perform a town action on this town.

Parameters:
town_id The town to perform the action on.
town_action The action to perform on the town.
Precondition:
IsValidTown(town_id).

IsActionAvailable(town_id, town_action).

Returns:
True if the action succeeded.

Definition at line 155 of file ai_town.cpp.

References CMD_DO_TOWN_ACTION, AIObject::DoCommand(), EnforcePrecondition, IsActionAvailable(), and IsValidTown().

AITown::TownRating AITown::GetRating ( TownID  town_id,
AICompany::CompanyID  company_id 
) [static]

Get the rating of a company within a town.

Parameters:
town_id The town to get the rating for.
company_id The company to get the rating for.
Precondition:
IsValidTown(town_id).

AICompany.ResolveCompanyID(company) != AICompany::COMPANY_INVALID.

Returns:
The rating as shown to humans.

Definition at line 163 of file ai_town.cpp.

References AICompany::COMPANY_INVALID, HasBit(), IsValidTown(), max(), AICompany::ResolveCompanyID(), TOWN_RATING_APPALLING, TOWN_RATING_INVALID, and TOWN_RATING_NONE.

int AITown::GetAllowedNoise ( TownID  town_id  )  [static]

Get the maximum level of noise that still can be added by airports before the town start to refuse building a new airport.

Parameters:
town_id The town to get the allowed noise from.
Returns:
The noise that still can be added.

Definition at line 174 of file ai_town.cpp.

References _settings_game, Station::airport_type, GameSettings::economy, Station::facilities, IsValidTown(), max(), EconomySettings::station_noise_level, and Station::town.

AITown::RoadLayout AITown::GetRoadLayout ( TownID  town_id  )  [static]

Get the road layout for a town.

Parameters:
town_id The town to get the road layout from.
Returns:
The RoadLayout for the town.

Definition at line 191 of file ai_town.cpp.

References IsValidTown(), and ROAD_LAYOUT_INVALID.


The documentation for this class was generated from the following files:

Generated on Fri Jul 31 22:33:36 2009 for OpenTTD by  doxygen 1.5.6