[Orxonox-commit 1748] r6466 - in code/branches/pickup3/src: libraries/core modules/pickup orxonox orxonox/interfaces orxonox/pickup orxonox/worldentities/pawns

dafrick at orxonox.net dafrick at orxonox.net
Thu Mar 4 11:56:26 CET 2010


Author: dafrick
Date: 2010-03-04 11:56:26 +0100 (Thu, 04 Mar 2010)
New Revision: 6466

Modified:
   code/branches/pickup3/src/libraries/core/OrxonoxClass.h
   code/branches/pickup3/src/libraries/core/Super.h
   code/branches/pickup3/src/modules/pickup/CMakeLists.txt
   code/branches/pickup3/src/modules/pickup/DroppedItem.cc
   code/branches/pickup3/src/modules/pickup/DroppedItem.h
   code/branches/pickup3/src/modules/pickup/PickupCollection.cc
   code/branches/pickup3/src/modules/pickup/PickupCollection.h
   code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
   code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
   code/branches/pickup3/src/modules/pickup/PickupSpawner.h
   code/branches/pickup3/src/orxonox/CMakeLists.txt
   code/branches/pickup3/src/orxonox/OrxonoxPrereqs.h
   code/branches/pickup3/src/orxonox/interfaces/CMakeLists.txt
   code/branches/pickup3/src/orxonox/interfaces/InterfaceCompilation.cc
   code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
   code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
   code/branches/pickup3/src/orxonox/pickup/CMakeLists.txt
   code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h
Log:
Lots of things done in pickups module. Compiles, but it seems, that I've also introduced an error preventing steering of the spaceship.


Modified: code/branches/pickup3/src/libraries/core/OrxonoxClass.h
===================================================================
--- code/branches/pickup3/src/libraries/core/OrxonoxClass.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/libraries/core/OrxonoxClass.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -38,6 +38,7 @@
 #define _OrxonoxClass_H__
 
 #include "CorePrereqs.h"
+#include "Super.h"
 
 #include <set>
 #include <vector>
@@ -106,6 +107,8 @@
             bool isDirectChildOf(const OrxonoxClass* object);
             bool isParentOf(const OrxonoxClass* object);
             bool isDirectParentOf(const OrxonoxClass* object);
+            
+            virtual void clone(OrxonoxClass* item) {}
 
             inline unsigned int getReferenceCount() const
                 { return this->referenceCount_; }
@@ -168,6 +171,9 @@
             //! 'Fast map' that holds this-pointers of all derived types
             std::vector<std::pair<unsigned int, void*> > objectPointers_;
     };
+    
+    SUPER_FUNCTION(11, OrxonoxClass, clone, true);
+    
 }
 
 #endif /* _OrxonoxClass_H__ */

Modified: code/branches/pickup3/src/libraries/core/Super.h
===================================================================
--- code/branches/pickup3/src/libraries/core/Super.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/libraries/core/Super.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -269,6 +269,13 @@
         
     #define SUPER_changedUsed(classname, functionname, ...) \
         SUPER_NOARGS(classname, functionname)
+        
+    #define SUPER_clone(classname, functionname, ...) \
+        SUPER_ARGS(classname, functionname, __VA_ARGS__)
+        
+    #define SUPER_changedCarrier(classname, functionname, ...) \
+        SUPER_NOARGS(classname, functionname)
+        
     // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
 
@@ -523,6 +530,15 @@
         SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedUsed, false)
             ()
         SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
+
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(11, clone, true, OrxonoxClass* item)
+            (item)
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
+        
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false)
+            ()
+        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
+
         // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
 }
@@ -577,6 +593,8 @@
     SUPER_INTRUSIVE_DECLARATION(changedName);
     SUPER_INTRUSIVE_DECLARATION(changedGametype);
     SUPER_INTRUSIVE_DECLARATION(changedUsed);
+    SUPER_INTRUSIVE_DECLARATION(clone);
+    SUPER_INTRUSIVE_DECLARATION(changedCarrier);
     // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
 
 

Modified: code/branches/pickup3/src/modules/pickup/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/modules/pickup/CMakeLists.txt	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/CMakeLists.txt	2010-03-04 10:56:26 UTC (rev 6466)
@@ -1,8 +1,15 @@
 SET_SOURCE_FILES(PICKUP_SRC_FILES
+  DroppedItem.cc
+  Pickup.cc
   PickupCollection.cc
+  PickupCollectionIdentifier.cc
+  PickupManager.cc
+  PickupRepresentation.cc
   PickupSpawner.cc
 )
 
