[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 | |
---|
[2146] | 29 | /** |
---|
| 30 | @file LocalQuest.cc |
---|
| 31 | @brief |
---|
| 32 | Implementation of the LocalQuest class. |
---|
| 33 | */ |
---|
| 34 | |
---|
[2105] | 35 | #include "OrxonoxStableHeaders.h" |
---|
| 36 | #include "LocalQuest.h" |
---|
| 37 | |
---|
[1992] | 38 | #include "core/CoreIncludes.h" |
---|
[2068] | 39 | #include "util/Exception.h" |
---|
[1992] | 40 | |
---|
[2205] | 41 | #include "orxonox/objects/infos/PlayerInfo.h" |
---|
[2146] | 42 | #include "QuestEffect.h" |
---|
| 43 | |
---|
[1992] | 44 | namespace orxonox { |
---|
| 45 | |
---|
| 46 | CreateFactory(LocalQuest); |
---|
| 47 | |
---|
[2146] | 48 | /** |
---|
| 49 | @brief |
---|
[2159] | 50 | Constructor. Registers and initializes the object. |
---|
[2146] | 51 | */ |
---|
[2092] | 52 | LocalQuest::LocalQuest(BaseObject* creator) : Quest(creator) |
---|
[2021] | 53 | { |
---|
[2146] | 54 | RegisterObject(LocalQuest); |
---|
| 55 | } |
---|
[2092] | 56 | |
---|
[1992] | 57 | /** |
---|
| 58 | @brief |
---|
| 59 | Destructor. |
---|
| 60 | */ |
---|
| 61 | LocalQuest::~LocalQuest() |
---|
| 62 | { |
---|
[2092] | 63 | |
---|
[1992] | 64 | } |
---|
[2092] | 65 | |
---|
[2146] | 66 | /** |
---|
| 67 | @brief |
---|
| 68 | Method for creating a LocalQuest object through XML. |
---|
| 69 | */ |
---|
[2076] | 70 | void LocalQuest::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 71 | { |
---|
| 72 | SUPER(LocalQuest, XMLPort, xmlelement, mode); |
---|
| 73 | |
---|
[2081] | 74 | COUT(3) << "New LocalQuest {" << this->getId() << "} created." << std::endl; |
---|
[2076] | 75 | } |
---|
[2092] | 76 | |
---|
[2146] | 77 | /** |
---|
| 78 | @brief |
---|
[2191] | 79 | Fails the Quest for a given player. |
---|
[2146] | 80 | Invokes all the failEffects on the player. |
---|
| 81 | @param player |
---|
| 82 | The player. |
---|
| 83 | @return |
---|
[2191] | 84 | Returns true if the Quest could be failed, false if not. |
---|
[2146] | 85 | */ |
---|
[2205] | 86 | bool LocalQuest::fail(PlayerInfo* player) |
---|
[2068] | 87 | { |
---|
[2146] | 88 | if(this->isFailable(player)) //!< Checks whether the quest can be failed. |
---|
| 89 | { |
---|
| 90 | this->setStatus(player, questStatus::failed); |
---|
[2159] | 91 | QuestEffect::invokeEffects(player, this->getFailEffectList()); //!< Invoke the failEffects. |
---|
[2146] | 92 | return true; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | COUT(2) << "A non-failable quest was trying to be failed." << std::endl; |
---|
| 96 | return false; |
---|
[2068] | 97 | } |
---|
[2092] | 98 | |
---|
[1992] | 99 | /** |
---|
| 100 | @brief |
---|
[2191] | 101 | Completes the Quest for a given player. |
---|
| 102 | Invokes all the complete QuestEffects on the player. |
---|
[2146] | 103 | @param player |
---|
| 104 | The player. |
---|
| 105 | @return |
---|
[2191] | 106 | Returns true if the Quest could be completed, false if not. |
---|
[2146] | 107 | */ |
---|
[2205] | 108 | bool LocalQuest::complete(PlayerInfo* player) |
---|
[2146] | 109 | { |
---|
[2191] | 110 | if(this->isCompletable(player)) //!< Checks whether the Quest can be completed. |
---|
[2146] | 111 | { |
---|
| 112 | this->setStatus(player, questStatus::completed); |
---|
[2191] | 113 | QuestEffect::invokeEffects(player, this->getCompleteEffectList()); //!< Invoke the complete QuestEffects. |
---|
[2146] | 114 | return true; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | COUT(2) << "A non-completable quest was trying to be completed." << std::endl; |
---|
| 118 | return false; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | @brief |
---|
[2191] | 123 | Checks whether the Quest can be started. |
---|
[1996] | 124 | @param player |
---|
| 125 | The player for whom is to be checked. |
---|
| 126 | @return |
---|
[2191] | 127 | Returns true if the Quest can be started, false if not. |
---|
[2068] | 128 | @throws |
---|
[2205] | 129 | Throws an exception if isInactive(PlayerInfo*) throws one. |
---|
[1996] | 130 | */ |
---|
[2205] | 131 | bool LocalQuest::isStartable(const PlayerInfo* player) const |
---|
[1996] | 132 | { |
---|
| 133 | return this->isInactive(player); |
---|
| 134 | } |
---|
[2092] | 135 | |
---|
[1996] | 136 | /** |
---|
| 137 | @brief |
---|
[2191] | 138 | Checks whether the Quest can be failed. |
---|
[1996] | 139 | @param player |
---|
| 140 | The player for whom is to be checked. |
---|
| 141 | @return |
---|
[2191] | 142 | Returns true if the Quest can be failed, false if not. |
---|
[2068] | 143 | @throws |
---|
[2205] | 144 | Throws an exception if isActive(PlayerInfo*) throws one. |
---|
[1996] | 145 | */ |
---|
[2205] | 146 | bool LocalQuest::isFailable(const PlayerInfo* player) const |
---|
[1996] | 147 | { |
---|
| 148 | return this->isActive(player); |
---|
| 149 | } |
---|
[2092] | 150 | |
---|
[1996] | 151 | /** |
---|
| 152 | @brief |
---|
[2191] | 153 | Checks whether the Quest can be completed. |
---|
[1996] | 154 | @param player |
---|
| 155 | The player for whom is to be checked. |
---|
| 156 | @return |
---|
[2191] | 157 | Returns true if the Quest can be completed, false if not. |
---|
[2068] | 158 | @throws |
---|
[2205] | 159 | Throws an exception if isInactive(PlayerInfo*) throws one. |
---|
[1996] | 160 | */ |
---|
[2205] | 161 | bool LocalQuest::isCompletable(const PlayerInfo* player) const |
---|
[1996] | 162 | { |
---|
| 163 | return this->isActive(player); |
---|
| 164 | } |
---|
[2092] | 165 | |
---|
[1996] | 166 | /** |
---|
| 167 | @brief |
---|
[2191] | 168 | Returns the status of the Quest for a specific player. |
---|
[1992] | 169 | @param player |
---|
[1996] | 170 | The player. |
---|
| 171 | @return |
---|
[2191] | 172 | Returns the status of the Quest for the input player. |
---|
[2068] | 173 | @throws |
---|
| 174 | Throws an Exception if player is NULL. |
---|
[1992] | 175 | */ |
---|
[2205] | 176 | questStatus::Enum LocalQuest::getStatus(const PlayerInfo* player) const |
---|
[1992] | 177 | { |
---|
[2146] | 178 | if(player == NULL) //!< No player has no defined status. |
---|
[2068] | 179 | { |
---|
[2205] | 180 | ThrowException(Argument, "The input PlayerInfo* is NULL."); |
---|
[2068] | 181 | } |
---|
[2092] | 182 | |
---|
[2205] | 183 | std::map<const PlayerInfo*, questStatus::Enum>::const_iterator it = this->playerStatus_.find(player); |
---|
[2146] | 184 | if (it != this->playerStatus_.end()) //!< If there is a player in the map. |
---|
[2093] | 185 | { |
---|
| 186 | return it->second; |
---|
| 187 | } |
---|
[2146] | 188 | |
---|
| 189 | return questStatus::inactive; //!< If the player is not yet in the map, that means the status of the quest form him is 'inactive'. |
---|
[1992] | 190 | } |
---|
[2092] | 191 | |
---|
[1992] | 192 | /** |
---|
| 193 | @brief |
---|
| 194 | Sets the status for a specific player. |
---|
[2146] | 195 | But be careful wit this one, the status will just be set without checking for its validity. You have to know what you're doing. Really! |
---|
[1992] | 196 | @param player |
---|
[2146] | 197 | The player the status should be set for. |
---|
[1992] | 198 | @param status |
---|
[2146] | 199 | The status to be set. |
---|
[2068] | 200 | @return |
---|
| 201 | Returns false if player is NULL. |
---|
[1992] | 202 | */ |
---|
[2205] | 203 | bool LocalQuest::setStatus(PlayerInfo* player, const questStatus::Enum & status) |
---|
[1992] | 204 | { |
---|
[2146] | 205 | if(player == NULL) //!< We can't set a status for no player. |
---|
[2068] | 206 | { |
---|
| 207 | return false; |
---|
[2093] | 208 | } |
---|
[2146] | 209 | |
---|
[2021] | 210 | this->playerStatus_[player] = status; |
---|
| 211 | return true; |
---|
[1992] | 212 | } |
---|
| 213 | |
---|
| 214 | } |
---|