[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 | */ |
---|
| 28 | |
---|
[2105] | 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "QuestHint.h" |
---|
| 31 | |
---|
[1992] | 32 | #include "core/CoreIncludes.h" |
---|
[2068] | 33 | #include "util/Exception.h" |
---|
[2021] | 34 | |
---|
| 35 | #include "Quest.h" |
---|
[1992] | 36 | |
---|
| 37 | namespace orxonox { |
---|
| 38 | |
---|
| 39 | CreateFactory(QuestHint); |
---|
| 40 | |
---|
[2068] | 41 | /** |
---|
| 42 | @brief |
---|
| 43 | Constructor. |
---|
| 44 | */ |
---|
[2092] | 45 | QuestHint::QuestHint(BaseObject* creator) : QuestItem(creator) |
---|
[2021] | 46 | { |
---|
[2092] | 47 | RegisterObject(QuestHint); |
---|
| 48 | |
---|
[2068] | 49 | this->initialize(); |
---|
[2021] | 50 | } |
---|
[2092] | 51 | |
---|
[1992] | 52 | /** |
---|
| 53 | @brief |
---|
| 54 | Destructor. |
---|
| 55 | */ |
---|
| 56 | QuestHint::~QuestHint() |
---|
| 57 | { |
---|
[2092] | 58 | |
---|
[1992] | 59 | } |
---|
[2092] | 60 | |
---|
[2068] | 61 | void QuestHint::initialize(void) |
---|
| 62 | { |
---|
| 63 | RegisterObject(QuestHint); |
---|
| 64 | } |
---|
[2092] | 65 | |
---|
[2068] | 66 | void QuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 67 | { |
---|
[2093] | 68 | SUPER(QuestHint, XMLPort, xmlelement, mode); |
---|
[2092] | 69 | |
---|
[2093] | 70 | COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl; |
---|
[2068] | 71 | } |
---|
| 72 | |
---|
[2092] | 73 | |
---|
[1996] | 74 | /** |
---|
| 75 | @brief |
---|
| 76 | Checks whether the hint is active for a specific player. |
---|
| 77 | @param player |
---|
| 78 | The player. |
---|
[2068] | 79 | @throws |
---|
| 80 | Throws an Argument Exception if the input Player-pointer is NULL. |
---|
[1996] | 81 | @return |
---|
[2068] | 82 | Returns true if the hint is active for the specified player. |
---|
[1996] | 83 | */ |
---|
[2021] | 84 | bool QuestHint::isActive(Player* player) |
---|
[1992] | 85 | { |
---|
[2068] | 86 | if(player == NULL) |
---|
| 87 | { |
---|
| 88 | ThrowException(Argument, "The input Player* is NULL."); |
---|
| 89 | return false; |
---|
| 90 | } |
---|
[2092] | 91 | |
---|
[2021] | 92 | std::map<Player*, questHintStatus::Enum>::iterator it = this->playerStatus_.find(player); |
---|
[2093] | 93 | if (it != this->playerStatus_.end()) |
---|
| 94 | { |
---|
| 95 | return it->second; |
---|
| 96 | } |
---|
| 97 | return questStatus::inactive; |
---|
[1992] | 98 | } |
---|
[2092] | 99 | |
---|
[2021] | 100 | /** |
---|
| 101 | @brief |
---|
[2068] | 102 | Activates a QuestHint for a given player. |
---|
[2021] | 103 | @param player |
---|
[2068] | 104 | The player. |
---|
[2021] | 105 | @return |
---|
[2068] | 106 | Returns true if the activation was successful, false if there were problems. |
---|
[2021] | 107 | */ |
---|
| 108 | bool QuestHint::activate(Player* player) |
---|
[1992] | 109 | { |
---|
[2068] | 110 | if(this->quest_->isActive(player)) |
---|
[1992] | 111 | { |
---|
[2093] | 112 | if(!(this->isActive(player))) |
---|
| 113 | { |
---|
| 114 | this->playerStatus_[player] = questHintStatus::active; |
---|
| 115 | return true; |
---|
| 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
[2068] | 119 | COUT(2) << "An already active questHint was trying to get activated." << std::endl; |
---|
| 120 | return false; |
---|
[2093] | 121 | } |
---|
[1992] | 122 | } |
---|
[2093] | 123 | COUT(2) << "A hint of a non-active quest was trying to get activated." << std::endl; |
---|
| 124 | return false; |
---|
[1992] | 125 | } |
---|
| 126 | |
---|
[2021] | 127 | /** |
---|
| 128 | @brief |
---|
[2068] | 129 | Sets the quest the QuestHitn belongs to. |
---|
[2021] | 130 | @param quest |
---|
| 131 | @return |
---|
| 132 | */ |
---|
[2068] | 133 | bool QuestHint::setQuest(Quest* quest) |
---|
[1992] | 134 | { |
---|
[2068] | 135 | if(quest == NULL) |
---|
| 136 | { |
---|
| 137 | COUT(2) << "The input Quest* is NULL." << std::endl; |
---|
| 138 | return false; |
---|
| 139 | } |
---|
[2092] | 140 | |
---|
[1992] | 141 | this->quest_ = quest; |
---|
[2068] | 142 | return true; |
---|
[1992] | 143 | } |
---|
| 144 | |
---|
| 145 | } |
---|