Skip to content

Commit

Permalink
[core] Remove usage of "*std::find_if" pattern (#4645)
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good authored Nov 21, 2023
1 parent aee843c commit 0d86ef2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
30 changes: 27 additions & 3 deletions src/map/utils/petutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,20 @@ namespace petutils
uint32 petID = PPet->m_PetID;

// clang-format off
Pet_t* PPetData = *std::find_if(g_PPetList.begin(), g_PPetList.end(), [petID](Pet_t* t)
auto maybePetData = std::find_if(g_PPetList.begin(), g_PPetList.end(), [petID](Pet_t* t)
{
return t->PetID == petID;
});
// clang-format on

if (maybePetData == g_PPetList.end())
{
ShowError(fmt::format("Could not look up pet data for id: {}", petID));
return;
}

auto* PPetData = *maybePetData;

uint8 mLvl = PMaster->GetMLevel();

if (PMaster->GetMJob() == JOB_SMN)
Expand Down Expand Up @@ -920,12 +928,20 @@ namespace petutils
uint32 petID = PPet->m_PetID;

// clang-format off
Pet_t* PPetData = *std::find_if(g_PPetList.begin(), g_PPetList.end(), [petID](Pet_t* t)
auto maybePetData = std::find_if(g_PPetList.begin(), g_PPetList.end(), [petID](Pet_t* t)
{
return t->PetID == petID;
});
// clang-format on

if (maybePetData == g_PPetList.end())
{
ShowError(fmt::format("Could not look up pet data for id: {}", petID));
return;
}

auto* PPetData = *maybePetData;

static_cast<CItemWeapon*>(PPet->m_Weapons[SLOT_MAIN])->setDelay((uint16)(floor(1000.0f * (240.0f / 60.0f))));
static_cast<CItemWeapon*>(PPet->m_Weapons[SLOT_MAIN])->setBaseDelay((uint16)(floor(1000.0f * (240.0f / 60.0f))));
// Get the Jug pet cap level
Expand Down Expand Up @@ -1581,12 +1597,20 @@ namespace petutils
}

// clang-format off
Pet_t* PPetData = *std::find_if(g_PPetList.begin(), g_PPetList.end(), [PetID](Pet_t* t)
auto maybePetData = std::find_if(g_PPetList.begin(), g_PPetList.end(), [PetID](Pet_t* t)
{
return t->PetID == PetID;
});
// clang-format on

if (maybePetData == g_PPetList.end())
{
ShowError(fmt::format("Could not look up pet data for id: {}", PetID));
return;
}

auto* PPetData = *maybePetData;

if (PMaster->GetMJob() != JOB_DRG && PetID == PETID_WYVERN)
{
return;
Expand Down
17 changes: 15 additions & 2 deletions src/map/utils/trustutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,17 @@ namespace trustutils

CTrustEntity* SpawnTrust(CCharEntity* PMaster, uint32 TrustID)
{
CTrustEntity* PTrust = LoadTrust(PMaster, TrustID);
if (PTrust == nullptr)
{
return nullptr;
}

if (PMaster->PParty == nullptr)
{
PMaster->PParty = new CParty(PMaster);
}

CTrustEntity* PTrust = LoadTrust(PMaster, TrustID);
PMaster->PTrusts.insert(PMaster->PTrusts.end(), PTrust);
PMaster->StatusEffectContainer->CopyConfrontationEffect(PTrust);
PTrust->setBattleID(PMaster->getBattleID());
Expand Down Expand Up @@ -374,12 +379,20 @@ namespace trustutils
auto* PTrust = new CTrustEntity(PMaster);

// clang-format off
auto* trustData = *std::find_if(g_PTrustList.begin(), g_PTrustList.end(), [TrustID](Trust_t* t)
auto maybeTrustData = std::find_if(g_PTrustList.begin(), g_PTrustList.end(), [TrustID](Trust_t* t)
{
return t->trustID == TrustID;
});
// clang-format on

if (maybeTrustData == g_PTrustList.end())
{
ShowError(fmt::format("Could not look up trust data for id: {}", TrustID));
return PTrust;
}

auto* trustData = *maybeTrustData;

PTrust->loc = PMaster->loc;
PTrust->m_OwnerID.id = PMaster->id;
PTrust->m_OwnerID.targid = PMaster->targid;
Expand Down

0 comments on commit 0d86ef2

Please sign in to comment.