00001 /* $Id: utility.hpp 53981 2012-04-23 05:16:55Z gabba $ */ 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_UTILITY_HPP_ 00021 #define WB_UTILITY_HPP_ 00022 00023 #include <vector> 00024 00025 #include "typedefs.hpp" 00026 00027 class unit; 00028 00029 namespace wb { 00030 00031 /// @return The current viewing team's index 00032 size_t viewer_team(); 00033 00034 /// @return The current viewing side's number (i.e. team index + 1) 00035 int viewer_side(); 00036 00037 /// @return The side_actions instance belonging to the current viewing team 00038 side_actions_ptr viewer_actions(); 00039 00040 /// @return The side_actions instance belonging to the current playing team 00041 side_actions_ptr current_side_actions(); 00042 00043 /** 00044 * For a given leader on a keep, find another leader on another keep in the same castle. 00045 * @retval NULL if no such leader has been found 00046 */ 00047 unit const* find_backup_leader(unit const& leader); 00048 00049 /** 00050 * @return a leader from the specified team who can recruit on the specified hex 00051 * @retval NULL if no such leader has been found 00052 */ 00053 unit* find_recruiter(size_t team_index, map_location const&); 00054 00055 /// Applies the future unit map and @return a pointer to the unit at hex 00056 /// @retval NULL if none is visible to the specified viewer side 00057 unit* future_visible_unit(map_location hex, int viewer_side = wb::viewer_side()); 00058 00059 /// Applies the future unit map and @return a pointer to the unit at hex 00060 /// @retval NULL if none is visible to the specified viewer side 00061 /// @param on_side Only search for units of this side. 00062 unit* future_visible_unit(int on_side, map_location hex, int viewer_side = wb::viewer_side()); 00063 00064 /// Computes the MP cost for u to travel path 00065 int path_cost(std::vector<map_location> const& path, unit const& u); 00066 00067 struct temporary_unit_hider { 00068 temporary_unit_hider(unit& u); 00069 ~temporary_unit_hider(); 00070 unit* const unit_; 00071 }; 00072 00073 /** 00074 * Finalizer class to help with exception safety 00075 * sets variable to value on destruction 00076 */ 00077 template <typename T> 00078 class variable_finalizer 00079 { 00080 public: 00081 variable_finalizer(T & variable, T value): 00082 variable_(&variable), 00083 value_(value) 00084 {} 00085 ~variable_finalizer() 00086 { 00087 if (variable_ != NULL) 00088 { 00089 *variable_ = value_; 00090 } 00091 } 00092 /** Stop tracking the variable, i.e. this object won't do anything on destruction. */ 00093 void clear() 00094 { 00095 variable_ = NULL; 00096 } 00097 private: 00098 T * variable_; 00099 T value_; 00100 }; 00101 00102 void ghost_owner_unit(unit* unit); 00103 void unghost_owner_unit(unit* unit); 00104 00105 /** Return whether the whiteboard has actions. */ 00106 bool has_actions(); 00107 00108 } //end namespace wb 00109 00110 #endif /* WB_UTILITY_HPP_ */
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |