summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2009-02-14 21:22:42 +0000
committeryexo <yexo@openttd.org>2009-02-14 21:22:42 +0000
commitfa0cf4bbd12ed9537d0605692aded157bc71a344 (patch)
tree08ba8ca2df5f787b42750a85edccda553459c95f /src/ai
parentc59caa45b70551f111628b1b8f275ed0b194eef3 (diff)
downloadopenttd-fa0cf4bbd12ed9537d0605692aded157bc71a344.tar.xz
(svn r15492) -Change [API CHANGE]: Split AIVehicle::MoveWagon in MoveWagon and MoveWagonChain (frosch).
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_vehicle.cpp24
-rw-r--r--src/ai/api/ai_vehicle.hpp50
-rw-r--r--src/ai/api/ai_vehicle.hpp.sq6
3 files changed, 70 insertions, 10 deletions
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp
index 8951cb5f2..d0f62136f 100644
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -79,7 +79,7 @@
return 0;
}
-/* static */ bool AIVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon)
+/* static */ bool AIVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon)
{
EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id));
EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)));
@@ -97,6 +97,16 @@
return AIObject::DoCommand(0, v->index | ((w == NULL ? INVALID_VEHICLE : w->index) << 16), move_attached_wagons ? 1 : 0, CMD_MOVE_RAIL_VEHICLE);
}
+/* static */ bool AIVehicle::MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon)
+{
+ return _MoveWagonInternal(source_vehicle_id, source_wagon, false, dest_vehicle_id, dest_wagon);
+}
+
+/* static */ bool AIVehicle::MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon)
+{
+ return _MoveWagonInternal(source_vehicle_id, source_wagon, true, dest_vehicle_id, dest_wagon);
+}
+
/* static */ int AIVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo)
{
if (!IsValidVehicle(vehicle_id)) return -1;
@@ -122,7 +132,7 @@
return AIObject::DoCommand(0, vehicle_id, v->type == VEH_TRAIN ? 1 : 0, GetCmdSellVeh(v));
}
-/* static */ bool AIVehicle::SellWagon(VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
+/* static */ bool AIVehicle::_SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons)
{
EnforcePrecondition(false, IsValidVehicle(vehicle_id) && wagon < GetNumWagons(vehicle_id));
EnforcePrecondition(false, ::GetVehicle(vehicle_id)->type == VEH_TRAIN);
@@ -133,6 +143,16 @@
return AIObject::DoCommand(0, v->index, sell_attached_wagons ? 1 : 0, CMD_SELL_RAIL_WAGON);
}
+/* static */ bool AIVehicle::SellWagon(VehicleID vehicle_id, int wagon)
+{
+ return _SellWagonInternal(vehicle_id, wagon, false);
+}
+
+/* static */ bool AIVehicle::SellWagonChain(VehicleID vehicle_id, int wagon)
+{
+ return _SellWagonInternal(vehicle_id, wagon, true);
+}
+
/* static */ bool AIVehicle::SendVehicleToDepot(VehicleID vehicle_id)
{
EnforcePrecondition(false, IsValidVehicle(vehicle_id));
diff --git a/src/ai/api/ai_vehicle.hpp b/src/ai/api/ai_vehicle.hpp
index 5b9a276c6..5c363e4f4 100644
--- a/src/ai/api/ai_vehicle.hpp
+++ b/src/ai/api/ai_vehicle.hpp
@@ -328,7 +328,6 @@ public:
* Move a wagon after another wagon.
* @param source_vehicle_id The vehicle to move a wagon away from.
* @param source_wagon The wagon in source_vehicle to move.
- * @param move_attached_wagons Also move all wagons attached to the wagon to move.
* @param dest_vehicle_id The vehicle to move the wagon to, or -1 to create a new vehicle.
* @param dest_wagon The wagon in dest_vehicle to place source_wagon after.
* @pre IsValidVehicle(source_vehicle_id).
@@ -336,9 +335,24 @@ public:
* @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
* @pre GetVehicleType(source_vehicle_id) == VEHICLE_RAIL.
* @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VEHICLE_RAIL.
- * @return Whether or not moving the wagon(s) succeeded.
+ * @return Whether or not moving the wagon succeeded.
*/
- static bool MoveWagon(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon);
+ static bool MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
+
+ /**
+ * Move a chain of wagons after another wagon.
+ * @param source_vehicle_id The vehicle to move a wagon away from.
+ * @param source_wagon The first wagon in source_vehicle to move.
+ * @param dest_vehicle_id The vehicle to move the wagons to, or -1 to create a new vehicle.
+ * @param dest_wagon The wagon in dest_vehicle to place source_wagon and following wagons after.
+ * @pre IsValidVehicle(source_vehicle_id).
+ * @pre source_wagon < GetNumWagons(source_vehicle_id).
+ * @pre dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)).
+ * @pre GetVehicleType(source_vehicle_id) == VEHICLE_RAIL.
+ * @pre dest_vehicle_id == -1 || GetVehicleType(dest_vehicle_id) == VEHICLE_RAIL.
+ * @return Whether or not moving the wagons succeeded.
+ */
+ static bool MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
/**
* Gets the capacity of the given vehicle when refited to the given cargo type.
@@ -383,16 +397,29 @@ public:
* Sells the given wagon from the vehicle.
* @param vehicle_id The vehicle to sell a wagon from.
* @param wagon The wagon to sell.
- * @param sell_attached_wagons Sell all wagons attached to the one we want to sell.
* @pre IsValidVehicle(vehicle_id).
* @pre wagon < GetNumWagons(vehicle_id).
* @pre You must own the vehicle.
* @pre The vehicle must be stopped in the depot.
* @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED
* @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT
- * @return True if and only if the wagon(s) has been sold.
+ * @return True if and only if the wagon has been sold.
+ */
+ static bool SellWagon(VehicleID vehicle_id, int wagon);
+
+ /**
+ * Sells all wagons from the vehicle starting from a given position.
+ * @param vehicle_id The vehicle to sell a wagon from.
+ * @param wagon The wagon to sell.
+ * @pre IsValidVehicle(vehicle_id).
+ * @pre wagon < GetNumWagons(vehicle_id).
+ * @pre You must own the vehicle.
+ * @pre The vehicle must be stopped in the depot.
+ * @exception AIVehicle::ERR_VEHICLE_IS_DESTROYED
+ * @exception AIVehicle::ERR_VEHICLE_NOT_IN_DEPOT
+ * @return True if and only if the wagons have been sold.
*/
- static bool SellWagon(VehicleID vehicle_id, int wagon, bool sell_attached_wagons);
+ static bool SellWagonChain(VehicleID vehicle_id, int wagon);
/**
* Sends the given vehicle to a depot.
@@ -486,6 +513,17 @@ public:
* @return True if the vehicle has shared orders.
*/
static bool HasSharedOrders(VehicleID vehicle_id);
+
+private:
+ /**
+ * Internal function used by SellWagon(Chain).
+ */
+ static bool _SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons);
+
+ /**
+ * Internal function used by MoveWagon(Chain).
+ */
+ static bool _MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon);
};
#endif /* AI_VEHICLE_HPP */
diff --git a/src/ai/api/ai_vehicle.hpp.sq b/src/ai/api/ai_vehicle.hpp.sq
index 5cfa61089..499564b94 100644
--- a/src/ai/api/ai_vehicle.hpp.sq
+++ b/src/ai/api/ai_vehicle.hpp.sq
@@ -122,11 +122,13 @@ void SQAIVehicle_Register(Squirrel *engine) {
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::IsStoppedInDepot, "IsStoppedInDepot", 2, "?i");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::BuildVehicle, "BuildVehicle", 3, "?ii");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::CloneVehicle, "CloneVehicle", 4, "?iib");
- SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::MoveWagon, "MoveWagon", 6, "?iibii");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::MoveWagon, "MoveWagon", 5, "?iiii");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::MoveWagonChain, "MoveWagonChain", 5, "?iiii");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::GetRefitCapacity, "GetRefitCapacity", 3, "?ii");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::RefitVehicle, "RefitVehicle", 3, "?ii");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellVehicle, "SellVehicle", 2, "?i");
- SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellWagon, "SellWagon", 4, "?iib");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellWagon, "SellWagon", 3, "?ii");
+ SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SellWagonChain, "SellWagonChain", 3, "?ii");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SendVehicleToDepot, "SendVehicleToDepot", 2, "?i");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::StartStopVehicle, "StartStopVehicle", 2, "?i");
SQAIVehicle.DefSQStaticMethod(engine, &AIVehicle::SkipToVehicleOrder, "SkipToVehicleOrder", 3, "?ii");