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