1 // Copyright (C) 2007, 2008, 2009, 2014 Ben Asselstine 2 // 3 // This program is free software; you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation; either version 3 of the License, or 6 // (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Library General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program; if not, write to the Free Software 15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 // 02110-1301, USA. 17 18 #pragma once 19 #ifndef QUEST_CITY_OCCUPY_H 20 #define QUEST_CITY_OCCUPY_H 21 22 #include <sigc++/trackable.h> 23 24 #include <list> 25 #include "Quest.h" 26 27 class City; 28 class XML_Helper; 29 30 //! A Quest where the Hero must occupy a City owned by another Player. 31 /** 32 * A hero that receives this quest has to occupy a specific city to fulfill 33 * it. The Quest is completed when this happens, but the quest is expired if 34 * the user conquers the correct city but forgets to occupy the city. 35 */ 36 class QuestCityOccupy : public Quest, public sigc::trackable 37 { 38 public: 39 //! Default constructor. 40 /** 41 * Make a new city occupation quest. 42 * 43 * @param q_mgr The quests manager to associate this quest with. 44 * @param hero The Id of the Hero who is responsible for the quest. 45 */ 46 QuestCityOccupy(QuestsManager& q_mgr, guint32 hero); 47 48 //! Destructor. ~QuestCityOccupy()49 ~QuestCityOccupy() {}; 50 51 //! Loading constructor. 52 /** 53 * @param q_mgr The quests manager to associate this quest with. 54 * @param helper The opened saved-game file to load this quest from. 55 */ 56 QuestCityOccupy(QuestsManager& q_mgr, XML_Helper* helper); 57 58 // Construct from remote action. 59 QuestCityOccupy(QuestsManager& q_mgr, guint32 hero, guint32 target); 60 61 62 // Get Methods 63 64 //! Return a description of how well the city occupation quest is going. 65 Glib::ustring getProgress() const; 66 67 //! Return a queue of strings to show when the quest is compeleted. 68 void getSuccessMsg(std::queue<Glib::ustring>& msgs) const; 69 70 //! Return a queue of strings to show when the quest has expired. 71 void getExpiredMsg(std::queue<Glib::ustring>& msgs) const; 72 73 //! Returns the id of the City object to be occupied. getCityId()74 guint32 getCityId() const {return d_city;} 75 76 77 // Methods that operate on the class data but do not modify the class. 78 79 //! Returns a pointer to the City object to be occupied. 80 City* getCity() const; 81 82 //! Saves the occupy quest data to an opened saved-game file. 83 bool save(XML_Helper* helper) const; 84 85 86 // Methods that need to be implemented from the superclass. 87 88 //! Callback for when an Army object is killed. 89 /** 90 * @note This method is not used. 91 */ 92 void armyDied(Army *a, bool heroIsCulprit); 93 94 //! Callback for when a City object is defeated. 95 /** 96 * This method notifies the Quest that a City has fallen, and what the 97 * conquering action (pillage/sack/raze/occupy) was. It also notifies 98 * whether or not the hero responsible for this quest was involved in 99 * the conquering, and how much gold was taken as a result. 100 * 101 * If the city isn't occupied then the Quest is expired. 102 * If the city is occupied then the Quest is completed. 103 * 104 * @param city The City object that has been conquered. 105 * @param action What action was taken by the Player. See 106 * CityDefeatedAction for more information. 107 * @param heroIsCulprit Whether or not the Hero object associated with 108 * this Quest object is responsible for 109 * conquering the given City object. 110 * @param gold How many gold pieces were taken as a result 111 * of the action. 112 */ 113 void cityAction(City *city, CityDefeatedAction action, 114 bool heroIsCulprit, int gold); 115 116 117 // Static Methods 118 119 //! Returns whether or not this quest is impossible. 120 /** 121 * Scans all City objects in the Citylist to see if there is one the 122 * active player can occupy. 123 * 124 * @note This method is static because it is executed before the 125 * Quest is instantiated. It is also called from within the 126 * instantiated Quest. 127 * 128 * @param heroId The Id of the Hero responsible for the occupy quest. 129 * 130 * @return Whether or not the quest is possible. 131 */ 132 static bool isFeasible(guint32 heroId); 133 134 private: 135 136 //! Make a quest description about the city that needs to be occupied. 137 void initDescription(); 138 139 //! Return a pointer to a random city not owned by the given player. 140 /** 141 * Find a city to occupy. 142 * 143 * Scan through all of the City objects in the Citylist for a city 144 * that is not owned by the given player or by neutral. Pick a random 145 * one and return it. 146 * 147 * @param player The player whose City objects are exempt from being 148 * selected as a target for occupation. 149 * 150 * @return A pointer to a City object that can be occupied by the Hero. 151 * If no valid City objects are found, this method returns NULL. 152 */ 153 static City* chooseToOccupy(Player *player); 154 155 //! The Id of the target City object to occupy. 156 guint32 d_city; 157 }; 158 159 #endif 160