1 // Copyright (C) 2008, 2009 Ben Asselstine
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.
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.
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
23 #include "GraphicsCache.h"
24 #include "xmlhelper.h"
25 #include "ucompose.hpp"
26 #include "shieldset.h"
28 std::string Shield::d_tag = "shield";
30 //#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
33 Shield::Shield(XML_Helper* helper)
35 helper->getData(d_owner, "owner");
36 helper->getData(d_color, "color");
39 Shield::Shield(Shield::Colour owner, Gdk::Color color)
41 d_owner = guint32(owner);
47 for (iterator it = begin(); it != end(); it++)
51 Gdk::Color Shield::get_default_color_for_no(int player_no)
54 switch (player_no % MAX_PLAYERS)
56 case Shield::WHITE: c.set_rgb_p(252.0/255.0,252.0/255.0,252.0/255.0); break;
57 //case 1: color.r = 80; color.b = 28; color.g = 172; break;
58 case Shield::GREEN: c.set_rgb_p(80.0/255.0, 195.0/255.0, 28.0/255.0); break;
59 case Shield::YELLOW: c.set_rgb_p(252.0/255.0,236.0/255.0,32.0/255.0); break;
60 case Shield::LIGHT_BLUE: c.set_rgb_p(0,252.0/255.0,252.0/255.0); break;
61 case Shield::RED: c.set_rgb_p(252.0/255.0,160.0/255.0,0);break;
62 case Shield::DARK_BLUE:
63 c.set_rgb_p(44.0/255.0,184.0/255.0,252.0/255.0); break;
64 case Shield::ORANGE: c.set_rgb_p(196.0/255.0, 28.0/255.0, 0); break;
65 case Shield::BLACK: c.set_rgb_p(0,0,0); break;
71 Gdk::Color Shield::get_default_color_for_neutral()
74 color.set_rgb_p(204.0/255.0,204.0/255.0,204.0/255.0);
78 std::string Shield::colourToString(const Shield::Colour c)
83 return "Shield::WHITE"; break;
85 return "Shield::GREEN"; break;
87 return "Shield::YELLOW"; break;
88 case Shield::LIGHT_BLUE:
89 return "Shield::LIGHT_BLUE"; break;
91 return "Shield::RED"; break;
92 case Shield::DARK_BLUE:
93 return "Shield::DARK_BLUE"; break;
95 return "Shield::ORANGE"; break;
97 return "Shield::BLACK"; break;
99 return "Shield::NEUTRAL"; break;
101 return "Shield::NEUTRAL";
104 bool Shield::save(XML_Helper *helper) const
108 retval &= helper->openTag(d_tag);
109 retval &= helper->saveData("owner", d_owner);
110 retval &= helper->saveData("color", d_color);
111 for (const_iterator it = begin(); it != end(); it++)
113 retval &= helper->closeTag();
117 void Shield::instantiateImages(Shieldset *s)
119 for (iterator it = begin(); it != end(); it++)
121 if ((*it)->getImageName().empty() == false)
122 (*it)->instantiateImages(s->getFile((*it)->getImageName()), s);
125 void Shield::uninstantiateImages()
127 for (iterator it = begin(); it != end(); it++)
128 (*it)->uninstantiateImages();
131 ShieldStyle *Shield::getFirstShieldstyle(ShieldStyle::Type type)
133 for (iterator i = begin(); i != end(); i++)
135 if ((*i)->getType() == type)