(svn r9290) [NoAI] -Fix: AITown and AIIndustry segfaulted if you gave a negative value as param to most functions
--- a/src/ai/api/ai_industry.cpp Sun Mar 18 19:39:27 2007 +0000
+++ b/src/ai/api/ai_industry.cpp Sun Mar 18 19:52:09 2007 +0000
@@ -25,6 +25,7 @@
char *AIIndustry::GetName(IndustryID industry_id)
{
+ if (!this->IsValidIndustry(industry_id)) return NULL;
static const int len = 64;
char *industry_name = MallocT<char>(len);
@@ -36,6 +37,7 @@
TileIndex AIIndustry::GetLocation(IndustryID industry_id)
{
+ if (!this->IsValidIndustry(industry_id)) return INVALID_TILE;
const Industry *i = ::GetIndustry(industry_id);
return i->xy;
}
--- a/src/ai/api/ai_town.cpp Sun Mar 18 19:39:27 2007 +0000
+++ b/src/ai/api/ai_town.cpp Sun Mar 18 19:52:09 2007 +0000
@@ -25,6 +25,7 @@
char *AITown::GetName(TownID town_id)
{
+ if (!this->IsValidTown(town_id)) return NULL;
static const int len = 64;
char *town_name = MallocT<char>(len);
@@ -36,12 +37,14 @@
int32 AITown::GetPopulation(TownID town_id)
{
+ if (!this->IsValidTown(town_id)) return 0;
const Town *t = ::GetTown(town_id);
return t->population;
}
TileIndex AITown::GetLocation(TownID town_id)
{
+ if (!this->IsValidTown(town_id)) return INVALID_TILE;
const Town *t = ::GetTown(town_id);
return t->xy;
}