initial commit, lordsawar source, slightly modified
[lordsawar] / src / shield.h
1 //  Copyright (C) 2008, 2009 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #ifndef SHIELD_H
19 #define SHIELD_H
20
21 #include <gtkmm.h>
22 #include <string>
23 #include <sigc++/trackable.h>
24 #include <sigc++/signal.h>
25
26 #include "shieldstyle.h"
27
28 class Player;
29 class XML_Helper;
30 class Shieldset;
31
32 //! A single set of shields for a player
33 /**
34  *
35  */
36 class Shield : public std::list<ShieldStyle*>, public sigc::trackable
37 {
38     public:
39
40         //! The xml tag of this object in a shieldset configuration file.
41         static std::string d_tag; 
42
43         //! The notional player that the Shield goes with.
44         enum Colour {WHITE = 0, GREEN = 1, YELLOW = 2, LIGHT_BLUE = 3, RED = 4,
45           DARK_BLUE = 5, ORANGE = 6, BLACK = 7, NEUTRAL = 8};
46
47         //! Loading constructor.
48         /**
49          * Make a new Shield object by reading it in from an opened shieldset
50          * configuration file.
51          *
52          * @param helper  The opened shieldset configuration file to read the
53          *                shield object from.
54          */
55         Shield(XML_Helper* helper);
56         
57         //! Default constructor.
58         Shield(Shield::Colour owner, Gdk::Color color);
59
60         //! Destructor.
61         virtual ~Shield();
62
63
64         // Get Methods
65
66         //! Returns the player that this shield will belong to.
67         guint32 getOwner() const {return d_owner;}
68
69         //! Returns the colour of the player shield.
70         Gdk::Color getColor() const {return d_color;}
71
72
73         // Set Methods
74
75         //! Sets the colour of the player shield.
76         void setColor(Gdk::Color c) {d_color = c;}
77
78
79         // Methods that operate on class data and do not modify the class.
80
81         //! Save the shield to an opened shieldset configuration file.
82         bool save(XML_Helper *helper) const;
83
84         //! Get the first shieldstyle in the shield with the given type.
85         ShieldStyle *getFirstShieldstyle(ShieldStyle::Type type);
86
87
88         // Methods that operate on class data and modify the class.
89
90         //! Load the images associated with this shield.
91         void instantiateImages(Shieldset *s);
92
93         //! Destroy the images associated with this shield.
94         void uninstantiateImages();
95
96
97         // Static Methods
98
99         /**
100          * Get the default colour for the Player with the given Id.
101          *
102          * @note This colour is used to graphically shade Army, Shield, Flags,
103          * and selector pictures.
104          *
105          * @note This is not used to obtain the Neutral player's colour.
106          *
107          * @param player_no  The player's Id for which we want the colour.
108          *
109          * @return The default colour associated with the player.
110          */
111         //! Get standard colour for a player.
112         static Gdk::Color get_default_color_for_no(int player_no);
113
114         //! Get standard colour for the neutral player.
115         static Gdk::Color get_default_color_for_neutral();
116
117         //! Convert the Shield::Colour enumerated value to a string.
118         static std::string colourToString(const Shield::Colour c);
119     protected:
120
121         //! The player of the shield.
122         /**
123          * Equates to the shieldset.shield.d_colour XML entities in the 
124          * shieldset configuration file.
125          * Equates to the Shield::Colour enumeration.
126          */
127         guint32 d_owner;
128
129         //! The player's colour.
130         /**
131          * Mask portions of images are shaded in this colour.
132          */
133         Gdk::Color d_color;
134 };
135
136 #endif // SHIELD_H