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_SACK_H 20 #define QUEST_CITY_SACK_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 sack a City owned by another Player. 31 /** 32 * A hero that receives this quest has to sack 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 sack the city. 35 * 36 * Sacking involves cashing in all of the Army production bases that the City 37 * offers, except for the weakest one. 38 */ 39 class QuestCitySack : public Quest, public sigc::trackable 40 { 41 public: 42 //! Default constructor. 43 /** 44 * Make a new city sacking quest. 45 * 46 * @param q_mgr The quests manager to associate this quest with. 47 * @param hero The Id of the Hero who is responsible for the quest. 48 */ 49 QuestCitySack(QuestsManager& q_mgr, guint32 hero); 50 51 //! Destructor. ~QuestCitySack()52 ~QuestCitySack() {}; 53 54 //! Loading constructor. 55 /** 56 * @param q_mgr The quests manager to associate this quest with. 57 * @param helper The opened saved-game file to load this quest from. 58 */ 59 QuestCitySack(QuestsManager& q_mgr, XML_Helper* helper); 60 61 // Construct from remote action. 62 QuestCitySack(QuestsManager& q_mgr, guint32 hero, guint32 target); 63 64 // Get Methods 65 66 //! Return a description of how well the city sacking quest is going. 67 Glib::ustring getProgress() const; 68 69 //! Return a queue of strings to show when the quest is compeleted. 70 void getSuccessMsg(std::queue<Glib::ustring>& msgs) const; 71 72 //! Return a queue of strings to show when the quest has expired. 73 void getExpiredMsg(std::queue<Glib::ustring>& msgs) const; 74 75 //! Returns the id of the City object to be sacked. getCityId()76 guint32 getCityId() const {return d_city;} 77 78 79 // Methods that operate on the class data but do not modify the class. 80 81 //! Saves the sacking quest data to an opened saved-game file. 82 bool save(XML_Helper* helper) const; 83 84 //! Returns a pointer to the City object to be sacked. 85 City* getCity() const; 86 87 88 // Methods that need to be implemented from the superclass. 89 90 //! Callback for when an Army object is killed. 91 /** 92 * @note This method is not used. 93 */ 94 void armyDied(Army *a, bool heroIsCulprit); 95 96 //! Callback for when a City object is defeated. 97 /** 98 * This method notifies the Quest that a City has fallen, and what the 99 * conquering action (pillage/sack/raze/occupy) was. It also notifies 100 * whether or not the hero responsible for this quest was involved in 101 * the conquering, and how much gold was taken as a result. 102 * 103 * If the city isn't sacked then the Quest is expired. 104 * If the city is sacked then the Quest is completed. 105 * 106 * @param city The City object that has been conquered. 107 * @param action What action was taken by the Player. See 108 * CityDefeatedAction for more information. 109 * @param heroIsCulprit Whether or not the Hero object associated with 110 * this Quest object is responsible for 111 * conquering the given City object. 112 * @param gold How many gold pieces were taken as a result 113 * of the action. 114 */ 115 void cityAction(City *city, CityDefeatedAction action, 116 bool heroIsCulprit, int gold); 117 118 119 // Static Methods 120 121 //! Returns whether or not this quest is impossible. 122 /** 123 * Scans all City objects in the Citylist to see if there is one the 124 * active player can sack. 125 * 126 * @note This method is static because it is executed before the 127 * Quest is instantiated. It is also called from within the 128 * instantiated Quest. 129 * 130 * @param heroId The Id of the Hero responsible for the sacking quest. 131 * 132 * @return Whether or not the quest is possible. 133 */ 134 static bool isFeasible(guint32 heroId); 135 136 private: 137 138 //! Make a quest description about the city that needs to be sacked. 139 void initDescription(); 140 141 //! Return a pointer to a random city not owned by the given player. 142 /** 143 * Find a city to sack. 144 * 145 * Scan through all of the City objects in the Citylist for a city 146 * that is not owned by the given player or by neutral. Pick a random 147 * one that has more than 1 Army production base and return it. 148 * 149 * @param player The player whose City objects are exempt from being 150 * selected as a target for sacking. 151 * 152 * @return A pointer to a City object that can be sacked by the Hero. 153 * If no valid City objects are found, this method returns NULL. 154 */ 155 static City* chooseToSack(Player *p); 156 157 //! The Id of the target City object to sack. 158 guint32 d_city; 159 }; 160 161 #endif 162