[1992] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Damian 'Mozork' Frick |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
[2146] | 28 | |
---|
| 29 | /** |
---|
| 30 | @file QuestHint.cc |
---|
| 31 | @brief |
---|
| 32 | Implementation of the QuestHint class. |
---|
| 33 | */ |
---|
[1992] | 34 | |
---|
[2105] | 35 | #include "OrxonoxStableHeaders.h" |
---|
| 36 | #include "QuestHint.h" |
---|
| 37 | |
---|
[1992] | 38 | #include "core/CoreIncludes.h" |
---|
[2068] | 39 | #include "util/Exception.h" |
---|
[2021] | 40 | |
---|
[2205] | 41 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
[2021] | 42 | #include "Quest.h" |
---|
[1992] | 43 | |
---|
| 44 | namespace orxonox { |
---|
| 45 | |
---|
| 46 | CreateFactory(QuestHint); |
---|
| 47 | |
---|
[2068] | 48 | /** |
---|
| 49 | @brief |
---|
[2159] | 50 | Constructor. Registers the object. |
---|
[2068] | 51 | */ |
---|
[2092] | 52 | QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator) |
---|
[2021] | 53 | { |
---|
[2146] | 54 | RegisterObject(QuestHint); |
---|
| 55 | } |
---|
[2092] | 56 | |
---|
[1992] | 57 | /** |
---|
| 58 | @brief |
---|
| 59 | Destructor. |
---|
| 60 | */ |
---|
| 61 | QuestHint::~QuestHint() |
---|
| 62 | { |
---|
[2092] | 63 | |
---|
[1992] | 64 | } |
---|
[2092] | 65 | |
---|
[2146] | 66 | /** |
---|
| 67 | @brief |
---|
| 68 | Method for creating a QuestHint object through XML. |
---|
| 69 | */ |
---|
[2068] | 70 | void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
[2093] | 72 | SUPER(QuestHint, XMLPort, xmlelement, mode); |
---|
[2092] | 73 | |
---|
[2093] | 74 | COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl; |
---|
[2068] | 75 | } |
---|
| 76 | |
---|
[2092] | 77 | |
---|
[1996] | 78 | /** |
---|
| 79 | @brief |
---|
[2191] | 80 | Checks whether the QuestHint is active for a specific player. |
---|
[1996] | 81 | @param player |
---|
| 82 | The player. |
---|
[2068] | 83 | @throws |
---|
| 84 | Throws an Argument Exception if the input Player-pointer is NULL. |
---|
[1996] | 85 | @return |
---|
[2191] | 86 | Returns true if the QuestHint is active for the specified player. |
---|
[1996] | 87 | */ |
---|
[2205] | 88 | bool QuestHint::isActive(const PlayerInfo* player) const |
---|
[1992] | 89 | { |
---|
[2146] | 90 | if(player == NULL) //!< NULL-Pointers are ugly! |
---|
[2068] | 91 | { |
---|
[2205] | 92 | ThrowException(Argument, "The input PlayerInfo* is NULL."); |
---|
[2068] | 93 | return false; |
---|
| 94 | } |
---|
[2092] | 95 | |
---|
[2146] | 96 | //! Find the player. |
---|
[2205] | 97 | std::map<const PlayerInfo*, questHintStatus::Enum>::const_iterator it = this->playerStatus_.find(player); |
---|
[2146] | 98 | if (it != this->playerStatus_.end()) //!< If the player is in the map. |
---|
[2093] | 99 | { |
---|
| 100 | return it->second; |
---|
| 101 | } |
---|
[2146] | 102 | |
---|
[2093] | 103 | return questStatus::inactive; |
---|
[1992] | 104 | } |
---|
[2092] | 105 | |
---|
[2021] | 106 | /** |
---|
| 107 | @brief |
---|
[2068] | 108 | Activates a QuestHint for a given player. |
---|
[2021] | 109 | @param player |
---|
[2068] | 110 | The player. |
---|
[2021] | 111 | @return |
---|
[2068] | 112 | Returns true if the activation was successful, false if there were problems. |
---|
[2021] | 113 | */ |
---|
[2205] | 114 | bool QuestHint::setActive(PlayerInfo* player) |
---|
[1992] | 115 | { |
---|
[2146] | 116 | if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active. |
---|
[1992] | 117 | { |
---|
[2146] | 118 | if(!(this->isActive(player))) //!< If the hint is already active, activation is pointless. |
---|
[2093] | 119 | { |
---|
| 120 | this->playerStatus_[player] = questHintStatus::active; |
---|
| 121 | return true; |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
[2068] | 125 | COUT(2) << "An already active questHint was trying to get activated." << std::endl; |
---|
| 126 | return false; |
---|
[2093] | 127 | } |
---|
[1992] | 128 | } |
---|
[2146] | 129 | |
---|
[2093] | 130 | COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; |
---|
| 131 | return false; |
---|
[1992] | 132 | } |
---|
| 133 | |
---|
[2021] | 134 | /** |
---|
| 135 | @brief |
---|
[2191] | 136 | Sets the Quest the QuestHint belongs to. |
---|
[2021] | 137 | @param quest |
---|
[2191] | 138 | The Quest to be set as Quest the QuestHint is attached to. |
---|
[2021] | 139 | @return |
---|
[2146] | 140 | Returns true if successful. |
---|
[2021] | 141 | */ |
---|
[2068] | 142 | bool QuestHint::setQuest(Quest* quest) |
---|
[1992] | 143 | { |
---|
[2146] | 144 | if(quest == NULL) //!< NULL-Pointer. Again..? |
---|
[2068] | 145 | { |
---|
| 146 | COUT(2) << "The input Quest* is NULL." << std::endl; |
---|
| 147 | return false; |
---|
| 148 | } |
---|
[2092] | 149 | |
---|
[1992] | 150 | this->quest_ = quest; |
---|
[2068] | 151 | return true; |
---|
[1992] | 152 | } |
---|
| 153 | |
---|
| 154 | } |
---|