diff --git a/src/arrow.cpp b/src/arrow.cpp index d451cae235b..f784c52217f 100644 --- a/src/arrow.cpp +++ b/src/arrow.cpp @@ -31,34 +31,54 @@ static lg::log_domain log_arrows("arrows"); #define DBG_ARR LOG_STREAM(debug, log_arrows) arrow::arrow(display* screen) -:screen_(screen), layer_(display::LAYER_ARROWS), color_("red"), style_("") +:screen_(screen), + layer_(display::LAYER_ARROWS), + color_("red"), + style_("") { } -void arrow::set_path(const arrow_path_t &path) +bool arrow::set_path(const arrow_path_t &path) { previous_path_ = path_; path_ = path; - update_symbols(previous_path_); + if (valid_path()) + { + update_symbols(previous_path_); + return true; + } + else + { + return false; + } } void arrow::set_color(const std::string& color) { color_ = color; - update_symbols(path_); + if (valid_path()) + { + update_symbols(path_); + } } void arrow::set_style(const std::string& style) { style_ = style; - update_symbols(path_); + if (valid_path()) + { + update_symbols(path_); + } } void arrow::set_layer(const display::tdrawing_layer & layer) { layer_ = layer; - invalidate_arrow_path(path_); - notify_arrow_changed(); + if (valid_path()) + { + invalidate_arrow_path(path_); + notify_arrow_changed(); + } } const arrow_path_t & arrow::get_path() const @@ -66,7 +86,6 @@ const arrow_path_t & arrow::get_path() const return path_; } - const arrow_path_t & arrow::get_previous_path() const { return previous_path_; @@ -78,6 +97,14 @@ void arrow::draw_hex(const map_location & loc) loc, image::get_image(symbols_map_[loc], image::SCALED_TO_ZOOM)); } +bool arrow::valid_path() const +{ + if (path_.size() >= 2) + return true; + else + return false; +} + void arrow::add_observer(arrow_observer & observer) { observers_.push_back(&observer); @@ -90,6 +117,12 @@ void arrow::remove_observer(arrow_observer & observer) void arrow::update_symbols(arrow_path_t old_path) { + if (!valid_path()) + { + WRN_ARR << "arrow::update_symbols called with invalid path\n"; + return; + } + foreach(map_location loc, old_path) { symbols_map_.erase(loc); diff --git a/src/arrow.hpp b/src/arrow.hpp index cb56e8cf0fd..fb5788365fb 100644 --- a/src/arrow.hpp +++ b/src/arrow.hpp @@ -47,7 +47,8 @@ public: notify_arrow_deleted(); } - virtual void set_path(const arrow_path_t &path); + /// returns false if the received path is invalid + virtual bool set_path(const arrow_path_t &path); /** * The string color parameter is in the same format expected by the @@ -72,6 +73,9 @@ public: void draw_hex(const map_location & hex); + /// Checks that the path is not of length 0 or 1 + bool valid_path() const; + void add_observer(arrow_observer & observer); void remove_observer(arrow_observer & observer); @@ -84,16 +88,16 @@ protected: */ void update_symbols(arrow_path_t old_path); + void invalidate_arrow_path(arrow_path_t path); + private: //operations - void invalidate_arrow_path(arrow_path_t path); - void notify_arrow_changed(); void notify_arrow_deleted(); -private: +protected: //properties display* screen_; @@ -110,6 +114,8 @@ private: arrow_symbols_map_t symbols_map_; +private: + //properties std::list observers_; }; diff --git a/src/whiteboard/manager.cpp b/src/whiteboard/manager.cpp index 36abe31d10d..1f82664d4c2 100644 --- a/src/whiteboard/manager.cpp +++ b/src/whiteboard/manager.cpp @@ -58,18 +58,25 @@ void manager::set_route(const std::vector &steps) { display *screen = (display*) resources::screen; move_arrow_ = new arrow(screen); + move_arrow_->set_color("white"); screen->add_arrow(*move_arrow_); } + move_arrow_->set_path(route_); } } void manager::create_move_from_route(unit& subject) { - team& current_team = (*resources::teams)[resources::controller->current_side()]; + int current_side = resources::controller->current_side(); + team& current_team = (*resources::teams)[current_side]; + LOG_WB << "Creating move for unit " << subject.name() << " [" << subject.id() << "]" << " from " << subject.get_location() << " to " << route_.back() << "\n"; + + move_arrow_->set_color(team::get_side_color_index(current_side)); + current_team.get_side_actions().queue_move(subject, route_.back(), *move_arrow_); //ownership of the arrow transferred to the new move action move_arrow_ = NULL; diff --git a/src/whiteboard/manager.hpp b/src/whiteboard/manager.hpp index 40351be4569..402954af84b 100644 --- a/src/whiteboard/manager.hpp +++ b/src/whiteboard/manager.hpp @@ -45,7 +45,6 @@ public: * Determine whether the whiteboard is activated. */ bool active(){ return active_; } - void set_active(bool active){ active_ = active; } /**