From 70c51c3a86dae6e1c2ed2071aae39db140fe625f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 23 Mar 2020 02:39:36 -0400 Subject: [PATCH] CPlayer: Un-nest code within FinishNewScan() Makes this function much nicer to read. --- Runtime/World/CPlayer.cpp | 42 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 5088641a3..38b781e8b 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -1195,18 +1195,36 @@ static CAssetId UpdatePersistentScanPercent(u32 prevLogScans, u32 logScans, u32 } void CPlayer::FinishNewScan(CStateManager& mgr) { - if (TCastToPtr act = mgr.ObjectById(x310_orbitTargetId)) - if (act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) - if (auto scanInfo = act->GetScannableObjectInfo()) - if (mgr.GetPlayerState()->GetScanTime(scanInfo->GetScannableObjectId()) >= 1.f) - if (IsDataLoreResearchScan(scanInfo->GetScannableObjectId())) { - auto scanCompletion = mgr.CalculateScanCompletionRate(); - CAssetId message = UpdatePersistentScanPercent(mgr.GetPlayerState()->GetLogScans(), scanCompletion.first, - scanCompletion.second); - if (message.IsValid()) - mgr.ShowPausedHUDMemo(message, 0.f); - mgr.GetPlayerState()->SetScanCompletionRate(scanCompletion); - } + const TCastToConstPtr act = mgr.ObjectById(x310_orbitTargetId); + + if (!act) { + return; + } + + if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) { + return; + } + + const auto* const scanInfo = act->GetScannableObjectInfo(); + if (!scanInfo) { + return; + } + + if (mgr.GetPlayerState()->GetScanTime(scanInfo->GetScannableObjectId()) < 1.f) { + return; + } + + if (!IsDataLoreResearchScan(scanInfo->GetScannableObjectId())) { + return; + } + + const auto scanCompletion = mgr.CalculateScanCompletionRate(); + const CAssetId message = UpdatePersistentScanPercent(mgr.GetPlayerState()->GetLogScans(), scanCompletion.first, + scanCompletion.second); + if (message.IsValid()) { + mgr.ShowPausedHUDMemo(message, 0.f); + } + mgr.GetPlayerState()->SetScanCompletionRate(scanCompletion); } void CPlayer::SetScanningState(EPlayerScanState state, CStateManager& mgr) {