whiteboard/move.hpp

Go to the documentation of this file.
00001 /* $Id: move.hpp 53789 2012-04-05 21:16:56Z ejls $ */
00002 /*
00003  Copyright (C) 2010 - 2012 by Gabriel Morin <gabrielmorin (at) gmail (dot) com>
00004  Part of the Battle for Wesnoth Project http://www.wesnoth.org
00005 
00006  This program is free software; you can redistribute it and/or modify
00007  it under the terms of the GNU General Public License as published by
00008  the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010  This program is distributed in the hope that it will be useful,
00011  but WITHOUT ANY WARRANTY.
00012 
00013  See the COPYING file for more details.
00014  */
00015 
00016 /**
00017  * @file
00018  */
00019 
00020 #ifndef WB_MOVE_HPP_
00021 #define WB_MOVE_HPP_
00022 
00023 #include "action.hpp"
00024 
00025 struct temporary_unit_mover;
00026 
00027 namespace wb {
00028 
00029 /**
00030  * A planned move, represented on the map by an arrow and
00031  * a ghosted unit in the destination hex.
00032  */
00033 class move : public action
00034 {
00035 public:
00036     friend class validate_visitor;
00037     friend class highlight_visitor;
00038 
00039     move(size_t team_index, bool hidden, unit& mover, const pathfind::marked_route& route,
00040             arrow_ptr arrow, fake_unit_ptr fake_unit);
00041     move(config const&, bool hidden); // For deserialization
00042     virtual ~move(){}
00043 
00044     virtual std::ostream& print(std::ostream& s) const;
00045 
00046     virtual void accept(visitor& v);
00047 
00048     virtual void execute(bool& success, bool& complete);
00049 
00050     /** Return the unit targeted by this action. Null if unit doesn't exist. */
00051     virtual unit* get_unit() const;
00052     /** @return pointer to the fake unit used only for visuals */
00053     virtual fake_unit_ptr get_fake_unit() { return fake_unit_; }
00054 
00055     virtual map_location get_source_hex() const;
00056     virtual map_location get_dest_hex() const;
00057 
00058     virtual void set_route(const pathfind::marked_route& route);
00059     virtual const pathfind::marked_route& get_route() const { assert(route_); return *route_; }
00060     /// attempts to pathfind a new marked route for this path between these two hexes;
00061     /// returns true and assigns it to the internal route if successful.
00062     virtual bool calculate_new_route(const map_location& source_hex, const map_location& dest_hex);
00063 
00064     virtual arrow_ptr get_arrow() { return arrow_; }
00065 
00066     /** Applies temporarily the result of this action to the specified unit map. */
00067     virtual void apply_temp_modifier(unit_map& unit_map);
00068     /** Removes the result of this action from the specified unit map. */
00069     virtual void remove_temp_modifier(unit_map& unit_map);
00070 
00071     /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */
00072     virtual void draw_hex(map_location const& hex);
00073     /** Assigns a turn number to display to this planned move. Assigning zero removes any turn number. */
00074     virtual void set_turn_number(int turn) { turn_number_ = turn; }
00075 
00076     virtual map_location get_numbering_hex() const;
00077 
00078     virtual void set_valid(bool valid);
00079     virtual bool is_valid() const { return valid_; }
00080 
00081     virtual config to_config() const;
00082 
00083     ///@todo Make use of safe_enum idiom?
00084     enum ARROW_BRIGHTNESS {ARROW_BRIGHTNESS_STANDARD, ARROW_BRIGHTNESS_HIGHLIGHTED, ARROW_BRIGHTNESS_FOCUS};
00085     void set_arrow_brightness(ARROW_BRIGHTNESS x) {arrow_brightness_=x; update_arrow_style();}
00086     enum ARROW_TEXTURE {ARROW_TEXTURE_VALID, ARROW_TEXTURE_INVALID};
00087     void set_arrow_texture(ARROW_TEXTURE x) {arrow_texture_=x; update_arrow_style();}
00088 
00089 protected:
00090 
00091     boost::shared_ptr<move> shared_from_this() {
00092         return boost::static_pointer_cast<move>(action::shared_from_this());
00093     }
00094 
00095     void calculate_move_cost();
00096 
00097     size_t unit_underlying_id_;
00098     std::string unit_id_;
00099     boost::scoped_ptr<pathfind::marked_route> route_;
00100     int movement_cost_;
00101     /// Turn end number to draw if greater than zero. Assigned by the map builder.
00102     int turn_number_;
00103 
00104     arrow_ptr arrow_;
00105     fake_unit_ptr fake_unit_;
00106 
00107     bool valid_;
00108 
00109     ARROW_BRIGHTNESS arrow_brightness_;
00110     ARROW_TEXTURE arrow_texture_;
00111 
00112 private:
00113     virtual void do_hide();
00114     virtual void do_show();
00115 
00116     void hide_fake_unit();
00117     void show_fake_unit();
00118 
00119     void init();
00120     void update_arrow_style();
00121     boost::scoped_ptr<temporary_unit_mover> mover_;
00122     bool fake_unit_hidden_;
00123 };
00124 
00125 /** Dumps an move on a stream, for debug purposes. */
00126 std::ostream &operator<<(std::ostream &s, move_ptr move);
00127 std::ostream &operator<<(std::ostream &s, move_const_ptr move);
00128 
00129 } // end namespace wb
00130 
00131 #endif /* WB_MOVE_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs