File indexing completed on 2024-04-28 07:54:18
0001 /* This file is part of KsirK. 0002 Copyright (C) 2001-2007 Gael de Chalendar <kleag@free.fr> 0003 0004 KsirK is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation, either version 2 0007 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0017 02110-1301, USA 0018 */ 0019 0020 #ifndef KSIRKSKINEDITORCOUNTRY_H 0021 #define KSIRKSKINEDITORCOUNTRY_H 0022 0023 #include <QPoint> 0024 #include <QString> 0025 #include <QList> 0026 #include <QColor> 0027 0028 class QSvgRenderer; 0029 class QGraphicsSvgItem; 0030 class QGraphicsScene; 0031 0032 #include <ostream> 0033 0034 namespace KsirkSkinEditor 0035 { 0036 0037 class Continent; 0038 class ONU; 0039 0040 /** 0041 * Each country of the map is represented by a Country object. It has a name, 0042 * a point for its flag and points for its canon, cavalry, etc. 0043 * Also, it stores pointers to the objects that represent its owner and the 0044 * sprites of its flag and its armies. 0045 */ 0046 class Country 0047 { 0048 public: 0049 /** 0050 * Constructor 0051 * @param theName The name of this country. 0052 * @param anchorPoint The point around which the highlighting will be placed. 0053 * @param centralPoint The point around which the fighter will be placed. 0054 * @param flagPoint The point (top left corner) where the flag sprite is drawn. 0055 * @param cannonPoint The point (top left corner) where the cannon sprite is drawn. 0056 * @param cavalryPoint The point (top left corner) where the cavalry sprite is drawn. 0057 * @param infantryPoint The point (top left corner) where the infantry sprite is drawn. 0058 * @param id The unique integer identifier of this country. 0059 */ 0060 Country(const QString& theName, 0061 const QPointF& anchorPoint, 0062 const QPointF& centralPoint, 0063 const QPointF& flagPoint, const QPointF& cannonPoint, const QPointF& cavalryPoint, 0064 const QPointF& infantryPoint/*, unsigned int id*/); 0065 0066 /** Default destructor */ 0067 ~Country(); 0068 0069 /** 0070 * Removes the sprites (flag and soldiers), the owner, etc. 0071 * The sprites ared deleted. 0072 */ 0073 void reset(); 0074 0075 /** 0076 * Creates the sprite of the contry's flag. Eventually removes a previously 0077 * existing sprite. 0078 * @param theFlagFileName The flag's sprite file name :-) 0079 * @param backGnd The background onto which this country sprites will be drawn. 0080 */ 0081 void flag(const QString& theFlagFileName); 0082 0083 /** 0084 * Test if this is a neighbour of country 0085 * @param country The country to test if this one communicate with. 0086 * @return true if @ref country communicate with this; false otherwise. 0087 */ 0088 bool communicateWith(const Country *country) const; 0089 0090 /** 0091 * Returns the continent this country is in. 0092 * @return The continent this country is in. 0093 */ 0094 inline Continent* continent() {return m_continent;} 0095 0096 /** 0097 * Sets the continent this country is in. 0098 */ 0099 inline void setContinent(Continent* continent) {m_continent = continent;} 0100 0101 /** 0102 * Return the name of the country 0103 */ 0104 const QString& name() const; 0105 0106 const QPointF& anchorPoint() const; 0107 /** 0108 * Return a point inside the country territory around which are drawn the 0109 * fighters. 0110 */ 0111 const QPointF& centralPoint() const; 0112 0113 /** 0114 * Return the point where the flag is displayed 0115 */ 0116 const QPointF& pointFlag() const; 0117 0118 /** 0119 * Return the point where the cannons are displayed 0120 */ 0121 const QPointF& pointCannon() const; 0122 0123 /** 0124 * Return the point where the cavalrymen are displayed 0125 */ 0126 const QPointF& pointCavalry() const; 0127 0128 /** 0129 * Return the point where the infantrymen are displayed 0130 */ 0131 const QPointF& pointInfantry() const; 0132 0133 /** 0134 * Set the anchor point. 0135 */ 0136 void anchorPoint(const QPointF pt); 0137 0138 /** 0139 * Set the point guaranteed to be inside this country territory and around 0140 * which are drawn the fighters. 0141 */ 0142 void centralPoint(const QPointF pt); 0143 0144 /** 0145 * Set the point where the flag is displayed 0146 */ 0147 void pointFlag(const QPointF pt); 0148 0149 /** 0150 * Set the point where the cannons are displayed 0151 */ 0152 void pointCannon(const QPointF pt); 0153 0154 /** 0155 * Set the point where the cavalrymen are displayed 0156 */ 0157 void pointCavalry(const QPointF pt); 0158 0159 /** 0160 * Set the point where the infantrymen are displayed 0161 */ 0162 void pointInfantry(const QPointF pt); 0163 0164 /** Sets the list of neighbour countries. */ 0165 void neighbours(const QList<Country*>& neighboursVect); 0166 0167 //@{ 0168 /** Returns the list of neighbour countries */ 0169 QList< Country* >& neighbours(); 0170 const QList< Country* >& neighbours() const; 0171 //@} 0172 0173 void highlight(QGraphicsScene* scene, ONU* onu, const QColor& color = Qt::white, qreal opacity = 1.0); 0174 0175 void clearHighlighting(); 0176 0177 bool isHighlightingLocked(); 0178 void releaseHighlightingLock(); 0179 0180 inline QGraphicsSvgItem* highlighting() {return m_highlighting;} 0181 0182 private: 0183 0184 /** 0185 * A pointer to the continent this country is in. 0186 */ 0187 Continent* m_continent; 0188 0189 /** 0190 * The name of the country 0191 */ 0192 QString m_name; 0193 0194 /** the array of neigbours of this country */ 0195 QList<Country*> m_neighbours; 0196 0197 QPointF m_anchorPoint; 0198 0199 /** 0200 * a point situated inside this country teritory such that any click on 0201 * this point (for example by an AI player) will be a click on this country 0202 */ 0203 QPointF m_centralPoint; 0204 0205 /** 0206 * the point of the upper left corner of the country's flag sprite 0207 */ 0208 QPointF m_pointFlag; 0209 0210 /** 0211 * the point of the upper left corner of the country's first cannon sprite 0212 * the subsequent cannons sprites are shifted by a fixed number of pixels 0213 */ 0214 QPointF m_pointCannon; 0215 0216 /** 0217 * the point of the upper left corner of the country's first cavalryman 0218 * sprite.The subsequent cavalrymen sprites are shifted by a fixed number 0219 * of pixels 0220 */ 0221 QPointF m_pointCavalry; 0222 0223 /** 0224 * the point of the upper left corner of the country's first soldier sprite 0225 * The subsequent soldier sprites are shifted by a fixed number of pixels 0226 */ 0227 QPointF m_pointInfantry; 0228 0229 /** The unique integer identifier of this country. */ 0230 // unsigned int m_id; 0231 0232 QGraphicsSvgItem* m_highlighting; 0233 0234 QSvgRenderer* m_renderer; 0235 0236 bool m_highlighting_locked; 0237 0238 }; 0239 0240 QDataStream& operator>>(QDataStream& stream, Country* country); 0241 0242 } 0243 0244 #endif 0245