1 // Copyright (C) 2001, 2003 Michael Bartl
2 // Copyright (C) 2002, 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
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.
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.
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
23 #define DEFAULT_RUIN_NAME "Ruin"
25 #include <sigc++/trackable.h>
26 #include "NamedLocation.h"
34 //! A ruin on the game map.
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.
41 * Sometimes a ruin contains a sage which lets the player choose from a
44 * Sometimes a ruin is hidden to all players except one player.
46 class Ruin : public NamedLocation, public sigc::trackable
49 //! The xml tag of this object in a saved-game file.
50 static std::string d_tag;
56 //! A stronghold ruin is a little stronger.
60 //! Default constructor.
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.
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);
79 //! Alternative copying constructor that changes the ruin position.
80 Ruin(const Ruin&, Vector<int> pos);
82 //! Loading constructor.
84 * @param helper The opened saved-game file to load the ruin from.
86 Ruin(XML_Helper* helper, guint32 tile_width);
94 //! Returns the type of the ruin.
95 int getType() const {return d_type;};
97 //! Return whether or not the ruin has been searched already.
98 bool isSearched() const {return d_searched;}
100 //! Returns the keeper that guards the ruin from Hero units.
101 Stack* getOccupant() const {return d_occupant;}
103 //! Returns whether or not this is a "hidden" ruin.
104 bool isHidden() const {return d_hidden;}
106 //! Returns whether or not this ruin has a sage.
107 bool hasSage() const {return d_sage;}
109 //! Returns the player that owns this hidden ruin.
111 * When the ruin has been searched, the owner is the player whose
114 Player *getOwner() const {return d_owner;}
116 //! Returns the reward for this ruin.
117 Reward *getReward() const {return d_reward;}
119 //! Returns whether or not the ruin lacks a non-default name.
120 bool isUnnamed() const {return getName() == getDefaultName() ? true : false;};
124 //! Sets the type of the ruin.
125 void setType(int type) {d_type = type;};
127 //! Change whether or not the ruin has been successfully searched.
128 void setSearched(bool searched) {d_searched = searched;
131 //! Set the keeper of the ruin.
132 void setOccupant(Stack* occupant) {d_occupant = occupant;}
134 //! Change the "hidden" flag of the ruin.
135 void setHidden (bool hidden) {d_hidden = hidden;}
137 //! Sets whether or not this ruin has a sage.
138 void setSage(bool sage) {d_sage = sage;}
140 //! Sets the player that owns this hidden ruin.
141 void setOwner(Player *owner) {d_owner = owner;}
143 //! Sets the reward for this ruin.
144 void setReward(Reward *r) {d_reward = r;}
147 // Methods that operate on class data and modify the class.
149 //! Put a random reward in this ruin.
151 * @note This method does not remove an existing reward before putting
154 void populateWithRandomReward();
157 // Methods that operate on class data and do not modify the class.
159 //! Callback for loading the ruin data.
160 bool load(std::string tag, XML_Helper* helper);
162 //! Saves the ruin data to an opened saved-game file.
163 bool save(XML_Helper* helper) const;
165 //! Create a sage object (a list of rewards).
166 Sage* generateSage() const;
170 //! Get the default name of any ruin.
171 static std::string getDefaultName() {return _(DEFAULT_RUIN_NAME);};
173 //! Convert a Ruin::Type enumerated value to a string.
174 static std::string ruinTypeToString(const Ruin::Type type);
176 //! Convert a string containing a Ruin::Type to an enumerated value.
177 static Ruin::Type ruinTypeFromString(const std::string str);
183 //! Whether or not the Ruin has already successfully been searched.
186 //! The type of the ruin.
189 //! The keeper of the ruin.
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.
196 //! Whether or not the ruin is a hidden ruin.
198 * Hidden ruins are rewards. Only a certain player can see the Ruin.
202 //! The player who can see the hidden ruin.
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.
210 //! The ruin contains a sage.
212 * A Sage offers the Hero the choice of many rewards.
216 //! The reward to give if the Hero is successful in beating the keeper.