diff options
author | michi_cc <michi_cc@openttd.org> | 2011-11-05 15:31:21 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2011-11-05 15:31:21 +0000 |
commit | a22b4f1f9154a508aef79cd6d8cc21d5c84eb559 (patch) | |
tree | ef3b508833f20176662b033ec94120a0ada9aa12 /src/ai/api/ai_order.cpp | |
parent | 6a2735d24ed54158b93eac217e803dcd89f67a9e (diff) | |
download | openttd-a22b4f1f9154a508aef79cd6d8cc21d5c84eb559.tar.xz |
(svn r23120) -Feature: [NoAI] Support for refit orders.
Diffstat (limited to 'src/ai/api/ai_order.cpp')
-rw-r--r-- | src/ai/api/ai_order.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp index 9fa8eca6a..a3ab21e4c 100644 --- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -12,6 +12,7 @@ #include "../../stdafx.h" #include "ai_order.hpp" #include "ai_vehicle.hpp" +#include "ai_cargo.hpp" #include "../ai_instance.hpp" #include "../../debug.h" #include "../../vehicle_base.h" @@ -117,6 +118,14 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or return order->GetType() == OT_DUMMY; } +/* static */ bool AIOrder::IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position) +{ + if (!IsValidVehicleOrder(vehicle_id, order_position)) return false; + + const Order *order = ::ResolveOrder(vehicle_id, order_position); + return order != NULL && order->IsRefit(); +} + /* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id) { if (AIVehicle::IsValidVehicle(vehicle_id)) return false; @@ -323,6 +332,15 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or return (AIOrder::StopLocation)order->GetStopLocation(); } +/* static */ CargoID AIOrder::GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position) +{ + if (!IsValidVehicleOrder(vehicle_id, order_position)) return CT_NO_REFIT; + if (order_position != ORDER_CURRENT && !IsGotoStationOrder(vehicle_id, order_position) && !IsGotoDepotOrder(vehicle_id, order_position)) return CT_NO_REFIT; + + const Order *order = ::ResolveOrder(vehicle_id, order_position); + return order->IsRefit() ? order->GetRefitCargo() : CT_NO_REFIT; +} + /* static */ bool AIOrder::SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to) { EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); @@ -372,6 +390,17 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or return AIObject::DoCommand(0, p1, p2, CMD_MODIFY_ORDER); } +/* static */ bool AIOrder::SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo) +{ + EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position)); + EnforcePrecondition(false, IsGotoStationOrder(vehicle_id, order_position) || (IsGotoDepotOrder(vehicle_id, order_position) && refit_cargo != CT_AUTO_REFIT)); + EnforcePrecondition(false, AICargo::IsValidCargo(refit_cargo) || refit_cargo == CT_AUTO_REFIT || refit_cargo == CT_NO_REFIT); + + uint32 p1 = vehicle_id; + uint32 p2 = refit_cargo | AIOrder::ResolveOrderPosition(vehicle_id, order_position) << 16; + return AIObject::DoCommand(0, p1, p2, CMD_ORDER_REFIT); +} + /* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags) { EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id)); |