* Get the distance between two orders of a vehicle. Conditional orders are resolved * and the bigger distance of the two order branches is returned. * @param prev Origin order. * @param cur Destination order. * @param v The vehicle to get the distance for. * @param conditional_depth Internal param for resolving conditional orders. * @return Maximum distance between the two orders. */
| 587 | * @return Maximum distance between the two orders. |
| 588 | */ |
| 589 | uint GetOrderDistance(VehicleOrderID prev, VehicleOrderID cur, const Vehicle *v, int conditional_depth) |
| 590 | { |
| 591 | assert(v->orders != nullptr); |
| 592 | const OrderList &orderlist = *v->orders; |
| 593 | auto orders = orderlist.GetOrders(); |
| 594 | |
| 595 | if (orders[cur].IsType(OT_CONDITIONAL)) { |
| 596 | if (conditional_depth > v->GetNumOrders()) return 0; |
| 597 | |
| 598 | conditional_depth++; |
| 599 | |
| 600 | int dist1 = GetOrderDistance(prev, orders[cur].GetConditionSkipToOrder(), v, conditional_depth); |
| 601 | int dist2 = GetOrderDistance(prev, orderlist.GetNext(cur), v, conditional_depth); |
| 602 | return std::max(dist1, dist2); |
| 603 | } |
| 604 | |
| 605 | TileIndex prev_tile = orders[prev].GetLocation(v, true); |
| 606 | TileIndex cur_tile = orders[cur].GetLocation(v, true); |
| 607 | if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0; |
| 608 | return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile); |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Add an order to the orderlist of a vehicle. |
no test coverage detected