| 581 | } |
| 582 | |
| 583 | sp<AEquipment> Agent::addEquipmentByType(GameState &state, StateRef<AEquipmentType> equipmentType, |
| 584 | bool allowFailure) |
| 585 | { |
| 586 | Vec2<int> pos; |
| 587 | bool slotFound = false; |
| 588 | EquipmentSlotType prefSlotType = EquipmentSlotType::General; |
| 589 | bool prefSlot = false; |
| 590 | if (equipmentType->type == AEquipmentType::Type::Ammo) |
| 591 | { |
| 592 | auto wpn = addEquipmentAsAmmoByType(equipmentType); |
| 593 | if (wpn) |
| 594 | { |
| 595 | return wpn; |
| 596 | } |
| 597 | prefSlotType = EquipmentSlotType::General; |
| 598 | prefSlot = true; |
| 599 | } |
| 600 | else if (equipmentType->type == AEquipmentType::Type::Armor) |
| 601 | { |
| 602 | switch (equipmentType->body_part) |
| 603 | { |
| 604 | case BodyPart::Body: |
| 605 | prefSlotType = EquipmentSlotType::ArmorBody; |
| 606 | break; |
| 607 | case BodyPart::Legs: |
| 608 | prefSlotType = EquipmentSlotType::ArmorLegs; |
| 609 | break; |
| 610 | case BodyPart::Helmet: |
| 611 | prefSlotType = EquipmentSlotType::ArmorHelmet; |
| 612 | break; |
| 613 | case BodyPart::LeftArm: |
| 614 | prefSlotType = EquipmentSlotType::ArmorLeftHand; |
| 615 | break; |
| 616 | case BodyPart::RightArm: |
| 617 | prefSlotType = EquipmentSlotType::ArmorRightHand; |
| 618 | break; |
| 619 | } |
| 620 | prefSlot = true; |
| 621 | } |
| 622 | if (prefSlot) |
| 623 | { |
| 624 | for (auto &slot : type->equipment_layout->slots) |
| 625 | { |
| 626 | if (slot.type != prefSlotType) |
| 627 | { |
| 628 | continue; |
| 629 | } |
| 630 | if (canAddEquipment(slot.bounds.p0, equipmentType)) |
| 631 | { |
| 632 | pos = slot.bounds.p0; |
| 633 | slotFound = true; |
| 634 | break; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | if (!slotFound) |
| 639 | { |
| 640 | for (auto &slot : type->equipment_layout->slots) |
no test coverage detected