(svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
--- a/projects/openttd.vcproj Wed Mar 14 11:14:26 2007 +0000
+++ b/projects/openttd.vcproj Wed Mar 14 11:14:57 2007 +0000
@@ -892,12 +892,9 @@
</File>
</Filter>
<Filter
- Name="AI Files"
+ Name="AI Headers"
Filter="">
<File
- RelativePath=".\..\src\ai\core\ai.cpp">
- </File>
- <File
RelativePath=".\..\src\ai\core\ai.h">
</File>
<File
@@ -910,9 +907,22 @@
RelativePath=".\..\src\ai\core\ai_controller.hpp">
</File>
<File
+ RelativePath=".\..\src\ai\core\ai_map.hpp">
+ </File>
+ <File
RelativePath=".\..\src\ai\core\ai_object.hpp">
</File>
<File
+ RelativePath=".\..\src\ai\core\ai_town.hpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="AI Core"
+ Filter="">
+ <File
+ RelativePath=".\..\src\ai\core\ai.cpp">
+ </File>
+ <File
RelativePath=".\..\src\ai\core\base\random.cpp">
</File>
<File
@@ -922,9 +932,22 @@
RelativePath=".\..\src\ai\core\company\money.cpp">
</File>
<File
+ RelativePath=".\..\src\ai\core\map\conversion.cpp">
+ </File>
+ <File
+ RelativePath=".\..\src\ai\core\map\query.cpp">
+ </File>
+ <File
RelativePath=".\..\src\ai\core\object\commands.cpp">
</File>
<File
+ RelativePath=".\..\src\ai\core\town\query.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="AIs"
+ Filter="">
+ <File
RelativePath=".\..\src\ai\NoAI\NoAI.cpp">
</File>
<File
--- a/projects/openttd_vs80.vcproj Wed Mar 14 11:14:26 2007 +0000
+++ b/projects/openttd_vs80.vcproj Wed Mar 14 11:14:57 2007 +0000
@@ -1413,13 +1413,9 @@
</File>
</Filter>
<Filter
- Name="AI Files"
+ Name="AI Headers"
>
<File
- RelativePath=".\..\src\ai\core\ai.cpp"
- >
- </File>
- <File
RelativePath=".\..\src\ai\core\ai.h"
>
</File>
@@ -1436,10 +1432,26 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\core\ai_map.hpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\core\ai_object.hpp"
>
</File>
<File
+ RelativePath=".\..\src\ai\core\ai_town.hpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="AI Core"
+ >
+ <File
+ RelativePath=".\..\src\ai\core\ai.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\core\base\random.cpp"
>
</File>
@@ -1452,10 +1464,26 @@
>
</File>
<File
+ RelativePath=".\..\src\ai\core\map\conversion.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\..\src\ai\core\map\query.cpp"
+ >
+ </File>
+ <File
RelativePath=".\..\src\ai\core\object\commands.cpp"
>
</File>
<File
+ RelativePath=".\..\src\ai\core\town\query.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="AIs"
+ >
+ <File
RelativePath=".\..\src\ai\NoAI\NoAI.cpp"
>
</File>
--- a/source.list Wed Mar 14 11:14:26 2007 +0000
+++ b/source.list Wed Mar 14 11:14:57 2007 +0000
@@ -267,17 +267,26 @@
table/unmovable_land.h
table/water_land.h
-# AI Files
-ai/core/ai.cpp
+# AI Headers
ai/core/ai.h
ai/core/ai_base.hpp
ai/core/ai_company.hpp
ai/core/ai_controller.hpp
+ai/core/ai_map.hpp
ai/core/ai_object.hpp
+ai/core/ai_town.hpp
+
+# AI Core
+ai/core/ai.cpp
ai/core/base/random.cpp
ai/core/company/name.cpp
ai/core/company/money.cpp
+ai/core/map/conversion.cpp
+ai/core/map/query.cpp
ai/core/object/commands.cpp
+ai/core/town/query.cpp
+
+# AIs
ai/NoAI/NoAI.cpp
ai/NoAI/NoAI.hpp
ai/squirrel/squirrel.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/core/ai_town.hpp Wed Mar 14 11:14:57 2007 +0000
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/** @file ai_town.hpp Everything to query towns */
+
+#ifndef AI_TOWN_HPP
+#define AI_TOWN_HPP
+
+#include "ai_object.hpp"
+
+class AITown : public AIObject {
+public:
+ /**
+ * Gets the maximum town index; there are no valid towns with a higher index
+ * @return the maximum town index
+ * @post return >= 0
+ */
+ TownID GetMaxTownID();
+
+ /**
+ * Gets the number of towns
+ * @return the number of towns
+ * @post return >= 0
+ */
+ int32 GetTownCount();
+
+ /**
+ * Checks whether the given town index is valid
+ * @param town_id the index to check
+ * @return true if and only if the town is valid
+ */
+ bool IsValidTown(TownID town_id);
+
+ /**
+ * Get the name of the town
+ * @param town_id the town to get the name of
+ * @pre this->IsValidTown(town)
+ * @return the name of the town
+ * @note the returned name must be freed
+ */
+ char *GetName(TownID town_id);
+
+ /**
+ * Gets the number of inhabitants in the town
+ * @param town_id the town to get the name of
+ * @pre this->IsValidTown(town)
+ * @return the number of inhabitants
+ * @post return >= 0
+ */
+ int32 GetPopulation(TownID town_id);
+
+ /**
+ * Gets the location of inhabitants in the town
+ * @param town_id the location of the town
+ * @pre this->IsValidTown(town)
+ * @return the number of inhabitants
+ * @post return >= 0
+ */
+ TileIndex GetLocation(TownID town_id);
+};
+
+#endif /* AI_TOWN_HPP */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/core/town/query.cpp Wed Mar 14 11:14:57 2007 +0000
@@ -0,0 +1,47 @@
+/* $Id$ */
+
+/** @file query.cpp handles the town-related functions of the AITown class */
+
+#include "../ai_town.hpp"
+#include "../../../town.h"
+#include "../../../strings.h"
+#include "../../../variables.h" /* For SetDParam */
+
+TownID AITown::GetMaxTownID()
+{
+ return ::GetMaxTownIndex();
+}
+
+int32 AITown::GetTownCount()
+{
+ return ::GetNumTowns();
+}
+
+bool AITown::IsValidTown(TownID town_id)
+{
+ return ::IsValidTownID(town_id);
+}
+
+char *AITown::GetName(TownID town_id)
+{
+ static const int len = 64;
+ char *town_name = MallocT<char>(len);
+
+ const Town *t = ::GetTown(town_id);
+ SetDParam(0, t->townnameparts);
+ GetString(town_name, t->townnametype, &town_name[len - 1]);
+
+ return town_name;
+}
+
+int32 AITown::GetPopulation(TownID town_id)
+{
+ const Town *t = ::GetTown(town_id);
+ return t->population;
+}
+
+TileIndex AITown::GetLocation(TownID town_id)
+{
+ const Town *t = ::GetTown(town_id);
+ return t->xy;
+}