+ADD_SUBDIRECTORY(items)
+
 ORXONOX_ADD_LIBRARY(pickup
   MODULE
   FIND_HEADER_FILES
@@ -15,4 +22,3 @@
     orxonox
   SOURCE_FILES ${PICKUP_SRC_FILES}
 )
-

Modified: code/branches/pickup3/src/modules/pickup/DroppedItem.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.cc	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.cc	2010-03-04 10:56:26 UTC (rev 6466)
@@ -74,6 +74,7 @@
         return this->pickup_;
     }
     
+    //TODO; Doesn't seem to be needed anymore, just put setPosition in the constructor.
     void DroppedItem::createDrop(const Vector3& position)
     {
         this->setPosition(position);

Modified: code/branches/pickup3/src/modules/pickup/DroppedItem.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -34,7 +34,7 @@
 #ifndef _DroppedItem_H__
 #define _DroppedItem_H__
 
-#include "pickup/PickupPrereqs.h"
+#include "PickupPrereqs.h"
 
 #include "PickupSpawner.h"
 

Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.cc	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.cc	2010-03-04 10:56:26 UTC (rev 6466)
@@ -71,10 +71,22 @@
     {
         SUPER(PickupCollection, XMLPort, xmlelement, mode);
         
-        //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML...
+        //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML, doubt that, though.
         XMLPortObject(PickupCollection, PickupCollection, "pickupables", addPickupable, getPickupable, xmlelement, mode);
+        
+        this->initializeIdentifier();
     }
     
+    void PickupCollection::initializeIdentifier(void)
+    {
+        this->pickupCollectionIdentifier_.addClass(this->getIdentifier());
+        
+        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+        {
+            this->pickupCollectionIdentifier_.addPickup((*it)->getPickupIdentifier());
+        }
+    }
+    
     /**
     @brief
         Add the input Pickupable to list of Pickupables combined by this PickupCollection.
@@ -113,119 +125,37 @@
         //! Change used for all Pickupables this PickupCollection consists of.
         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
         {
-            (*it)->changedUsed();
+            (*it)->setUsed(this->isUsed());
         }
     }
     
-    /**
-    @brief
-        Puts the PickupCollection in use.
-    @return
-        Returns true if successful.
-    */
-    //TODO: Revert if one fails? (same for unused)
-    bool PickupCollection::use(void)
+    void PickupCollection::changedCarrier()
     {
-        if(this->isUsed())
-            return false;
+        SUPER(PickupCollection, changedCarrier);
         
-        bool success = true;
-        //! Set all Pickupables to used.
+        //! Change the carrier for all Pickupables this PickupCollection consists of.
         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
         {
-            if(!(*it)->use())
-            {
-                success = false;
-            }
+            (*it)->setCarrier(this->getCarrier());
         }
-        
-        this->changedUsed();
-        
-        return success;
     }
     
-    /**
-    @brief
-        Puts the PickupCollection out of use.
-    @return
-        Returns true if successful.
-    */
-    bool PickupCollection::unuse(void)
+    //TODO: Steal description from Pickupable.
+    void PickupCollection::clone(OrxonoxClass* item)
     {
-        if(!this->isUsed())
-            return false;
+        if(item == NULL)
+            item = new PickupCollection(this);
         
-        bool success = true;
-        //! Set all Pickupables to unused.
-        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
-        {
-            if(!(*it)->unuse())
-            {
-                success = false;
-            }
-        }
+        SUPER(PickupCollection, clone, item);
         
-        this->changedUsed();
-        
-        return success;
-    }
-
-    /**
-    @brief
-        Is invoked when the pickup is picked up.
-    @param carrier
-        The PickupCarrier that is picking up this pickup.
-    @return
-        Returns true if successful.
-    */
-    //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?
-    bool PickupCollection::pickup(PickupCarrier* carrier)
-    {
-        if(this->getOwner() != NULL)
-        {
-            COUT(2) << "Pickup wanted to get picked up by a new carrier, but it already has a carrier." << std::endl;
-            return false;
-        }
+        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
         {
-            (*it)->setOwner(carrier);
-        }
-        
-        this->setOwner(carrier);
-        
-        return true;
-    }
-    
-    /**
-    @brief
-        Drop the pickup.
-    @return
-        Return true if successful.
-    */
-    bool PickupCollection::drop(void)
-    {
-        this->unuse();
-        this->setOwner(NULL);
-        
-        //TODO: Create new Pickupspawner/DroppedPickup
-        return true;
-    }
-    
-    //TODO: Steal description from Pickupable.
-    Pickupable* PickupCollection::clone()
-    {
-        Template* collectionTemplate = Template::getTemplate(this->getIdentifier()->getName());
-        BaseObject* newObject = collectionTemplate->getBaseclassIdentifier()->fabricate(this);
-        
-        PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject);
-        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
-        {
             Pickupable* newPickup = (*it)->clone();
-            newCollection->pickups_.push_back(newPickup);
+            pickup->addPickupable(newPickup);
         }
-        
-        Pickupable* pickup = dynamic_cast<Pickupable*>(newCollection);
-        return pickup;
+
+        pickup->initializeIdentifier();
     }
     
 }
