From 17831b78d407a5abfc9389b35202b807ce5df8c4 Mon Sep 17 00:00:00 2001 From: joveeater Date: Wed, 8 Nov 2023 00:18:59 +0000 Subject: [PATCH 065/318] fix: npc splints and clean up iterator errors (#3592) * Fix splints and clean up iterator errors * style(autofix.ci): automated formatting --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/item.cpp | 1 + src/npcmove.cpp | 13 ++++++++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 3674560e548..d772312c36a 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -483,6 +483,7 @@ item &item::operator=( const item &source ) invlet = source.invlet; active = source.active; activated_by = source.activated_by; + is_favorite = source.is_favorite; contents.clear_items(); diff --git a/src/npcmove.cpp b/src/npcmove.cpp index c3470703e8a..3a0cd430288 100644 --- a/src/npcmove.cpp +++ b/src/npcmove.cpp @@ -4736,6 +4736,7 @@ bool npc::adjust_worn() return false; }; + item *splint = nullptr; for( auto &elem : worn ) { if( !elem->has_flag( flag_SPLINT ) ) { continue; @@ -4744,11 +4745,21 @@ bool npc::adjust_worn() if( !covers_broken( *elem, elem->get_side() ) ) { const bool needs_change = covers_broken( *elem, opposite_side( elem->get_side() ) ); // Try to change side (if it makes sense), or take off. - if( ( needs_change && change_side( *elem ) ) || takeoff( *elem ) ) { + if( needs_change && change_side( *elem ) ) { return true; } + + if( can_takeoff( *elem ).success() ) { + splint = elem; + break; + } + } } + if( splint ) { + takeoff( *splint ); + return true; + } return false; } -- 2.42.0