File indexing completed on 2024-04-28 07:54:19

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 <QDataStream>
0024 #include <iostream>
0025 #include <QList>
0026 
0027 namespace KsirkSkinEditor
0028 {
0029 
0030 /**
0031   * This is a representation of a goal to be reached by a player.
0032   *
0033   * A goal can be a combination of a number of countries to conquier, some 
0034   * continents to conquier entirely or some players to eliminate.
0035   * @author Gael de Chalendar
0036   */
0037 class Goal
0038 {
0039 public:
0040   /**
0041     * The different kind of goals
0042     */
0043   enum GoalType {
0044     NoGoal,     /**< The goal is to conquer all the world. */
0045     GoalPlayer, /**< The goal is to eliminate one player. */
0046     Countries,  /**< The goal is to conquier a given number of countries. */
0047     Continents  /**< The goal is to conquier a few continents. */
0048   };
0049 
0050   
0051   /**
0052     * The different kind of goal displaying
0053     */
0054   enum DisplayType {
0055     GoalDesc = 1,   /**< The description of the goal is displayed. */
0056     GoalAdvance = 2 /**< The advance step. */
0057   };
0058   
0059   Goal();
0060   
0061   /** Copy constructor */
0062   Goal(const Goal& goal);
0063   
0064   /** Default destructor */
0065   ~Goal();
0066 
0067   //@{
0068   /** Accessors for the goal type */
0069   inline GoalType type() const {return m_type;}
0070   inline GoalType type() {return m_type;}
0071   inline void setType(GoalType type) {m_type = type;}
0072   //@}
0073 
0074   //@{
0075   /** Accessors for the goal description */
0076   inline const QString& description() const {return m_description;}
0077   inline QString& description() {return m_description;}
0078   inline void setDescription(const QString& desc) {m_description = desc;}
0079   //@}
0080 
0081   //@{
0082   /** Accessors for the number of countries to conquier to reach this goal */
0083   inline unsigned int nbCountries() const {return m_nbCountries;}
0084   inline unsigned int nbCountries() {return m_nbCountries;}
0085   inline void setNbCountries(unsigned int nb) {m_nbCountries = nb;}
0086   //@}
0087 
0088   //@{
0089   /** Accessors for the minimal number of armies to put on each country to 
0090     * reach this goal */
0091   inline unsigned int nbArmiesByCountry() const {return m_nbArmiesByCountry;}
0092   inline unsigned int nbArmiesByCountry() {return m_nbArmiesByCountry;}
0093   inline void setNbArmiesByCountry(unsigned int nb) {m_nbArmiesByCountry = nb;}
0094   //@}
0095 
0096   //@{
0097   /** Accessors for the list of continents to conquier to reach this goal */
0098   inline QList<QString>& continents() {return m_continents;}
0099   inline const QList<QString>& continents() const {return m_continents;}
0100   //@}
0101 
0102   //@{
0103   /** Accessors for the list of players to eliminate to reach this goal */
0104   inline QList<QString>& players() {return m_players;}
0105   inline const QList<QString>& players() const {return m_players;}
0106   //@}
0107 
0108   /**
0109     * Displays this goal in a message dialog
0110     * @param displayType the manner to display this goal: final goal or advance.
0111     */
0112   void show(int displayType = GoalDesc);
0113     
0114   
0115   /**
0116     * Saves a XML representation of the goal for game saving purpose
0117     * @param xmlStream The stream to write on
0118     */
0119   void saveXml(std::ostream& xmlStream) const;
0120   
0121   /**
0122     * Builds this goal's description.
0123     * @param displayType the manner to display this goal: final goal or advance.
0124     * @return a string containing this goal's description.
0125     */
0126   QString message(int displayType = GoalDesc) const;
0127 
0128   private:
0129 
0130   GoalType m_type;
0131   QString m_description;
0132   unsigned int m_nbCountries;
0133   unsigned int m_nbArmiesByCountry;
0134   QList<QString> m_continents;
0135   QList<QString> m_players;
0136 };
0137 
0138 QDataStream& operator<<(QDataStream& stream, const Goal& goal);
0139 QDataStream& operator>>(QDataStream& stream, Goal& goal);
0140 
0141 }
0142 
0143 #endif