[Orxonox-commit 1794] r6512 - in code/branches/pickup3: data/levels data/levels/templates src/modules/pickup src/modules/pickup/items src/orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Thu Mar 11 16:30:30 CET 2010


Author: dafrick
Date: 2010-03-11 16:30:30 +0100 (Thu, 11 Mar 2010)
New Revision: 6512

Added:
   code/branches/pickup3/data/levels/pickup.oxw
   code/branches/pickup3/src/modules/pickup/items/TestPickup.cc
   code/branches/pickup3/src/modules/pickup/items/TestPickup.h
Modified:
   code/branches/pickup3/data/levels/templates/pickup_representation_templates.oxt
   code/branches/pickup3/src/modules/pickup/DroppedPickup.cc
   code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
   code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc
   code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
   code/branches/pickup3/src/modules/pickup/PickupSpawner.h
   code/branches/pickup3/src/modules/pickup/items/CMakeLists.txt
   code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
   code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
Log:
Added additional pickup (TestPickup), and did some bug $fixing.


Added: code/branches/pickup3/data/levels/pickup.oxw
===================================================================
--- code/branches/pickup3/data/levels/pickup.oxw	                        (rev 0)
+++ code/branches/pickup3/data/levels/pickup.oxw	2010-03-11 15:30:30 UTC (rev 6512)
@@ -0,0 +1,76 @@
+<?lua
+  include("stats.oxo")
+  include("hudtemplates3.oxo")
+?>
+
+<?lua
+  include("templates/spaceship_assff.oxt")
+  include("templates/spaceship_pirate.oxt")
+  include("templates/pickup_representation_templates.oxt")
+?>
+
+<Level
+ name         = "Sample"
+ description  = "Just a few tests"
+>
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+<?lua
+  include("includes/pickups.oxi")
+?>
+    
+    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <TestPickup testType="drop" />
+        </pickup>
+    </PickupSpawner>
+    
+    <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <TestPickup testType="use" />
+        </pickup>
+    </PickupSpawner>
+
+    <PickupSpawner position="-50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=onUse healthType=limited />
+        </pickup>
+    </PickupSpawner>
+    
+    <PickupSpawner position="-25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup template=smallhealthpickup />
+        </pickup>
+    </PickupSpawner>
+    
+    <PickupSpawner position="0,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup template=mediumhealthpickup />
+        </pickup>
+    </PickupSpawner>
+    
+    <PickupSpawner position="25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup template=hugehealthpickup />
+        </pickup>
+    </PickupSpawner>
+    
+    <PickupSpawner position="50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup template=crazyhealthpickup />
+        </pickup>
+    </PickupSpawner>
+
+    <!--PickupSpawner position="100,100,100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=limited />
+        </pickup>
+    </PickupSpawner-->
+
+    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+    <SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+  </Scene>
+</Level>

Modified: code/branches/pickup3/data/levels/templates/pickup_representation_templates.oxt
===================================================================
--- code/branches/pickup3/data/levels/templates/pickup_representation_templates.oxt	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/data/levels/templates/pickup_representation_templates.oxt	2010-03-11 15:30:30 UTC (rev 6512)
@@ -3,7 +3,11 @@
         <spawner-representation>
             <StaticEntity>
                 <attached>
-                    <Billboard position="0,0,0" colour="0.5,1.0,0" material="Examples/Flare" />
+                    <Billboard position="0,0,0" colour="0.50,0.90,0.25" material="Sphere2" scale=0.1>
+                        <attached>
+                            <Billboard position="0,0,0" colour="0.36,0.81,0.10" material="Cross" scale=0.3 />
+                        </attached>
+                    </Billboard>
                 </attached>
             </StaticEntity>
         </spawner-representation>
@@ -24,7 +28,11 @@
         <spawner-representation>
             <StaticEntity>
                 <attached>
-                    <Billboard position="0,0,0" colour="0,1.0,0.5" material="Examples/Flare" />
+                    <Billboard position="0,0,0" colour="0.50,0.90,0.25" material="Sphere2" scale=0.1>
+                        <attached>
+                            <Billboard position="0,0,0" colour="0.36,0.81,0.10" material="Cross" scale=0.5 />
+                        </attached>
+                    </Billboard>
                 </attached>
             </StaticEntity>
         </spawner-representation>
