File indexing completed on 2024-10-06 06:48:48

0001 /* This file is part of KsirK.
0002    Copyright (C) 2005-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_GAMELOGICGOAL_H
0021 #define KSIRK_GAMELOGICGOAL_H
0022 
0023 // #include <set>
0024 #include <QTextStream>
0025 #include <QString>
0026 #include <QList>
0027 
0028 #include <QDataStream>
0029 
0030 namespace Ksirk {
0031 
0032 namespace GameLogic {
0033 
0034 class GameAutomaton;
0035 class Player;
0036 
0037 /**
0038   * This is a representation of a goal to be reached by a player.
0039   *
0040   * A goal can be a combination of a number of countries to conquier, some 
0041   * continents to conquier entirely or some players to eliminate.
0042   * @author Gael de Chalendar
0043   */
0044 class Goal
0045 {
0046 public:
0047   /**
0048     * The different kind of goals
0049     */
0050   enum GoalType {
0051     NoGoal,     /**< The goal is to conquer all the world. */
0052     GoalPlayer, /**< The goal is to eliminate one player. */
0053     Countries,  /**< The goal is to conquier a given number of countries. */
0054     Continents  /**< The goal is to conquier a few continents. */
0055   };
0056 
0057   
0058   /**
0059     * The different kind of goal displaying
0060     */
0061   enum DisplayType {
0062     GoalDesc = 1,   /**< The description of the goal is displayed. */
0063     GoalAdvance = 2 /**< The advance step. */
0064   };
0065   
0066   explicit Goal(GameAutomaton* automaton);
0067   
0068   /** Copy constructor */
0069   Goal(const Goal& goal) = default;
0070   Goal &operator=(const Goal& goal) = default;
0071   
0072   /** Default destructor */
0073   ~Goal();
0074   
0075   //@{
0076   /** Accessors for the goal type */
0077   inline GoalType type() const {return m_type;}
0078   inline GoalType type() {return m_type;}
0079   inline void type(GoalType type) {m_type = type;}
0080   //@}
0081 
0082   //@{
0083   /** Accessors for the goal description */
0084   inline const QString& description() const {return m_description;}
0085   inline QString& description() {return m_description;}
0086   inline void description(const QString& desc) {m_description = desc;}
0087   //@}
0088 
0089   //@{
0090   /** Accessors for the number of countries to conquier to reach this goal */
0091   inline unsigned int nbCountries() const {return m_nbCountries;}
0092   inline unsigned int nbCountries() {return m_nbCountries;}
0093   inline void nbCountries(unsigned int nb) {m_nbCountries = nb;}
0094   //@}
0095 
0096   //@{
0097   /** Accessors for the minimal number of armies to put on each country to 
0098     * reach this goal */
0099   inline unsigned int nbArmiesByCountry() const {return m_nbArmiesByCountry;}
0100   inline unsigned int nbArmiesByCountry() {return m_nbArmiesByCountry;}
0101   inline void nbArmiesByCountry(unsigned int nb) {m_nbArmiesByCountry = nb;}
0102   //@}
0103 
0104   //@{
0105   /** Accessors for the list of continents to conquier to reach this goal */
0106   inline QList<QString>& continents() {return m_continents;}
0107   inline const QList<QString>& continents() const {return m_continents;}
0108   //@}
0109 
0110   //@{
0111   /** Accessors for the list of players to eliminate to reach this goal */
0112   inline QList<QString>& players() {return m_players;}
0113   inline const QList<QString>& players() const {return m_players;}
0114   //@}
0115 
0116   //@{
0117   /** Accessors for the player concerned by this goal */
0118   inline const Player* player() const {return m_player;}
0119   inline Player* player() {return m_player;}
0120   inline void player(Player*  p) {m_player = p;}
0121   //@}
0122 
0123   /** 
0124     * Test if this goal is reached for the given player
0125     * @param player The player to test this goal for
0126     * @return true if this goal is reached for the given player ; false otherwise.
0127     */
0128   bool checkFor(const Player* player) const;
0129   
0130   /** 
0131     * Test if countries conditions of this goal are reached for the given player
0132     * @param player The player to test this goal countries conditions for
0133     * @return true if the countries conditions of this goal are reached for the 
0134     * given player ; false otherwise.
0135     */
0136   bool checkCountriesFor(const Player* player) const;
0137 
0138   /** 
0139     * Test if continents conditions of this goal are reached for the given player
0140     * @param player The player to test this goal continents conditions for
0141     * @return true if the continents conditions of this goal are reached for the 
0142     * given player ; false otherwise.
0143     */
0144   bool checkContinentsFor(const Player* player) const;
0145 
0146   /**
0147     * Displays this goal in a message dialog
0148     * @param displayType the manner to display this goal: final goal or advance.
0149     */
0150   void show(int displayType = GoalDesc);
0151     
0152   
0153   /**
0154     * Saves a XML representation of the goal for game saving purpose
0155     * @param xmlStream The stream to write on
0156     */
0157   void saveXml(QTextStream& xmlStream) const;
0158   
0159   /**
0160     * Builds this goal's description.
0161     * @param displayType the manner to display this goal: final goal (default) or advance.
0162     * @return a string containing this goal's description.
0163     */
0164   QString message(int displayType = GoalDesc) const;
0165 
0166   GameAutomaton* m_automaton;
0167   private:
0168     /** Default constructor */
0169   Goal();
0170 
0171   GoalType m_type;
0172   QString m_description;
0173   unsigned int m_nbCountries;
0174   unsigned int m_nbArmiesByCountry;
0175   QList<QString> m_continents;
0176   QList<QString> m_players;
0177   Player* m_player;
0178 };
0179 
0180 QDataStream& operator<<(QDataStream& stream, const Goal& goal);
0181 QDataStream& operator>>(QDataStream& stream, Goal& goal);
0182 
0183 }
0184 
0185 }
0186 
0187 #endif