initial commit, lordsawar source, slightly modified
[lordsawar] / src / ruin.h
1 // Copyright (C) 2001, 2003 Michael Bartl
2 // Copyright (C) 2002, 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef RUIN_H
21 #define RUIN_H
22
23 #define DEFAULT_RUIN_NAME  "Ruin"
24 #include <string>
25 #include <sigc++/trackable.h>
26 #include "NamedLocation.h"
27 #include "stack.h"
28 #include "Namable.h"
29
30 class Stack;
31 class Reward;
32 class Sage;
33
34 //! A ruin on the game map.
35 /** 
36  * A ruin is a simple feature on the map which contains an id, a flag whether 
37  * it has already been searched and optionally an occupant (called "keeper").
38  * If a ruin is searched, the player starts a fight with the keeper. If the
39  * player wins, the ruin becomes searched and the player gets a reward.
40  *
41  * Sometimes a ruin contains a sage which lets the player choose from a 
42  * variety of rewards.
43  *
44  * Sometimes a ruin is hidden to all players except one player.
45  */
46 class Ruin : public NamedLocation, public sigc::trackable
47 {
48     public:
49         //! The xml tag of this object in a saved-game file.
50         static std::string d_tag; 
51
52         //! The kind of ruin.
53         enum Type {
54           //! A normal ruin.
55           RUIN = 0, 
56           //! A stronghold ruin is a little stronger.
57           STRONGHOLD = 1
58         };
59
60         //! Default constructor.
61         /** 
62           * @param pos          The location of the ruin.
63           * @param width        The span of tiles that the ruin covers.
64           * @param name         The name of the ruin.
65           * @param occupant     The monster occupying the ruin.
66           * @param searched     Sets the searchedness flag of the ruin.
67           * @param hidden       Sets the hidden flag of the ruin.
68           * @param owner        Who can see this hidden ruin.
69           * @param sage         if this ruin contains a sage or not.
70           */
71         Ruin(Vector<int> pos, guint32 width, 
72              std::string name = DEFAULT_RUIN_NAME, int type = Ruin::RUIN, 
73              Stack* occupant = 0, bool searched = false, bool hidden = false, 
74              Player *owner = 0, bool sage = false);
75
76         //! Copy constructor.
77         Ruin(const Ruin&);
78
79         //! Alternative copying constructor that changes the ruin position.
80         Ruin(const Ruin&, Vector<int> pos);
81
82         //! Loading constructor.
83         /**
84          * @param helper  The opened saved-game file to load the ruin from.
85          */
86         Ruin(XML_Helper* helper, guint32 tile_width);
87
88         //!Destructor.
89         ~Ruin();
90
91
92         // Get Methods
93
94         //! Returns the type of the ruin.
95         int getType() const {return d_type;};
96
97         //! Return whether or not the ruin has been searched already.
98         bool isSearched() const {return d_searched;}
99
100         //! Returns the keeper that guards the ruin from Hero units.
101         Stack* getOccupant() const {return d_occupant;}
102
103         //! Returns whether or not this is a "hidden" ruin.
104         bool isHidden() const {return d_hidden;}
105
106         //! Returns whether or not this ruin has a sage.
107         bool hasSage() const {return d_sage;}
108
109         //! Returns the player that owns this hidden ruin.
110         /**
111          * When the ruin has been searched, the owner is the player whose
112          * hero searched it.
113          */
114         Player *getOwner() const {return d_owner;}
115
116         //! Returns the reward for this ruin.
117         Reward *getReward() const {return d_reward;}
118
119         //! Returns whether or not the ruin lacks a non-default name.
120         bool isUnnamed() const {return getName() == getDefaultName() ? true : false;};
121
122         // Set Methods
123
124         //! Sets the type of the ruin.
125         void setType(int type) {d_type = type;};
126
127         //! Change whether or not the ruin has been successfully searched.
128         void setSearched(bool searched) {d_searched = searched; 
129           d_reward = NULL;}
130         
131         //! Set the keeper of the ruin.
132         void setOccupant(Stack* occupant) {d_occupant = occupant;}
133         
134         //! Change the "hidden" flag of the ruin.
135         void setHidden (bool hidden) {d_hidden = hidden;}
136
137         //! Sets whether or not this ruin has a sage.
138         void setSage(bool sage) {d_sage = sage;}
139
140         //! Sets the player that owns this hidden ruin.
141         void setOwner(Player *owner) {d_owner = owner;}
142
143         //! Sets the reward for this ruin.
144         void setReward(Reward *r) {d_reward = r;}
145
146
147         // Methods that operate on class data and modify the class.
148
149         //! Put a random reward in this ruin.
150         /**
151          * @note This method does not remove an existing reward before putting
152          *       a new one in it.
153          */
154         void populateWithRandomReward();
155
156
157         // Methods that operate on class data and do not modify the class.
158         
159         //! Callback for loading the ruin data.
160         bool load(std::string tag, XML_Helper* helper);
161
162         //! Saves the ruin data to an opened saved-game file.
163         bool save(XML_Helper* helper) const;
164
165         //! Create a sage object (a list of rewards).
166         Sage* generateSage() const;
167
168         // Static Methods
169
170         //! Get the default name of any ruin.
171         static std::string getDefaultName() {return _(DEFAULT_RUIN_NAME);};
172
173         //! Convert a Ruin::Type enumerated value to a string.
174         static std::string ruinTypeToString(const Ruin::Type type);
175
176         //! Convert a string containing a Ruin::Type to an enumerated value.
177         static Ruin::Type ruinTypeFromString(const std::string str);
178
179     private:
180
181         // DATA
182
183         //! Whether or not the Ruin has already successfully been searched.
184         bool d_searched;
185
186         //! The type of the ruin.
187         guint32 d_type;
188
189         //! The keeper of the ruin.
190         /**
191          * The Hero unit fights this stack when it is searched.  The stack
192          * consists of a single Army unit that is cabable of defending ruins.
193          */
194         Stack* d_occupant;
195
196         //! Whether or not the ruin is a hidden ruin.
197         /**
198          * Hidden ruins are rewards.  Only a certain player can see the Ruin.
199          */
200         bool d_hidden;
201
202         //! The player who can see the hidden ruin.
203         /**
204          * Owning a ruin only makes sense if it is a hidden ruin.
205          * Only this player can see the hidden ruin, although other players
206          * may occupy the same tile.
207          */
208         Player *d_owner;
209
210         //! The ruin contains a sage.
211         /**
212          * A Sage offers the Hero the choice of many rewards.
213          */
214         bool d_sage;
215
216         //! The reward to give if the Hero is successful in beating the keeper.
217         Reward *d_reward;
218 };
219
220 #endif // RUIN_H