1 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
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.
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.
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
17 #ifndef QUEST_CITY_OCCUPY_H
18 #define QUEST_CITY_OCCUPY_H
20 #include <sigc++/trackable.h>
28 //! A Quest where the Hero must occupy a City owned by another Player.
30 * A hero that receives this quest has to occupy 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 occupy the city.
34 class QuestCityOccupy : public Quest, public sigc::trackable
37 //! Default constructor.
39 * Make a new city occupation quest.
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.
44 QuestCityOccupy(QuestsManager& q_mgr, guint32 hero);
46 //! Loading constructor.
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.
51 QuestCityOccupy(QuestsManager& q_mgr, XML_Helper* helper);
53 // Construct from remote action.
54 QuestCityOccupy(QuestsManager& q_mgr, guint32 hero, guint32 target);
59 //! Return a description of how well the city occupation quest is going.
60 std::string getProgress() const;
62 //! Return a queue of strings to show when the quest is compeleted.
63 void getSuccessMsg(std::queue<std::string>& msgs) const;
65 //! Return a queue of strings to show when the quest has expired.
66 void getExpiredMsg(std::queue<std::string>& msgs) const;
68 //! Returns the id of the City object to be occupied.
69 guint32 getCityId() const {return d_city;}
72 // Methods that operate on the class data but do not modify the class.
74 //! Returns a pointer to the City object to be occupied.
75 City* getCity() const;
77 //! Saves the occupy quest data to an opened saved-game file.
78 bool save(XML_Helper* helper) const;
81 // Methods that need to be implemented from the superclass.
83 //! Callback for when an Army object is killed.
85 * @note This method is not used.
87 void armyDied(Army *a, bool heroIsCulprit);
89 //! Callback for when a City object is defeated.
91 * This method notifies the Quest that a City has fallen, and what the
92 * conquering action (pillage/sack/raze/occupy) was. It also notifies
93 * whether or not the hero responsible for this quest was involved in
94 * the conquering, and how much gold was taken as a result.
96 * If the city isn't occupied then the Quest is expired.
97 * If the city is occupied then the Quest is completed.
99 * @param city The City object that has been conquered.
100 * @param action What action was taken by the Player. See
101 * CityDefeatedAction for more information.
102 * @param heroIsCulprit Whether or not the Hero object associated with
103 * this Quest object is responsible for
104 * conquering the given City object.
105 * @param gold How many gold pieces were taken as a result
108 void cityAction(City *city, CityDefeatedAction action,
109 bool heroIsCulprit, int gold);
114 //! Returns whether or not this quest is impossible.
116 * Scans all City objects in the Citylist to see if there is one the
117 * active player can occupy.
119 * @note This method is static because it is executed before the
120 * Quest is instantiated. It is also called from within the
121 * instantiated Quest.
123 * @param heroId The Id of the Hero responsible for the occupy quest.
125 * @return Whether or not the quest is possible.
127 static bool isFeasible(guint32 heroId);
131 //! Make a quest description about the city that needs to be occupied.
132 void initDescription();
134 //! Return a pointer to a random city not owned by the given player.
136 * Find a city to occupy.
138 * Scan through all of the City objects in the Citylist for a city
139 * that is not owned by the given player or by neutral. Pick a random
142 * @param player The player whose City objects are exempt from being
143 * selected as a target for occupation.
145 * @return A pointer to a City object that can be occupied by the Hero.
146 * If no valid City objects are found, this method returns NULL.
148 static City* chooseToOccupy(Player *player);
150 //! The Id of the target City object to occupy.