\ No newline at end of file

Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -29,12 +29,14 @@
 #ifndef _PickupCollection_H__
 #define _PickupCollection_H__
 
-#include "pickup/PickupPrereqs.h"
+#include "PickupPrereqs.h"
 
 #include "interfaces/Pickupable.h"
 #include "core/BaseObject.h"
 #include "core/XMLPort.h"
 
+#include "PickupCollectionIdentifier.h"
+
 #include <list>
 
 namespace orxonox
@@ -59,17 +61,21 @@
 
             virtual void changedUsed(void);
             
-            virtual bool use(void);
-            virtual bool unuse(void);
+            virtual void changedCarrier(void);
             
-            virtual bool pickup(PickupCarrier* carrier);
-            virtual bool drop(void);
+            virtual void clone(OrxonoxClass* item);
             
-            virtual Pickupable* clone(void);
+            virtual const PickupIdentifier* getPickupIdentifier(void)
+                { return &this->pickupCollectionIdentifier_; }
             
             bool addPickupable(Pickupable* pickup);
             const Pickupable* getPickupable(unsigned int index);
             
+        protected:
+            void initializeIdentifier(void);
+            
+            PickupCollectionIdentifier pickupCollectionIdentifier_;
+            
         private:
             
             std::vector<Pickupable*> pickups_;

Modified: code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupPrereqs.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/PickupPrereqs.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -66,9 +66,16 @@
 {
 
     class DroppedItem;
+    class Pickup;
     class PickupCollection;
+    class PickupCollectionIdentifier;
+    class PickupManager;
+    class PickupRepresentation;
     class PickupSpawner;
     
+    //items
+    class HealthPickup;
+    
 }
 
 #endif /* _PickupPrereqs_H__ */

Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.cc	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.cc	2010-03-04 10:56:26 UTC (rev 6466)
@@ -38,6 +38,8 @@
 #include "core/Template.h"
 #include "core/XMLPort.h"
 #include "worldentities/pawns/Pawn.h"
+#include "PickupManager.h"
+#include "PickupRepresentation.h"
 //#include "PickupInventory.h"    // HACK; Only for hack, remove later
 
 
