summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_town.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-11-23 16:09:46 +0000
committertruebrain <truebrain@openttd.org>2011-11-23 16:09:46 +0000
commitef02931a3232abb594c1d00db8c1faacd829999f (patch)
tree04976dddb31d74236466978f9cda04073e6d477c /src/ai/api/ai_town.cpp
parent44a1ae8cf20f3869a044b697b9d8e2ec9d0048d9 (diff)
downloadopenttd-ef02931a3232abb594c1d00db8c1faacd829999f.tar.xz
(svn r23302) -Add: [NoAI] AITown::GetCargoGoal and AITown::GetGrowthRate to query statistics about a town regarding its growing
Diffstat (limited to 'src/ai/api/ai_town.cpp')
-rw-r--r--src/ai/api/ai_town.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp
index c1efe5ec7..79ce96ec7 100644
--- a/src/ai/api/ai_town.cpp
+++ b/src/ai/api/ai_town.cpp
@@ -18,6 +18,7 @@
#include "../../strings_func.h"
#include "../../company_func.h"
#include "../../station_base.h"
+#include "../../landscape.h"
#include "table/strings.h"
/* static */ int32 AITown::GetTownCount()
@@ -102,6 +103,35 @@
return t->received[towneffect_id].old_act;
}
+/* static */ uint32 AITown::GetCargoGoal(TownID town_id, AICargo::TownEffect towneffect_id)
+{
+ if (!IsValidTown(town_id)) return -1;
+ if (!AICargo::IsValidTownEffect(towneffect_id)) return -1;
+
+ const Town *t = ::Town::Get(town_id);
+
+ switch (t->goal[towneffect_id]) {
+ case TOWN_GROWTH_WINTER:
+ if (TileHeight(t->xy) >= GetSnowLine() && t->population > 90) return 1;
+ return 0;
+
+ case TOWN_GROWTH_DESERT:
+ if (GetTropicZone(t->xy) == TROPICZONE_DESERT && t->population > 60) return 1;
+ return 0;
+
+ default: return t->goal[towneffect_id];
+ }
+}
+
+/* static */ int32 AITown::GetGrowthRate(TownID town_id)
+{
+ if (!IsValidTown(town_id)) return false;
+
+ const Town *t = ::Town::Get(town_id);
+
+ return (t->growth_rate * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS;
+}
+
/* static */ int32 AITown::GetDistanceManhattanToTile(TownID town_id, TileIndex tile)
{
return AIMap::DistanceManhattan(tile, GetLocation(town_id));