Skip to content

Commit

Permalink
favor to return a smart pointer in ai/actions recall_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 17, 2014
1 parent d119fe7 commit 393a16e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/ai/actions.cpp
Expand Up @@ -53,6 +53,7 @@
#include "../statistics.hpp"
#include "../team.hpp"
#include "../unit.hpp"
#include "../unit_ptr.hpp"
#include "../synced_context.hpp"

namespace ai {
Expand Down Expand Up @@ -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<UnitPtr >::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)
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/ai/actions.hpp
Expand Up @@ -24,6 +24,7 @@

#include "../actions/move.hpp"
#include "lua/unit_advancements_aspect.hpp"
#include "../unit_ptr.hpp"

namespace pathfind {
struct plain_route;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 393a16e

Please sign in to comment.