- Timestamp:
- Nov 19, 2008, 11:50:03 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem2/src/orxonox/objects/quest/QuestEffectBeacon.cc
r2209 r2221 27 27 */ 28 28 29 /** 30 @file QuestEffectBeacon.cc 31 @brief 32 Implementation of the QuestEffectBeacon class. 33 */ 34 29 35 #include "OrxonoxStableHeaders.h" 30 36 #include "QuestEffectBeacon.h" … … 44 50 CreateFactory(QuestEffectBeacon); 45 51 52 /** 53 @brief 54 Constructor. Registers the object and initializes defaults. 55 */ 46 56 QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator) 47 57 { … … 49 59 50 60 this->status_ = QuestEffectBeaconStatus::active; 51 this->times_ = -1; 52 this->trigger_ = NULL; 53 } 54 61 this->times_ = INFINITE; 62 } 63 64 /** 65 Destructor. 66 */ 55 67 QuestEffectBeacon::~QuestEffectBeacon() 56 68 { 57 69 } 58 70 71 /** 72 @brief 73 Method for creating a QuestEffectBeacon object through XML. 74 */ 59 75 void QuestEffectBeacon::XMLPort(Element& xmlelement, XMLPort::Mode mode) 60 76 { … … 62 78 63 79 XMLPortParam(QuestEffectBeacon, "times", setTimes, getTimes, xmlelement, mode); 64 XMLPortObject(QuestEffectBeacon, QuestEffect, "", addEffect, getEffect, xmlelement, mode); 65 XMLPortObject(QuestEffectBeacon, PlayerTrigger, "", addTrigger, getTrigger, xmlelement, mode); 66 } 67 80 XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode); 81 } 82 83 /** 84 @brief 85 Processes an event for this QuestEffectBeacon. 86 */ 68 87 void QuestEffectBeacon::processEvent(Event& event) 69 88 { 89 SUPER(QuestEffectBeacon, processEvent, event); 90 70 91 SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger); 71 92 } 72 93 94 /** 95 @brief 96 Executes the QuestEffectBeacon. 97 This means extracting the ControllableEntity from the PlayerTrigger, provided by the Event causing the execution, and the extracting the PlayerInfo from the received ControllableEntity and invoking the QuestEffectbeacon's QuestEffects on the received PlayerInfo. 98 @param b 99 TDO: What is this??? 100 @param trigger 101 Apointer to the PlayerTrigger that threw the Event. 102 @return 103 Returns true if successfully executed, false if not. 104 */ 73 105 bool QuestEffectBeacon::execute(bool b, PlayerTrigger* trigger) 74 106 { 75 107 if(!b) 76 108 { 109 //TDO: Better message, please. 77 110 COUT(2) << "b is false." << std::endl; 78 111 } 79 if(!(this->isActive())) 112 if(!(this->isActive())) //!< If the QuestEffectBeacon is inactive it cannot be executed. 80 113 { 81 114 COUT(3) << "The QuestEffectBeacon is inactive." << std::endl; 82 115 return false; 83 116 } 84 117 118 if(!trigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for ControllableEntities which means we cannot extract one. 119 { 120 return false; 121 } 122 123 //! Extracting the ControllableEntity form the PlayerTrigger. 85 124 ControllableEntity* entity = trigger->getTriggeringPlayer(); 86 125 … … 91 130 } 92 131 132 //! Extract the PlayerInfo from the ControllableEntity. 93 133 PlayerInfo* player = entity->getPlayer(); 94 134 … … 99 139 } 100 140 101 COUT(3) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl; 102 103 bool check = QuestEffect::invokeEffects(player, this->effects_); 141 COUT(3) << "QuestEffectBeacon executed on player: " << player << " ." << std::endl; 142 143 bool check = QuestEffect::invokeEffects(player, this->effects_); //!< Invoke the QuestEffects on the PlayerInfo. 104 144 if(check) 105 145 { 106 this->decrementTimes(); 146 this->decrementTimes(); //!< Decrement the number of times the beacon can be used. 107 147 return true; 108 148 } 109 149 110 150 return false; 111 151 } 112 152 113 bool QuestEffectBeacon::isActive(void) 114 { 115 return this->status_ == QuestEffectBeaconStatus::active; 116 } 117 153 /** 154 @brief 155 Set the status of the QuestEffectBeacon. 156 @param activate 157 If true the QuestEffectBeacon is activated, if false it is deactivated. 158 @return 159 Returns whether the activation/deactivation was successful. 160 */ 161 bool QuestEffectBeacon::setActive(bool activate) 162 { 163 if(this->getTimes() == 0 && activate) //!< A QuestEffectBeacon that can be executed only 0 times is always inactive. 164 { 165 return false; 166 } 167 168 if(activate) 169 { 170 this->status_ = QuestEffectBeaconStatus::active; 171 return true; 172 } 173 174 this->status_ = QuestEffectBeaconStatus::inactive; 175 return true; 176 } 177 178 /** 179 @brief 180 Decrement the number of times the QuestEffectBeacon can be executed. 181 @return 182 Returns true if successful. 183 */ 118 184 bool QuestEffectBeacon::decrementTimes(void) 119 185 { 120 if(!(this->isActive())) 121 { 122 return false; 123 } 124 if(this->getTimes() == -1)186 if(!(this->isActive())) //!< The QuestEffectBeacon mus be active to decrement the number of times it can be executed. 187 { 188 return false; 189 } 190 if(this->getTimes() == INFINITE) //!< If times is infinity the QuestEffectBeacon can be executed an infinite number fo times. 125 191 { 126 192 return true; 127 193 } 128 194 129 this->times_ = this->times_ - 1; 130 if(this->getTimes() == 0) 195 this->times_ = this->times_ - 1; //!< Decrement number of times the QuestEffectBeacon can be executed. 196 if(this->getTimes() == 0) //!< Set the QuestEffectBeacon to inactive when the number of times it can be executed is reduced to 0. 131 197 { 132 198 this->status_ = QuestEffectBeaconStatus::inactive; … … 136 202 } 137 203 138 204 /** 205 @brief 206 Set the number of times the QuestEffectBeacon can be executed. 207 The number must be eighter <= 0, or INFINITY which is '-1'. 208 @param n 209 The number of times the QuestEffectBeacon can be executed. 210 The number must be eighter <= 0, or INFINITY which is '-1'. 211 @return 212 Returns true if successful. 213 */ 139 214 bool QuestEffectBeacon::setTimes(const int & n) 140 215 { 141 if(n < -1)216 if(n < 0 && n != INFINITE) 142 217 { 143 218 return false; … … 148 223 } 149 224 150 151 /** 152 @brief 153 225 /** 226 @brief 227 Adds a QuestEffect to the QuestEffectBeacon. 228 @param effect 229 A pointer to the QuestEffect to be added. 230 @return 231 Returns true if successful. 154 232 */ 155 233 bool QuestEffectBeacon::addEffect(QuestEffect* effect) 156 234 { 157 if(effect == NULL) 235 if(effect == NULL) //!< NULL-pointers are not well liked here... 158 236 { 159 237 COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl; … … 167 245 } 168 246 169 bool QuestEffectBeacon::addTrigger(PlayerTrigger* trigger) 170 { 171 if(this->trigger_ != NULL) 172 { 173 COUT(2) << "A Trigger was trying to be added, where one was already set." << std::endl; 174 return false; 175 } 176 if(trigger == NULL) 177 { 178 COUT(2) << "A NULL-Trigger was trying to be added." << std::endl; 179 return false; 180 } 181 182 COUT(3) << "A Trigger was added to a QuestEffectBeacon." << std::endl; 183 this->trigger_ = trigger; 184 return true; 185 } 186 187 /** 188 @brief 189 247 /** 248 @brief 249 Returns the QuestEffect at the given index. 250 @param index 251 The index. 252 @return 253 Returns a pointer to the QuestEffect at the given index. 190 254 */ 191 255 const QuestEffect* QuestEffectBeacon::getEffect(unsigned int index) const … … 203 267 } 204 268 205 const PlayerTrigger* QuestEffectBeacon::getTrigger(unsigned int index) const206 {207 if(index == 0)208 {209 return this->trigger_;210 }211 212 return NULL;213 }214 215 269 }
Note: See TracChangeset
for help on using the changeset viewer.