1 /* This file is part of KsirK. 2 Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr> 3 4 KsirK is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public 6 License as published by the Free Software Foundation, either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 02110-1301, USA 18 */ 19 20 #ifndef KSIRK_GAMELOGICGOAL_H 21 #define KSIRK_GAMELOGICGOAL_H 22 23 // #include <set> 24 #include <QTextStream> 25 26 #include <QDataStream> 27 28 namespace Ksirk { 29 30 namespace GameLogic { 31 32 class GameAutomaton; 33 class Player; 34 35 /** 36 * This is a representation of a goal to be reached by a player. 37 * 38 * A goal can be a combination of a number of countries to conquier, some 39 * continents to conquier entirely or some players to eliminate. 40 * @author Gael de Chalendar 41 */ 42 class Goal 43 { 44 public: 45 /** 46 * The different kind of goals 47 */ 48 enum GoalType { 49 NoGoal, /**< The goal is to conquer all the world. */ 50 GoalPlayer, /**< The goal is to eliminate one player. */ 51 Countries, /**< The goal is to conquier a given number of countries. */ 52 Continents /**< The goal is to conquier a few continents. */ 53 }; 54 55 56 /** 57 * The different kind of goal displaying 58 */ 59 enum DisplayType { 60 GoalDesc = 1, /**< The description of the goal is displayed. */ 61 GoalAdvance = 2 /**< The advance step. */ 62 }; 63 64 explicit Goal(GameAutomaton* automaton); 65 66 /** Copy constructor */ 67 Goal(const Goal& goal) = default; 68 Goal &operator=(const Goal& goal) = default; 69 70 /** Default destructor */ 71 ~Goal(); 72 73 //@{ 74 /** Accessors for the goal type */ type()75 inline GoalType type() const {return m_type;} type()76 inline GoalType type() {return m_type;} type(GoalType type)77 inline void type(GoalType type) {m_type = type;} 78 //@} 79 80 //@{ 81 /** Accessors for the goal description */ description()82 inline const QString& description() const {return m_description;} description()83 inline QString& description() {return m_description;} description(const QString & desc)84 inline void description(const QString& desc) {m_description = desc;} 85 //@} 86 87 //@{ 88 /** Accessors for the number of countries to conquier to reach this goal */ nbCountries()89 inline unsigned int nbCountries() const {return m_nbCountries;} nbCountries()90 inline unsigned int nbCountries() {return m_nbCountries;} nbCountries(unsigned int nb)91 inline void nbCountries(unsigned int nb) {m_nbCountries = nb;} 92 //@} 93 94 //@{ 95 /** Accessors for the minimal number of armies to put on each country to 96 * reach this goal */ nbArmiesByCountry()97 inline unsigned int nbArmiesByCountry() const {return m_nbArmiesByCountry;} nbArmiesByCountry()98 inline unsigned int nbArmiesByCountry() {return m_nbArmiesByCountry;} nbArmiesByCountry(unsigned int nb)99 inline void nbArmiesByCountry(unsigned int nb) {m_nbArmiesByCountry = nb;} 100 //@} 101 102 //@{ 103 /** Accessors for the list of continents to conquier to reach this goal */ continents()104 inline QList<QString>& continents() {return m_continents;} continents()105 inline const QList<QString>& continents() const {return m_continents;} 106 //@} 107 108 //@{ 109 /** Accessors for the list of players to eliminate to reach this goal */ players()110 inline QList<QString>& players() {return m_players;} players()111 inline const QList<QString>& players() const {return m_players;} 112 //@} 113 114 //@{ 115 /** Accessors for the player concerned by this goal */ player()116 inline const Player* player() const {return m_player;} player()117 inline Player* player() {return m_player;} player(Player * p)118 inline void player(Player* p) {m_player = p;} 119 //@} 120 121 /** 122 * Test if this goal is reached for the given player 123 * @param player The player to test this goal for 124 * @return true if this goal is reached for the given player ; false otherwise. 125 */ 126 bool checkFor(const Player* player) const; 127 128 /** 129 * Test if countries conditions of this goal are reached for the given player 130 * @param player The player to test this goal countries conditions for 131 * @return true if the countries conditions of this goal are reached for the 132 * given player ; false otherwise. 133 */ 134 bool checkCountriesFor(const Player* player) const; 135 136 /** 137 * Test if continents conditions of this goal are reached for the given player 138 * @param player The player to test this goal continents conditions for 139 * @return true if the continents conditions of this goal are reached for the 140 * given player ; false otherwise. 141 */ 142 bool checkContinentsFor(const Player* player) const; 143 144 /** 145 * Displays this goal in a message dialog 146 * @param displayType the manner to display this goal: final goal or advance. 147 */ 148 void show(int displayType = GoalDesc); 149 150 151 /** 152 * Saves a XML representation of the goal for game saving purpose 153 * @param xmlStream The stream to write on 154 */ 155 void saveXml(QTextStream& xmlStream) const; 156 157 /** 158 * Builds this goal's description. 159 * @param displayType the manner to display this goal: final goal (default) or advance. 160 * @return a string containing this goal's description. 161 */ 162 QString message(int displayType = GoalDesc) const; 163 164 GameAutomaton* m_automaton; 165 private: 166 /** Default constructor */ 167 Goal(); 168 169 GoalType m_type; 170 QString m_description; 171 unsigned int m_nbCountries; 172 unsigned int m_nbArmiesByCountry; 173 QList<QString> m_continents; 174 QList<QString> m_players; 175 Player* m_player; 176 }; 177 178 QDataStream& operator<<(QDataStream& stream, const Goal& goal); 179 QDataStream& operator>>(QDataStream& stream, Goal& goal); 180 181 } 182 183 } 184 185 #endif 186