summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_instance.cpp1
-rw-r--r--src/ai/api/ai_cargolist.cpp12
-rw-r--r--src/ai/api/ai_cargolist.hpp15
-rw-r--r--src/ai/api/ai_cargolist.hpp.sq18
-rw-r--r--src/ai/api/ai_changelog.hpp1
5 files changed, 47 insertions, 0 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 13180b53f..1cae588f7 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -186,6 +186,7 @@ void AIInstance::RegisterAPI()
SQAICargoList_Register(this->engine);
SQAICargoList_IndustryAccepting_Register(this->engine);
SQAICargoList_IndustryProducing_Register(this->engine);
+ SQAICargoList_StationAccepting_Register(this->engine);
SQAICompany_Register(this->engine);
SQAIDate_Register(this->engine);
SQAIDepotList_Register(this->engine);
diff --git a/src/ai/api/ai_cargolist.cpp b/src/ai/api/ai_cargolist.cpp
index 1ee1c462d..4b226f65d 100644
--- a/src/ai/api/ai_cargolist.cpp
+++ b/src/ai/api/ai_cargolist.cpp
@@ -12,8 +12,10 @@
#include "../../stdafx.h"
#include "ai_cargolist.hpp"
#include "ai_industry.hpp"
+#include "ai_station.hpp"
#include "../../cargotype.h"
#include "../../industry.h"
+#include "../../station_base.h"
AICargoList::AICargoList()
{
@@ -48,3 +50,13 @@ AICargoList_IndustryProducing::AICargoList_IndustryProducing(IndustryID industry
}
}
}
+
+AICargoList_StationAccepting::AICargoList_StationAccepting(StationID station_id)
+{
+ if (!AIStation::IsValidStation(station_id)) return;
+
+ Station *st = ::Station::Get(station_id);
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::GES_ACCEPTANCE)) this->AddItem(i);
+ }
+}
diff --git a/src/ai/api/ai_cargolist.hpp b/src/ai/api/ai_cargolist.hpp
index f4449466b..0efd72ae2 100644
--- a/src/ai/api/ai_cargolist.hpp
+++ b/src/ai/api/ai_cargolist.hpp
@@ -57,4 +57,19 @@ public:
AICargoList_IndustryProducing(IndustryID industry_id);
};
+/**
+ * Creates a list of cargos that the given station accepts.
+ * @ingroup AIList
+ */
+class AICargoList_StationAccepting : public AIList {
+public:
+ /** Get the name of this class to identify it towards squirrel. */
+ static const char *GetClassName() { return "AICargoList_StationAccepting"; }
+
+ /**
+ * @param station_id The station to get the list of cargos it accepts from.
+ */
+ AICargoList_StationAccepting(StationID station_id);
+};
+
#endif /* AI_CARGOLIST_HPP */
diff --git a/src/ai/api/ai_cargolist.hpp.sq b/src/ai/api/ai_cargolist.hpp.sq
index 14c727c05..2ba0154a4 100644
--- a/src/ai/api/ai_cargolist.hpp.sq
+++ b/src/ai/api/ai_cargolist.hpp.sq
@@ -64,3 +64,21 @@ void SQAICargoList_IndustryProducing_Register(Squirrel *engine)
SQAICargoList_IndustryProducing.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AICargoList_StationAccepting to be used as Squirrel parameter */
+ template <> AICargoList_StationAccepting *GetParam(ForceType<AICargoList_StationAccepting *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICargoList_StationAccepting *)instance; }
+ template <> AICargoList_StationAccepting &GetParam(ForceType<AICargoList_StationAccepting &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargoList_StationAccepting *)instance; }
+ template <> const AICargoList_StationAccepting *GetParam(ForceType<const AICargoList_StationAccepting *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICargoList_StationAccepting *)instance; }
+ template <> const AICargoList_StationAccepting &GetParam(ForceType<const AICargoList_StationAccepting &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargoList_StationAccepting *)instance; }
+ template <> int Return<AICargoList_StationAccepting *>(HSQUIRRELVM vm, AICargoList_StationAccepting *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AICargoList_StationAccepting", res, NULL, DefSQDestructorCallback<AICargoList_StationAccepting>); return 1; }
+} // namespace SQConvert
+
+void SQAICargoList_StationAccepting_Register(Squirrel *engine)
+{
+ DefSQClass <AICargoList_StationAccepting> SQAICargoList_StationAccepting("AICargoList_StationAccepting");
+ SQAICargoList_StationAccepting.PreRegister(engine, "AIList");
+ SQAICargoList_StationAccepting.AddConstructor<void (AICargoList_StationAccepting::*)(StationID station_id), 2>(engine, "xi");
+
+ SQAICargoList_StationAccepting.PostRegister(engine);
+}
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index 68777440b..0026efab0 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -23,6 +23,7 @@
*
* \li AICargo::CT_AUTO_REFIT
* \li AICargo::CT_NO_REFIT
+ * \li AICargoList_StationAccepting
* \li AICompany::GetQuarterlyIncome
* \li AICompany::GetQuarterlyExpenses
* \li AICompany::GetQuarterlyCargoDelivered