src/ai/api/ai_town.cpp
branchnoai
changeset 9737 ee408edf3851
parent 9736 183b38e0a480
child 9814 be51ea0adc29
equal deleted inserted replaced
9736:183b38e0a480 9737:ee408edf3851
     7 #include "../../strings_func.h"
     7 #include "../../strings_func.h"
     8 #include "../../town_type.h"
     8 #include "../../town_type.h"
     9 #include "../../core/alloc_func.hpp"
     9 #include "../../core/alloc_func.hpp"
    10 #include "table/strings.h"
    10 #include "table/strings.h"
    11 
    11 
    12 TownID AITown::GetMaxTownID()
    12 /* static */ TownID AITown::GetMaxTownID()
    13 {
    13 {
    14 	return ::GetMaxTownIndex();
    14 	return ::GetMaxTownIndex();
    15 }
    15 }
    16 
    16 
    17 int32 AITown::GetTownCount()
    17 /* static */ int32 AITown::GetTownCount()
    18 {
    18 {
    19 	return ::GetNumTowns();
    19 	return ::GetNumTowns();
    20 }
    20 }
    21 
    21 
    22 /* static */ bool AITown::IsValidTown(TownID town_id)
    22 /* static */ bool AITown::IsValidTown(TownID town_id)
    23 {
    23 {
    24 	return ::IsValidTownID(town_id);
    24 	return ::IsValidTownID(town_id);
    25 }
    25 }
    26 
    26 
    27 char *AITown::GetName(TownID town_id)
    27 /* static */ char *AITown::GetName(TownID town_id)
    28 {
    28 {
    29 	if (!IsValidTown(town_id)) return NULL;
    29 	if (!IsValidTown(town_id)) return NULL;
    30 	static const int len = 64;
    30 	static const int len = 64;
    31 	char *town_name = MallocT<char>(len);
    31 	char *town_name = MallocT<char>(len);
    32 
    32 
    34 	::GetString(town_name, STR_TOWN, &town_name[len - 1]);
    34 	::GetString(town_name, STR_TOWN, &town_name[len - 1]);
    35 
    35 
    36 	return town_name;
    36 	return town_name;
    37 }
    37 }
    38 
    38 
    39 int32 AITown::GetPopulation(TownID town_id)
    39 /* static */ int32 AITown::GetPopulation(TownID town_id)
    40 {
    40 {
    41 	if (!IsValidTown(town_id)) return 0;
    41 	if (!IsValidTown(town_id)) return 0;
    42 	const Town *t = ::GetTown(town_id);
    42 	const Town *t = ::GetTown(town_id);
    43 	return t->population;
    43 	return t->population;
    44 }
    44 }
    45 
    45 
    46 TileIndex AITown::GetLocation(TownID town_id)
    46 /* static */ TileIndex AITown::GetLocation(TownID town_id)
    47 {
    47 {
    48 	if (!IsValidTown(town_id)) return INVALID_TILE;
    48 	if (!IsValidTown(town_id)) return INVALID_TILE;
    49 	const Town *t = ::GetTown(town_id);
    49 	const Town *t = ::GetTown(town_id);
    50 	return t->xy;
    50 	return t->xy;
    51 }
    51 }