(svn r10540) [NoAI] -Add: added AIStationVehicleList, which lists all vehicles that go to a given station
--- a/bin/ai/regression/regression.nut Fri Jul 13 10:49:57 2007 +0000
+++ b/bin/ai/regression/regression.nut Fri Jul 13 11:04:00 2007 +0000
@@ -237,6 +237,17 @@
for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
print(" " + i + " => " + list.GetValue(i));
}
+
+ list = AIStationVehicleList(0);
+
+ print("");
+ print("--StationVehicleList--");
+ print(" Count(): " + list.Count());
+ list.Valuate(AIVehicleListLocation());
+ print(" Location ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
}
function Regression::Road()
--- a/bin/ai/regression/regression.txt Fri Jul 13 10:49:57 2007 +0000
+++ b/bin/ai/regression/regression.txt Fri Jul 13 11:04:00 2007 +0000
@@ -654,7 +654,7 @@
RemoveRoadStation(): false
Station Types
BuildRoadStation(bus): true
- BuildRoadStation(bus): true
+ BuildRoadStation(truck): true
BuildRoadStation(truck): true
BuildRoadStation(bus): true
BuildRoadStation(truck): true
@@ -1651,3 +1651,21 @@
ShareOrders(): false
ShareOrders(): true
UnshareOrders(): true
+ AppendOrder(): true
+
+--VehicleStationList--
+ Count(): 2
+ Location ListDump:
+ 1 => 33420
+ 0 => 33411
+ CargoWaiting(0) ListDump:
+ 1 => 0
+ 0 => 0
+ CargoWaiting(1) ListDump:
+ 1 => 0
+ 0 => 0
+
+--StationVehicleList--
+ Count(): 1
+ Location ListDump:
+ 1024 => 33417
--- a/src/ai/ai_squirrel.cpp Fri Jul 13 10:49:57 2007 +0000
+++ b/src/ai/ai_squirrel.cpp Fri Jul 13 11:04:00 2007 +0000
@@ -219,6 +219,7 @@
SQAIStationListLocationRegister(this->engine);
SQAIStationListRegister(this->engine);
SQAIStationRegister(this->engine);
+ SQAIStationVehicleListRegister(this->engine);
SQAITestModeRegister(this->engine);
SQAITileListBuildableRegister(this->engine);
SQAITileListCargoAcceptanceRegister(this->engine);
--- a/src/ai/api/ai_vehiclelist.cpp Fri Jul 13 10:49:57 2007 +0000
+++ b/src/ai/api/ai_vehiclelist.cpp Fri Jul 13 11:04:00 2007 +0000
@@ -1,5 +1,6 @@
#include "ai_vehiclelist.hpp"
#include "../../player.h"
+#include "../../station.h"
#include "../../vehicle.h"
AIVehicleList::AIVehicleList()
@@ -9,3 +10,21 @@
if (v->owner == _current_player && v->IsPrimaryVehicle()) this->AddItem(v->index);
}
}
+
+AIStationVehicleList::AIStationVehicleList(StationID station)
+{
+ Vehicle *v;
+
+ FOR_ALL_VEHICLES(v) {
+ if (v->owner == _current_player && v->IsPrimaryVehicle()) {
+ const Order *order;
+
+ FOR_VEHICLE_ORDERS(v, order) {
+ if (order->type == OT_GOTO_STATION && order->dest == station) {
+ this->AddItem(v->index);
+ break;
+ }
+ }
+ }
+ }
+}
--- a/src/ai/api/ai_vehiclelist.hpp Fri Jul 13 10:49:57 2007 +0000
+++ b/src/ai/api/ai_vehiclelist.hpp Fri Jul 13 11:04:00 2007 +0000
@@ -23,4 +23,21 @@
AIVehicleList();
};
+/**
+ * Class that creates a list of vehicles that go to a given station.
+ */
+class AIStationVehicleList : public AIAbstractList {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AIStationVehicleList"; }
+
+ /**
+ * The constructor to make a list of vehicles that goes to this station.
+ * @param station The station to get the list of vehicles that go here from.
+ */
+ AIStationVehicleList(StationID station);
+};
+
#endif /* AI_VEHICLELIST_HPP */
--- a/src/ai/api/ai_vehiclelist.hpp.sq Fri Jul 13 10:49:57 2007 +0000
+++ b/src/ai/api/ai_vehiclelist.hpp.sq Fri Jul 13 11:04:00 2007 +0000
@@ -17,3 +17,21 @@
SQAIVehicleList.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AIStationVehicleList to be used as Squirrel parameter */
+ template <> AIStationVehicleList *GetParam(ForceType<AIStationVehicleList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIStationVehicleList *)instance; }
+ template <> AIStationVehicleList &GetParam(ForceType<AIStationVehicleList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIStationVehicleList *)instance; }
+ template <> const AIStationVehicleList *GetParam(ForceType<const AIStationVehicleList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIStationVehicleList *)instance; }
+ template <> const AIStationVehicleList &GetParam(ForceType<const AIStationVehicleList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIStationVehicleList *)instance; }
+}; // namespace SQConvert
+
+void SQAIStationVehicleListRegister(Squirrel *engine) {
+ DefSQClass <AIStationVehicleList> SQAIStationVehicleList("AIStationVehicleList");
+ SQAIStationVehicleList.PreRegister(engine, "AIAbstractList");
+ SQAIStationVehicleList.AddConstructor<void (AIStationVehicleList::*)(StationID station), 2>(engine, "xi");
+
+ SQAIStationVehicleList.DefSQStaticMethod(engine, &AIStationVehicleList::GetClassName, "GetClassName", 1, "x");
+
+ SQAIStationVehicleList.PostRegister(engine);
+}