| [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 | */ | 
|---|
| [6417] | 28 |  | 
|---|
| [2261] | 29 | /** | 
|---|
| [7456] | 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" | 
|---|
| [3196] | 37 | #include "core/XMLPort.h" | 
|---|
| [7456] | 38 |  | 
|---|
|  | 39 | #include "Quest.h" | 
|---|
|  | 40 | #include "QuestDescription.h" | 
|---|
| [2261] | 41 | #include "QuestManager.h" | 
|---|
| [1992] | 42 |  | 
|---|
| [2662] | 43 | namespace orxonox | 
|---|
|  | 44 | { | 
|---|
| [9667] | 45 | RegisterClass(QuestHint); | 
|---|
| [1992] | 46 |  | 
|---|
| [2068] | 47 | /** | 
|---|
|  | 48 | @brief | 
|---|
| [2261] | 49 | Constructor. Registers the object. | 
|---|
| [2068] | 50 | */ | 
|---|
| [9667] | 51 | QuestHint::QuestHint(Context* context) : QuestItem(context) | 
|---|
| [2021] | 52 | { | 
|---|
| [2092] | 53 | RegisterObject(QuestHint); | 
|---|
| [2021] | 54 | } | 
|---|
| [2092] | 55 |  | 
|---|
| [1992] | 56 | /** | 
|---|
|  | 57 | @brief | 
|---|
|  | 58 | Destructor. | 
|---|
|  | 59 | */ | 
|---|
|  | 60 | QuestHint::~QuestHint() | 
|---|
|  | 61 | { | 
|---|
| [7163] | 62 | if(this->isRegistered()) | 
|---|
|  | 63 | QuestManager::getInstance().unregisterHint(this); | 
|---|
| [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 |  | 
|---|
| [7456] | 74 | QuestManager::getInstance().registerHint(this); // Registers the QuestHint with the QuestManager. | 
|---|
| [6417] | 75 |  | 
|---|
| [8858] | 76 | orxout(verbose, context::quests) << "New QuestHint {" << this->getId() << "} created." << 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. | 
|---|
|  | 85 | @return | 
|---|
| [2261] | 86 | Returns true if the QuestHint is active for the specified player. | 
|---|
| [1996] | 87 | */ | 
|---|
| [2261] | 88 | bool QuestHint::isActive(const PlayerInfo* player) const | 
|---|
| [1992] | 89 | { | 
|---|
| [11071] | 90 | if(player == nullptr) // If the player is nullptr, the Quest obviously can't be active. | 
|---|
| [2068] | 91 | return false; | 
|---|
| [2092] | 92 |  | 
|---|
| [7456] | 93 | // Find the player. | 
|---|
| [11071] | 94 | std::map<const PlayerInfo*, QuestHintStatus>::const_iterator it = this->playerStatus_.find(player); | 
|---|
| [7456] | 95 | if (it != this->playerStatus_.end()) // If the player is in the map. | 
|---|
| [11071] | 96 | return (it->second == QuestHintStatus::Active); | 
|---|
| [6417] | 97 |  | 
|---|
| [11071] | 98 | return false; | 
|---|
| [1992] | 99 | } | 
|---|
| [2092] | 100 |  | 
|---|
| [2021] | 101 | /** | 
|---|
|  | 102 | @brief | 
|---|
| [2068] | 103 | Activates a QuestHint for a given player. | 
|---|
| [2021] | 104 | @param player | 
|---|
| [2068] | 105 | The player. | 
|---|
| [2021] | 106 | @return | 
|---|
| [2068] | 107 | Returns true if the activation was successful, false if there were problems. | 
|---|
| [2021] | 108 | */ | 
|---|
| [2261] | 109 | bool QuestHint::setActive(PlayerInfo* player) | 
|---|
| [1992] | 110 | { | 
|---|
| [7456] | 111 | if(this->quest_->isActive(player)) // For a hint to get activated the quest must be active. | 
|---|
| [1992] | 112 | { | 
|---|
| [7456] | 113 | if(!(this->isActive(player)))  // If the hint is already active, activation is pointless. | 
|---|
| [2093] | 114 | { | 
|---|
| [3280] | 115 | this->playerStatus_[player] = QuestHintStatus::Active; | 
|---|
| [6417] | 116 |  | 
|---|
| [7403] | 117 | this->getDescription()->sendAddHintNotification(player); | 
|---|
| [2093] | 118 | return true; | 
|---|
|  | 119 | } | 
|---|
|  | 120 | else | 
|---|
|  | 121 | { | 
|---|
| [8858] | 122 | orxout(verbose, context::quests) << "An already active questHint was trying to get activated." << endl; | 
|---|
| [2068] | 123 | return false; | 
|---|
| [2093] | 124 | } | 
|---|
| [1992] | 125 | } | 
|---|
| [6417] | 126 |  | 
|---|
| [8858] | 127 | orxout(verbose, context::quests) << "A hint of a non-active quest was trying to get activated." << endl; | 
|---|
| [2093] | 128 | return false; | 
|---|
| [1992] | 129 | } | 
|---|
|  | 130 |  | 
|---|
| [2021] | 131 | /** | 
|---|
|  | 132 | @brief | 
|---|
| [2261] | 133 | Sets the Quest the QuestHint belongs to. | 
|---|
| [2021] | 134 | @param quest | 
|---|
| [2261] | 135 | The Quest to be set as Quest the QuestHint is attached to. | 
|---|
| [2021] | 136 | @return | 
|---|
| [2261] | 137 | Returns true if successful. | 
|---|
| [2021] | 138 | */ | 
|---|
| [2068] | 139 | bool QuestHint::setQuest(Quest* quest) | 
|---|
| [1992] | 140 | { | 
|---|
| [7552] | 141 | assert(quest); | 
|---|
| [2092] | 142 |  | 
|---|
| [1992] | 143 | this->quest_ = quest; | 
|---|
| [2068] | 144 | return true; | 
|---|
| [1992] | 145 | } | 
|---|
|  | 146 |  | 
|---|
|  | 147 | } | 
|---|