initial commit, lordsawar source, slightly modified
[lordsawar] / src / QEnemyArmies.h
1 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2004 Andrea Paternesi
3 // Copyright (C) 2007, 2008, 2009 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 #ifndef QUEST_ENEMY_ARMIES_H
22 #define QUEST_ENEMY_ARMIES_H
23
24 #include <sigc++/trackable.h>
25
26 #include <list>
27 #include "Quest.h"
28 #include "army.h"
29 #include "player.h"
30
31
32 //! A Quest to kill a certain number of another Player's Army objects.
33 /**
34  * A hero that receives this quest has to kill a number of armies.  The Quest 
35  * is completed when this happens, or the quest is expired if enemy Player 
36  * dies.
37  */
38 class QuestEnemyArmies : public Quest, public sigc::trackable
39 {
40 public:
41     //! Default constructor.
42     /**
43      * Make a new kill-armies 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     QuestEnemyArmies(QuestsManager& q_mgr, guint32 hero);
49
50     // Construct from remote action.
51     QuestEnemyArmies(QuestsManager& q_mgr, guint32 hero,
52                      guint32 armies_to_kill, guint32 victim_player);
53
54     //! Loading constructor.
55     /**
56      * @param q_mgr   The quests manager to associate this quest with.
57      * @param helper  The opened saved-game file to load this quest from.
58      */
59     QuestEnemyArmies(QuestsManager& q_mgr, XML_Helper* helper);
60
61
62     // Get Methods
63
64     //! Return a description of how many armies have been killed so far.
65     std::string getProgress() const;
66
67     //! Return a queue of strings to show when the quest is compeleted.
68     void getSuccessMsg(std::queue<std::string>& msgs) const;
69
70     //! Return a queue of strings to show when the quest has expired.
71     void getExpiredMsg(std::queue<std::string>& msgs) const;
72
73     //! Returns the number of Army objects to be killed in this Quest.
74     guint32 getArmiesToKill() {return d_to_kill;}
75
76     //! Returns the enemy player whose Army objects are to be killed.
77     guint32 getVictimPlayerId() {return d_victim_player->getId();}
78
79
80     // Methods that operate on the class data but do not modify the class.
81
82     //! Saves the kill-armies quest data to an opened saved-game file.
83     bool save(XML_Helper* helper) const;
84
85
86     // Methods that need to be implemented from the superclass.
87
88     //! Callback for when an Army object is killed.
89     /**
90      * This method is used to account for the number armies killed by the
91      * Hero.
92      *
93      * @param army           A pointer to the Army object that has been
94      *                       killed.
95      * @param heroIsCulprit  Whether or not the Hero object responsible for
96      *                       this Quest was involved with the killing of
97      *                       the given Army object.
98      */
99     void armyDied(Army *army, bool heroIsCulprit);
100
101     //! Callback for when a City is defeated.
102     /**
103      * @note This method is not used.
104      */
105     void cityAction(City *city, CityDefeatedAction action, 
106                     bool heroIsCulprit, int gold);
107
108
109     // Static Methods
110
111     //! Returns whether or not this quest is impossible.
112     /**
113      * Scans all Player objects in the Playerlist to see if there is one 
114      * that is alive that isn't the neutral player.
115      *
116      * @note This method is static because it is executed before the
117      *       Quest is instantiated.  It is also called from within the
118      *       instantiated Quest.
119      *
120      * @param heroId  The Id of the Hero responsible for the kill-armies 
121      *                quest.
122      *
123      * @return Whether or not the quest is possible.
124      */
125     static bool isFeasible(guint32 heroId);
126
127 private:
128
129     //! Generate a description of the Quest.
130     void initDescription();
131
132     //! Recalculate the positions on the map of the target Army objects.
133     void update_targets();
134
135     //! The number of Army objects the Hero must kill to succeed.
136     guint32 d_to_kill;
137
138     //! The number of Army objects the Hero has already killed.
139     guint32 d_killed;
140
141     //! The victim player who the Hero is targeting Army objects of.
142     Player *d_victim_player;
143 };
144
145 #endif