Changeset 6466 for code/branches/pickup3/src/modules/pickup
- Timestamp:
- Mar 4, 2010, 11:56:26 AM (15 years ago)
- Location:
- code/branches/pickup3/src/modules/pickup
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/modules/pickup/CMakeLists.txt
r6420 r6466 1 1 SET_SOURCE_FILES(PICKUP_SRC_FILES 2 DroppedItem.cc 3 Pickup.cc 2 4 PickupCollection.cc 5 PickupCollectionIdentifier.cc 6 PickupManager.cc 7 PickupRepresentation.cc 3 8 PickupSpawner.cc 4 9 ) 10 11 ADD_SUBDIRECTORY(items) 5 12 6 13 ORXONOX_ADD_LIBRARY(pickup … … 16 23 SOURCE_FILES ${PICKUP_SRC_FILES} 17 24 ) 18 -
code/branches/pickup3/src/modules/pickup/DroppedItem.cc
r6421 r6466 75 75 } 76 76 77 //TODO; Doesn't seem to be needed anymore, just put setPosition in the constructor. 77 78 void DroppedItem::createDrop(const Vector3& position) 78 79 { -
code/branches/pickup3/src/modules/pickup/DroppedItem.h
r6421 r6466 35 35 #define _DroppedItem_H__ 36 36 37 #include " pickup/PickupPrereqs.h"37 #include "PickupPrereqs.h" 38 38 39 39 #include "PickupSpawner.h" -
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
r6421 r6466 72 72 SUPER(PickupCollection, XMLPort, xmlelement, mode); 73 73 74 //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML ...74 //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML, doubt that, though. 75 75 XMLPortObject(PickupCollection, PickupCollection, "pickupables", addPickupable, getPickupable, xmlelement, mode); 76 77 this->initializeIdentifier(); 78 } 79 80 void PickupCollection::initializeIdentifier(void) 81 { 82 this->pickupCollectionIdentifier_.addClass(this->getIdentifier()); 83 84 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 85 { 86 this->pickupCollectionIdentifier_.addPickup((*it)->getPickupIdentifier()); 87 } 76 88 } 77 89 … … 114 126 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 115 127 { 116 (*it)-> changedUsed();128 (*it)->setUsed(this->isUsed()); 117 129 } 118 130 } 119 131 120 /** 121 @brief 122 Puts the PickupCollection in use. 123 @return 124 Returns true if successful. 125 */ 126 //TODO: Revert if one fails? (same for unused) 127 bool PickupCollection::use(void) 132 void PickupCollection::changedCarrier() 128 133 { 129 if(this->isUsed()) 130 return false; 134 SUPER(PickupCollection, changedCarrier); 131 135 132 bool success = true; 133 //! Set all Pickupables to used. 136 //! Change the carrier for all Pickupables this PickupCollection consists of. 134 137 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 135 138 { 136 if(!(*it)->use()) 137 { 138 success = false; 139 } 139 (*it)->setCarrier(this->getCarrier()); 140 140 } 141 142 this->changedUsed();143 144 return success;145 }146 147 /**148 @brief149 Puts the PickupCollection out of use.150 @return151 Returns true if successful.152 */153 bool PickupCollection::unuse(void)154 {155 if(!this->isUsed())156 return false;157 158 bool success = true;159 //! Set all Pickupables to unused.160 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)161 {162 if(!(*it)->unuse())163 {164 success = false;165 }166 }167 168 this->changedUsed();169 170 return success;171 }172 173 /**174 @brief175 Is invoked when the pickup is picked up.176 @param carrier177 The PickupCarrier that is picking up this pickup.178 @return179 Returns true if successful.180 */181 //TODO: Something should happen in the carrier as well, maybe just in the carrier. Owner might not be correct if the carrier hands the pickup down or up. Maybe even a Pawn as input instead fo a carrier. Or do this in Spawner?182 bool PickupCollection::pickup(PickupCarrier* carrier)183 {184 if(this->getOwner() != NULL)185 {186 COUT(2) << "Pickup wanted to get picked up by a new carrier, but it already has a carrier." << std::endl;187 return false;188 }189 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)190 {191 (*it)->setOwner(carrier);192 }193 194 this->setOwner(carrier);195 196 return true;197 }198 199 /**200 @brief201 Drop the pickup.202 @return203 Return true if successful.204 */205 bool PickupCollection::drop(void)206 {207 this->unuse();208 this->setOwner(NULL);209 210 //TODO: Create new Pickupspawner/DroppedPickup211 return true;212 141 } 213 142 214 143 //TODO: Steal description from Pickupable. 215 Pickupable* PickupCollection::clone()144 void PickupCollection::clone(OrxonoxClass* item) 216 145 { 217 Template* collectionTemplate = Template::getTemplate(this->getIdentifier()->getName());218 BaseObject* newObject = collectionTemplate->getBaseclassIdentifier()->fabricate(this);146 if(item == NULL) 147 item = new PickupCollection(this); 219 148 220 PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject); 149 SUPER(PickupCollection, clone, item); 150 151 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item); 221 152 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 222 153 { 223 154 Pickupable* newPickup = (*it)->clone(); 224 newCollection->pickups_.push_back(newPickup);155 pickup->addPickupable(newPickup); 225 156 } 226 227 Pickupable* pickup = dynamic_cast<Pickupable*>(newCollection); 228 return pickup; 157 158 pickup->initializeIdentifier(); 229 159 } 230 160 -
code/branches/pickup3/src/modules/pickup/PickupCollection.h
r6421 r6466 30 30 #define _PickupCollection_H__ 31 31 32 #include " pickup/PickupPrereqs.h"32 #include "PickupPrereqs.h" 33 33 34 34 #include "interfaces/Pickupable.h" 35 35 #include "core/BaseObject.h" 36 36 #include "core/XMLPort.h" 37 38 #include "PickupCollectionIdentifier.h" 37 39 38 40 #include <list> … … 60 62 virtual void changedUsed(void); 61 63 62 virtual bool use(void); 63 virtual bool unuse(void); 64 virtual void changedCarrier(void); 64 65 65 virtual bool pickup(PickupCarrier* carrier); 66 virtual bool drop(void); 66 virtual void clone(OrxonoxClass* item); 67 67 68 virtual Pickupable* clone(void); 68 virtual const PickupIdentifier* getPickupIdentifier(void) 69 { return &this->pickupCollectionIdentifier_; } 69 70 70 71 bool addPickupable(Pickupable* pickup); 71 72 const Pickupable* getPickupable(unsigned int index); 73 74 protected: 75 void initializeIdentifier(void); 76 77 PickupCollectionIdentifier pickupCollectionIdentifier_; 72 78 73 79 private: -
code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
r6421 r6466 67 67 68 68 class DroppedItem; 69 class Pickup; 69 70 class PickupCollection; 71 class PickupCollectionIdentifier; 72 class PickupManager; 73 class PickupRepresentation; 70 74 class PickupSpawner; 75 76 //items 77 class HealthPickup; 71 78 72 79 } -
code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
r6421 r6466 39 39 #include "core/XMLPort.h" 40 40 #include "worldentities/pawns/Pawn.h" 41 #include "PickupManager.h" 42 #include "PickupRepresentation.h" 41 43 //#include "PickupInventory.h" // HACK; Only for hack, remove later 42 44 … … 59 61 PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator) 60 62 { 63 RegisterObject(PickupSpawner); 64 61 65 this->initialize(); 66 67 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(NULL); 68 69 COUT(1) << "MUP4 " << representation << std::endl; 70 this->attach(representation->getSpawnerRepresentation(this)); 71 72 COUT(1) << "MUP6" << std::endl; 62 73 } 63 74 … … 78 89 PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator) 79 90 { 91 RegisterObject(PickupSpawner); 92 80 93 this->initialize(); 81 94 … … 85 98 this->respawnTime_ = respawnTime; 86 99 this->setMaxSpawnedItems(maxSpawnedItems); 100 101 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier()); 102 this->attach(representation->getSpawnerRepresentation(this)); 87 103 } 88 104 … … 93 109 void PickupSpawner::initialize(void) 94 110 { 95 RegisterObject(PickupSpawner);96 97 111 this->pickup_ = NULL; 98 112 … … 215 229 Time since last tick. 216 230 */ 217 //TODO: Replace this with a real DistanceTrigger? 231 //TODO: Replace this with a real DistanceTrigger? Or better with collisions? 218 232 void PickupSpawner::tick(float dt) 219 233 { … … 259 273 if (pickup != NULL) //!< If everything went ok, and pickup is not NULL. 260 274 { 275 //TODO: Not correct anymore. 261 276 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn); 262 277 if(carrier == NULL) … … 266 281 } 267 282 268 if( pickup->pickup(carrier))283 if(carrier->pickup(pickup)) 269 284 { 270 285 COUT(3) << "Pickup got picked up." << std::endl; -
code/branches/pickup3/src/modules/pickup/PickupSpawner.h
r6421 r6466 35 35 #define _PickupSpawner_H__ 36 36 37 #include " pickup/PickupPrereqs.h"37 #include "PickupPrereqs.h" 38 38 39 39 #include <string>
Note: See TracChangeset
for help on using the changeset viewer.