Author: crab
Date: Thu Apr 30 18:34:44 2009
New Revision: 35350

URL: http://svn.gna.org/viewcvs/wesnoth?rev=35350&view=rev
Log:
New helper function team_unit_cost to calculate total cost of units owned by 
side

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

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=35350&r1=35349&r2=35350&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Thu Apr 30 18:34:44 2009
@@ -2979,6 +2979,18 @@
        return res;
 }
 
+int team_units_cost(const unit_map& units, unsigned int side)
+{
+       int res = 0;
+       for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
+               if(i->second.side() == side) {
+                       res += i->second.cost();
+               }
+       }
+
+       return res;
+}
+
 int team_upkeep(const unit_map& units, unsigned int side)
 {
        int res = 0;

Modified: trunk/src/unit.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.hpp?rev=35350&r1=35349&r2=35350&view=diff
==============================================================================
--- trunk/src/unit.hpp (original)
+++ trunk/src/unit.hpp Thu Apr 30 18:34:44 2009
@@ -484,6 +484,10 @@
 
 /** Returns the number of units of the given side (team). */
 int team_units(const unit_map& units, unsigned int team_num);
+
+/** Returns the total cost of units of the given side (team, 1-based). */
+int team_units_cost(const unit_map& units, unsigned int team_num);
+
 int team_upkeep(const unit_map& units, unsigned int team_num);
 unit_map::const_iterator team_leader(unsigned int side, const unit_map& units);
 unit_map::iterator find_visible_unit(unit_map& units,


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

Reply via email to