@@ -45,7 +53,11 @@
         <spawner-representation>
             <StaticEntity>
                 <attached>
-                    <Billboard position="0,0,0" colour="0,1.0,0.5" material="Examples/Flare" />
+                    <Billboard position="0,0,0" colour="0.50,0.90,0.25" material="Sphere2" scale=0.1>
+                        <attached>
+                            <Billboard position="0,0,0" colour="0.36,0.81,0.10" material="Cross" scale=0.7 />
+                        </attached>
+                    </Billboard>
                 </attached>
             </StaticEntity>
         </spawner-representation>
@@ -66,7 +78,11 @@
         <spawner-representation>
             <StaticEntity>
                 <attached>
-                    <Billboard position="0,0,0" colour="0,1.0,0.5" material="Examples/Flare" />
+                    <Billboard position="0,0,0" colour="0.50,0.90,0.25" material="Sphere2" scale=0.1>
+                        <attached>
+                            <Billboard position="0,0,0" colour="0.36,0.81,0.10" material="Cross" scale=1.2 />
+                        </attached>
+                    </Billboard>
                 </attached>
             </StaticEntity>
         </spawner-representation>

Modified: code/branches/pickup3/src/modules/pickup/DroppedPickup.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedPickup.cc	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/DroppedPickup.cc	2010-03-11 15:30:30 UTC (rev 6512)
@@ -39,6 +39,9 @@
 
 namespace orxonox
 {
+    
+    CreateFactory(DroppedPickup);
+    
     /**
     @brief
         Default constructor. Registers object and sets default values.
@@ -62,13 +65,15 @@
     @param triggerDistance
         The distance at which the PickupSpawner triggers. Default is 10.
     */
-    DroppedPickup::DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance) : PickupSpawner(creator, pickup, triggerDistance, 0, 1)
+    DroppedPickup::DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance) : PickupSpawner(creator, pickup, triggerDistance, 10, 1)
     {   
         RegisterObject(DroppedPickup);
         
         this->initialize();
         
         this->setPosition(position);
+        this->setActive(false);
+        this->startRespawnTimer();
     }
 
     /**

Modified: code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupPrereqs.h	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/PickupPrereqs.h	2010-03-11 15:30:30 UTC (rev 6512)
@@ -75,6 +75,7 @@
     
     //items
     class HealthPickup;
+    class TestPickup;
     
 }
 

Modified: code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc	2010-03-11 15:30:30 UTC (rev 6512)
@@ -153,11 +153,16 @@
     StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
     {
         StaticEntity* representation = new StaticEntity(spawner);
-        //TODO: Nicer...
-        Billboard* billboard = new Billboard(spawner);
-        billboard->setColour(ColourValue(1.0, 0.0, 0.0));
-        billboard->setMaterial("Examples/Flare");
-        representation->attach(billboard);
+        Billboard* sphere = new Billboard(spawner);
+        sphere->setColour(ColourValue(0.95, 0.85, 0.27));
+        sphere->setMaterial("Sphere2");
+        sphere->setScale(0.1);
+        Billboard* icon = new Billboard(spawner);
+        icon->setColour(ColourValue(0.89, 0.79, 0.08));
+        icon->setMaterial("Asterix");
+        icon->setScale(0.5);
+        sphere->attach(icon);
+        representation->attach(sphere);
         return representation;
     }
     

Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.cc	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.cc	2010-03-11 15:30:30 UTC (rev 6512)
@@ -215,7 +215,7 @@
         if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0)
         {
             //TODO: Nicer? Does this even work?
-            this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
+            this->startRespawnTimer();
 
             this->setActive(false);
             this->fireEvent();
@@ -230,6 +230,15 @@
     
     /**
     @brief
+        Starts the respawn timer.
+    */
+    void PickupSpawner::startRespawnTimer(void)
+    {
+        this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
+    }
+    
+    /**
+    @brief
         Sets a Pickupable for the PickupSpawner to spawn.
     @param pickup
         The Pickupable to be set.

Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.h	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.h	2010-03-11 15:30:30 UTC (rev 6512)
@@ -100,6 +100,8 @@
 
         protected:
             void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
+                        
+            void startRespawnTimer(void);
             
             virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
             

Modified: code/branches/pickup3/src/modules/pickup/items/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/modules/pickup/items/CMakeLists.txt	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/modules/pickup/items/CMakeLists.txt	2010-03-11 15:30:30 UTC (rev 6512)
@@ -1,3 +1,4 @@
 ADD_SOURCE_FILES(PICKUP_SRC_FILES
   HealthPickup.cc
+  TestPickup.cc
 )

Added: code/branches/pickup3/src/modules/pickup/items/TestPickup.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/items/TestPickup.cc	                        (rev 0)
+++ code/branches/pickup3/src/modules/pickup/items/TestPickup.cc	2010-03-11 15:30:30 UTC (rev 6512)
@@ -0,0 +1,153 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+*/
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "interfaces/PickupCarrier.h"
+#include "worldentities/pawns/Pawn.h"
+#include "pickup/PickupIdentifier.h"
+
+#include "TestPickup.h"
+
+namespace orxonox {
+ 
+    CreateFactory(TestPickup);
+    
+    /*static*/ const std::string TestPickup::testTypeNone_s = "none";
+    /*static*/ const std::string TestPickup::testTypeUse_s = "use";
+    /*static*/ const std::string TestPickup::testTypeDrop_s = "drop";
+    
+    TestPickup::TestPickup(BaseObject* creator) : Pickup(creator)
+    {
+        RegisterObject(TestPickup);
+        
+        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+        this->setActivationTypeDirect(pickupActivationType::immediate);
+        this->setDurationTypeDirect(pickupDurationType::once);
+        this->testType_ = pickupTestType::none;
+    }
+    
+    TestPickup::~TestPickup()
+    {
+        
+    }
+    
+    void TestPickup::initializeIdentifier(void)
+    {
+        std::string val = this->getTestType();
+        std::string type = "testType";
+        this->pickupIdentifier_->addParameter(type, val);
+    }
+    
+    void TestPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
+    {
+        SUPER(TestPickup, XMLPort, xmlelement, mode);
+        
+        XMLPortParam(TestPickup, "testType", setTestType, getTestType, xmlelement, mode);
+        
+        this->initializeIdentifier();
+    }
+    
+    void TestPickup::changedUsed(void)
+    {
+        SUPER(TestPickup, changedUsed);
+        
+        if(this->isUsed())
+        {
+            PickupCarrier* carrier = this->getCarrier();
+            if(this->getTestTypeDirect() != pickupTestType::none && carrier != NULL)
+            {
+                std::set<Pickupable*> pickups = carrier->getPickups();
+                for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
+                {
+                    Pickup* pickup = dynamic_cast<Pickup*>(*it);
+                    if(this->getTestTypeDirect() == pickupTestType::use)
+                    {
+                        if(pickup != NULL && pickup != this && pickup->isOnUse() && !pickup->isUsed())
+                        {
+                            pickup->setUsed(true);
+                        }
+                    }
+                    if(this->getTestTypeDirect() == pickupTestType::drop)
+                    {
+                        if(pickup != NULL && pickup != this)
+                        {
+                            carrier->drop(pickup);
+                        }
+                    }
+                }
+            }
+            this->destroy();
+        }
+    }
+    
+    const std::string& TestPickup::getTestType(void)
+    {
+        switch(this->getTestTypeDirect())
+        {
+            case pickupTestType::none:
+                return TestPickup::testTypeNone_s;
+            case pickupTestType::use:
+                return TestPickup::testTypeUse_s;
+            case pickupTestType::drop:
+                return TestPickup::testTypeDrop_s;
+            default:
+                return BLANKSTRING;
+        }
+    }
+    
+    void TestPickup::setTestType(const std::string& type)
+    {
+        if(type == TestPickup::testTypeNone_s)
+        {
+            this->setTestTypeDirect(pickupTestType::none);
+        }
+        else if(type == TestPickup::testTypeUse_s)
+        {
+            this->setTestTypeDirect(pickupTestType::use);
+        }
+        else if(type == TestPickup::testTypeDrop_s)
+        {
+            this->setTestTypeDirect(pickupTestType::drop);
+        }
+    }
+    
+    void TestPickup::clone(OrxonoxClass*& item)
+    {
+        if(item == NULL)
+            item = new TestPickup(this);
+        
+        SUPER(TestPickup, clone, item);
+        
+        TestPickup* pickup = dynamic_cast<TestPickup*>(item);
+        pickup->setTestTypeDirect(this->getTestTypeDirect());
+        
+        pickup->initializeIdentifier();
+    }
+    
+}

