[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 | |
---|
| 29 | #include "core/CoreIncludes.h" |
---|
| 30 | #include "Quest.h" |
---|
| 31 | |
---|
| 32 | namespace orxonox { |
---|
| 33 | |
---|
| 34 | CreateFactory(Quest); |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | @brief |
---|
| 38 | Constructor. Creates a quest with a given id, title and description. |
---|
| 39 | @param id |
---|
| 40 | The unique identifier of the quest. |
---|
| 41 | @param title |
---|
| 42 | The title of the quest. |
---|
| 43 | @param description |
---|
| 44 | The description of the quest. |
---|
| 45 | */ |
---|
| 46 | Quest::Quest(std::string id, std::string title = "", std::string description = "") : QuestItem(id, title, description) |
---|
| 47 | { |
---|
| 48 | initialize(); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | @brief |
---|
| 53 | Destructor. |
---|
| 54 | */ |
---|
| 55 | Quest::~Quest() |
---|
| 56 | { |
---|
| 57 | //TDO: Unload lists... |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | @brief |
---|
| 62 | Initializes the object. Needs to be called first in every constructor of this class. |
---|
| 63 | */ |
---|
| 64 | void Quest::initialize(void) |
---|
| 65 | { |
---|
| 66 | RegisterObject(Quest); |
---|
| 67 | |
---|
| 68 | this->parentQuest_ = 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | @brief |
---|
[1996] | 73 | Sets the parent quest of the quest. |
---|
| 74 | @param quest |
---|
| 75 | A pointer to the quest to be set as parent quest. |
---|
| 76 | */ |
---|
| 77 | bool setParentQuest(Quest* quest) |
---|
| 78 | { |
---|
| 79 | this->parentQuest_ = quest; |
---|
| 80 | return true; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | @brief |
---|
| 85 | Adds a sub quest to the quest. |
---|
| 86 | @param quest |
---|
| 87 | A pointer to the quest to be set as sub quest. |
---|
| 88 | */ |
---|
| 89 | bool addSubQuest(Quest & quest) |
---|
| 90 | { |
---|
| 91 | this->subQuests_.push_back = quest; |
---|
| 92 | return true; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | @brief |
---|
[1992] | 97 | Adds a Hint to the list of hints |
---|
| 98 | @param hint |
---|
| 99 | The hint that should be added to the list of hints. |
---|
| 100 | */ |
---|
| 101 | void Quest::addHint(QuestHint & hint) |
---|
| 102 | { |
---|
| 103 | if ( hint != NULL ) |
---|
| 104 | { |
---|
| 105 | this->hints_.push_back(hint); |
---|
| 106 | hint.setQuest(this); |
---|
| 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
| 110 | COUT(2) << "A NULL-QuestHint was trying to be added." << std::endl; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | @brief |
---|
| 116 | Starts the quest. |
---|
| 117 | @param player |
---|
| 118 | The player. |
---|
[1996] | 119 | @return |
---|
| 120 | Returns true if the quest could be started, false if not. |
---|
[1992] | 121 | */ |
---|
[1996] | 122 | bool Quest::start(const Player & player) |
---|
[1992] | 123 | { |
---|
[1996] | 124 | if(this->isStartable(player)) |
---|
[1992] | 125 | { |
---|
| 126 | this->setStatus(player, questStatus::active); |
---|
[1996] | 127 | return true; |
---|
[1992] | 128 | } |
---|
[1996] | 129 | COUT(2) << "A non-startable quest was trying to be started." << std::endl; |
---|
| 130 | return false; |
---|
[1992] | 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
| 134 | @brief |
---|
| 135 | Fails the quest. |
---|
| 136 | @param player |
---|
| 137 | The player. |
---|
[1996] | 138 | @return |
---|
| 139 | Returns true if the quest could be failed, false if not. |
---|
[1992] | 140 | */ |
---|
| 141 | void Quest::fail(Player & player) |
---|
| 142 | { |
---|
[1996] | 143 | if(this->isFailable(player)) |
---|
[1992] | 144 | { |
---|
| 145 | this->setStatus(player, questStatus::failed); |
---|
| 146 | QuestEffect::invokeEffects(player, this->failEffects_); |
---|
[1996] | 147 | return true; |
---|
[1992] | 148 | } |
---|
[1996] | 149 | COUT(2) << "A non-failable quest was trying to be failed." << std::endl; |
---|
| 150 | return false; |
---|
[1992] | 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | @brief |
---|
| 155 | Completes the quest. |
---|
| 156 | @param player |
---|
| 157 | The player. |
---|
[1996] | 158 | @return |
---|
| 159 | Returns true if the quest could be completed, false if not. |
---|
[1992] | 160 | */ |
---|
| 161 | void Quest::complete(Player & player) |
---|
| 162 | { |
---|
[1996] | 163 | if(this->isCompletable(player)) |
---|
[1992] | 164 | { |
---|
| 165 | this->setStatus(player, questStatus::completed); |
---|
| 166 | QuestEffect::invokeEffects(player, this->completeEffects_); |
---|
[1996] | 167 | return true; |
---|
[1992] | 168 | } |
---|
[1996] | 169 | COUT(2) << "A non-completable quest was trying to be completed." << std::endl; |
---|
| 170 | return false; |
---|
[1992] | 171 | } |
---|
| 172 | |
---|
| 173 | } |
---|