(svn r10538) [NoAI] -Add: added AIVehicleStationList, which lists all stations a vehicle goes to
--- a/bin/ai/regression/regression.nut Fri Jul 13 10:42:23 2007 +0000
+++ b/bin/ai/regression/regression.nut Fri Jul 13 10:48:08 2007 +0000
@@ -215,6 +215,28 @@
print(" ShareOrders(): " + order.ShareOrders(1025, 1));
print(" ShareOrders(): " + order.ShareOrders(1025, 1024));
print(" UnshareOrders(): " + order.UnshareOrders(1025));
+ print(" AppendOrder(): " + order.AppendOrder(1024, 33420, AIOrder.AIOF_NONE));
+
+ local list = AIVehicleStationList(1024);
+
+ print("");
+ print("--VehicleStationList--");
+ print(" Count(): " + list.Count());
+ list.Valuate(AIStationListLocation());
+ print(" Location ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
+ list.Valuate(AIStationListCargoWaiting(0));
+ print(" CargoWaiting(0) ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
+ list.Valuate(AIStationListCargoWaiting(1));
+ print(" CargoWaiting(1) ListDump:");
+ for (local i = list.Begin(); list.HasNext(); i = list.Next()) {
+ print(" " + i + " => " + list.GetValue(i));
+ }
}
function Regression::Road()
@@ -263,7 +285,7 @@
print(" Station Types");
print(" BuildRoadStation(bus): " + road.BuildRoadStation(33411, 33410, false, false));
- print(" BuildRoadStation(bus): " + road.BuildRoadStation(33420, 33421, false, false));
+ print(" BuildRoadStation(truck): " + road.BuildRoadStation(33420, 33421, true, false));
print(" BuildRoadStation(truck): " + road.BuildRoadStation(33412, 33413, true, false));
print(" BuildRoadStation(bus): " + road.BuildRoadStation(33411 + 256, 33411, false, false));
print(" BuildRoadStation(truck): " + road.BuildRoadStation(33412 + 256, 33412 + 256 + 256, true, false));
--- a/src/ai/ai_squirrel.cpp Fri Jul 13 10:42:23 2007 +0000
+++ b/src/ai/ai_squirrel.cpp Fri Jul 13 10:48:08 2007 +0000
@@ -242,6 +242,7 @@
SQAIVehicleListRegister(this->engine);
SQAIVehicleListUnitNumberRegister(this->engine);
SQAIVehicleRegister(this->engine);
+ SQAIVehicleStationListRegister(this->engine);
this->engine->SetGlobalPointer(this->engine);
}
--- a/src/ai/api/ai_stationlist.cpp Fri Jul 13 10:42:23 2007 +0000
+++ b/src/ai/api/ai_stationlist.cpp Fri Jul 13 10:48:08 2007 +0000
@@ -1,8 +1,11 @@
/* $Id$ */
#include "ai_stationlist.hpp"
+#include "ai_vehicle.hpp"
#include "../../player.h"
#include "../../station.h"
+#include "../../order.h"
+#include "../../vehicle.h"
AIStationList::AIStationList(AIStationList::StationType type)
{
@@ -11,3 +14,14 @@
if (st->owner == _current_player && (type == AIStationList::STATION_ANY || (st->facilities & type) != 0)) this->AddItem(st->index);
}
}
+
+AIVehicleStationList::AIVehicleStationList(VehicleID vehicle_id)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return;
+
+ Vehicle *v = ::GetVehicle(vehicle_id);
+
+ for (Order *o = v->orders; o != NULL; o = o->next) {
+ if (o->type == OT_GOTO_STATION) this->AddItem(o->dest);
+ }
+}
--- a/src/ai/api/ai_stationlist.hpp Fri Jul 13 10:42:23 2007 +0000
+++ b/src/ai/api/ai_stationlist.hpp Fri Jul 13 10:48:08 2007 +0000
@@ -33,4 +33,20 @@
};
DECLARE_ENUM_AS_BIT_SET(AIStationList::StationType);
+/**
+ * Class that creates a list of stations the vehicles goes to.
+ */
+class AIVehicleStationList : public AIAbstractList {
+public:
+ /**
+ * The name of the class, needed by several sub-processes.
+ */
+ static const char *GetClassName() { return "AIVehicleStationList"; }
+
+ /**
+ * The constructor to make a list of stations.
+ */
+ AIVehicleStationList(VehicleID vehicle_id);
+};
+
#endif /* AI_STATIONLIST_HPP */
--- a/src/ai/api/ai_stationlist.hpp.sq Fri Jul 13 10:42:23 2007 +0000
+++ b/src/ai/api/ai_stationlist.hpp.sq Fri Jul 13 10:48:08 2007 +0000
@@ -28,3 +28,21 @@
SQAIStationList.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AIVehicleStationList to be used as Squirrel parameter */
+ template <> AIVehicleStationList *GetParam(ForceType<AIVehicleStationList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleStationList *)instance; }
+ template <> AIVehicleStationList &GetParam(ForceType<AIVehicleStationList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleStationList *)instance; }
+ template <> const AIVehicleStationList *GetParam(ForceType<const AIVehicleStationList *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleStationList *)instance; }
+ template <> const AIVehicleStationList &GetParam(ForceType<const AIVehicleStationList &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleStationList *)instance; }
+}; // namespace SQConvert
+
+void SQAIVehicleStationListRegister(Squirrel *engine) {
+ DefSQClass <AIVehicleStationList> SQAIVehicleStationList("AIVehicleStationList");
+ SQAIVehicleStationList.PreRegister(engine, "AIAbstractList");
+ SQAIVehicleStationList.AddConstructor<void (AIVehicleStationList::*)(VehicleID vehicle_id), 2>(engine, "xi");
+
+ SQAIVehicleStationList.DefSQStaticMethod(engine, &AIVehicleStationList::GetClassName, "GetClassName", 1, "x");
+
+ SQAIVehicleStationList.PostRegister(engine);
+}