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_ENEMY_ARMYTYPES_H
20 #define QUEST_ENEMY_ARMYTYPES_H
21 
22 #include <sigc++/trackable.h>
23 
24 #include <list>
25 #include "Quest.h"
26 #include "vector.h"
27 
28 class Army;
29 class Player;
30 
31 //! A Quest to kill one army of another Player's Army objects.
32 /**
33  * A hero that receives this quest has to kill a single instance of a
34  * particular king of Army object (e.g. Ghosts).  The Quest is completed when
35  * this happens, and does not expire.
36  * This quest presumes that all players have the same Armyset.
37  */
38 class QuestEnemyArmytype : public Quest, public sigc::trackable
39 {
40 public:
41     //! Default constructor.
42     /**
43      * Make a new kill-armytype quest.
44      *
45      * @param q_mgr  The quests manager to associate this quest with.
46      * @param hero   The Id of the Hero who is responsible for the quest.
47      */
48     QuestEnemyArmytype(QuestsManager& q_mgr, guint32 hero);
49 
50     //! Destructor.
~QuestEnemyArmytype()51     ~QuestEnemyArmytype() {};
52 
53     //! Loading constructor.
54     /**
55      * @param q_mgr   The quests manager to associate this quest with.
56      * @param helper  The opened saved-game file to load this quest from.
57      */
58     QuestEnemyArmytype(QuestsManager& q_mgr, XML_Helper* helper);
59 
60     // Construct from remote action.
61     QuestEnemyArmytype(QuestsManager& q_mgr, guint32 hero, guint32 type_to_kill);
62 
63     // Get Methods
64 
65     //! Return a description of how the quest is going.
66     Glib::ustring getProgress() const;
67 
68     //! Return a queue of strings to show when the quest is compeleted.
69     void getSuccessMsg(std::queue<Glib::ustring>& msgs) const;
70 
71     //! Return a queue of strings to show when the quest has expired.
72     void getExpiredMsg(std::queue<Glib::ustring>& msgs) const;
73 
74     //! Returns the target army type the Hero must kill.
75     /**
76      * @return The index of the Army protoype in the Armyset belonging to
77      *         the Player who owns the Hero responsible for this Quest.
78      */
getArmytypeToKill()79     guint32 getArmytypeToKill() {return d_type_to_kill;}
80 
81 
82     // Methods that opreate on the class data and do not modify the class.
83 
84     //! Saves the kill-armytype quest data to an opened saved-game file.
85     bool save(XML_Helper* helper) const;
86 
87 
88     // Methods that need to be implemented from the superclass.
89 
90     //!Callback when an Army object is killed.
91     /**
92      * This method is used to check when the Hero kills the correct army
93      * type.
94      *
95      * @param army           A pointer to the Army object that has been
96      *                       killed.
97      * @param heroIsCulprit  Whether or not the Hero object responsible for
98      *                       this Quest was involved with the killing of
99      *                       the given Army object.
100      */
101     void armyDied(Army *a, bool heroIsCulprit);
102 
103     //! Callback for when a City is defeated.
104     /**
105      * @note This method is not used.
106      */
107     void cityAction(City *c, CityDefeatedAction action,
108 		    bool heroIsCulprit, int gold);
109 
110 
111     // Static Methods
112 
113     //! Returns whether or not this quest is impossible.
114     /**
115      * Scans all of the Stack objects for each Player in the Playerlist
116      * for Army objects that are awardable.  Pick a random one.
117      *
118      * @param heroId  The Id of the Hero responsible for the kill-armytype
119      *                quest.
120      *
121      * @return Whether or not the quest is possible.
122      */
123     static bool isFeasible(guint32 heroId);
124 
125 private:
126 
127     //! Generate a description of the Quest.
128     void initDescription();
129 
130     //! The kind of Army object the Hero must kill to succeed.
131     /**
132      * The index of the Army protoype in the Armyset belonging to the
133      * Player who owns the Hero responsible for this Quest.
134      */
135     guint32 d_type_to_kill;
136 };
137 
138 int getVictimArmytype(Player *p, std::list<Vector<int> >&targets);
139 
140 #endif
141