| 50 | } |
| 51 | |
| 52 | bool TryModifyWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> count, ModificationType type) |
| 53 | { |
| 54 | int arrayPos = GetArraySlot(kWeapons, objectID); |
| 55 | if (-1 == arrayPos) |
| 56 | return false; |
| 57 | |
| 58 | auto weaponPickup = kWeapons[arrayPos]; |
| 59 | |
| 60 | // Set the SelectedAmmo type to WeaponAmmoType::Ammo1 (0) if adding the weapon for the first time. |
| 61 | // Note that this refers to the index of the weapon's ammo array, and not the weapon's actual ammunition count. |
| 62 | auto& currentWeapon = lara.Weapons[(int)weaponPickup.LaraWeaponType]; |
| 63 | |
| 64 | if (!currentWeapon.Present) |
| 65 | currentWeapon.SelectedAmmo = WeaponAmmoType::Ammo1; |
| 66 | |
| 67 | bool add = ModificationType::Add == type || ((ModificationType::Set == type) && count != 0); |
| 68 | currentWeapon.Present = add; |
| 69 | |
| 70 | if(!add) |
| 71 | { |
| 72 | if (weaponPickup.LaraWeaponType == lara.Control.Weapon.GunType || |
| 73 | weaponPickup.LaraWeaponType == lara.Control.Weapon.LastGunType) |
| 74 | { |
| 75 | lara.Control.Weapon.RequestGunType = LaraWeaponType::None; |
| 76 | |
| 77 | // If Lara has pistols and it's not the pistols we're removing, set them |
| 78 | // as the "next weapon" so that Lara equips them next. |
| 79 | if (LaraWeaponType::Pistol == weaponPickup.LaraWeaponType || !lara.Weapons[(int)LaraWeaponType::Pistol].Present) |
| 80 | lara.Control.Weapon.LastGunType = LaraWeaponType::None; |
| 81 | else |
| 82 | lara.Control.Weapon.LastGunType = LaraWeaponType::Pistol; |
| 83 | } |
| 84 | |
| 85 | if (HolsterType::Hips == weaponPickup.Holster && |
| 86 | lara.Control.Weapon.HolsterInfo.LeftHolster == GetWeaponHolsterSlot(weaponPickup.LaraWeaponType)) |
| 87 | { |
| 88 | lara.Control.Weapon.HolsterInfo.LeftHolster = HolsterSlot::Empty; |
| 89 | lara.Control.Weapon.HolsterInfo.RightHolster = HolsterSlot::Empty; |
| 90 | } |
| 91 | else if (HolsterType::Back == weaponPickup.Holster && |
| 92 | lara.Control.Weapon.HolsterInfo.BackHolster == GetWeaponHolsterSlot(weaponPickup.LaraWeaponType)) |
| 93 | { |
| 94 | lara.Control.Weapon.HolsterInfo.BackHolster = HolsterSlot::Empty; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | // Adding a weapon will not give the player any ammo even if they already have the weapon. |
| 102 | bool TryAddingWeapon(LaraInfo& lara, GAME_OBJECT_ID objectID) |
no test coverage detected