MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / TryModifyingAmmo

Function TryModifyingAmmo

TombEngine/Game/pickup/pickup_ammo.cpp:42–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42bool 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
74bool TryAddingAmmo(LaraInfo& lara, GAME_OBJECT_ID objectID, std::optional<int> amount)
75{

Callers 3

SetInventoryCountFunction · 0.85
TryAddingAmmoFunction · 0.85
TryRemovingAmmoFunction · 0.85

Calls 6

GetArraySlotFunction · 0.85
SetInfiniteMethod · 0.80
HasInfiniteMethod · 0.80
valueMethod · 0.45
GetCountMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected