src/ai/core/town/query.cpp
branchnoai
changeset 9380 f4c7eb98b43d
child 9405 df6f3b4b0038
equal deleted inserted replaced
9379:6e89b780c2c9 9380:f4c7eb98b43d
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file query.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 
       
    10 TownID AITown::GetMaxTownID()
       
    11 {
       
    12 	return ::GetMaxTownIndex();
       
    13 }
       
    14 
       
    15 int32 AITown::GetTownCount()
       
    16 {
       
    17 	return ::GetNumTowns();
       
    18 }
       
    19 
       
    20 bool AITown::IsValidTown(TownID town_id)
       
    21 {
       
    22 	return ::IsValidTownID(town_id);
       
    23 }
       
    24 
       
    25 char *AITown::GetName(TownID town_id)
       
    26 {
       
    27 	static const int len = 64;
       
    28 	char *town_name = MallocT<char>(len);
       
    29 
       
    30 	const Town *t = ::GetTown(town_id);
       
    31 	SetDParam(0, t->townnameparts);
       
    32 	GetString(town_name, t->townnametype, &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 }