Author: mordante
Date: Sat Oct 15 20:06:19 2011
New Revision: 51493

URL: http://svn.gna.org/viewcvs/wesnoth?rev=51493&view=rev
Log:
Add unit_map::has_unit().

This allows to check whether a unit exists in the map.

Modified:
    trunk/src/unit_map.cpp
    trunk/src/unit_map.hpp

Modified: trunk/src/unit_map.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_map.cpp?rev=51493&r1=51492&r2=51493&view=diff
==============================================================================
--- trunk/src/unit_map.cpp (original)
+++ trunk/src/unit_map.cpp Sat Oct 15 20:06:19 2011
@@ -17,6 +17,7 @@
 /** @file */
 
 #include "unit_id.hpp"
+#include "foreach.hpp"
 #include "log.hpp"
 #include "unit.hpp"
 
@@ -438,3 +439,15 @@
 }
 
 #endif
+
+bool unit_map::has_unit(const unit * const u)
+{
+       assert(u);
+
+       foreach(const unit_pod& item, ilist_) {
+               if(item.unit_ == u) {
+                       return true;
+               }
+       }
+       return false;
+}

Modified: trunk/src/unit_map.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_map.hpp?rev=51493&r1=51492&r2=51493&view=diff
==============================================================================
--- trunk/src/unit_map.hpp (original)
+++ trunk/src/unit_map.hpp Sat Oct 15 20:06:19 2011
@@ -415,6 +415,17 @@
 #endif
        ;
 
+       /**
+        * Is the unit in the map?
+        *
+        * @pre                       @p u != @c NULL
+        *
+        * @param u                   Pointer to the unit to find.
+        *
+        * @returns                   True if found, false otherwise.
+        */
+       bool has_unit(const unit * const u);
+
 private:
        ///Creates and inserts a unit_pod called the_end_ as a sentinel in the 
ilist
        void init_end(){


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to