00001 /* $Id: action.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_ACTION_HPP_ 00021 #define WB_ACTION_HPP_ 00022 00023 #include "typedefs.hpp" 00024 00025 namespace wb { 00026 00027 class visitor; 00028 00029 /** 00030 * Abstract base class for all the whiteboard planned actions. 00031 */ 00032 class action : public boost::enable_shared_from_this<action> 00033 { 00034 public: 00035 action(size_t team_index, bool hidden); 00036 action(config const&, bool hidden); // For deserialization 00037 virtual ~action(); 00038 00039 virtual std::ostream& print(std::ostream& s) const = 0; 00040 00041 virtual void accept(visitor& v) = 0; 00042 00043 /** 00044 * Output parameters: 00045 * success: Whether or not to continue an execute-all after this execution 00046 * complete: Whether or not to delete this action after execution 00047 */ 00048 virtual void execute(bool& success, bool& complete) = 0; 00049 00050 /** Applies temporarily the result of this action to the specified unit map. */ 00051 virtual void apply_temp_modifier(unit_map& unit_map) = 0; 00052 /** Removes the result of this action from the specified unit map. */ 00053 virtual void remove_temp_modifier(unit_map& unit_map) = 0; 00054 00055 /** Gets called by display when drawing a hex, to allow actions to draw to the screen. */ 00056 virtual void draw_hex(const map_location& hex) = 0; 00057 00058 /** Sets whether or not the action should be drawn on the screen. */ 00059 void hide(); 00060 void show(); 00061 bool hidden() const {return hidden_;} 00062 00063 /** Indicates whether this hex is the preferred hex to draw the numbering for this action. */ 00064 bool is_numbering_hex(const map_location& hex) const {return hex==get_numbering_hex();} 00065 virtual map_location get_numbering_hex() const = 0; 00066 00067 /** Return the unit targeted by this action. Null if unit doesn't exist. */ 00068 virtual unit* get_unit() const = 0; 00069 /** @return pointer to the fake unit used only for visuals */ 00070 virtual fake_unit_ptr get_fake_unit() = 0; 00071 /** Returns the index of the team that owns this action */ 00072 size_t team_index() const { return team_index_; } 00073 /** Returns the number of the side that owns this action, i.e. the team index + 1. */ 00074 int side_number() const 00075 { 00076 return static_cast<int>(team_index_) + 1; 00077 } 00078 00079 /** 00080 * Indicates to an action whether its status is invalid, and whether it should change its 00081 * display (and avoid any change to the game state) accordingly 00082 */ 00083 virtual void set_valid(bool valid) = 0; 00084 virtual bool is_valid() const = 0; 00085 00086 /** Constructs and returns a config object representing this object. */ 00087 virtual config to_config() const; 00088 /** Constructs an object of a subclass of wb::action using a config. Current behavior is to return a null pointer for unrecognized config. */ 00089 static action_ptr from_config(config const&, bool hidden); 00090 00091 struct ctor_err : public game::error 00092 { 00093 ctor_err(const std::string& message) : game::error(message){} 00094 }; 00095 00096 private: 00097 /** Called by the non-virtual hide() and show(), respectively. */ 00098 virtual void do_hide() {} 00099 virtual void do_show() {} 00100 00101 size_t team_index_; 00102 bool hidden_; 00103 }; 00104 00105 std::ostream& operator<<(std::ostream& s, action_ptr action); 00106 std::ostream& operator<<(std::ostream& s, action_const_ptr action); 00107 00108 } // end namespace wb 00109 00110 #endif /* WB_ACTION_HPP_ */
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:48 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |