summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_instance.cpp2
-rw-r--r--src/ai/api/ai_vehiclelist.cpp30
-rw-r--r--src/ai/api/ai_vehiclelist.hpp29
-rw-r--r--src/ai/api/ai_vehiclelist.hpp.sq34
4 files changed, 92 insertions, 3 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 11684e0ec..6a40f2fa0 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -225,6 +225,8 @@ void AIInstance::RegisterAPI()
SQAITunnel_Register(this->engine);
SQAIVehicle_Register(this->engine);
SQAIVehicleList_Register(this->engine);
+ SQAIVehicleList_DefaultGroup_Register(this->engine);
+ SQAIVehicleList_Group_Register(this->engine);
SQAIVehicleList_SharedOrders_Register(this->engine);
SQAIVehicleList_Station_Register(this->engine);
SQAIWaypoint_Register(this->engine);
diff --git a/src/ai/api/ai_vehiclelist.cpp b/src/ai/api/ai_vehiclelist.cpp
index 424f4e6bb..c7daff5c5 100644
--- a/src/ai/api/ai_vehiclelist.cpp
+++ b/src/ai/api/ai_vehiclelist.cpp
@@ -3,6 +3,7 @@
/** @file ai_vehiclelist.cpp Implementation of AIVehicleList and friends. */
#include "ai_vehiclelist.hpp"
+#include "ai_group.hpp"
#include "ai_station.hpp"
#include "ai_vehicle.hpp"
#include "../../company_func.h"
@@ -10,7 +11,7 @@
AIVehicleList::AIVehicleList()
{
- Vehicle *v;
+ const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->owner == _current_company && v->IsPrimaryVehicle()) this->AddItem(v->index);
}
@@ -20,8 +21,7 @@ AIVehicleList_Station::AIVehicleList_Station(StationID station_id)
{
if (!AIStation::IsValidStation(station_id)) return;
- Vehicle *v;
-
+ const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->owner == _current_company && v->IsPrimaryVehicle()) {
const Order *order;
@@ -44,3 +44,27 @@ AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id)
this->AddItem(v->index);
}
}
+
+AIVehicleList_Group::AIVehicleList_Group(GroupID group_id)
+{
+ if (!AIGroup::IsValidGroup((AIGroup::GroupID)group_id)) return;
+
+ const Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->owner == _current_company && v->IsPrimaryVehicle()) {
+ if (v->group_id == group_id) this->AddItem(v->index);
+ }
+ }
+}
+
+AIVehicleList_DefaultGroup::AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type)
+{
+ if (vehicle_type < AIVehicle::VT_RAIL || vehicle_type > AIVehicle::VT_AIR) return;
+
+ const Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->owner == _current_company && v->IsPrimaryVehicle()) {
+ if (v->type == vehicle_type && v->group_id == AIGroup::GROUP_DEFAULT) this->AddItem(v->index);
+ }
+ }
+}
diff --git a/src/ai/api/ai_vehiclelist.hpp b/src/ai/api/ai_vehiclelist.hpp
index a18d938b1..171de7d2e 100644
--- a/src/ai/api/ai_vehiclelist.hpp
+++ b/src/ai/api/ai_vehiclelist.hpp
@@ -6,6 +6,7 @@
#define AI_VEHICLELIST_HPP
#include "ai_abstractlist.hpp"
+#include "ai_vehicle.hpp"
/**
* Creates a list of vehicles of which you are the owner.
@@ -45,4 +46,32 @@ public:
AIVehicleList_SharedOrders(VehicleID vehicle_id);
};
+/**
+ * Creates a list of vehicles that are in a group.
+ * @ingroup AIList
+ */
+class AIVehicleList_Group : public AIAbstractList {
+public:
+ static const char *GetClassName() { return "AIVehicleList_Group"; }
+
+ /**
+ * @param group_id The ID of the group the vehicles are in.
+ */
+ AIVehicleList_Group(GroupID group_id);
+};
+
+/**
+ * Creates a list of vehicles that are in the default group.
+ * @ingroup AIList
+ */
+class AIVehicleList_DefaultGroup : public AIAbstractList {
+public:
+ static const char *GetClassName() { return "AIVehicleList_DefaultGroup"; }
+
+ /**
+ * @param vehicle_type The VehicleType to get the list of vehicles for.
+ */
+ AIVehicleList_DefaultGroup(AIVehicle::VehicleType vehicle_type);
+};
+
#endif /* AI_VEHICLELIST_HPP */
diff --git a/src/ai/api/ai_vehiclelist.hpp.sq b/src/ai/api/ai_vehiclelist.hpp.sq
index b5af401a1..9f00f61d8 100644
--- a/src/ai/api/ai_vehiclelist.hpp.sq
+++ b/src/ai/api/ai_vehiclelist.hpp.sq
@@ -53,3 +53,37 @@ void SQAIVehicleList_SharedOrders_Register(Squirrel *engine) {
SQAIVehicleList_SharedOrders.PostRegister(engine);
}
+
+namespace SQConvert {
+ /* Allow AIVehicleList_Group to be used as Squirrel parameter */
+ template <> AIVehicleList_Group *GetParam(ForceType<AIVehicleList_Group *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_Group *)instance; }
+ template <> AIVehicleList_Group &GetParam(ForceType<AIVehicleList_Group &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_Group *)instance; }
+ template <> const AIVehicleList_Group *GetParam(ForceType<const AIVehicleList_Group *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_Group *)instance; }
+ template <> const AIVehicleList_Group &GetParam(ForceType<const AIVehicleList_Group &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_Group *)instance; }
+ template <> int Return<AIVehicleList_Group *>(HSQUIRRELVM vm, AIVehicleList_Group *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIVehicleList_Group", res, NULL, DefSQDestructorCallback<AIVehicleList_Group>); return 1; }
+}; // namespace SQConvert
+
+void SQAIVehicleList_Group_Register(Squirrel *engine) {
+ DefSQClass <AIVehicleList_Group> SQAIVehicleList_Group("AIVehicleList_Group");
+ SQAIVehicleList_Group.PreRegister(engine, "AIAbstractList");
+ SQAIVehicleList_Group.AddConstructor<void (AIVehicleList_Group::*)(GroupID group_id), 2>(engine, "xi");
+
+ SQAIVehicleList_Group.PostRegister(engine);
+}
+
+namespace SQConvert {
+ /* Allow AIVehicleList_DefaultGroup to be used as Squirrel parameter */
+ template <> AIVehicleList_DefaultGroup *GetParam(ForceType<AIVehicleList_DefaultGroup *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_DefaultGroup *)instance; }
+ template <> AIVehicleList_DefaultGroup &GetParam(ForceType<AIVehicleList_DefaultGroup &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_DefaultGroup *)instance; }
+ template <> const AIVehicleList_DefaultGroup *GetParam(ForceType<const AIVehicleList_DefaultGroup *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_DefaultGroup *)instance; }
+ template <> const AIVehicleList_DefaultGroup &GetParam(ForceType<const AIVehicleList_DefaultGroup &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_DefaultGroup *)instance; }
+ template <> int Return<AIVehicleList_DefaultGroup *>(HSQUIRRELVM vm, AIVehicleList_DefaultGroup *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIVehicleList_DefaultGroup", res, NULL, DefSQDestructorCallback<AIVehicleList_DefaultGroup>); return 1; }
+}; // namespace SQConvert
+
+void SQAIVehicleList_DefaultGroup_Register(Squirrel *engine) {
+ DefSQClass <AIVehicleList_DefaultGroup> SQAIVehicleList_DefaultGroup("AIVehicleList_DefaultGroup");
+ SQAIVehicleList_DefaultGroup.PreRegister(engine, "AIAbstractList");
+ SQAIVehicleList_DefaultGroup.AddConstructor<void (AIVehicleList_DefaultGroup::*)(AIVehicle::VehicleType vehicle_type), 2>(engine, "xi");
+
+ SQAIVehicleList_DefaultGroup.PostRegister(engine);
+}