| 414 | } |
| 415 | |
| 416 | void BuyAndSellScreen::executeOrders() |
| 417 | { |
| 418 | auto player = state->getPlayer(); |
| 419 | for (auto &l : transactionControls) |
| 420 | { |
| 421 | for (auto &c : l.second) |
| 422 | { |
| 423 | if (!c->getLinked() || c->getLinked()->front().lock() == c) |
| 424 | { |
| 425 | if (c->itemType != TransactionControl::Type::Vehicle && |
| 426 | state->economy.find(c->itemId) == state->economy.end()) |
| 427 | { |
| 428 | LogError("Economy not found for %s: How are we selling it then!?", c->itemId); |
| 429 | continue; |
| 430 | } |
| 431 | |
| 432 | int i = 0; |
| 433 | auto &economy = state->economy[c->itemId]; |
| 434 | for (auto &b : state->player_bases) |
| 435 | { |
| 436 | int order = c->tradeState.shipmentsTotal(i++); |
| 437 | |
| 438 | // Sell |
| 439 | if (order > 0) |
| 440 | { |
| 441 | switch (c->itemType) |
| 442 | { |
| 443 | case TransactionControl::Type::Vehicle: |
| 444 | { |
| 445 | StateRef<Vehicle> vehicle{state.get(), c->itemId}; |
| 446 | // Expecting sold vehicle to be parked |
| 447 | // Offload agents |
| 448 | while (!vehicle->currentAgents.empty()) |
| 449 | { |
| 450 | auto agent = *vehicle->currentAgents.begin(); |
| 451 | agent->enterBuilding(*state, vehicle->currentBuilding); |
| 452 | } |
| 453 | // Offload cargo |
| 454 | for (auto &c : vehicle->cargo) |
| 455 | { |
| 456 | vehicle->currentBuilding->cargo.push_back(c); |
| 457 | } |
| 458 | vehicle->die(*state, true); |
| 459 | player->balance += c->price; |
| 460 | break; |
| 461 | } |
| 462 | case TransactionControl::Type::AgentEquipmentBio: |
| 463 | { |
| 464 | // kill aliens |
| 465 | b.second->inventoryAgentEquipment[c->itemId] -= order; |
| 466 | break; |
| 467 | } |
| 468 | case TransactionControl::Type::AgentEquipmentCargo: |
| 469 | { |
| 470 | economy.currentStock += order; |
| 471 | player->balance += order * economy.currentPrice; |
| 472 | StateRef<AEquipmentType> equipment{state.get(), c->itemId}; |
| 473 |
nothing calls this directly
no test coverage detected