2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Weapon/CWeaponMgr.hpp"
|
2016-12-10 02:35:20 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
void CWeaponMgr::Add(TUniqueId uid, EWeaponType type) {
|
2020-04-07 17:32:02 +00:00
|
|
|
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) {
|
2020-04-07 17:32:02 +00:00
|
|
|
const auto& weapon = x0_weapons[uid];
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
s32 totalActive = 0;
|
2020-04-07 17:32:02 +00:00
|
|
|
for (size_t i = 0; i < 10; ++i) {
|
|
|
|
totalActive += weapon[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalActive != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-04-07 17:32:02 +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) {
|
2020-04-07 17:32:02 +00:00
|
|
|
if (GetIndex(uid) < 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Add(uid, type);
|
2020-04-07 17:32:02 +00:00
|
|
|
} else {
|
2020-04-07 17:40:12 +00:00
|
|
|
x0_weapons[uid][size_t(type)]++;
|
2020-04-07 17:32:02 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWeaponMgr::DecrCount(TUniqueId uid, EWeaponType type) {
|
2020-04-07 17:32:02 +00:00
|
|
|
if (GetIndex(uid) < 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-07 17:32:02 +00:00
|
|
|
}
|
2017-03-26 05:53:04 +00:00
|
|
|
|
2020-04-07 17:32:02 +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 {
|
2020-04-07 17:32:02 +00:00
|
|
|
if (GetIndex(uid) < 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return 0;
|
2020-04-07 17:32:02 +00:00
|
|
|
}
|
2018-06-13 19:36:11 +00:00
|
|
|
|
2020-04-07 17:32:02 +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 {
|
2020-04-07 17:32:02 +00:00
|
|
|
const auto iter = x0_weapons.find(uid);
|
|
|
|
|
|
|
|
if (iter == x0_weapons.cend()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return -1;
|
2020-04-07 17:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return s32(std::distance(x0_weapons.cbegin(), iter));
|
2017-03-26 05:53:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|