changeset 15458:53df44fca900 draft

(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.
author frosch <frosch@openttd.org>
date Sat, 10 Jul 2010 10:54:30 +0000
parents a4ca05c4772a
children 5815672c4374
files src/ai/api/ai_changelog.hpp src/ai/api/ai_industrytype.hpp src/ai/api/ai_industrytype.hpp.sq src/ai/api/ai_rail.cpp src/ai/api/ai_rail.hpp
diffstat 5 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
  *
--- a/src/ai/api/ai_industrytype.hpp
+++ b/src/ai/api/ai_industrytype.hpp
@@ -24,6 +24,14 @@
 	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.
--- 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 @@
 	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");
--- 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;
--- a/src/ai/api/ai_rail.hpp
+++ b/src/ai/api/ai_rail.hpp
@@ -261,8 +261,8 @@
 	 * @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 @@
 	 * @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