src/ai/core/town/query.cpp
author rubidium
Wed, 14 Mar 2007 11:14:57 +0000
branchnoai
changeset 9380 f4c7eb98b43d
child 9405 df6f3b4b0038
permissions -rw-r--r--
(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
/* $Id$ */

/** @file query.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 */

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);

	const Town *t = ::GetTown(town_id);
	SetDParam(0, t->townnameparts);
	GetString(town_name, t->townnametype, &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;
}