@@ -58,7 +60,16 @@
     */
     PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator)
     {
+        RegisterObject(PickupSpawner);
+        
         this->initialize();
+        
+        PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(NULL);
+        
+        COUT(1) << "MUP4 " << representation << std::endl;
+        this->attach(representation->getSpawnerRepresentation(this));
+        
+        COUT(1) << "MUP6" << std::endl;
     }
 
     /**
@@ -77,6 +88,8 @@
     */
     PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)
     {
+        RegisterObject(PickupSpawner);
+        
         this->initialize();
   
         this->pickup_ = pickup;
@@ -84,6 +97,9 @@
         this->triggerDistance_ = triggerDistance;
         this->respawnTime_ = respawnTime;
         this->setMaxSpawnedItems(maxSpawnedItems);
+        
+        PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
+        this->attach(representation->getSpawnerRepresentation(this));
     }
 
     /**
@@ -92,8 +108,6 @@
     */
     void PickupSpawner::initialize(void)
     {
-        RegisterObject(PickupSpawner);
-
         this->pickup_ = NULL;
         
         this->triggerDistance_ = 20;
@@ -214,7 +228,7 @@
     @param dt
         Time since last tick.
     */
-    //TODO: Replace this with a real DistanceTrigger?
+    //TODO: Replace this with a real DistanceTrigger? Or better with collisions?
     void PickupSpawner::tick(float dt)
     {
         //! If the PickupSpawner is active.
@@ -258,6 +272,7 @@
             Pickupable* pickup = this->getPickup();
             if (pickup != NULL) //!< If everything went ok, and pickup is not NULL.
             {
+                //TODO: Not correct anymore.
                 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
                 if(carrier == NULL)
                 {
@@ -265,7 +280,7 @@
                     return;
                 }
                 
-                if(pickup->pickup(carrier))
+                if(carrier->pickup(pickup))
                 {
                     COUT(3) << "Pickup got picked up." << std::endl;
 

Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -34,7 +34,7 @@
 #ifndef _PickupSpawner_H__
 #define _PickupSpawner_H__
 
-#include "pickup/PickupPrereqs.h"
+#include "PickupPrereqs.h"
 
 #include <string>
 #include "tools/Timer.h"

Modified: code/branches/pickup3/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/orxonox/CMakeLists.txt	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/CMakeLists.txt	2010-03-04 10:56:26 UTC (rev 6466)
@@ -46,6 +46,7 @@
 ADD_SUBDIRECTORY(interfaces)
 ADD_SUBDIRECTORY(items)
 ADD_SUBDIRECTORY(overlays)
+ADD_SUBDIRECTORY(pickup)
 ADD_SUBDIRECTORY(sound)
 ADD_SUBDIRECTORY(weaponsystem)
 ADD_SUBDIRECTORY(worldentities)

Modified: code/branches/pickup3/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/pickup3/src/orxonox/OrxonoxPrereqs.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/OrxonoxPrereqs.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -134,6 +134,9 @@
     class Map;
     class OrxonoxOverlay;
     class OverlayGroup;
+    
+    // pickup
+    class PickupIdentifier;
 
     //sound
     class AmbientSound;

Modified: code/branches/pickup3/src/orxonox/interfaces/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/CMakeLists.txt	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/interfaces/CMakeLists.txt	2010-03-04 10:56:26 UTC (rev 6466)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   InterfaceCompilation.cc
+  Pickupable.cc
   RadarViewable.cc
 )

Modified: code/branches/pickup3/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/InterfaceCompilation.cc	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/interfaces/InterfaceCompilation.cc	2010-03-04 10:56:26 UTC (rev 6466)
@@ -33,7 +33,6 @@
 */
 
 #include "GametypeMessageListener.h"
-#include "Pickupable.h"
 #include "PickupCarrier.h"
 #include "PlayerTrigger.h"
 #include "RadarListener.h"
@@ -54,17 +53,6 @@
     }
     
     //----------------------------
-    // Pickupable
-    //----------------------------
-    Pickupable::Pickupable()
-    {
-        RegisterRootObject(Pickupable);
-
-        this->used_ = false;
-        this->owner_ = NULL;
-    }
-    
-    //----------------------------
     // PickupCarrier
     //----------------------------
     PickupCarrier::PickupCarrier()

Modified: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -36,22 +36,63 @@
 
 #include "OrxonoxPrereqs.h"
 #include "core/OrxonoxClass.h"
+#include "Pickupable.h"
 
 #include <set>
+#include <list>
 
 namespace orxonox
 {
 
-    class _OrxonoxExport PickupCarrier : public OrxonoxClass
+    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
     {
+        friend class Pickupable;
         
         public:
             PickupCarrier();
             virtual ~PickupCarrier() {}
+            
+            //TODO: Secure uniqueness of each item in the set, if neccessary, check.
+            inline bool pickup(Pickupable* pickup)
+                {
+                    bool pickedUp = this->pickups_.insert(pickup).second;
+                    if(pickedUp) pickup->pickedUp(this);
+                    return pickedUp;
+                }
+                
+            inline bool drop(Pickupable* pickup)
+                { 
+                   bool dropped = this->pickups_.erase(pickup) == 1;
+                   if(dropped)
+                   {
+                       pickup->dropped();
+                        //TODO: Create Spawner.
+                   }
+                   return dropped;
+                }
+                
+            inline bool isTarget(Pickupable* pickup)
+                {
+                    if(pickup->isTarget(this))
+                        return true;
+                    const std::list<PickupCarrier*>* children = this->getChildren();
+                    for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
+                    {
+                        if((*it)->isTarget(pickup))
+                            return true;
+                    }
+                    
+                    return false;
+                }
+            
+        protected:            
+            //TODO: Good return type?
+            virtual const std::list<PickupCarrier*>* getChildren(void) = 0;
+            virtual PickupCarrier* getParent(void) = 0;
         
         private:
+            std::set<Pickupable*> pickups_;
             
-            std::set<Pickupable*> pickups_;
         
     };
     

Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -37,67 +37,33 @@
 #include "OrxonoxPrereqs.h"
 #include "core/OrxonoxClass.h"
 
-#include "core/Identifier.h"
 #include "core/Super.h"
-#include "interfaces/PickupCarrier.h"
-#include "worldentities/pawns/Pawn.h"
+#include "pickup/PickupIdentifier.h"
 #include <list>
 
 namespace orxonox
 {
-
-    //! Enum for the activation type.
-    namespace pickupActivationType
-    {
-        enum Value
-        {
-            immediate,
-            onUse,
-        };
-    }
     
-    //! Enum for the duration tyoe.
-    namespace pickupDurationType
-    {
-        enum Value
-        {
-            once,
-            continuous,
-        };
-    }
-    
     /**
     @brief
-        An Interface (or more precisely an abstract Class) to model and manage different (all kinds of) pickups.
+        An Interface (or more precisely an abstract Class) to model and represent different (all kinds of) pickups.
     @author
         Damian 'Mozork' Frick
     */
     //TODO: Add stuff like weight/space ?
     class _OrxonoxExport Pickupable : virtual public OrxonoxClass
     {
+        
         public:
             Pickupable(); //!< Default constructor.
             virtual ~Pickupable() {} //!< Default destructor.
-            
-            /**
-            @brief Get the activation type of the pickup.
-            @return Returns the activation type of the pickup.
-            */
-            inline pickupActivationType::Value getActivationType(void)
-                { return this->activationType_; }
-            /**
-            @brief Get the duration type of the pickup.
-            @return Returns the duration type of the pickup.
-            */
-            inline pickupDurationType::Value getDurationType(void)
-                { return this->durationType_; }
                 
             /**
-            @brief Get the owner of the pickup.
-            @return Returns a pointer to the owner of the pickup.
+            @brief Get the carrier of the pickup.
+            @return Returns a pointer to the carrier of the pickup.
             */
-            inline PickupCarrier* getOwner(void)
-                { return this->owner_; }
+            inline PickupCarrier* getCarrier(void)
+                { return this->carrier_; }
                 
             /**
             @brief Get whether the pickup is currently in use or not.
@@ -106,92 +72,57 @@
             inline bool isUsed(void)
                 { return this->used_; }
                 
-            /**
-            @brief Get whether the given pawn is a target of this pickup.
-            @param pawn The Pawn of which it has to be determinde whether it is a target of this pickup.
-            @return Retruns true if the given Pawn is a target.
-            */
-            //TODO: Determine whether Pawn includes all possible cases and if PickupCarrier wouldn't be better.
-            inline bool isTarget(Pawn* pawn)
-                {
-                    Identifier* identifier = pawn->getIdentifier();
-                    for(std::list<Identifier*>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
-                    {
-                        if(identifier->isA(*it))
-                            return true;
-                    }
-                    return false;
-                }
-                
-            /**
-            @brief  Should be called when the pickup has transitetd from used to unused or the other way around.
-                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changeUsed method.
-            */
-            virtual inline void changedUsed(void)
-                {
-                    if(this->isUsed())
-                        this->used_ = false;
-                    else
-                        this->used_ = true;
-                }
+            bool isTarget(PickupCarrier* carrier);
+            bool addTarget(PickupCarrier* target);
 
-            /**
-            @brief  Sets the pickup to used and makes sure the effects of the pickup take effect at the right places.
-                    This method needs to be implemented by any Class inheriting from Pickupable.
-            @return Returns false if for some reason the method could not take effect, e.g. because it is already in use, or some other circumstance.
-            */
-            virtual bool use(void) = 0;
-            /**
-            @brief  Sets the pickup to unused and makes sure the effects of the pickup no longer take effect.
-                    This method needs to be implemented by any Class inheriting from Pickupable.
-            @return Returns false if for some reason the method could not take effect, e.g. because the pickup is already unused, or some other circumstance.
-            */
-            virtual bool unuse(void) = 0;
+            bool setUsed(bool used);
             
-            /**
-            @brief  Adds the pickup to the input PickupCarrier.
-                    This method needs to be implemented by any Class inheriting from Pickupable.
-            @return Returns false if, for some reason, the pickup could not be picked up.
-            */
-            //TODO: Maybe better in PickupCarrier?
-            virtual bool pickup(PickupCarrier* carrier) = 0;
-            /**
-            @brief  Drops the pickup. Creates a PickupSpawner at the place the Pickup has been dropped.
-                    This method needs to be implemented by any Class inheriting from Pickupable.
-            @return Returns false if the pickup could not be dropped.
-            */
-            //TODO: Probably could be done here?
-            virtual bool drop(void) = 0;
+            bool pickedUp(PickupCarrier* carrier);
+            bool dropped(void);
             
+            inline bool isPickedUp(void)
+                { return this->pickedUp_; }
+            
+            Pickupable* clone(void);
+            
+            virtual const PickupIdentifier* getPickupIdentifier(void)
+                { return &this->pickupIdentifier_; }
+                
+            virtual void clone(OrxonoxClass* item);
+            
             /**
-            @brief  Creates a duplicate of the pickup.
-                    This method needs to e implemented by any Class inheriting from Pickupable.
-            @return Returns the clone of this pickup as a pointer to a Pickupable.
+            @brief  Should be called when the pickup has transited from used to unused or the other way around.
+                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method.
             */
-            //TODO: Would be nicer if standard case was implemented here.
-            virtual Pickupable* clone(void) = 0;
+            virtual void changedUsed(void) {}
             
             /**
-            @brief Sets the owner of the pickup.
-            @param owner Sets the input PickupCarrier as the owner of the pickup.
+            @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
+                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
             */
-            //TODO: Protected? Check for NULL and return true/false?
-            inline void setOwner(PickupCarrier* owner)
-                { this->owner_ = owner; }
+            virtual void changedCarrier(void) {}
             
-        private:
+            bool setCarrier(PickupCarrier* carrier);
             
-            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
-            pickupDurationType::Value durationType_; //!< The duration type of the pickup.
+        protected:
+            void initializeIdentifier(void) {}
             
+            PickupIdentifier pickupIdentifier_;
+            
+        private:
+            inline void setPickedUp(bool pickedUp)
+                { this->pickedUp_ = pickedUp; }
+            
             bool used_; //!< Whether the pickup is currently in use or not.
+            bool pickedUp_; //!< Whether the pickup is currently picked up or not.
             
-            PickupCarrier* owner_; //!< The owner of the pickup.
+            PickupCarrier* carrier_; //!< The owner of the pickup.
             std::list<Identifier*> targets_; //!< The possible targets of this pickup.
 
     };
     
-    SUPER_FUNCTION(10, Pickupable, changedUsed, true)
+    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
+    SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
 }
 
 #endif /* _Pickupable_H__ */

Modified: code/branches/pickup3/src/orxonox/pickup/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/orxonox/pickup/CMakeLists.txt	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/pickup/CMakeLists.txt	2010-03-04 10:56:26 UTC (rev 6466)
@@ -1,11 +1,4 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
-  BaseItem.cc
-  EquipmentItem.cc
-  ModifierPickup.cc
-  PassiveItem.cc
-  PickupCollection.cc
-  PickupInventory.cc
-  UsableItem.cc
+  PickupIdentifier.cc
 )
 
-ADD_SUBDIRECTORY(items)

Modified: code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h	2010-03-03 22:46:32 UTC (rev 6465)
+++ code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h	2010-03-04 10:56:26 UTC (rev 6466)
@@ -32,14 +32,13 @@
 #include "OrxonoxPrereqs.h"
 
 #include <string>
+#include "interfaces/PickupCarrier.h"
 #include "interfaces/RadarViewable.h"
 #include "worldentities/ControllableEntity.h"
-//TODO: Remove.
-//#include "pickup/PickupCollection.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable
+    class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable, public PickupCarrier
     {
         friend class WeaponSystem;
 
@@ -138,6 +137,10 @@
 
             //TODO: Remove.
             //PickupCollection pickups_;
+            virtual const std::list<PickupCarrier*>* getChildren(void)
+                { return new std::list<PickupCarrier*>(); }
+            virtual PickupCarrier* getParent(void)
+                { return NULL; }
 
             float health_;
             float maxHealth_;




More information about the Orxonox-commit mailing list