Added: code/branches/pickup3/src/modules/pickup/items/TestPickup.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/items/TestPickup.h	                        (rev 0)
+++ code/branches/pickup3/src/modules/pickup/items/TestPickup.h	2010-03-11 15:30:30 UTC (rev 6512)
@@ -0,0 +1,85 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Damian 'Mozork' Frick
+ *   Co-authors:
+ *      ...
+ *
+*/
+
+#ifndef _TestPickup_H__
+#define _TestPickup_H__
+
+#include "pickup/PickupPrereqs.h"
+
+#include "pickup/Pickup.h"
+
+namespace orxonox {
+
+    namespace pickupTestType
+    {
+        enum Value
+        {
+            none,
+            use,
+            drop
+        };
+    }
+    
+    class _PickupExport TestPickup : public Pickup
+    {
+        friend class PickupCarrier;
+        
+        public:
+            TestPickup(BaseObject* creator);
+            virtual ~TestPickup();
+            
+            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
+            
+            virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
+            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
+            
+            inline pickupTestType::Value getTestTypeDirect(void)
+                { return this->testType_; }
+            const std::string& getTestType(void);
+            
+        protected:
+            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
+            
+            inline void setTestTypeDirect(pickupTestType::Value type)
+                { this->testType_ =  type; }
+            void setTestType(const std::string& type);
+            
+        private:
+            void initialize(void); //!< Initializes the member variables.
+            
+            pickupTestType::Value testType_;
+            static const std::string testTypeNone_s;
+            static const std::string testTypeUse_s;
+            static const std::string testTypeDrop_s;
+            
+        
+    };
+
+}
+
+#endif // _TestPickup_H__

