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