mirror of https://github.com/AxioDL/metaforce.git
CTeamAiMgr: Collapse two loops into count_if
Same behavior, less code. Ranges in C++20 will allow us to further simplify this in the future.
This commit is contained in:
parent
748dbb8740
commit
21a33b01ad
|
@ -1,5 +1,7 @@
|
||||||
#include "Runtime/World/CTeamAiMgr.hpp"
|
#include "Runtime/World/CTeamAiMgr.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Runtime/CStateManager.hpp"
|
#include "Runtime/CStateManager.hpp"
|
||||||
#include "Runtime/World/CPlayer.hpp"
|
#include "Runtime/World/CPlayer.hpp"
|
||||||
|
|
||||||
|
@ -301,20 +303,15 @@ void CTeamAiMgr::ClearTeamAiRole(TUniqueId aiId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CTeamAiMgr::GetNumAssignedOfRole(CTeamAiRole::ETeamAiRole testRole) const {
|
s32 CTeamAiMgr::GetNumAssignedOfRole(CTeamAiRole::ETeamAiRole testRole) const {
|
||||||
s32 ret = 0;
|
return static_cast<s32>(std::count_if(x58_roles.cbegin(), x58_roles.cend(),
|
||||||
for (const auto& role : x58_roles)
|
[testRole](const auto& role) { return role.GetTeamAiRole() == testRole; }));
|
||||||
if (role.GetTeamAiRole() == testRole)
|
|
||||||
++ret;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 CTeamAiMgr::GetNumAssignedAiRoles() const {
|
s32 CTeamAiMgr::GetNumAssignedAiRoles() const {
|
||||||
s32 ret = 0;
|
return static_cast<s32>(std::count_if(x58_roles.cbegin(), x58_roles.cend(), [](const auto& role) {
|
||||||
for (const auto& role : x58_roles)
|
const auto aiRole = role.GetTeamAiRole();
|
||||||
if (role.GetTeamAiRole() > CTeamAiRole::ETeamAiRole::Initial &&
|
return aiRole > CTeamAiRole::ETeamAiRole::Initial && aiRole <= CTeamAiRole::ETeamAiRole::Unassigned;
|
||||||
role.GetTeamAiRole() <= CTeamAiRole::ETeamAiRole::Unassigned)
|
}));
|
||||||
++ret;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CTeamAiRole* CTeamAiMgr::GetTeamAiRole(CStateManager& mgr, TUniqueId mgrId, TUniqueId aiId) {
|
CTeamAiRole* CTeamAiMgr::GetTeamAiRole(CStateManager& mgr, TUniqueId mgrId, TUniqueId aiId) {
|
||||||
|
|
Loading…
Reference in New Issue