/***************************************************************************
country.h - description
-------------------
begin : Wed Jul 18 2001
copyright : (C) 2001 by Gaël de Chalendar
email : Gael.de.Chalendar@libertysurf.fr
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#define KDE_NO_COMPAT
#ifndef COUNTRY_H
#define COUNTRY_H
#include "animsprite.h"
#include "animspriteslist.h"
#include "player.h"
#include
#include
#include
#include
class AnimSprite;
class AnimSpritesList;
class BackGnd;
class Player;
/**
* Each country of the map is represented by a Country object. It has a name,
* a point for its flag and points for its canon, horse, etc.
* Also, it stores pointers to the objects that represent its owner and the
* sprites of its flag and its armies.
*/
class Country : QObject
{
Q_OBJECT
public:
/**
* The data used to construct Country object are stored in the ONU
* @arg theName : the name of the country
* @arg points : this array stores the number of points that defines the
* frontier of the country and the coordinates of these points
* @arg number : the unique numerical id of the country
*/
// Country(QString theName, int points[], int number);
Country(const QString& theName,
const QPoint& flagPoint, const QPoint& cannonPoint, const QPoint& cavalryPoint,
const QPoint& infantryPoint);
~Country();
/**
* Removes the sprites (flag and soldiers), the owner, etc.
* The sprites ared deleted.
*/
void reset(void);
/**
* Ask each of the sprites to paint themselves
*/
void paint(void);
/**
* Creates the sprites necessary to disblay the armies of the country.
* Eventually removes previously existing sprites.
*/
void addArmies(BackGnd *backGnd);
/**
* Creates the sprite of the contry's flag. Eventually removes a previously
* existing sprite.
*/
void setFlag(const QString& theFlagFileName, BackGnd *backGnd);
/**
* Test if point is in the country. Uses the fact that each country is
* composed of one or more convex parts. So, a point inside the country is
* inside one of these parts. A point is inside a part if, for each linear
* borderline, the point is in the same half plane than the end point of
* the next borderline.
*/
// bool isIn(const QPoint &point);
/**
* Test if this is a neighbour of country
*/
bool communicateWith(const Country *country) const;
/**
* Change the owner of this to player
*/
void setOwner(Player *player);
/**
* return a pointer to the Player owner of this
*/
const Player * getOwner() const;
Player * getOwner();
/**
* Return the number of armies in this country
*/
int getNbArmies(void) const;
/**
* Return the number of armies that has been added during the last
* armies movement
*/
int getNbAddedArmies(void);
/**
* Change the number of armies to nb
*/
void setNbArmies(int nb);
/**
* Change the number of armies that has been added during the last
* armies movement to nb
*/
void setNbAddedArmies(int nb);
/**
* Add nb armies. Defaults to 1.
*/
void incrNbArmies(int nb=1);
/**
* Add nb armies to the number of armies that has been added during the
* last armies movement. Defaults to 1.
*/
void incrNbAddedArmies(int nb=1);
/**
* Remove nb armies. Defaults to 1.
*/
void decrNbArmies(int nb=1);
/**
* Remove nb armies to the number of armies that has been added during the
* last armies movement. Defaults to 1.
*/
void decrNbAddedArmies(int nb=1);
/**
* Return the name of the country
*/
const QString getName(void) const;
/**
* Return the point where the flag is displayed
*/
QPoint getPointFlag(void) const;
/**
* Return the point where the cannons are displayed
*/
QPoint getPointCannon(void);
/**
* Return the point where the cavalrymen are displayed
*/
QPoint getPointCavalry(void);
/**
* Return the point where the infantrymen are displayed
*/
QPoint getPointInfantry(void);
/**
* Set the point where the flag is displayed
*/
void setPointFlag(QPoint pt);
/**
* Set the point where the cannons are displayed
*/
void setPointCannon(QPoint pt);
/**
* Set the point where the cavalrymen are displayed
*/
void setPointCavalry(QPoint pt);
/**
* Set the point where the infantrymen are displayed
*/
void setPointInfantry(QPoint pt);
/**
* Return the list of cannon sprites
*/
AnimSpritesList *getSpritesCannons();
/**
* Return the list of Cavalrymen sprites
*/
AnimSpritesList *getSpritesCavalry();
/**
* Return the list of Infantrymen sprites
*/
AnimSpritesList *getSpritesInfantry();
/** No descriptions */
void setNeighbours(QPtrVector& neighboursVect);
/** No descriptions */
QPtrVector< Country >& getNeighbours(void);
/** No descriptions */
const QPtrVector< Country >& getNeighbours(void) const;
private:
/**
* This static member is a string that stores the adjacence mattrix of
* the countries. The (x,y) cell ( character number 45*(x-1)+(y-1) )
* value is 0 if country number x is not a neigbour of country number
* y ; 1 if countries numbers x and y are neighbours and 2 if is the
* same country. So, the 2s are on the diagonal but also elsewhere for
* countries made of several adjacent convex parts.
*/
// static QString ; //[45*45 + 1];
/**
* A pointer to the Player object that holds the country. 0 if it is not
* affected.
*/
Player* belongsTo;
/**
* This string is the line of the FrontiersTable mattrix that correspond to
* the current country/
*/
// QString communicateWithTab;
/**
* A pointer to the sprite of the country's flag
*/
AnimSprite *flag;
/**
* The number of points defining the frontiers of the country
*/
unsigned int nbPoints;
/**
* the number of armies held by the country (used to compute the number
* of soldiers, horses and cannons
*/
int nbArmies;
/**
* the number of armies added after the capture of the country or during an
* armies move. It must stay positive as one cannot remove more armies than
* he has added
*/
int nbArmiesAdded;
/**
* The identifiaction number of the country. Used during construction and
* to access the neighbours.
*/
// int num;
/**
* The name of the country
*/
QString name;
/** the array of neigbours of this country */
QPtrVector neighbours;
/**
* pointsArray stores the points that define the frontier of the country
* It is used to test if any point is inside the country or not
*/
// PointsArray *pointsArray;
/**
* the point of the upper left corner of the country's flag sprite
*/
QPoint pointFlag;
/**
* the point of the upper left corner of the country's first cannon sprite
* the subsequent cannons sprites are shifted by a fixed number of pixels
*/
QPoint pointCannon;
/**
* the point of the upper left corner of the country's first cavalryman
* sprite.The subsequent cavalrymen sprites are shifted by a fixed number
* of pixels
*/
QPoint pointCavalry;
/**
* the point of the upper left corner of the country's first soldier sprite
* The subsequent soldier sprites are shifted by a fixed number of pixels
*/
QPoint pointInfantry;
/**
* The list of the cannon sprites used to represent the armies of the
* country
*/
AnimSpritesList *spritesCannons;
/**
* The list of the cavalrymen sprites used to represent the armies of the
* country
*/
AnimSpritesList *spritesCavalry;
/**
* The list of the soldiers sprites used to represent the armies of the
* country
*/
AnimSpritesList *spritesInfantry;
/**
* The sameHalfPlane function allows to test if point is in the same
* half plane than the point number n3 in the points array compared
* to the line defined by the points numbers n1 and n2.
* This function is an helper function for isIn()
*/
// bool sameHalfPlane(int n1, int n2, int n3, const QPoint &point);
};
#endif // COUNTRY_H
Generated by: gael on noirdes.limsi.u-psud.fr on Fri Jan 3 17:03:38 2003, using kdoc 2.0a53. |