metaforce/Runtime/Weapon/CWeaponMgr.cpp

57 lines
1.1 KiB
C++
Raw Normal View History

#include "CWeaponMgr.hpp"
namespace urde
{
2017-03-26 05:53:04 +00:00
2018-06-13 19:36:11 +00:00
void CWeaponMgr::Add(TUniqueId uid, EWeaponType type)
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
x0_weapons.insert(std::make_pair(uid, rstl::reserved_vector<s32, 10>()));
x0_weapons[uid].resize(10);
++x0_weapons[uid][u32(type)];
2017-03-26 05:53:04 +00:00
}
2018-06-13 19:36:11 +00:00
void CWeaponMgr::Remove(TUniqueId uid)
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
s32 totalActive = 0;
for (u32 i = 0; i < 10; ++i)
totalActive += x0_weapons[uid][i];
2017-03-26 05:53:04 +00:00
2018-06-13 19:36:11 +00:00
if (totalActive == 0)
x0_weapons.erase(uid);
2017-03-26 05:53:04 +00:00
}
2018-06-13 19:36:11 +00:00
void CWeaponMgr::IncrCount(TUniqueId uid, EWeaponType type)
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
if (GetIndex(uid) < 0)
Add(uid, type);
else
x0_weapons[uid][u32(type)]++;
2017-03-26 05:53:04 +00:00
}
2018-06-13 19:36:11 +00:00
void CWeaponMgr::DecrCount(TUniqueId uid, EWeaponType type)
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
if (GetIndex(uid) < 0)
return;
2017-03-26 05:53:04 +00:00
2018-06-13 19:36:11 +00:00
x0_weapons[uid][u32(type)]--;
if (x0_weapons[uid][u32(type)] <= 0)
Remove(uid);
2017-03-26 05:53:04 +00:00
}
2018-06-13 19:36:11 +00:00
s32 CWeaponMgr::GetNumActive(TUniqueId uid, EWeaponType type) const
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
if (GetIndex(uid) < 0)
return 0;
return x0_weapons.at(uid)[u32(type)];
2017-03-26 05:53:04 +00:00
}
2018-06-13 19:36:11 +00:00
s32 CWeaponMgr::GetIndex(TUniqueId uid) const
2017-03-26 05:53:04 +00:00
{
2018-06-13 19:36:11 +00:00
if (x0_weapons.find(uid) == x0_weapons.end())
return -1;
return s32(std::distance(x0_weapons.begin(), x0_weapons.find(uid)));
2017-03-26 05:53:04 +00:00
}
}