1 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2004 Andrea Paternesi
3 // Copyright (C) 2007, 2008, 2009, 2014 Ben Asselstine
4 // Copyright (C) 2008 Ole Laursen
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 //  02110-1301, USA.
20 
21 #pragma once
22 #ifndef QUEST_ENEMY_ARMIES_H
23 #define QUEST_ENEMY_ARMIES_H
24 
25 #include <sigc++/trackable.h>
26 
27 #include <list>
28 #include "Quest.h"
29 
30 class Army;
31 class Player;
32 
33 //! A Quest to kill a certain number of another Player's Army objects.
34 /**
35  * A hero that receives this quest has to kill a number of armies.  The Quest
36  * is completed when this happens, or the quest is expired if enemy Player
37  * dies.
38  */
39 class QuestEnemyArmies : public Quest, public sigc::trackable
40 {
41 public:
42     //! Default constructor.
43     /**
44      * Make a new kill-armies 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     QuestEnemyArmies(QuestsManager& q_mgr, guint32 hero);
50 
51     // Construct from remote action.
52     QuestEnemyArmies(QuestsManager& q_mgr, guint32 hero,
53 		     guint32 armies_to_kill, guint32 victim_player);
54 
55     //! Destructor.
~QuestEnemyArmies()56     ~QuestEnemyArmies() {};
57 
58     //! Loading constructor.
59     /**
60      * @param q_mgr   The quests manager to associate this quest with.
61      * @param helper  The opened saved-game file to load this quest from.
62      */
63     QuestEnemyArmies(QuestsManager& q_mgr, XML_Helper* helper);
64 
65 
66     // Get Methods
67 
68     //! Return a description of how many armies have been killed so far.
69     Glib::ustring getProgress() const;
70 
71     //! Return a queue of strings to show when the quest is compeleted.
72     void getSuccessMsg(std::queue<Glib::ustring>& msgs) const;
73 
74     //! Return a queue of strings to show when the quest has expired.
75     void getExpiredMsg(std::queue<Glib::ustring>& msgs) const;
76 
77     //! Returns the number of Army objects to be killed in this Quest.
getArmiesToKill()78     guint32 getArmiesToKill() {return d_to_kill;}
79 
80     //! Returns the enemy player whose Army objects are to be killed.
81     guint32 getVictimPlayerId();
82 
83     // Methods that operate on the class data but do not modify the class.
84 
85     //! Saves the kill-armies quest data to an opened saved-game file.
86     bool save(XML_Helper* helper) const;
87 
88 
89     // Methods that need to be implemented from the superclass.
90 
91     //! Callback for when an Army object is killed.
92     /**
93      * This method is used to account for the number armies killed by the
94      * Hero.
95      *
96      * @param army           A pointer to the Army object that has been
97      *                       killed.
98      * @param heroIsCulprit  Whether or not the Hero object responsible for
99      *                       this Quest was involved with the killing of
100      *                       the given Army object.
101      */
102     void armyDied(Army *army, bool heroIsCulprit);
103 
104     //! Callback for when a City is defeated.
105     /**
106      * @note This method is not used.
107      */
108     void cityAction(City *city, CityDefeatedAction action,
109 		    bool heroIsCulprit, int gold);
110 
111 
112     // Static Methods
113 
114     //! Returns whether or not this quest is impossible.
115     /**
116      * Scans all Player objects in the Playerlist to see if there is one
117      * that is alive that isn't the neutral player.
118      *
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.
122      *
123      * @param heroId  The Id of the Hero responsible for the kill-armies
124      *                quest.
125      *
126      * @return Whether or not the quest is possible.
127      */
128     static bool isFeasible(guint32 heroId);
129 
130 private:
131 
132     //! Generate a description of the Quest.
133     void initDescription();
134 
135     //! Recalculate the positions on the map of the target Army objects.
136     void update_targets();
137 
138     //! The number of Army objects the Hero must kill to succeed.
139     guint32 d_to_kill;
140 
141     //! The number of Army objects the Hero has already killed.
142     guint32 d_killed;
143 
144     //! The victim player who the Hero is targeting Army objects of.
145     Player *d_victim_player;
146 };
147 
148 Player* getVictimPlayer(Player *p);
149 
150 #endif
151