| 472 | } |
| 473 | |
| 474 | void TransferScreen::executeOrders() |
| 475 | { |
| 476 | auto player = state->getPlayer(); |
| 477 | |
| 478 | // Step 01: Re-direct all vehicles and agents if transferring |
| 479 | std::set<sp<TransactionControl>> linkedControls; |
| 480 | for (auto t : std::set<Type>{Type::BioChemist, Type::Engineer, Type::Physicist, Type::Soldier, |
| 481 | Type::Vehicle}) |
| 482 | { |
| 483 | for (auto &c : transactionControls[t]) |
| 484 | { |
| 485 | if (linkedControls.find(c) != linkedControls.end()) |
| 486 | { |
| 487 | continue; |
| 488 | } |
| 489 | |
| 490 | StateRef<Base> newBase; |
| 491 | int i = 0; |
| 492 | for (auto &b : state->player_bases) |
| 493 | { |
| 494 | if (c->tradeState.shipmentsTotal(i++) == -1) |
| 495 | { |
| 496 | newBase = b.second->building->base; |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | if (newBase) |
| 501 | { |
| 502 | switch (c->itemType) |
| 503 | { |
| 504 | case TransactionControl::Type::BioChemist: |
| 505 | case TransactionControl::Type::Engineer: |
| 506 | case TransactionControl::Type::Physicist: |
| 507 | { |
| 508 | StateRef<Agent> agent{state.get(), c->itemId}; |
| 509 | if (agent->lab_assigned) |
| 510 | { |
| 511 | StateRef<Lab> lab{state.get(), agent->lab_assigned}; |
| 512 | agent->lab_assigned->removeAgent(lab, agent); |
| 513 | } |
| 514 | agent->transfer(*state, newBase->building); |
| 515 | break; |
| 516 | } |
| 517 | case TransactionControl::Type::Soldier: |
| 518 | { |
| 519 | StateRef<Agent> agent{state.get(), c->itemId}; |
| 520 | agent->transfer(*state, newBase->building); |
| 521 | break; |
| 522 | } |
| 523 | case TransactionControl::Type::Vehicle: |
| 524 | { |
| 525 | StateRef<Vehicle> vehicle{state.get(), c->itemId}; |
| 526 | if (vehicle->homeBuilding != newBase->building) |
| 527 | { |
| 528 | bool wasInBase = vehicle->currentBuilding == vehicle->homeBuilding; |
| 529 | vehicle->homeBuilding = newBase->building; |
| 530 | if (wasInBase) |
| 531 | { |
nothing calls this directly
no test coverage detected