From 393a16e871688aab5b8b993c7335340af56c46a7 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 17 Jun 2014 19:32:26 -0400 Subject: [PATCH] favor to return a smart pointer in ai/actions recall_unit --- src/ai/actions.cpp | 9 +++++---- src/ai/actions.hpp | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ai/actions.cpp b/src/ai/actions.cpp index 684a8b85b9f4..39c9646efe5d 100644 --- a/src/ai/actions.cpp +++ b/src/ai/actions.cpp @@ -53,6 +53,7 @@ #include "../statistics.hpp" #include "../team.hpp" #include "../unit.hpp" +#include "../unit_ptr.hpp" #include "../synced_context.hpp" namespace ai { @@ -500,14 +501,14 @@ recall_result::recall_result(side_number side, { } -const unit * recall_result::get_recall_unit(const team &my_team) +UnitConstPtr recall_result::get_recall_unit(const team &my_team) { const std::vector::const_iterator rec = find_if_matches_id(my_team.recall_list(), unit_id_); if (rec == my_team.recall_list().end()) { set_error(E_NOT_AVAILABLE_FOR_RECALLING); - return NULL; + return UnitConstPtr(); } - return rec->get(); + return *rec; } bool recall_result::test_enough_gold(const team &my_team) @@ -531,7 +532,7 @@ void recall_result::do_check_before() } //Unit available for recalling? - const unit * to_recall = get_recall_unit(my_team); + const UnitConstPtr & to_recall = get_recall_unit(my_team); if ( !to_recall ) { return; } diff --git a/src/ai/actions.hpp b/src/ai/actions.hpp index fe7091c5cefc..47945aa657e5 100644 --- a/src/ai/actions.hpp +++ b/src/ai/actions.hpp @@ -24,6 +24,7 @@ #include "../actions/move.hpp" #include "lua/unit_advancements_aspect.hpp" +#include "../unit_ptr.hpp" namespace pathfind { struct plain_route; @@ -219,7 +220,7 @@ class recall_result : public action_result { virtual void do_execute(); virtual void do_init_for_execution(); private: - const unit * get_recall_unit( + UnitConstPtr get_recall_unit( const team& my_team); bool test_enough_gold( const team& my_team);