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