--- a/bin/ai/regression/regression.nut Tue Feb 26 21:45:33 2008 +0000
+++ b/bin/ai/regression/regression.nut Tue Feb 26 22:03:18 2008 +0000
@@ -97,6 +97,19 @@
}
}
+function Regression::CargoList()
+{
+ local list = AICargoList();
+
+ print("");
+ print("--CargoList--");
+ print(" Count(): " + list.Count());
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" Cargo " + i);
+ print(" GetCargoLabel(): " + AICargo.GetCargoLabel(i));
+ }
+}
+
function Regression::Company()
{
print("");
@@ -979,6 +992,7 @@
this.List();
this.Airport();
this.Cargo();
+ this.CargoList();
this.Company();
this.Engine();
this.EngineList();
--- a/bin/ai/regression/regression.txt Tue Feb 26 21:45:33 2008 +0000
+++ b/bin/ai/regression/regression.txt Tue Feb 26 22:03:18 2008 +0000
@@ -469,6 +469,31 @@
GetCargoIncome(100, 10): 0
GetCargoIncome(10, 100): 0
+--CargoList--
+ Count(): 11
+ Cargo 10
+ GetCargoLabel(): VALU
+ Cargo 9
+ GetCargoLabel(): STEL
+ Cargo 8
+ GetCargoLabel(): IORE
+ Cargo 7
+ GetCargoLabel(): WOOD
+ Cargo 6
+ GetCargoLabel(): GRAI
+ Cargo 5
+ GetCargoLabel(): GOOD
+ Cargo 4
+ GetCargoLabel(): LVST
+ Cargo 3
+ GetCargoLabel(): OIL_
+ Cargo 2
+ GetCargoLabel(): MAIL
+ Cargo 1
+ GetCargoLabel(): COAL
+ Cargo 0
+ GetCargoLabel(): PASS
+
--Company--
SetCompanyName(): true
SetCompanyName(): true
--- a/source.list Tue Feb 26 21:45:33 2008 +0000
+++ b/source.list Tue Feb 26 22:03:18 2008 +0000
@@ -403,6 +403,7 @@
ai/api/ai_airport.hpp
ai/api/ai_base.hpp
ai/api/ai_cargo.hpp
+ai/api/ai_cargolist.hpp
ai/api/ai_company.hpp
ai/api/ai_controller.hpp
ai/api/ai_engine.hpp
@@ -446,6 +447,7 @@
ai/api/ai_airport.cpp
ai/api/ai_base.cpp
ai/api/ai_cargo.cpp
+ai/api/ai_cargolist.cpp
ai/api/ai_company.cpp
ai/api/ai_controller.cpp
ai/api/ai_engine.cpp
--- a/src/ai/ai_squirrel.cpp Tue Feb 26 21:45:33 2008 +0000
+++ b/src/ai/ai_squirrel.cpp Tue Feb 26 22:03:18 2008 +0000
@@ -27,6 +27,7 @@
#include "api/ai_airport.hpp.sq"
#include "api/ai_base.hpp.sq"
#include "api/ai_cargo.hpp.sq"
+#include "api/ai_cargolist.hpp.sq"
#include "api/ai_company.hpp.sq"
#include "api/ai_controller.hpp.sq"
#include "api/ai_engine.hpp.sq"
@@ -219,6 +220,7 @@
SQAIAirport_Register(this->engine);
SQAIBase_Register(this->engine);
SQAICargo_Register(this->engine);
+ SQAICargoList_Register(this->engine);
SQAICompany_Register(this->engine);
SQAIController_Register(this->engine);
SQAIEngine_Register(this->engine);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_cargolist.cpp Tue Feb 26 22:03:18 2008 +0000
@@ -0,0 +1,13 @@
+#include "ai_cargolist.hpp"
+#include "../../cargotype.h"
+
+AICargoList::AICargoList()
+{
+ for (byte i = 0; i < NUM_CARGO; i++) {
+ const CargoSpec *c = ::GetCargo(i);
+ if (c->IsValid()) {
+ this->AddItem(i);
+ }
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_cargolist.hpp Tue Feb 26 22:03:18 2008 +0000
@@ -0,0 +1,22 @@
+/** @file ai_cargolist.hpp list all the cargos */
+/** @defgroup AICargoList AICargoList - Valuators and lists working on/with AICargoList */
+
+#ifndef AI_CARGOLIST_HPP
+#define AI_CARGOLIST_HPP
+
+#include "ai_abstractlist.hpp"
+
+/**
+ * Creates a list of cargos that can be produced in the current game.
+ * @ingroup AICargoList
+ */
+class AICargoList : public AIAbstractList {
+public:
+ static const char *GetClassName() { return "AICargoList"; }
+ AICargoList();
+
+private:
+ const char *GetListName() const { return "AICargoList"; }
+};
+
+#endif /* AI_CARGOLIST_HPP */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ai/api/ai_cargolist.hpp.sq Tue Feb 26 22:03:18 2008 +0000
@@ -0,0 +1,20 @@
+#include "ai_cargolist.hpp"
+
+namespace SQConvert {
+ /* Allow AICargoList to be used as Squirrel parameter */
+ template <> AICargoList *GetParam(ForceType<AICargoList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICargoList *)instance; }
+ template <> AICargoList &GetParam(ForceType<AICargoList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargoList *)instance; }
+ template <> const AICargoList *GetParam(ForceType<const AICargoList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICargoList *)instance; }
+ template <> const AICargoList &GetParam(ForceType<const AICargoList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargoList *)instance; }
+ template <> int Return<AICargoList *>(HSQUIRRELVM vm, AICargoList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AICargoList", res, NULL, DefSQDestructorCallback<AICargoList>); return 1; }
+}; // namespace SQConvert
+
+void SQAICargoList_Register(Squirrel *engine) {
+ DefSQClass <AICargoList> SQAICargoList("AICargoList");
+ SQAICargoList.PreRegister(engine, "AIAbstractList");
+ SQAICargoList.AddConstructor<void (AICargoList::*)(), 1>(engine, "x");
+
+ SQAICargoList.DefSQStaticMethod(engine, &AICargoList::GetClassName, "GetClassName", 1, "x");
+
+ SQAICargoList.PostRegister(engine);
+}