diff options
-rw-r--r-- | bin/ai/regression/regression.nut | 2 | ||||
-rw-r--r-- | bin/ai/regression/regression.txt | 2 | ||||
-rw-r--r-- | src/ai/api/ai_order.cpp | 29 | ||||
-rw-r--r-- | src/ai/api/ai_order.hpp | 9 | ||||
-rw-r--r-- | src/ai/api/ai_order.hpp.sq | 1 |
5 files changed, 28 insertions, 15 deletions
diff --git a/bin/ai/regression/regression.nut b/bin/ai/regression/regression.nut index d873d3708..4a2e8433f 100644 --- a/bin/ai/regression/regression.nut +++ b/bin/ai/regression/regression.nut @@ -826,7 +826,7 @@ function Regression::Order() print(" GetOrderCount(): " + AIOrder.GetOrderCount(12)); print(" IsValidVehicleOrder(): " + AIOrder.IsValidVehicleOrder(12, 1)); print(" RemoveOrder(): " + AIOrder.RemoveOrder(12, 0)); - print(" ChangeOrder(): " + AIOrder.ChangeOrder(12, 0, AIOrder.AIOF_FULL_LOAD)); + print(" SetOrderFlags(): " + AIOrder.SetOrderFlags(12, 0, AIOrder.AIOF_FULL_LOAD)); print(" GetOrderDestination(): " + AIOrder.GetOrderDestination(12, 0)); print(" CopyOrders(): " + AIOrder.CopyOrders(12, 1)); print(" CopyOrders(): " + AIOrder.CopyOrders(13, 12)); diff --git a/bin/ai/regression/regression.txt b/bin/ai/regression/regression.txt index 9c58e8965..6d225fb28 100644 --- a/bin/ai/regression/regression.txt +++ b/bin/ai/regression/regression.txt @@ -8348,7 +8348,7 @@ GetOrderCount(): 2 IsValidVehicleOrder(): true RemoveOrder(): true - ChangeOrder(): true + SetOrderFlags(): true GetOrderDestination(): 33411 CopyOrders(): false CopyOrders(): true diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index b46e44353..e22c08ea1 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -4,6 +4,7 @@ #include "ai_order.hpp" #include "ai_vehicle.hpp" +#include "ai_log.hpp" #include "../ai_instance.hpp" #include "../../debug.h" #include "../../vehicle_base.h" @@ -306,25 +307,25 @@ static OrderType GetOrderTypeByTile(TileIndex t) } /** - * Callback handler as ChangeOrder possibly needs multiple DoCommand calls + * Callback handler as SetOrderFlags possibly needs multiple DoCommand calls * to be able to set all order flags correctly. As we need to wait till the * command has completed before we know the next bits to change we need to * call the function multiple times. Each time it'll reduce the difference * between the wanted and the current order. * @param instance The AI we are doing the callback for. */ -static void _DoCommandReturnChangeOrder(class AIInstance *instance) +static void _DoCommandReturnSetOrderFlags(class AIInstance *instance) { - AIObject::SetLastCommandRes(AIOrder::_ChangeOrder()); + AIObject::SetLastCommandRes(AIOrder::_SetOrderFlags()); AIInstance::DoCommandReturn(instance); } -/* static */ bool AIOrder::_ChangeOrder() +/* static */ bool AIOrder::_SetOrderFlags() { /* Make sure we don't go into an infinite loop */ int retry = AIObject::GetCallbackVariable(3) - 1; if (retry < 0) { - DEBUG(ai, 0, "Possible infinite loop in ChangeOrder detected"); + DEBUG(ai, 0, "Possible infinite loop in SetOrderFlags() detected"); return false; } AIObject::SetCallbackVariable(3, retry); @@ -343,22 +344,22 @@ static void _DoCommandReturnChangeOrder(class AIInstance *instance) AIOrderFlags current = GetOrderFlags(vehicle_id, order_position); if ((current & AIOF_NON_STOP_FLAGS) != (order_flags & AIOF_NON_STOP_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnChangeOrder); + return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags); } switch (order->GetType()) { case OT_GOTO_DEPOT: if ((current & AIOF_SERVICE_IF_NEEDED) != (order_flags & AIOF_SERVICE_IF_NEEDED)) { - return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnChangeOrder); + return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_DEPOT_ACTION, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags); } break; case OT_GOTO_STATION: if ((current & AIOF_UNLOAD_FLAGS) != (order_flags & AIOF_UNLOAD_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnChangeOrder); + return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags); } if ((current & AIOF_LOAD_FLAGS) != (order_flags & AIOF_LOAD_FLAGS)) { - return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnChangeOrder); + return AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER, NULL, &_DoCommandReturnSetOrderFlags); } break; @@ -370,7 +371,7 @@ static void _DoCommandReturnChangeOrder(class AIInstance *instance) return true; } -/* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags) +/* static */ bool AIOrder::SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags) { AIObject::SetCallbackVariable(0, vehicle_id); AIObject::SetCallbackVariable(1, order_position); @@ -378,7 +379,13 @@ static void _DoCommandReturnChangeOrder(class AIInstance *instance) /* In case another client(s) change orders at the same time we could * end in an infinite loop. This stops that from happening ever. */ AIObject::SetCallbackVariable(3, 8); - return AIOrder::_ChangeOrder(); + return AIOrder::_SetOrderFlags(); +} + +/* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags) +{ + AILog::Warning("AIOrder::ChangeOrder is deprecated and will be removed soon, please use AIOrder::SetOrderFlags instead."); + return SetOrderFlags(vehicle_id, order_position, order_flags); } /* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target) diff --git a/src/ai/api/ai_order.hpp b/src/ai/api/ai_order.hpp index 5365b56ff..c39513f19 100644 --- a/src/ai/api/ai_order.hpp +++ b/src/ai/api/ai_order.hpp @@ -339,9 +339,9 @@ public: #ifndef DOXYGEN_SKIP /** - * Internal function to help ChangeOrder. + * Internal function to help SetOrderFlags. */ - static bool _ChangeOrder(); + static bool _SetOrderFlags(); #endif /* DOXYGEN_SKIP */ /** @@ -354,6 +354,11 @@ public: * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY * @return True if and only if the order was changed. */ + static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags); + + /** + * Deprecated, use SetOrderFlags instead. + */ static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags); /** diff --git a/src/ai/api/ai_order.hpp.sq b/src/ai/api/ai_order.hpp.sq index 7c66fe10d..388fec391 100644 --- a/src/ai/api/ai_order.hpp.sq +++ b/src/ai/api/ai_order.hpp.sq @@ -92,6 +92,7 @@ void SQAIOrder_Register(Squirrel *engine) { SQAIOrder.DefSQStaticMethod(engine, &AIOrder::InsertOrder, "InsertOrder", 5, ".iiii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::InsertConditionalOrder, "InsertConditionalOrder", 4, ".iii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::RemoveOrder, "RemoveOrder", 3, ".ii"); + SQAIOrder.DefSQStaticMethod(engine, &AIOrder::SetOrderFlags, "SetOrderFlags", 4, ".iii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ChangeOrder, "ChangeOrder", 4, ".iii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::MoveOrder, "MoveOrder", 4, ".iii"); SQAIOrder.DefSQStaticMethod(engine, &AIOrder::CopyOrders, "CopyOrders", 3, ".ii"); |