mirror of https://github.com/OpenTTD/OpenTTD
(svn r15345) -Add [NoAI]: Add AIVehicle::HasSharedOrders() and AIVehicleList_SharedOrders.
parent
364e2a110d
commit
62a11eb5a9
|
@ -390,3 +390,11 @@
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ bool AIVehicle::HasSharedOrders(VehicleID vehicle_id)
|
||||||
|
{
|
||||||
|
if (!IsValidVehicle(vehicle_id)) return false;
|
||||||
|
|
||||||
|
Vehicle *v = ::GetVehicle(vehicle_id);
|
||||||
|
return v->orders.list != NULL && v->orders.list->GetNumVehicles() > 1;
|
||||||
|
}
|
||||||
|
|
|
@ -478,6 +478,14 @@ public:
|
||||||
* @return True if the vehicle is articulated.
|
* @return True if the vehicle is articulated.
|
||||||
*/
|
*/
|
||||||
static bool IsArticulated(VehicleID vehicle_id);
|
static bool IsArticulated(VehicleID vehicle_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the vehicle has shared orders.
|
||||||
|
* @param vehicle_id The vehicle to check.
|
||||||
|
* @pre IsValidVehicle(vehicle_id).
|
||||||
|
* @return True if the vehicle has shared orders.
|
||||||
|
*/
|
||||||
|
static bool HasSharedOrders(VehicleID vehicle_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* AI_VEHICLE_HPP */
|
#endif /* AI_VEHICLE_HPP */
|
||||||
|
|
|
@ -137,6 +137,7 @@ void SQAIVehicle_Register(Squirrel *engine) {
|
||||||
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetCargoLoad, "GetCargoLoad", 3, "xii");
|
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetCargoLoad, "GetCargoLoad", 3, "xii");
|
||||||
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetGroupID, "GetGroupID", 2, "xi");
|
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetGroupID, "GetGroupID", 2, "xi");
|
||||||
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsArticulated, "IsArticulated", 2, "xi");
|
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsArticulated, "IsArticulated", 2, "xi");
|
||||||
|
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::HasSharedOrders, "HasSharedOrders", 2, "xi");
|
||||||
|
|
||||||
SQAIVehicle.PostRegister(engine);
|
SQAIVehicle.PostRegister(engine);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "ai_vehiclelist.hpp"
|
#include "ai_vehiclelist.hpp"
|
||||||
#include "ai_station.hpp"
|
#include "ai_station.hpp"
|
||||||
|
#include "ai_vehicle.hpp"
|
||||||
#include "../../company_func.h"
|
#include "../../company_func.h"
|
||||||
#include "../../vehicle_base.h"
|
#include "../../vehicle_base.h"
|
||||||
|
|
||||||
|
@ -34,3 +35,17 @@ AIVehicleList_Station::AIVehicleList_Station(StationID station_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AIVehicleList_SharedOrders::AIVehicleList_SharedOrders(VehicleID vehicle_id)
|
||||||
|
{
|
||||||
|
if (!AIVehicle::IsValidVehicle(vehicle_id)) return;
|
||||||
|
|
||||||
|
Vehicle *v = GetVehicle(vehicle_id)->FirstShared();
|
||||||
|
if (v == NULL) {
|
||||||
|
this->AddItem(vehicle_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (; v != NULL; v->NextShared()) {
|
||||||
|
this->AddItem(v->index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,4 +31,18 @@ public:
|
||||||
AIVehicleList_Station(StationID station_id);
|
AIVehicleList_Station(StationID station_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a list of vehicles that share orders.
|
||||||
|
* @ingroup AIList
|
||||||
|
*/
|
||||||
|
class AIVehicleList_SharedOrders : public AIAbstractList {
|
||||||
|
public:
|
||||||
|
static const char *GetClassName() { return "AIVehicleList_SharedOrders"; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param station_id The vehicle that the rest shared orders with.
|
||||||
|
*/
|
||||||
|
AIVehicleList_SharedOrders(VehicleID vehicle_id);
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* AI_VEHICLELIST_HPP */
|
#endif /* AI_VEHICLELIST_HPP */
|
||||||
|
|
|
@ -40,3 +40,22 @@ void SQAIVehicleList_Station_Register(Squirrel *engine) {
|
||||||
|
|
||||||
SQAIVehicleList_Station.PostRegister(engine);
|
SQAIVehicleList_Station.PostRegister(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace SQConvert {
|
||||||
|
/* Allow AIVehicleList_SharedOrders to be used as Squirrel parameter */
|
||||||
|
template <> AIVehicleList_SharedOrders *GetParam(ForceType<AIVehicleList_SharedOrders *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_SharedOrders *)instance; }
|
||||||
|
template <> AIVehicleList_SharedOrders &GetParam(ForceType<AIVehicleList_SharedOrders &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_SharedOrders *)instance; }
|
||||||
|
template <> const AIVehicleList_SharedOrders *GetParam(ForceType<const AIVehicleList_SharedOrders *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIVehicleList_SharedOrders *)instance; }
|
||||||
|
template <> const AIVehicleList_SharedOrders &GetParam(ForceType<const AIVehicleList_SharedOrders &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIVehicleList_SharedOrders *)instance; }
|
||||||
|
template <> int Return<AIVehicleList_SharedOrders *>(HSQUIRRELVM vm, AIVehicleList_SharedOrders *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "AIVehicleList_SharedOrders", res, NULL, DefSQDestructorCallback<AIVehicleList_SharedOrders>); return 1; }
|
||||||
|
}; // namespace SQConvert
|
||||||
|
|
||||||
|
void SQAIVehicleList_SharedOrders_Register(Squirrel *engine) {
|
||||||
|
DefSQClass <AIVehicleList_SharedOrders> SQAIVehicleList_SharedOrders("AIVehicleList_SharedOrders");
|
||||||
|
SQAIVehicleList_SharedOrders.PreRegister(engine, "AIAbstractList");
|
||||||
|
SQAIVehicleList_SharedOrders.AddConstructor<void (AIVehicleList_SharedOrders::*)(VehicleID vehicle_id), 2>(engine, "xi");
|
||||||
|
|
||||||
|
SQAIVehicleList_SharedOrders.DefSQStaticMethod(engine, &AIVehicleList_SharedOrders::GetClassName, "GetClassName", 1, "x");
|
||||||
|
|
||||||
|
SQAIVehicleList_SharedOrders.PostRegister(engine);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue