* Action for finalizing a refit. */
| 1431 | * Action for finalizing a refit. |
| 1432 | */ |
| 1433 | struct FinalizeRefitAction |
| 1434 | { |
| 1435 | CargoArray &consist_capleft; ///< Capacities left in the consist. |
| 1436 | Station *st; ///< Station to reserve cargo from. |
| 1437 | std::span<const StationID> next_station; ///< Next hops to reserve cargo for. |
| 1438 | bool do_reserve; ///< If the vehicle should reserve. |
| 1439 | |
| 1440 | /** |
| 1441 | * Create a finalizing action. |
| 1442 | * @param consist_capleft Capacities left in the consist. |
| 1443 | * @param st Station to reserve cargo from. |
| 1444 | * @param next_station Next hops to reserve cargo for. |
| 1445 | * @param do_reserve If we should reserve cargo or just add up the capacities. |
| 1446 | */ |
| 1447 | FinalizeRefitAction(CargoArray &consist_capleft, Station *st, std::span<const StationID> next_station, bool do_reserve) : |
| 1448 | consist_capleft(consist_capleft), st(st), next_station(next_station), do_reserve(do_reserve) {} |
| 1449 | |
| 1450 | /** |
| 1451 | * Reserve cargo from the station and update the remaining consist capacities with the |
| 1452 | * vehicle's remaining free capacity. |
| 1453 | * @param v Vehicle to be finalized. |
| 1454 | * @return true. |
| 1455 | */ |
| 1456 | bool operator()(Vehicle *v) |
| 1457 | { |
| 1458 | if (this->do_reserve) { |
| 1459 | this->st->goods[v->cargo_type].GetOrCreateData().cargo.Reserve(v->cargo_cap - v->cargo.RemainingCount(), |
| 1460 | &v->cargo, this->next_station, v->GetCargoTile()); |
| 1461 | } |
| 1462 | this->consist_capleft[v->cargo_type] += v->cargo_cap - v->cargo.RemainingCount(); |
| 1463 | return true; |
| 1464 | } |
| 1465 | }; |
| 1466 | |
| 1467 | /** |
| 1468 | * Refit a vehicle in a station. |
no outgoing calls
no test coverage detected