(svn r12431) [NoAI] -Add: added AIEventSubsidiaryOffer, which keeps you informed about new Subsidiaries
/* $Id$ */
/** @file ai_town.cpp handles the town-related functions of the AITown class */
#include "ai_town.hpp"
#include "ai_map.hpp"
#include "../../town.h"
#include "../../strings_func.h"
#include "../../town_type.h"
#include "../../core/alloc_func.hpp"
#include "table/strings.h"
/* static */ TownID AITown::GetMaxTownID()
{
return ::GetMaxTownIndex();
}
/* static */ int32 AITown::GetTownCount()
{
return ::GetNumTowns();
}
/* static */ bool AITown::IsValidTown(TownID town_id)
{
return ::IsValidTownID(town_id);
}
/* static */ char *AITown::GetName(TownID town_id)
{
if (!IsValidTown(town_id)) return NULL;
static const int len = 64;
char *town_name = MallocT<char>(len);
::SetDParam(0, town_id);
::GetString(town_name, STR_TOWN, &town_name[len - 1]);
return town_name;
}
/* static */ int32 AITown::GetPopulation(TownID town_id)
{
if (!IsValidTown(town_id)) return 0;
const Town *t = ::GetTown(town_id);
return t->population;
}
/* static */ TileIndex AITown::GetLocation(TownID town_id)
{
if (!IsValidTown(town_id)) return INVALID_TILE;
const Town *t = ::GetTown(town_id);
return t->xy;
}
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceManhattan(tile, GetLocation(town_id));
}
/* static */ int32 AITown::GetDistanceSquareToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceSquare(tile, GetLocation(town_id));
}