| 40 | } |
| 41 | |
| 42 | bool TryModifyingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> amount, ModificationType modType) |
| 43 | { |
| 44 | int arrayPos = GetArraySlot(Ammo, objectID); |
| 45 | if (arrayPos == NO_VALUE) |
| 46 | return false; |
| 47 | |
| 48 | const auto& ammoPickup = Ammo[arrayPos]; |
| 49 | |
| 50 | auto& currentWeapon = lara.Weapons[(int)ammoPickup.LaraWeaponType]; |
| 51 | auto& currentAmmo = currentWeapon.Ammo[(int)ammoPickup.AmmoType]; |
| 52 | |
| 53 | switch(modType) |
| 54 | { |
| 55 | case ModificationType::Set: |
| 56 | currentAmmo = amount.value(); |
| 57 | currentAmmo.SetInfinite(amount == NO_VALUE); |
| 58 | break; |
| 59 | |
| 60 | default: |
| 61 | if (!currentAmmo.HasInfinite()) |
| 62 | { |
| 63 | int defaultModify = modType == ModificationType::Add ? ammoPickup.Amount : -ammoPickup.Amount; |
| 64 | int newVal = (int)currentAmmo.GetCount() + (amount.has_value() ? amount.value() : defaultModify); |
| 65 | currentAmmo = std::max(0, newVal); |
| 66 | } |
| 67 | |
| 68 | break; |
| 69 | }; |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | bool TryAddingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> amount) |
| 75 | { |
no test coverage detected