Modified: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h	2010-03-11 15:30:30 UTC (rev 6512)
@@ -39,11 +39,16 @@
 #include <list>
 #include <set>
 #include "Pickupable.h"
+#include "core/Identifier.h"
 
 #include "core/OrxonoxClass.h"
 
 namespace orxonox
 {
+    
+    class Pickup;
+    class HealthPickup;
+    class TestPickup;
 
     /**
     @brief
@@ -54,6 +59,10 @@
     class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
     {
         friend class Pickupable; //!< The Pickupable has full acces to its PickupCarrier.
+        //TODO: Ugly workaround.
+        friend class Pickup;
+        friend class HealthPickup;
+        friend class TestPickup;
         
         public:
             PickupCarrier(); //!< Constructor.
@@ -68,7 +77,10 @@
                 {
                     bool pickedUp = this->pickups_.insert(pickup).second;
                     if(pickedUp)
+                    {
+                        COUT(4) << "Picked up Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
                         pickup->pickedUp(this);
+                    }
                     return pickedUp;
                 }
                 
@@ -80,12 +92,13 @@
             */
             bool drop(Pickupable* pickup, bool drop = true)
                 { 
-                   bool dropped = this->pickups_.erase(pickup) == 1;
-                   if(dropped && drop)
-                   {
-                       pickup->dropped();
-                   }
-                   return dropped;
+                    bool dropped = this->pickups_.erase(pickup) == 1;
+                    if(dropped && drop)
+                    {
+                        COUT(4) << "Dropping Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;
+                        pickup->dropped();
+                    }
+                    return dropped;
                 }
                 
             /**
@@ -160,6 +173,10 @@
             @return Returns the position as a Vector3.
             */
             virtual const Vector3& getCarrierPosition(void) = 0;
+                            
+            //TODO: Remove.
+            std::set<Pickupable*>& getPickups(void)
+                { return this->pickups_; }
         
         private:
             std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.

Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc	2010-03-11 15:18:06 UTC (rev 6511)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc	2010-03-11 15:30:30 UTC (rev 6512)
@@ -197,7 +197,9 @@
         this->setCarrier(NULL);
         //TODO: possible problem.
         if(!created)
+        {
             this->destroy();
+        }
         
         return true;
     }




More information about the Orxonox-commit mailing list