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