Changeset 6965 for code/branches/presentation3/src/modules
- Timestamp:
- May 24, 2010, 4:59:23 PM (15 years ago)
- Location:
- code/branches/presentation3/src/modules/pickup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/modules/pickup/PickupManager.cc
r6752 r6965 64 64 65 65 this->defaultRepresentation_ = new PickupRepresentation(); 66 this->pickupsIndex_ = 0; 66 67 67 68 COUT(3) << "PickupManager created." << std::endl; … … 149 150 return it->second; 150 151 } 151 152 PickupCarrier* PickupManager::getPawn(void) 153 { 152 153 int PickupManager::getNumPickups(void) 154 { 155 this->pickupsList_.clear(); 156 this->pickupsIndex_ = 0; 157 154 158 PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s); 159 PickupCarrier* carrier = NULL; 155 160 if (player != NULL) 156 returndynamic_cast<PickupCarrier*>(player->getControllableEntity());161 carrier = dynamic_cast<PickupCarrier*>(player->getControllableEntity()); 157 162 else 158 return NULL;159 }160 161 int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)162 {163 if(carrier == NULL)164 163 return 0; 165 return carrier->getNumCarrierChildren(); 166 } 167 168 PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier) 169 { 170 if(carrier == NULL) 171 return NULL; 172 return carrier->getCarrierChild(index); 173 } 174 175 const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier) 176 { 177 if(carrier == NULL) 178 return BLANKSTRING; 179 return carrier->getCarrierName(); 180 } 181 182 PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier) 183 { 184 Pickupable* pickup = carrier->getPickup(index); 185 if(pickup == NULL) 186 return NULL; 187 188 return this->getRepresentation(pickup->getPickupIdentifier()); 189 } 190 191 int PickupManager::getNumPickups(PickupCarrier* carrier) 192 { 193 if(carrier == NULL) 194 return 0; 195 return carrier->getNumPickups(); 196 } 197 198 void PickupManager::dropPickup(int index, PickupCarrier* carrier) 199 { 200 Pickupable* pickup = carrier->getPickup(index); 201 if(pickup != NULL) 164 165 std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier); 166 for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++) 167 { 168 std::set<Pickupable*> pickups = (*it)->getPickups(); 169 for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++) 170 { 171 this->pickupsList_.insert(*pickup); 172 } 173 } 174 delete carriers; 175 176 this->pickupsIterator_ = this->pickupsList_.begin(); 177 return this->pickupsList_.size(); 178 } 179 180 std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier) 181 { 182 //TODO: More efficiently. 183 std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>(); 184 carriers->insert(carriers->end(), carrier); 185 std::vector<PickupCarrier*>* children = carrier->getCarrierChildren(); 186 for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++) 187 { 188 std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it); 189 for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++) 190 { 191 carriers->insert(carriers->end(), *it2); 192 } 193 delete childrensChildren; 194 } 195 delete children; 196 return carriers; 197 } 198 199 void PickupManager::dropPickup(orxonox::Pickupable* pickup) 200 { 201 if(!pickup->isPickedUp()) 202 return; 203 204 PickupCarrier* carrier = pickup->getCarrier(); 205 if(pickup != NULL && carrier != NULL) 202 206 carrier->drop(pickup); 203 207 } 204 205 void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use) 206 { 207 Pickupable* pickup = carrier->getPickup(index); 208 if(pickup != NULL) 208 209 void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use) 210 { 211 if(!pickup->isPickedUp()) 212 return; 213 214 PickupCarrier* carrier = pickup->getCarrier(); 215 if(pickup != NULL && carrier != NULL) 209 216 pickup->setUsed(use); 210 217 } -
code/branches/presentation3/src/modules/pickup/PickupManager.h
r6725 r6965 71 71 72 72 // tolua_begin 73 orxonox::PickupCarrier* getPawn(void); 74 75 int getNumCarrierChildren(orxonox::PickupCarrier* carrier); 76 orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier); 77 78 const std::string& getCarrierName(orxonox::PickupCarrier* carrier); 79 80 int getNumPickups(orxonox::PickupCarrier* carrier); 81 PickupRepresentation* getPickupRepresentation(int index, orxonox::PickupCarrier* carrier); 82 void dropPickup(int index, orxonox::PickupCarrier* carrier); 83 void usePickup(int index, orxonox::PickupCarrier* carrier, bool use); 73 int getNumPickups(void); 74 orxonox::Pickupable* popPickup(void) { this->pickupsIndex_++; return *(this->pickupsIterator_++); } 75 int getPickupIndex(void) { return this->pickupsIndex_-1; } 76 orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup) { if(pickup != NULL) return this->getRepresentation(pickup->getPickupIdentifier()); return NULL; } 77 78 void dropPickup(orxonox::Pickupable* pickup); 79 void usePickup(orxonox::Pickupable* pickup, bool use); 84 80 // tolua_end 85 81 … … 90 86 PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. 91 87 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations. 88 89 std::set<Pickupable*> pickupsList_; 90 std::set<Pickupable*>::iterator pickupsIterator_; 91 int pickupsIndex_; 92 93 std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier); 92 94 93 95 }; // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.