[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 | |
---|
[2261] | 29 | /** |
---|
[2779] | 30 | @file AddQuestHint.cc |
---|
[2662] | 31 | @brief Implementation of the AddQuestHint class. |
---|
[2261] | 32 | */ |
---|
| 33 | |
---|
[2105] | 34 | #include "OrxonoxStableHeaders.h" |
---|
| 35 | #include "AddQuestHint.h" |
---|
| 36 | |
---|
[1992] | 37 | #include "core/CoreIncludes.h" |
---|
[2068] | 38 | #include "util/Exception.h" |
---|
[2021] | 39 | |
---|
[2261] | 40 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
[2021] | 41 | #include "QuestManager.h" |
---|
[2081] | 42 | #include "QuestItem.h" |
---|
[2095] | 43 | #include "QuestHint.h" |
---|
[1992] | 44 | |
---|
[2662] | 45 | namespace orxonox |
---|
| 46 | { |
---|
[1992] | 47 | CreateFactory(AddQuestHint); |
---|
| 48 | |
---|
[2261] | 49 | /** |
---|
| 50 | @brief |
---|
| 51 | Constructor. Registers the object. |
---|
| 52 | */ |
---|
[2092] | 53 | AddQuestHint::AddQuestHint(BaseObject* creator) : QuestEffect(creator) |
---|
[2021] | 54 | { |
---|
[2092] | 55 | RegisterObject(AddQuestHint); |
---|
[2021] | 56 | } |
---|
[2092] | 57 | |
---|
[1992] | 58 | /** |
---|
| 59 | @brief |
---|
| 60 | Destructor. |
---|
| 61 | */ |
---|
| 62 | AddQuestHint::~AddQuestHint() |
---|
| 63 | { |
---|
| 64 | } |
---|
[2092] | 65 | |
---|
[2261] | 66 | /** |
---|
| 67 | @brief |
---|
| 68 | Method for creating a AddQuestHint object through XML. |
---|
| 69 | */ |
---|
[2076] | 70 | void AddQuestHint::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
| 72 | SUPER(AddQuestHint, XMLPort, xmlelement, mode); |
---|
[2092] | 73 | |
---|
[2076] | 74 | XMLPortParam(AddQuestHint, "hintId", setHintId, getHintId, xmlelement, mode); |
---|
[2261] | 75 | |
---|
| 76 | COUT(3) << "New AddQuestHint, with target QuestHint {" << this->getHintId() << "}, created." << std::endl; |
---|
[2076] | 77 | } |
---|
[1992] | 78 | |
---|
[2261] | 79 | /** |
---|
| 80 | @brief |
---|
| 81 | Sets the id of the QuestHint to be added to the player the QuestEffect is invoked on. |
---|
| 82 | @param id |
---|
| 83 | The QuestHint id. |
---|
| 84 | @param |
---|
| 85 | Returns true if successful. |
---|
| 86 | */ |
---|
| 87 | bool AddQuestHint::setHintId(const std::string & id) |
---|
[2081] | 88 | { |
---|
| 89 | if(!QuestItem::isId(id)) |
---|
| 90 | { |
---|
| 91 | COUT(2) << "Invalid id. QuestItem id {" << id << "} could not be set." << std::endl; |
---|
[2261] | 92 | return false; |
---|
[2081] | 93 | } |
---|
[2261] | 94 | |
---|
[2081] | 95 | this->hintId_ = id; |
---|
[2261] | 96 | return true; |
---|
[2081] | 97 | } |
---|
| 98 | |
---|
[1992] | 99 | /** |
---|
| 100 | @brief |
---|
[2261] | 101 | Invokes the QuestEffect. |
---|
[1992] | 102 | @param player |
---|
| 103 | The player. |
---|
[2068] | 104 | @return |
---|
[2261] | 105 | Returns true if the QuestEffect was successfully invoked. |
---|
[1992] | 106 | */ |
---|
[2261] | 107 | bool AddQuestHint::invoke(PlayerInfo* player) |
---|
[1992] | 108 | { |
---|
[2261] | 109 | if(player == NULL) //!< NULL-pointers are evil! |
---|
[2068] | 110 | { |
---|
| 111 | COUT(2) << "The input player is NULL." << std::endl; |
---|
| 112 | return false; |
---|
| 113 | } |
---|
| 114 | |
---|
[2261] | 115 | COUT(3) << "AddQuestHint on player: " << player << " ." << std::endl; |
---|
| 116 | |
---|
[2068] | 117 | try |
---|
| 118 | { |
---|
[2785] | 119 | QuestHint* hint = QuestManager::getInstance().findHint(this->hintId_); |
---|
[2261] | 120 | if(hint == NULL || !hint->setActive(player)) |
---|
[2093] | 121 | { |
---|
| 122 | return false; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | catch(const Exception& e) |
---|
| 126 | { |
---|
| 127 | COUT(2) << e.getFullDescription() << std::endl; |
---|
| 128 | return false; |
---|
| 129 | } |
---|
[2092] | 130 | |
---|
[2662] | 131 | COUT(3) << "QuestHint {" << this->getHintId() << "} successfully added to player: " << player << " ." << std::endl; |
---|
[2093] | 132 | return true; |
---|
[2092] | 133 | |
---|
[1992] | 134 | } |
---|
| 135 | } |
---|