summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_cargolist.hpp2
-rw-r--r--src/ai/api/ai_changelog.hpp7
-rw-r--r--src/ai/api/ai_industry.cpp16
-rw-r--r--src/ai/api/ai_industry.hpp13
-rw-r--r--src/ai/api/ai_industry.hpp.sq8
5 files changed, 34 insertions, 12 deletions
diff --git a/src/ai/api/ai_cargolist.hpp b/src/ai/api/ai_cargolist.hpp
index 2cac3e0c2..a933c1fc5 100644
--- a/src/ai/api/ai_cargolist.hpp
+++ b/src/ai/api/ai_cargolist.hpp
@@ -27,6 +27,8 @@ public:
/**
* Creates a list of cargos that the given industry accepts.
+ * @note This list also includes cargos that are temporarily not accepted
+ * by this industry, @see AIIndustry::IsCargoAccepted.
* @ingroup AIList
*/
class AICargoList_IndustryAccepting : public AIAbstractList {
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index b767778d9..672588c0f 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -30,12 +30,13 @@
* \li HasNext for all lists.
*
* Other changes:
- * \li AIRoad::BuildRoadStation now allows overbuilding.
- * \li AIRoad::BuildDriveThroughRoadStation now allows overbuilding.
+ * \li AIEngine::GetMaxTractiveEffort can be used for road vehicles.
* \li AIEngine::GetPower can be used for road vehicles.
* \li AIEngine::GetWeight can be used for road vehicles.
- * \li AIEngine::GetMaxTractiveEffort can be used for road vehicles.
+ * \li AIIndustry::IsCargoAccepted now returns CargoAcceptState instead of a boolean.
* \li AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders as well.
+ * \li AIRoad::BuildDriveThroughRoadStation now allows overbuilding.
+ * \li AIRoad::BuildRoadStation now allows overbuilding.
*
* \b 1.0.3
*
diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp
index c1cb42ef8..cb5c3cee4 100644
--- a/src/ai/api/ai_industry.cpp
+++ b/src/ai/api/ai_industry.cpp
@@ -15,6 +15,7 @@
#include "../../industry.h"
#include "../../strings_func.h"
#include "../../station_base.h"
+#include "../../newgrf_industries.h"
#include "table/strings.h"
/* static */ int32 AIIndustry::GetIndustryCount()
@@ -45,18 +46,21 @@
return industry_name;
}
-/* static */ bool AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
+/* static */ AIIndustry::CargoAcceptState AIIndustry::IsCargoAccepted(IndustryID industry_id, CargoID cargo_id)
{
- if (!IsValidIndustry(industry_id)) return false;
- if (!AICargo::IsValidCargo(cargo_id)) return false;
+ if (!IsValidIndustry(industry_id)) return CAS_NOT_ACCEPTED;
+ if (!AICargo::IsValidCargo(cargo_id)) return CAS_NOT_ACCEPTED;
- const Industry *i = ::Industry::Get(industry_id);
+ Industry *i = ::Industry::Get(industry_id);
for (byte j = 0; j < lengthof(i->accepts_cargo); j++) {
- if (i->accepts_cargo[j] == cargo_id) return true;
+ if (i->accepts_cargo[j] == cargo_id) {
+ if (IndustryTemporarilyRefusesCargo(i, cargo_id)) return CAS_TEMP_REFUSED;
+ return CAS_ACCEPTED;
+ }
}
- return false;
+ return CAS_NOT_ACCEPTED;
}
/* static */ int32 AIIndustry::GetStockpiledCargo(IndustryID industry_id, CargoID cargo_id)
diff --git a/src/ai/api/ai_industry.hpp b/src/ai/api/ai_industry.hpp
index 0d662d2b6..85f2a4dee 100644
--- a/src/ai/api/ai_industry.hpp
+++ b/src/ai/api/ai_industry.hpp
@@ -22,6 +22,13 @@ public:
/** Get the name of this class to identify it towards squirrel. */
static const char *GetClassName() { return "AIIndustry"; }
+ /** Ways for an industry to accept a cargo. */
+ enum CargoAcceptState {
+ CAS_NOT_ACCEPTED, ///< The CargoID is not accepted by this industry.
+ CAS_ACCEPTED, ///< The industry currently accepts this CargoID.
+ CAS_TEMP_REFUSED, ///< The industry temporarily refuses to accept this CargoID but may do so again in the future.
+ };
+
/**
* Gets the number of industries.
* @return The number of industries.
@@ -56,14 +63,14 @@ public:
static char *GetName(IndustryID industry_id);
/**
- * See if an industry accepts a certain cargo.
+ * See whether an industry currently accepts a certain cargo.
* @param industry_id The index of the industry.
* @param cargo_id The index of the cargo.
* @pre IsValidIndustry(industry_id).
* @pre AICargo::IsValidCargo(cargo_id).
- * @return True if and only if the industry accepts the cargo.
+ * @return Whether the industry accepts, temporarily refuses or never accepts this cargo.
*/
- static bool IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
+ static CargoAcceptState IsCargoAccepted(IndustryID industry_id, CargoID cargo_id);
/**
* Get the amount of cargo stockpiled for processing.
diff --git a/src/ai/api/ai_industry.hpp.sq b/src/ai/api/ai_industry.hpp.sq
index 86c7d90b7..e0ff0ff8c 100644
--- a/src/ai/api/ai_industry.hpp.sq
+++ b/src/ai/api/ai_industry.hpp.sq
@@ -12,6 +12,10 @@
#include "ai_industry.hpp"
namespace SQConvert {
+ /* Allow enums to be used as Squirrel parameters */
+ template <> AIIndustry::CargoAcceptState GetParam(ForceType<AIIndustry::CargoAcceptState>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIIndustry::CargoAcceptState)tmp; }
+ template <> int Return<AIIndustry::CargoAcceptState>(HSQUIRRELVM vm, AIIndustry::CargoAcceptState res) { sq_pushinteger(vm, (int32)res); return 1; }
+
/* Allow AIIndustry to be used as Squirrel parameter */
template <> AIIndustry *GetParam(ForceType<AIIndustry *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIIndustry *)instance; }
template <> AIIndustry &GetParam(ForceType<AIIndustry &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIIndustry *)instance; }
@@ -26,6 +30,10 @@ void SQAIIndustry_Register(Squirrel *engine)
SQAIIndustry.PreRegister(engine);
SQAIIndustry.AddConstructor<void (AIIndustry::*)(), 1>(engine, "x");
+ SQAIIndustry.DefSQConst(engine, AIIndustry::CAS_NOT_ACCEPTED, "CAS_NOT_ACCEPTED");
+ SQAIIndustry.DefSQConst(engine, AIIndustry::CAS_ACCEPTED, "CAS_ACCEPTED");
+ SQAIIndustry.DefSQConst(engine, AIIndustry::CAS_TEMP_REFUSED, "CAS_TEMP_REFUSED");
+
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryCount, "GetIndustryCount", 1, ".");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::IsValidIndustry, "IsValidIndustry", 2, ".i");
SQAIIndustry.DefSQStaticMethod(engine, &AIIndustry::GetIndustryID, "GetIndustryID", 2, ".i");