metaforce/Runtime/Weapon/CWeaponMgr.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

#include "Runtime/Weapon/CWeaponMgr.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
void CWeaponMgr::Add(TUniqueId uid, EWeaponType type) {
auto iter = x0_weapons.emplace(uid, rstl::reserved_vector<s32, 15>()).first;
iter->second.resize(15);
++iter->second[size_t(type)];
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
void CWeaponMgr::Remove(TUniqueId uid) {
const auto& weapon = x0_weapons[uid];
2018-12-08 05:30:43 +00:00
s32 totalActive = 0;
for (size_t i = 0; i < 10; ++i) {
totalActive += weapon[i];
}
if (totalActive != 0) {
return;
}
2017-03-26 05:53:04 +00:00
x0_weapons.erase(uid);
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
void CWeaponMgr::IncrCount(TUniqueId uid, EWeaponType type) {
if (GetIndex(uid) < 0) {
2018-12-08 05:30:43 +00:00
Add(uid, type);
} else {
x0_weapons[uid][size_t(type)]++;
}
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
void CWeaponMgr::DecrCount(TUniqueId uid, EWeaponType type) {
if (GetIndex(uid) < 0) {
2018-12-08 05:30:43 +00:00
return;
}
2017-03-26 05:53:04 +00:00
auto& weapon = x0_weapons[uid];
weapon[size_t(type)]--;
if (weapon[size_t(type)] > 0) {
return;
}
Remove(uid);
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
s32 CWeaponMgr::GetNumActive(TUniqueId uid, EWeaponType type) const {
if (GetIndex(uid) < 0) {
2018-12-08 05:30:43 +00:00
return 0;
}
2018-06-13 19:36:11 +00:00
return x0_weapons.at(uid)[size_t(type)];
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
s32 CWeaponMgr::GetIndex(TUniqueId uid) const {
const auto iter = x0_weapons.find(uid);
if (iter == x0_weapons.cend()) {
2018-12-08 05:30:43 +00:00
return -1;
}
return s32(std::distance(x0_weapons.cbegin(), iter));
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde