1 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2007, 2008 Ben Asselstine
3 // Copyright (C) 2008 Ole Laursen
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
32 //! A Hero is an Army unit capable of carrying items, going on quests and more.
34 * The Hero class is just like the Army class except that the Hero gets
35 * it's name, and gender set, and it's Army:Stat statistics are augmented by
36 * Item objects that are carried in a d_backpack.
38 * Heroes emerge in a City usually along with some powerful allies for a
39 * certain amount of gold pieces.
41 * Heroes are special because they can get a new Quest from a Temple, and
42 * search Ruin objects. They can pick up and drop Item objects, and can
43 * also plant standards into the ground.
45 * Heroes are also unique in that they can increase in experience levels.
47 class Hero : public Army
51 //! The xml tag of this object in a saved-game file.
52 static std::string d_tag;
54 //! The different genders a Hero unit can have.
56 * The purpose of this enumeration is to show the correct
57 * recruitment picture for Hero units when they emerge in a
58 * City, and the Player has to decide if they want it or not.
61 //! The hero has no gender (Not used).
65 //! The hero is female.
70 * Copies the prototype hero and creates a hero from it.
72 //! Default constructor.
73 Hero(const HeroProto& a);
76 * This performs a deep copy, including the Hero's items.
82 * @param helper The opened saved-file to read the Hero from.
84 //! Load a Hero from an opened saved-game file.
85 Hero(XML_Helper* helper);
93 //! Return the name of this hero.
94 virtual std::string getName() const {return d_name;};
96 //! Return that this object is a hero.
97 bool isHero() const {return true;};
99 //! Return the gender of the hero.
100 guint32 getGender() const {return d_gender;}
103 * Returns a stat of the hero. See Army::Stat, and Army::getStat.
105 * If modified is set to false, return the "raw", i.e. inherent
106 * value of the hero. Otherwise, all items are checked for a
109 guint32 getStat(Army::Stat stat, bool modified = true) const;
111 //! Returns the backpack of the hero.
112 Backpack* getBackpack() {return d_backpack;}
117 void setName(std::string name) {d_name = name;};
119 //! Set the gender of the hero.
120 void setGender(Gender gender){d_gender = gender;}
123 // Methods that operate on class data and do not modify the class.
125 //! Saves the Hero to a saved-game file.
126 bool save(XML_Helper* helper) const;
128 //! Is this hero on a quest?
129 bool hasQuest() const;
131 //! Return the natural command of the hero.
133 * Natural command is used for bonus calculations during a Fight.
135 * @return A number that is added to the strength to other Army and
136 * Hero units in the Stack.
138 guint32 calculateNaturalCommand();
143 //! Convert a Hero::Gender string to an enumerated value.
144 static Hero::Gender genderFromString(const std::string str);
146 //! Convert a Hero::Gender enumerated value to a string.
147 static std::string genderToString(const Hero::Gender gender);
150 * Increase the Hero unit's level, and increase one of three stats;
151 * Stat::STRENGTH, Stat::MOVES, or Stat::SIGHT.
153 * @param stat The stat to increase.
155 * @return How much the statistic increases or -1 upon error
156 * (e.g. because the XP is not enough).
158 //! Increase the Army's level, and increase a given stat.
159 int gainLevel(Stat stat);
162 * Calculate how much a stat is increased because the Hero unit
163 * has increased it's level.
165 * @param stat One of Stat::STRENGTH, Stat::MOVES, or Stat::SIGHT.
167 * @return The new value of the stat after it is increased.
169 //! Return how much the stat would be boosted by gaining a level.
170 int computeLevelGain(Stat stat) const;
172 //! Checks whether or not the Hero unit can advance a level.
173 bool canGainLevel() const;
175 //! Returns how many experience points the next level requires.
176 guint32 getXpNeededForNextLevel() const;
180 //! Callback for loading the backpack from a saved-game file.
181 bool loadBackpack(std::string tag, XML_Helper* helper);
183 //! The hero's backpack that holds any number of Item objects.
184 Backpack *d_backpack;
186 //! The name of the hero.
189 //! Gender of the hero
190 Hero::Gender d_gender;