summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-05-09 15:59:30 +0000
committeryexo <yexo@openttd.org>2010-05-09 15:59:30 +0000
commit37928e29f7f15680b946a1451fe202601d3ef81f (patch)
treec90ae0b8d246d65155338ee18043ca14b7d4d885 /src/ai
parent96c1fd61735ecc73dea18bd1cdf58c18b3b1a5c8 (diff)
downloadopenttd-37928e29f7f15680b946a1451fe202601d3ef81f.tar.xz
(svn r19773) -Add: [NoAI] AIIndustry::GetIndustryID(TileIndex)
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_changelog.hpp1
-rw-r--r--src/ai/api/ai_industry.cpp6
-rw-r--r--src/ai/api/ai_industry.hpp10
-rw-r--r--src/ai/api/ai_industry.hpp.sq1
4 files changed, 18 insertions, 0 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index 3474a1209..b8943a1da 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -20,6 +20,7 @@
*
* API additions:
* \li IsEnd for all lists.
+ * \li AIIndustry::GetIndustryID
* \li AIRail::GetMaxSpeed
*
* API removals:
diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp
index 6fb208ce9..c1cb42ef8 100644
--- a/src/ai/api/ai_industry.cpp
+++ b/src/ai/api/ai_industry.cpp
@@ -27,6 +27,12 @@
return ::Industry::IsValidID(industry_id);
}
+/* static */ IndustryID AIIndustry::GetIndustryID(TileIndex tile)
+{
+ if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return INVALID_INDUSTRY;
+ return ::GetIndustryIndex(tile);
+}
+
/* static */ char *AIIndustry::GetName(IndustryID industry_id)
{
if (!IsValidIndustry(industry_id)) return NULL;
diff --git a/src/ai/api/ai_industry.hpp b/src/ai/api/ai_industry.hpp
index cbaa9f407..815e37ad0 100644
--- a/src/ai/api/ai_industry.hpp
+++ b/src/ai/api/ai_industry.hpp
@@ -37,6 +37,16 @@ public:
static bool IsValidIndustry(IndustryID industry_id);
/**
+ * Get the IndustryID of a tile, if there is an industry.
+ * @param tile The tile to find the IndustryID of.
+ * @return IndustryID of the industry.
+ * @post Use IsValidIndustry() to see if the industry is valid.
+ * @note GetIndustryID will return an invalid IndustryID for the
+ * station tile of industries with a dock/heliport.
+ */
+ static IndustryID GetIndustryID(TileIndex tile);
+
+ /**
* Get the name of the industry.
* @param industry_id The industry to get the name of.
* @pre IsValidIndustry(industry_id).
diff --git a/src/ai/api/ai_industry.hpp.sq b/src/ai/api/ai_industry.hpp.sq
index ed1dd0c32..86c7d90b7 100644
--- a/src/ai/api/ai_industry.hpp.sq
+++ b/src/ai/api/ai_industry.hpp.sq
@@ -28,6 +28,7 @@ void SQAIIndustry_Register(Squirrel *engine)
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, ".");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, ".i");
+ SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryID, "GetIndustryID", 2, ".i");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetName, "GetName", 2, ".i");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsCargoAccepted, "IsCargoAccepted", 3, ".ii");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetStockpiledCargo, "GetStockpiledCargo", 3, ".ii");