(svn r15492) -Change [API CHANGE]: Split AIVehicle::MoveWagon in MoveWagon and MoveWagonChain (frosch).

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
yexo 16 years ago
parent 336abd66a2
commit 2b221f5afc

@ -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));

@ -7498,7 +7498,7 @@
BuildVehicle(): 17
BuildVehicle(): 18
BuildVehicle(): 19
MoveWagon(): true
MoveWagonChain(): true
GetNumWagons(): 3
GetLength(): 24
GetWagonEngineType(): 9

@ -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));

@ -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 */

@ -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");

Loading…
Cancel
Save