File indexing completed on 2024-09-08 06:48:37
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 KSIRK_COUNTRY_H 0021 #define KSIRK_COUNTRY_H 0022 0023 #include "Sprites/infantrysprite.h" 0024 #include "Sprites/cavalrysprite.h" 0025 #include "Sprites/cannonsprite.h" 0026 #include "Sprites/animspriteslist.h" 0027 0028 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API 0029 #include <libkdegamesprivate/kgame/kgameproperty.h> 0030 0031 #include <QPoint> 0032 #include <QString> 0033 0034 class QSvgRenderer; 0035 class QGraphicsSvgItem; 0036 0037 namespace Ksirk 0038 { 0039 0040 class BackGnd; 0041 class FlagSprite; 0042 0043 namespace GameLogic 0044 { 0045 class Player; 0046 class Continent; 0047 class GameAutomaton; 0048 0049 /** 0050 * Each country of the map is represented by a Country object. It has a name, 0051 * a point for its flag and points for its canon, cavalry, etc. 0052 * Also, it stores pointers to the objects that represent its owner and the 0053 * sprites of its flag and its armies. 0054 */ 0055 class Country 0056 { 0057 public: 0058 /** 0059 * Constructor 0060 * @param theName The name of this country. 0061 * @param centralPoint The point around which the fighter will be placed. 0062 * @param flagPoint The point (top left corner) where the flag sprite is drawn. 0063 * @param cannonPoint The point (top left corner) where the cannon sprite is drawn. 0064 * @param cavalryPoint The point (top left corner) where the cavalry sprite is drawn. 0065 * @param infantryPoint The point (top left corner) where the infantry sprite is drawn. 0066 * @param id The unique integer identifier of this country. 0067 */ 0068 Country(GameAutomaton* game, 0069 const QString& theName, 0070 const QPointF& anchorPoint, 0071 const QPointF& centralPoint, 0072 const QPointF& flagPoint, 0073 const QPointF& cannonPoint, 0074 const QPointF& cavalryPoint, 0075 const QPointF& infantryPoint); 0076 0077 /** Default destructor */ 0078 ~Country(); 0079 0080 GameAutomaton* automaton() {return m_automaton;} 0081 0082 /** 0083 * Removes the sprites (flag and soldiers), the owner, etc. 0084 * The sprites ared deleted. 0085 */ 0086 void reset(); 0087 0088 /** 0089 * Creates the sprites necessary to display the armies of the country. 0090 * Eventually removes previously existing sprites. 0091 * @param backGnd The background onto which this country sprites will be drawn. 0092 */ 0093 void createArmiesSprites(); 0094 0095 /** 0096 * Creates the sprite of the contry's flag. Eventually removes a previously 0097 * existing sprite. 0098 * @param theFlagFileName The flag's sprite file name :-) 0099 * @param backGnd The background onto which this country sprites will be drawn. 0100 */ 0101 void flag(const QString& theFlagFileName, BackGnd *backGnd); 0102 0103 /** 0104 * Test if this is a neighbour of country 0105 * @param country The country to test if this one communicate with. 0106 * @return true if @ref country communicate with this; false otherwise. 0107 */ 0108 bool communicateWith(const Country *country) const; 0109 0110 /** 0111 * Returns the continent this country is in. 0112 * @return The continent this country is in. 0113 */ 0114 inline Continent* continent() {return m_continent;} 0115 0116 /** 0117 * Sets the continent this country is in. 0118 */ 0119 inline void setContinent(Continent* continent) {m_continent = continent;} 0120 0121 /** 0122 * Change the owner of this to player and update the number of countries for 0123 * previous and new owners. 0124 * @param player The new owner of this country. 0125 */ 0126 void owner(Player *player); 0127 0128 //@{ 0129 /** 0130 * return a pointer to the Player owner of this country. 0131 */ 0132 const Player* owner() const; 0133 Player* owner(); 0134 //@} 0135 0136 /** 0137 * Return the number of armies in this country 0138 */ 0139 unsigned int nbArmies() const; 0140 0141 /** 0142 * Change the number of armies to nb 0143 */ 0144 void nbArmies(unsigned int nb); 0145 0146 /** 0147 * Add nb armies. Defaults to 1. 0148 */ 0149 void incrNbArmies(unsigned int nb=1); 0150 0151 /** 0152 * Remove nb armies. Defaults to 1. 0153 */ 0154 void decrNbArmies(unsigned int nb=1); 0155 0156 /** 0157 * Return the name of the country 0158 */ 0159 const QString name() const; 0160 0161 /** 0162 * Return the localized name of the country 0163 */ 0164 const QString i18name() const; 0165 0166 const QPointF& anchorPoint() const; 0167 /** 0168 * Return a point inside the country territory around which are drawn the 0169 * fighters. 0170 */ 0171 const QPointF& centralPoint() const; 0172 0173 /** 0174 * Return the point where the flag is displayed 0175 */ 0176 const QPointF& pointFlag() const; 0177 0178 /** 0179 * Return the point where the cannons are displayed 0180 */ 0181 const QPointF& pointCannon() const; 0182 0183 /** 0184 * Return the point where the cavalrymen are displayed 0185 */ 0186 const QPointF& pointCavalry() const; 0187 0188 /** 0189 * Return the point where the infantrymen are displayed 0190 */ 0191 const QPointF& pointInfantry() const; 0192 0193 /** 0194 * Set the anchor point. 0195 */ 0196 void anchorPoint(const QPointF pt); 0197 0198 /** 0199 * Set the point guaranteed to be inside this country territory and around 0200 * which are drawn the fighters. 0201 */ 0202 void centralPoint(const QPointF pt); 0203 0204 /** 0205 * Set the point where the flag is displayed 0206 */ 0207 void pointFlag(const QPointF pt); 0208 0209 /** 0210 * Set the point where the cannons are displayed 0211 */ 0212 void pointCannon(const QPointF pt); 0213 0214 /** 0215 * Set the point where the cavalrymen are displayed 0216 */ 0217 void pointCavalry(const QPointF pt); 0218 0219 /** 0220 * Set the point where the infantrymen are displayed 0221 */ 0222 void pointInfantry(const QPointF pt); 0223 0224 /** 0225 * Return the list of cannon sprites 0226 */ 0227 AnimSpritesList< CannonSprite >& spritesCannons(); 0228 0229 /** 0230 * Return the list of Cavalrymen sprites 0231 */ 0232 AnimSpritesList< CavalrySprite >& spritesCavalry(); 0233 0234 /** 0235 * Return the list of Infantrymen sprites 0236 */ 0237 AnimSpritesList< InfantrySprite >& spritesInfantry(); 0238 0239 /** Sets the list of neighbour countries. */ 0240 void neighbours(const QList<Country*>& neighboursVect); 0241 0242 //@{ 0243 /** Returns the list of neighbour countries */ 0244 QList< Country* >& neighbours(); 0245 const QList< Country* >& neighbours() const; 0246 //@} 0247 void clearAllSprites(); 0248 0249 /** Returns the point for the given sprite, depending on its actual class */ 0250 const QPointF& pointFor(const AnimSprite* sprite); 0251 0252 /** 0253 * Saves a XML representation of the country for game saving purpose 0254 * @param xmlStream The stream to write on 0255 */ 0256 void saveXml(QTextStream& xmlStream); 0257 0258 /** 0259 * Transmit data about this country on the network, through the given 0260 * stream. 0261 */ 0262 void send(QDataStream& stream); 0263 0264 //@{ 0265 /** Accessors to this country's unique integer identifier. */ 0266 /* unsigned int id() const {return m_id;} 0267 unsigned int id() {return m_id;} 0268 void id(unsigned int id) {m_id = id;}*/ 0269 //@} 0270 0271 /** 0272 * Tests if there is at least one enemey adjacent to this country. 0273 * @return true if this country has an enemy neighbour and false otherwise. 0274 */ 0275 bool hasAdjacentEnemy(); 0276 0277 void highlight(const QColor& color = Qt::white, qreal opacity = 1.0); 0278 0279 void highlightAsAttacker(); 0280 0281 void highlightAsDefender(); 0282 0283 void clearHighlighting(); 0284 0285 bool isHighlightingLocked(); 0286 void releaseHighlightingLock(); 0287 0288 /** 0289 * Copy information of the real country in a country of the arena. 0290 * @param trueCountry is the real country 0291 */ 0292 void copyForArena(Country* trueCountry); 0293 0294 private: 0295 GameAutomaton* m_automaton; 0296 0297 /** 0298 * A pointer to the continent this country is in. 0299 */ 0300 Continent* m_continent; 0301 0302 /** 0303 * A pointer to the Player object that holds the country. 0 if it is not 0304 * affected. 0305 */ 0306 Player* m_belongsTo; 0307 0308 /** 0309 * A pointer to the sprite of the country's flag 0310 */ 0311 FlagSprite* m_flag; 0312 0313 /** 0314 * the number of armies held by the country (used to compute the number 0315 * of soldiers, horses and cannons 0316 */ 0317 unsigned int m_nbArmies; 0318 0319 /** 0320 * The name of the country 0321 */ 0322 QString m_name; 0323 0324 /** the array of neigbours of this country */ 0325 QList<Country*> m_neighbours; 0326 0327 QPointF m_anchorPoint; 0328 0329 /** 0330 * a point situated inside this country teritory such that any click on 0331 * this point (for example by an AI player) will be a click on this country 0332 */ 0333 QPointF m_centralPoint; 0334 0335 /** 0336 * the point of the upper left corner of the country's flag sprite 0337 */ 0338 QPointF m_pointFlag; 0339 0340 /** 0341 * the point of the upper left corner of the country's first cannon sprite 0342 * the subsequent cannons sprites are shifted by a fixed number of pixels 0343 */ 0344 QPointF m_pointCannon; 0345 0346 /** 0347 * the point of the upper left corner of the country's first cavalryman 0348 * sprite.The subsequent cavalrymen sprites are shifted by a fixed number 0349 * of pixels 0350 */ 0351 QPointF m_pointCavalry; 0352 0353 /** 0354 * the point of the upper left corner of the country's first soldier sprite 0355 * The subsequent soldier sprites are shifted by a fixed number of pixels 0356 */ 0357 QPointF m_pointInfantry; 0358 0359 /** 0360 * The list of the cannon sprites used to represent the armies of the 0361 * country 0362 */ 0363 AnimSpritesList< CannonSprite > m_spritesCannons; 0364 0365 /** 0366 * The list of the cavalrymen sprites used to represent the armies of the 0367 * country 0368 */ 0369 AnimSpritesList< CavalrySprite > m_spritesCavalry; 0370 0371 /** 0372 * The list of the soldiers sprites used to represent the armies of the 0373 * country 0374 */ 0375 AnimSpritesList< InfantrySprite > m_spritesInfantry; 0376 0377 QGraphicsSvgItem* m_highlighting; 0378 0379 QSvgRenderer* m_renderer; 0380 0381 bool m_highlighting_locked; 0382 0383 QGraphicsSimpleTextItem* m_nbArmiesItem; 0384 }; 0385 0386 QDataStream& operator>>(QDataStream& stream, Country* country); 0387 0388 } // closing namespace GameLogic 0389 0390 } // closing namespace Ksirk 0391 0392 #endif // KSIRK_COUNTRY_H 0393