CWorld: Make use of find_if in GetAreaIdForSaveId()

Same behavior minus any explicit mutable state.
This commit is contained in:
Lioncash 2020-04-14 16:40:11 -04:00
parent 86b94ad915
commit 6436184a3f
1 changed files with 12 additions and 11 deletions

View File

@ -712,19 +712,20 @@ bool CWorld::AreSkyNeedsMet() const {
}
TAreaId CWorld::GetAreaIdForSaveId(s32 saveId) const {
if (saveId == -1)
if (saveId == -1) {
return kInvalidAreaId;
if (x18_areas.size() <= 0)
return kInvalidAreaId;
TAreaId cur = 0;
for (const auto& area : x18_areas) {
if (area->x88_areaId == saveId)
return cur;
++cur;
}
if (x18_areas.empty()) {
return kInvalidAreaId;
}
const auto iter = std::find_if(x18_areas.cbegin(), x18_areas.cend(),
[saveId](const auto& area) { return area->x88_areaId == saveId; });
if (iter == x18_areas.cend()) {
return kInvalidAreaId;
}
return TAreaId(std::distance(x18_areas.cbegin(), iter));
}
} // namespace urde