(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.

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
frosch 14 years ago
parent 1055c2b0fd
commit 969c059fea

@ -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
*

@ -23,6 +23,14 @@ class AIIndustryType : public AIObject {
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.

@ -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");

@ -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;

@ -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

Loading…
Cancel
Save