[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 | */ |
---|
[2261] | 28 | |
---|
| 29 | /** |
---|
[2911] | 30 | @file QuestHint.cc |
---|
[2662] | 31 | @brief Implementation of the QuestHint class. |
---|
[2261] | 32 | */ |
---|
[1992] | 33 | |
---|
[2105] | 34 | #include "QuestHint.h" |
---|
| 35 | |
---|
[1992] | 36 | #include "core/CoreIncludes.h" |
---|
[2068] | 37 | #include "util/Exception.h" |
---|
[2021] | 38 | |
---|
[2261] | 39 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
| 40 | #include "QuestManager.h" |
---|
[2662] | 41 | #include "QuestDescription.h" |
---|
[2021] | 42 | #include "Quest.h" |
---|
[1992] | 43 | |
---|
[2662] | 44 | namespace orxonox |
---|
| 45 | { |
---|
[1992] | 46 | CreateFactory(QuestHint); |
---|
| 47 | |
---|
[2068] | 48 | /** |
---|
| 49 | @brief |
---|
[2261] | 50 | Constructor. Registers the object. |
---|
[2068] | 51 | */ |
---|
[2092] | 52 | QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator) |
---|
[2021] | 53 | { |
---|
[2092] | 54 | RegisterObject(QuestHint); |
---|
[2021] | 55 | } |
---|
[2092] | 56 | |
---|
[1992] | 57 | /** |
---|
| 58 | @brief |
---|
| 59 | Destructor. |
---|
| 60 | */ |
---|
| 61 | QuestHint::~QuestHint() |
---|
| 62 | { |
---|
[2092] | 63 | |
---|
[1992] | 64 | } |
---|
[2092] | 65 | |
---|
[2261] | 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 | |
---|
[2911] | 74 | QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager. |
---|
[2261] | 75 | |
---|
[2093] | 76 | COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl; |
---|
[2068] | 77 | } |
---|
| 78 | |
---|
[2092] | 79 | |
---|
[1996] | 80 | /** |
---|
| 81 | @brief |
---|
[2261] | 82 | Checks whether the QuestHint is active for a specific player. |
---|
[1996] | 83 | @param player |
---|
| 84 | The player. |
---|
[2068] | 85 | @throws |
---|
| 86 | Throws an Argument Exception if the input Player-pointer is NULL. |
---|
[1996] | 87 | @return |
---|
[2261] | 88 | Returns true if the QuestHint is active for the specified player. |
---|
[1996] | 89 | */ |
---|
[2261] | 90 | bool QuestHint::isActive(const PlayerInfo* player) const |
---|
[1992] | 91 | { |
---|
[2261] | 92 | if(player == NULL) //!< NULL-Pointers are ugly! |
---|
[2068] | 93 | { |
---|
[2261] | 94 | ThrowException(Argument, "The input PlayerInfo* is NULL."); |
---|
[2068] | 95 | return false; |
---|
| 96 | } |
---|
[2092] | 97 | |
---|
[2261] | 98 | //! Find the player. |
---|
| 99 | std::map<const PlayerInfo*, questHintStatus::Enum>::const_iterator it = this->playerStatus_.find(player); |
---|
| 100 | if (it != this->playerStatus_.end()) //!< If the player is in the map. |
---|
[2093] | 101 | { |
---|
| 102 | return it->second; |
---|
| 103 | } |
---|
[2261] | 104 | |
---|
[2093] | 105 | return questStatus::inactive; |
---|
[1992] | 106 | } |
---|
[2092] | 107 | |
---|
[2021] | 108 | /** |
---|
| 109 | @brief |
---|
[2068] | 110 | Activates a QuestHint for a given player. |
---|
[2021] | 111 | @param player |
---|
[2068] | 112 | The player. |
---|
[2021] | 113 | @return |
---|
[2068] | 114 | Returns true if the activation was successful, false if there were problems. |
---|
[2021] | 115 | */ |
---|
[2261] | 116 | bool QuestHint::setActive(PlayerInfo* player) |
---|
[1992] | 117 | { |
---|
[2261] | 118 | if(this->quest_->isActive(player)) //!< For a hint to get activated the quest must be active. |
---|
[1992] | 119 | { |
---|
[2261] | 120 | if(!(this->isActive(player))) //!< If the hint is already active, activation is pointless. |
---|
[2093] | 121 | { |
---|
| 122 | this->playerStatus_[player] = questHintStatus::active; |
---|
[2662] | 123 | |
---|
| 124 | this->getDescription()->sendAddHintNotification(); |
---|
[2093] | 125 | return true; |
---|
| 126 | } |
---|
| 127 | else |
---|
| 128 | { |
---|
[2068] | 129 | COUT(2) << "An already active questHint was trying to get activated." << std::endl; |
---|
| 130 | return false; |
---|
[2093] | 131 | } |
---|
[1992] | 132 | } |
---|
[2261] | 133 | |
---|
[2093] | 134 | COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; |
---|
| 135 | return false; |
---|
[1992] | 136 | } |
---|
| 137 | |
---|
[2021] | 138 | /** |
---|
| 139 | @brief |
---|
[2261] | 140 | Sets the Quest the QuestHint belongs to. |
---|
[2021] | 141 | @param quest |
---|
[2261] | 142 | The Quest to be set as Quest the QuestHint is attached to. |
---|
[2021] | 143 | @return |
---|
[2261] | 144 | Returns true if successful. |
---|
[2021] | 145 | */ |
---|
[2068] | 146 | bool QuestHint::setQuest(Quest* quest) |
---|
[1992] | 147 | { |
---|
[2261] | 148 | if(quest == NULL) //!< NULL-Pointer. Again..? |
---|
[2068] | 149 | { |
---|
| 150 | COUT(2) << "The input Quest* is NULL." << std::endl; |
---|
| 151 | return false; |
---|
| 152 | } |
---|
[2092] | 153 | |
---|
[1992] | 154 | this->quest_ = quest; |
---|
[2068] | 155 | return true; |
---|
[1992] | 156 | } |
---|
| 157 | |
---|
| 158 | } |
---|