(svn r15614) -Add [NoAI]: AIVehicleList_Group(group_id) and AIVehicleList_DefaultGroup(vehicle_type).
This commit is contained in:
		@@ -225,6 +225,8 @@ void AIInstance::RegisterAPI()
 | 
				
			|||||||
	SQAITunnel_Register(this->engine);
 | 
						SQAITunnel_Register(this->engine);
 | 
				
			||||||
	SQAIVehicle_Register(this->engine);
 | 
						SQAIVehicle_Register(this->engine);
 | 
				
			||||||
	SQAIVehicleList_Register(this->engine);
 | 
						SQAIVehicleList_Register(this->engine);
 | 
				
			||||||
 | 
						SQAIVehicleList_DefaultGroup_Register(this->engine);
 | 
				
			||||||
 | 
						SQAIVehicleList_Group_Register(this->engine);
 | 
				
			||||||
	SQAIVehicleList_SharedOrders_Register(this->engine);
 | 
						SQAIVehicleList_SharedOrders_Register(this->engine);
 | 
				
			||||||
	SQAIVehicleList_Station_Register(this->engine);
 | 
						SQAIVehicleList_Station_Register(this->engine);
 | 
				
			||||||
	SQAIWaypoint_Register(this->engine);
 | 
						SQAIWaypoint_Register(this->engine);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
/** @file ai_vehiclelist.cpp Implementation of AIVehicleList and friends. */
 | 
					/** @file ai_vehiclelist.cpp Implementation of AIVehicleList and friends. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "ai_vehiclelist.hpp"
 | 
					#include "ai_vehiclelist.hpp"
 | 
				
			||||||
 | 
					#include "ai_group.hpp"
 | 
				
			||||||
#include "ai_station.hpp"
 | 
					#include "ai_station.hpp"
 | 
				
			||||||
#include "ai_vehicle.hpp"
 | 
					#include "ai_vehicle.hpp"
 | 
				
			||||||
#include "../../company_func.h"
 | 
					#include "../../company_func.h"
 | 
				
			||||||
@@ -10,7 +11,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
AIVehicleList::AIVehicleList()
 | 
					AIVehicleList::AIVehicleList()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Vehicle *v;
 | 
						const Vehicle *v;
 | 
				
			||||||
	FOR_ALL_VEHICLES(v) {
 | 
						FOR_ALL_VEHICLES(v) {
 | 
				
			||||||
		if (v->owner == _current_company && v->IsPrimaryVehicle()) this->AddItem(v->index);
 | 
							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;
 | 
						if (!AIStation::IsValidStation(station_id)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Vehicle *v;
 | 
						const Vehicle *v;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	FOR_ALL_VEHICLES(v) {
 | 
						FOR_ALL_VEHICLES(v) {
 | 
				
			||||||
		if (v->owner == _current_company && v->IsPrimaryVehicle()) {
 | 
							if (v->owner == _current_company && v->IsPrimaryVehicle()) {
 | 
				
			||||||
			const Order *order;
 | 
								const Order *order;
 | 
				
			||||||
@@ -44,3 +44,27 @@ AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id)
 | 
				
			|||||||
		this->AddItem(v->index);
 | 
							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);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@
 | 
				
			|||||||
#define AI_VEHICLELIST_HPP
 | 
					#define AI_VEHICLELIST_HPP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "ai_abstractlist.hpp"
 | 
					#include "ai_abstractlist.hpp"
 | 
				
			||||||
 | 
					#include "ai_vehicle.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Creates a list of vehicles of which you are the owner.
 | 
					 * Creates a list of vehicles of which you are the owner.
 | 
				
			||||||
@@ -45,4 +46,32 @@ public:
 | 
				
			|||||||
	AIVehicleList_SharedOrders(VehicleID vehicle_id);
 | 
						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 */
 | 
					#endif /* AI_VEHICLELIST_HPP */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,3 +53,37 @@ void SQAIVehicleList_SharedOrders_Register(Squirrel *engine) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	SQAIVehicleList_SharedOrders.PostRegister(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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user