summaryrefslogtreecommitdiff
path: root/src/ai/api/ai_order.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-02-04 23:18:19 +0000
committeryexo <yexo@openttd.org>2010-02-04 23:18:19 +0000
commit091d88f5143601a456c3688ff9305f144a5ed6e2 (patch)
tree54471dd005dd9a741cd3692537eda46f80274530 /src/ai/api/ai_order.cpp
parentd858264ca64c09802792457888e6f3506fada46d (diff)
downloadopenttd-091d88f5143601a456c3688ff9305f144a5ed6e2.tar.xz
(svn r19014) -Add: [NoAI] AIOrder::[G|S]etStopLocation to get/set the stop location of trains in a rail station
Diffstat (limited to 'src/ai/api/ai_order.cpp')
-rw-r--r--src/ai/api/ai_order.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index 3e7ff11af..cdc56ccf8 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -285,6 +285,16 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
return value;
}
+/* static */ AIOrder::StopLocation AIOrder::GetStopLocation(VehicleID vehicle_id, OrderPosition order_position)
+{
+ if (!IsValidVehicleOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID;
+ if (AIVehicle::GetVehicleType(vehicle_id) != AIVehicle::VT_RAIL) return STOPLOCATION_INVALID;
+ if (!IsGotoStationOrder(vehicle_id, order_position)) return STOPLOCATION_INVALID;
+
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
+ return (AIOrder::StopLocation)order->GetStopLocation();
+}
+
/* static */ bool AIOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to)
{
EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
@@ -322,6 +332,18 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
return AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_COND_VALUE | (value << 4), CMD_MODIFY_ORDER);
}
+/* static */ bool AIOrder::SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location)
+{
+ EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
+ EnforcePrecondition(false, AIVehicle::GetVehicleType(vehicle_id) == AIVehicle::VT_RAIL);
+ EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position));
+ EnforcePrecondition(false, stop_location >= STOPLOCATION_NEAR && stop_location <= STOPLOCATION_FAR);
+
+ uint32 p1 = vehicle_id | (order_position << 16);
+ uint32 p2 = MOF_STOP_LOCATION | (stop_location << 4);
+ return AIObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER);
+}
+
/* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags)
{
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));