summaryrefslogtreecommitdiff
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
commit2b221f5afc28c025fa0eee7148d72460827c63fb (patch)
tree08ba8ca2df5f787b42750a85edccda553459c95f
parent336abd66a2ba618df9388f3c5a06fdfd272a770e (diff)
downloadopenttd-2b221f5afc28c025fa0eee7148d72460827c63fb.tar.xz
(svn r15492) -Change [API CHANGE]: Split AIVehicle::MoveWagon in MoveWagon and MoveWagonChain (frosch).
-rw-r--r--bin/ai/regression/regression.nut2
-rw-r--r--bin/ai/regression/regression.txt2
-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
5 files changed, 72 insertions, 12 deletions
diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut
index 1c4b00311..6e69f2f88 100644
--- a/bin/ai/regression/regression.nut
+++ b/bin/ai/regression/regression.nut
@@ -1481,7 +1481,7 @@ function Regression::Vehicle()
print(" BuildVehicle(): " + AIVehicle.BuildVehicle(10008, 9));
print(" BuildVehicle(): " + AIVehicle.BuildVehicle(10008, 27));
print(" BuildVehicle(): " + AIVehicle.BuildVehicle(10008, 27));
- print(" MoveWagon(): " + AIVehicle.MoveWagon(18, 0, true, 17, 0));
+ print(" MoveWagonChain(): " + AIVehicle.MoveWagonChain(18, 0, 17, 0));
print(" GetNumWagons(): " + AIVehicle.GetNumWagons(17));
print(" GetLength(): " + AIVehicle.GetLength(17));
print(" GetWagonEngineType(): " + AIVehicle.GetWagonEngineType(17, 0));
diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt
index 350da2025..52365a10e 100644
--- a/bin/ai/regression/regression.txt
+++ b/bin/ai/regression/regression.txt
@@ -7498,7 +7498,7 @@
BuildVehicle(): 17
BuildVehicle(): 18
BuildVehicle(): 19
- MoveWagon(): true
+ MoveWagonChain(): true
GetNumWagons(): 3
GetLength(): 24
GetWagonEngineType(): 9
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");