src/ai/api/ai_town.cpp
branchnoai
changeset 9430 9e0a193b2bec
parent 9427 ef0c109c5661
child 9459 73300438e505
equal deleted inserted replaced
9429:25b7d020a3a9 9430:9e0a193b2bec
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file ai_town.cpp handles the town-related functions of the AITown class */
       
     4 
       
     5 #include "ai_town.hpp"
       
     6 #include "../../town.h"
       
     7 #include "../../strings.h"
       
     8 #include "../../variables.h" /* For SetDParam */
       
     9 #include "table/strings.h"
       
    10 
       
    11 TownID AITown::GetMaxTownID()
       
    12 {
       
    13 	return ::GetMaxTownIndex();
       
    14 }
       
    15 
       
    16 int32 AITown::GetTownCount()
       
    17 {
       
    18 	return ::GetNumTowns();
       
    19 }
       
    20 
       
    21 bool AITown::IsValidTown(TownID town_id)
       
    22 {
       
    23 	return ::IsValidTownID(town_id);
       
    24 }
       
    25 
       
    26 char *AITown::GetName(TownID town_id)
       
    27 {
       
    28 	static const int len = 64;
       
    29 	char *town_name = MallocT<char>(len);
       
    30 
       
    31 	SetDParam(0, town_id);
       
    32 	GetString(town_name, STR_TOWN, &town_name[len - 1]);
       
    33 
       
    34 	return town_name;
       
    35 }
       
    36 
       
    37 int32 AITown::GetPopulation(TownID town_id)
       
    38 {
       
    39 	const Town *t = ::GetTown(town_id);
       
    40 	return t->population;
       
    41 }
       
    42 
       
    43 TileIndex AITown::GetLocation(TownID town_id)
       
    44 {
       
    45 	const Town *t = ::GetTown(town_id);
       
    46 	return t->xy;
       
    47 }