src/ai/api/ai_town.cpp
author rubidium
Thu, 15 Mar 2007 22:46:22 +0000
branchnoai
changeset 9430 9e0a193b2bec
parent 9427 src/ai/api/town/query.cpp@ef0c109c5661
child 9459 73300438e505
permissions -rw-r--r--
(svn r9234) [NoAI] -Codechange: move away from the 'much' subdirectory approach for the API implementation.
/* $Id$ */

/** @file ai_town.cpp handles the town-related functions of the AITown class */

#include "ai_town.hpp"
#include "../../town.h"
#include "../../strings.h"
#include "../../variables.h" /* For SetDParam */
#include "table/strings.h"

TownID AITown::GetMaxTownID()
{
	return ::GetMaxTownIndex();
}

int32 AITown::GetTownCount()
{
	return ::GetNumTowns();
}

bool AITown::IsValidTown(TownID town_id)
{
	return ::IsValidTownID(town_id);
}

char *AITown::GetName(TownID town_id)
{
	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;
}

int32 AITown::GetPopulation(TownID town_id)
{
	const Town *t = ::GetTown(town_id);
	return t->population;
}

TileIndex AITown::GetLocation(TownID town_id)
{
	const Town *t = ::GetTown(town_id);
	return t->xy;
}