CScriptPlayerHint: Make use of std::any_of/std::find_if where applicable

Same behavior, can be simplified even further with ranges in the future.
This commit is contained in:
Lioncash 2020-04-12 14:00:31 -04:00
parent ff123f7820
commit 1d112134cf
1 changed files with 20 additions and 10 deletions

View File

@ -1,5 +1,7 @@
#include "Runtime/World/CScriptPlayerHint.hpp"
#include <algorithm>
#include "Runtime/CStateManager.hpp"
#include "Runtime/MP1/World/CMetroidPrimeRelay.hpp"
#include "Runtime/World/CActorParameters.hpp"
@ -19,20 +21,28 @@ CScriptPlayerHint::CScriptPlayerHint(TUniqueId uid, std::string_view name, const
void CScriptPlayerHint::Accept(IVisitor& visit) { visit.Visit(this); }
void CScriptPlayerHint::AddToObjectList(TUniqueId uid) {
for (TUniqueId existId : xe8_objectList)
if (uid == existId)
const bool inList =
std::any_of(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
if (inList) {
return;
if (xe8_objectList.size() != 8)
}
if (xe8_objectList.size() == xe8_objectList.capacity()) {
return;
}
xe8_objectList.push_back(uid);
}
void CScriptPlayerHint::RemoveFromObjectList(TUniqueId uid) {
for (auto it = xe8_objectList.begin(); it != xe8_objectList.end(); ++it) {
if (*it == uid) {
xe8_objectList.erase(it);
const auto iter =
std::find_if(xe8_objectList.cbegin(), xe8_objectList.cend(), [uid](const auto id) { return id == uid; });
if (iter == xe8_objectList.cend()) {
return;
}
}
xe8_objectList.erase(iter);
}
void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {