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