src/ai/api/ai_town.cpp
author truelight
Sun, 19 Aug 2007 13:16:06 +0000
branchnoai
changeset 9696 4384ed3de1f0
parent 9582 40f54a61bb17
child 9723 eee46cb39750
permissions -rw-r--r--
(svn r10937) [NoAI] -Add: added AIStation::GetName on request by Nickman
[NoAI] -Fix: AICompant::GetCompanyName returned \0 for invalid company instead of NULL
/* $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();
}

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

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

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

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