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