summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-07-10 10:54:30 +0000
committerfrosch <frosch@openttd.org>2010-07-10 10:54:30 +0000
commit969c059feae435ff5cabb2f33d10d939b318ec02 (patch)
treed5daa0d05cd4f59342be87002abe60b1bd2826d0
parent1055c2b0fd8feb8a4a3eb039c3170d7ee8160b46 (diff)
downloadopenttd-969c059feae435ff5cabb2f33d10d939b318ec02.tar.xz
(svn r20107) -Add: [NoAI] AIIndustryType::INDUSTRYTYPE_TOWN and AIIndustryType::INDUSTRYTYPE_UNKNOWN for AIRail::BuildNewGRFRailStation(). Note that BuildNewGRFRailStation() now checks the passed industry type for validity.
-rw-r--r--src/ai/api/ai_changelog.hpp2
-rw-r--r--src/ai/api/ai_industrytype.hpp8
-rw-r--r--src/ai/api/ai_industrytype.hpp.sq7
-rw-r--r--src/ai/api/ai_rail.cpp3
-rw-r--r--src/ai/api/ai_rail.hpp6
5 files changed, 24 insertions, 2 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index e907ce007..4b059d0ef 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -21,6 +21,8 @@
* API additions:
* \li IsEnd for all lists.
* \li AIIndustry::GetIndustryID
+ * \li AIIndustryType::INDUSTRYTYPE_TOWN
+ * \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
* \li AIRail::GetMaxSpeed
* \li AIRail::ERR_RAILTYPE_DISALLOWS_CROSSING
*
diff --git a/src/ai/api/ai_industrytype.hpp b/src/ai/api/ai_industrytype.hpp
index f5d2ca827..836748374 100644
--- a/src/ai/api/ai_industrytype.hpp
+++ b/src/ai/api/ai_industrytype.hpp
@@ -24,6 +24,14 @@ public:
static const char *GetClassName() { return "AIIndustryType"; }
/**
+ * Special IndustryTypes.
+ */
+ enum SpecialIndustryType {
+ INDUSTRYTYPE_UNKNOWN = 0xFE, //!< Unknown/unspecific industrytype. (Usable for AIRail::BuildNewGRFRailStation())
+ INDUSTRYTYPE_TOWN = 0xFF, //!< No industry, but town. (Usable for AIRail::BuildNewGRFRailStation())
+ };
+
+ /**
* Checks whether the given industry-type is valid.
* @param industry_type The type check.
* @return True if and only if the industry-type is valid.
diff --git a/src/ai/api/ai_industrytype.hpp.sq b/src/ai/api/ai_industrytype.hpp.sq
index 494566021..938477145 100644
--- a/src/ai/api/ai_industrytype.hpp.sq
+++ b/src/ai/api/ai_industrytype.hpp.sq
@@ -12,6 +12,10 @@
#include "ai_industrytype.hpp"
namespace SQConvert {
+ /* Allow enums to be used as Squirrel parameters */
+ template <> AIIndustryType::SpecialIndustryType GetParam(ForceType<AIIndustryType::SpecialIndustryType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIIndustryType::SpecialIndustryType)tmp; }
+ template <> int Return<AIIndustryType::SpecialIndustryType>(HSQUIRRELVM vm, AIIndustryType::SpecialIndustryType res) { sq_pushinteger(vm, (int32)res); return 1; }
+
/* Allow AIIndustryType to be used as Squirrel parameter */
template <> AIIndustryType *GetParam(ForceType<AIIndustryType *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIIndustryType *)instance; }
template <> AIIndustryType &GetParam(ForceType<AIIndustryType &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIIndustryType *)instance; }
@@ -26,6 +30,9 @@ void SQAIIndustryType_Register(Squirrel *engine)
SQAIIndustryType.PreRegister(engine);
SQAIIndustryType.AddConstructor<void (AIIndustryType::*)(), 1>(engine, "x");
+ SQAIIndustryType.DefSQConst(engine, AIIndustryType::INDUSTRYTYPE_UNKNOWN, "INDUSTRYTYPE_UNKNOWN");
+ SQAIIndustryType.DefSQConst(engine, AIIndustryType::INDUSTRYTYPE_TOWN, "INDUSTRYTYPE_TOWN");
+
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::IsValidIndustryType, "IsValidIndustryType", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::GetName, "GetName", 2, ".i");
SQAIIndustryType.DefSQStaticMethod(engine, &AIIndustryType::GetProducedCargo, "GetProducedCargo", 2, ".i");
diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp
index 36f060a50..51c9b04cf 100644
--- a/src/ai/api/ai_rail.cpp
+++ b/src/ai/api/ai_rail.cpp
@@ -12,6 +12,7 @@
#include "ai_rail.hpp"
#include "ai_map.hpp"
#include "ai_station.hpp"
+#include "ai_industrytype.hpp"
#include "../../command_type.h"
#include "../../debug.h"
#include "../../station_base.h"
@@ -158,6 +159,8 @@
EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF);
EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType()));
EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id));
+ EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry));
+ EnforcePrecondition(false, goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry));
uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8);
if (direction == RAILTRACK_NW_SE) p1 |= 1 << 4;
diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp
index 26d649aa4..97bedcb21 100644
--- a/src/ai/api/ai_rail.hpp
+++ b/src/ai/api/ai_rail.hpp
@@ -261,8 +261,8 @@ public:
* @param platform_length The length of each platform.
* @param station_id The station to join, AIStation::STATION_NEW or AIStation::STATION_JOIN_ADJACENT.
* @param cargo_id The CargoID of the cargo that will be transported from / to this station.
- * @param source_industry The IndustryType of the industry you'll transport goods from.
- * @param goal_industry The IndustryType of the industry you'll transport goods to.
+ * @param source_industry The IndustryType of the industry you'll transport goods from, AIIndustryType::INDUSTRYTYPE_UNKNOWN or AIIndustryType::INDUSTRYTYPE_TOWN.
+ * @param goal_industry The IndustryType of the industry you'll transport goods to, AIIndustryType::INDUSTRYTYPE_UNKNOWN or AIIndustryType::INDUSTRYTYPE_TOWN.
* @param distance The manhattan distance you'll transport the cargo over.
* @param source_station True if this is the source station, false otherwise.
* @pre IsRailTypeAvailable(GetCurrentRailType()).
@@ -271,6 +271,8 @@ public:
* @pre num_platforms > 0 && num_platforms <= 255.
* @pre platform_length > 0 && platform_length <= 255.
* @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id).
+ * @pre source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry).
+ * @pre goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIError::ERR_AREA_NOT_CLEAR
* @exception AIError::ERR_FLAT_LAND_REQUIRED