Changeset 7163 for code/trunk/src/modules/pickup/items/MetaPickup.cc
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pickup/items/MetaPickup.cc
r6709 r7163 34 34 #include "core/CoreIncludes.h" 35 35 #include "core/XMLPort.h" 36 #include "worldentities/pawns/Pawn.h" 36 37 #include "interfaces/PickupCarrier.h" 37 38 #include "pickup/PickupIdentifier.h" … … 40 41 41 42 namespace orxonox { 42 43 43 44 CreateFactory(MetaPickup); 44 45 45 46 //! Setting the static variables to their values. 46 47 /*static*/ const std::string MetaPickup::metaTypeNone_s = "none"; 47 48 /*static*/ const std::string MetaPickup::metaTypeUse_s = "use"; 48 49 /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop"; 49 50 /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy"; 51 /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier"; 52 50 53 /** 51 54 @brief … … 55 58 { 56 59 RegisterObject(MetaPickup); 57 60 58 61 this->initialize(); 59 62 } 60 63 61 64 /** 62 65 @brief … … 65 68 MetaPickup::~MetaPickup() 66 69 { 67 68 } 69 70 71 } 72 70 73 /** 71 74 @brief … … 75 78 { 76 79 this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier()); 77 80 78 81 this->setActivationTypeDirect(pickupActivationType::immediate); 79 82 this->setDurationTypeDirect(pickupDurationType::once); 80 83 this->metaType_ = pickupMetaType::none; 81 84 } 82 85 83 86 /** 84 87 @brief … … 91 94 this->pickupIdentifier_->addParameter(type, val); 92 95 } 93 96 94 97 /** 95 98 @brief … … 99 102 { 100 103 SUPER(MetaPickup, XMLPort, xmlelement, mode); 101 104 102 105 XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode); 103 106 104 107 this->initializeIdentifier(); 105 108 } 106 109 107 110 /** 108 111 @brief … … 113 116 { 114 117 SUPER(MetaPickup, changedUsed); 115 118 116 119 //! If the MetaPickup transited to used. 117 120 if(this->isUsed()) … … 120 123 if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL) 121 124 { 125 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier) 126 { 127 Pawn* pawn = orxonox_cast<Pawn*>(carrier); 128 pawn->kill(); 129 return; 130 } 122 131 std::set<Pickupable*> pickups = carrier->getPickups(); 123 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type.132 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type. 124 133 for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++) 125 134 { … … 136 145 if(pickup != NULL && pickup != this) 137 146 { 138 carrier->drop(pickup); 147 pickup->drop(); 148 } 149 } 150 if(this->getMetaTypeDirect() == pickupMetaType::destroy) 151 { 152 if(pickup != NULL && pickup != this) 153 { 154 pickup->Pickupable::destroy(); 139 155 } 140 156 } 141 157 } 142 158 } 143 this-> destroy();144 } 145 } 146 159 this->Pickupable::destroy(); 160 } 161 } 162 147 163 /** 148 164 @brief … … 155 171 if(item == NULL) 156 172 item = new MetaPickup(this); 157 173 158 174 SUPER(MetaPickup, clone, item); 159 175 160 176 MetaPickup* pickup = dynamic_cast<MetaPickup*>(item); 161 177 pickup->setMetaTypeDirect(this->getMetaTypeDirect()); 162 178 163 179 pickup->initializeIdentifier(); 164 180 } 165 181 166 182 /** 167 183 @brief … … 180 196 case pickupMetaType::drop: 181 197 return MetaPickup::metaTypeDrop_s; 198 case pickupMetaType::destroy: 199 return MetaPickup::metaTypeDestroy_s; 200 case pickupMetaType::destroyCarrier: 201 return MetaPickup::metaTypeDestroyCarrier_s; 182 202 default: 183 203 return BLANKSTRING; 184 204 } 185 205 } 186 206 187 207 /** 188 208 @brief … … 205 225 this->setMetaTypeDirect(pickupMetaType::drop); 206 226 } 207 } 208 227 else if(type == MetaPickup::metaTypeDestroy_s) 228 { 229 this->setMetaTypeDirect(pickupMetaType::destroy); 230 } 231 else if(type == MetaPickup::metaTypeDestroyCarrier_s) 232 { 233 this->setMetaTypeDirect(pickupMetaType::destroyCarrier); 234 } 235 else 236 COUT(2) << "Invalid metaType '" << type << "' in MetaPickup." << std::endl; 237 } 238 209 239 }
Note: See TracChangeset
for help on using the changeset viewer.