The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
helper.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Support functions for dealing with units.
18  */
19 
20 #include "resources.hpp"
21 #include "units/unit.hpp"
22 #include "units/helper.hpp"
23 
24 namespace unit_helper {
25 
27 {
28  return u.advances_to().size() + u.get_modification_advances().size();
29 }
30 
32 {
33  return u.valid() && u->advances() && number_of_possible_advances(*u) > 0;
34 }
35 
36 std::string resistance_color(const int resistance)
37 {
38  if (resistance < 0)
39  return std::string("#FF0000");
40 
41  if (resistance <= 20)
42  return std::string("#FFFF00");
43 
44  if (resistance <= 40)
45  return std::string("#FFFFFF");
46 
47  return std::string("#00FF00");
48 }
49 
50 }
Definition: unit.hpp:95
std::vector< config > get_modification_advances() const
Definition: unit.cpp:1630
bool will_certainly_advance(const unit_map::iterator &u)
Encapsulates the logic for deciding whether an iterator u points to a unit that can advance...
Definition: helper.cpp:31
const std::vector< std::string > & advances_to() const
Definition: unit.hpp:133
std::string resistance_color(const int resistance)
Definition: helper.cpp:36
int number_of_possible_advances(const unit &u)
Determines the total number of available advancements (of any kind) for a given unit.
Definition: helper.cpp:26
bool valid() const
Definition: map.hpp:229
GLsizei const GLcharARB ** string
Definition: glew.h:4503