[Orxonox-commit 1924] r6641 - in code/branches/ppspickups2: data/levels src/modules/pickup src/modules/pickup/items src/orxonox/interfaces

benedict at orxonox.net benedict at orxonox.net
Mon Mar 29 16:33:22 CEST 2010


Author: benedict
Date: 2010-03-29 16:33:22 +0200 (Mon, 29 Mar 2010)
New Revision: 6641

Modified:
   code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw
   code/branches/ppspickups2/src/modules/pickup/Pickup.cc
   code/branches/ppspickups2/src/modules/pickup/Pickup.h
   code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt
   code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc
   code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h
   code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h
Log:
Invisibility works. Timer for invi works.


Modified: code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw
===================================================================
--- code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw	2010-03-29 14:33:22 UTC (rev 6641)
@@ -6,7 +6,7 @@
 <?lua
   include("templates/spaceship_assff.oxt")
   include("templates/spaceship_pirate.oxt")
-  include("templates/pickup_representation_templates.oxt")
+  include("templates/pickup_representation_templates_invisible.oxt")
 ?>
 
 <Level
@@ -19,64 +19,15 @@
   >
 
 <?lua
-  include("includes/pickups.oxi")
+  include("includes/pickups_invisible.oxi")
 ?>
-    
-<!--
-    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
-        <pickup>
-            <MetaPickup metaType="drop" />
-        </pickup>
-    </PickupSpawner>
-    
-    <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
-        <pickup>
-            <MetaPickup metaType="use" />
-        </pickup>
-    </PickupSpawner>
 
-    <PickupSpawner position="-50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+    <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
         <pickup>
-            <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=permanent />
+            <InvisiblePickup template=invisiblepickup />
         </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="75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
-        <pickup>
-            <PickupCollection template=doublepickup />
-        </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 />

Modified: code/branches/ppspickups2/src/modules/pickup/Pickup.cc
===================================================================
--- code/branches/ppspickups2/src/modules/pickup/Pickup.cc	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/modules/pickup/Pickup.cc	2010-03-29 14:33:22 UTC (rev 6641)
@@ -38,26 +38,28 @@
 #include "pickup/PickupIdentifier.h"
 #include "DroppedPickup.h"
 
+#include "tools/Timer.h"
+
 namespace orxonox
 {
-    
+
     /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
     /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
     /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
     /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
-    
+
     Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
     {
         RegisterObject(Pickup);
-        
+
         this->initialize();
     }
-    
+
     Pickup::~Pickup()
     {
-        
+
     }
-    
+
     /**
     @brief
         Initializes the member variables.
@@ -67,22 +69,22 @@
         this->activationType_ = pickupActivationType::immediate;
         this->durationType_ = pickupDurationType::once;
     }
-    
+
     /**
     @brief
         Initializes the PickupIdentififer of this Pickup.
     */
     void Pickup::initializeIdentifier(void)
-    {        
+    {
         std::string val1 = this->getActivationType();
         std::string type1 = "activationType";
         this->pickupIdentifier_->addParameter(type1, val1);
-        
+
         std::string val2 = this->getDurationType();
         std::string type2 = "durationType";
         this->pickupIdentifier_->addParameter(type2, val2);
     }
-    
+
     /**
     @brief
         Method for creating a Pickup object through XML.
@@ -93,10 +95,10 @@
 
         XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
         XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
-        
+
         this->initializeIdentifier();
     }
-    
+
     /**
     @brief
         Get the activation type of the pickup.
@@ -115,7 +117,7 @@
                 return BLANKSTRING;
         }
     }
-        
+
     /**
     @brief
         Get the duration type of the pickup.
@@ -134,7 +136,7 @@
                 return BLANKSTRING;
         }
     }
-    
+
     /**
     @brief
         Set the activation type of the Pickup.
@@ -156,7 +158,7 @@
             COUT(1) << "Invalid activationType in pickup." << std::endl;
         }
     }
-        
+
     /**
     @brief
         Set the duration type of the Pickup.
@@ -178,7 +180,7 @@
             COUT(1) << "Invalid durationType in pickup." << std::endl;
         }
     }
-    
+
     /**
     @brief
         Should be called when the pickup has transited from picked up to dropped or the other way around.
@@ -187,14 +189,14 @@
     void Pickup::changedPickedUp(void)
     {
         SUPER(Pickup, changedPickedUp);
-        
+
         //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
         if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
         {
             this->setUsed(true);
         }
     }
-    
+
     /**
     @brief
         Creates a duplicate of the Pickup.
@@ -205,16 +207,16 @@
     {
         if(item == NULL)
             item = new Pickup(this);
-        
+
         SUPER(Pickup, clone, item);
-        
+
         Pickup* pickup = dynamic_cast<Pickup*>(item);
         pickup->setActivationTypeDirect(this->getActivationTypeDirect());
         pickup->setDurationTypeDirect(this->getDurationTypeDirect());
-        
+
         pickup->initializeIdentifier();
     }
-        
+
     /**
     @brief
         Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
@@ -230,5 +232,24 @@
         new DroppedPickup(this, this, this->getCarrier());
         return true;
     }
-    
+
+    /**
+    @brief
+        Starts the Pickup duration Timer.
+    */
+    bool Pickup::startPickupTimer(float durationTime)
+    {
+        if (durationTime<=0)
+        {
+            COUT(1) << "Invalid durationTime in pickup." << std::endl;
+            return false;
+        }
+        if (false) /*TODO*/
+        {
+            COUT(1) << "Pickup durationTimer already in use." << std::endl;
+            return false;
+        }
+        this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::PickupTimerCallBack, this)));
+        return true;
+    }
 }

Modified: code/branches/ppspickups2/src/modules/pickup/Pickup.h
===================================================================
--- code/branches/ppspickups2/src/modules/pickup/Pickup.h	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/modules/pickup/Pickup.h	2010-03-29 14:33:22 UTC (rev 6641)
@@ -37,9 +37,11 @@
 #include "pickup/PickupPrereqs.h"
 
 #include "core/BaseObject.h"
-#include "core/XMLPort.h"
+#include "core/XMLPort.h"
 
 #include "interfaces/Pickupable.h"
+
+#include "tools/Timer.h"
 
 namespace orxonox
 {
@@ -53,7 +55,7 @@
             onUse,
         };
     }
-    
+
     //! Enum for the duration tyoe.
     namespace pickupDurationType
     {
@@ -63,7 +65,7 @@
             continuous,
         };
     }
-    
+
     /**
     @brief
         Pickup class. Offers base functionality for a wide range of pickups.
@@ -73,15 +75,15 @@
     */
     class _PickupExport Pickup : public Pickupable, public BaseObject
     {
-        
+
         protected:
             Pickup(BaseObject* creator); //!< Constructor.
-        
+
         public:
             virtual ~Pickup(); //!< Destructor.
-            
+
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            
+
             /**
             @brief Get the activation type of the pickup.
             @return Returns the activation type of the pickup.
@@ -94,10 +96,10 @@
             */
             inline pickupDurationType::Value getDurationTypeDirect(void)
                 { return this->durationType_; }
-            
+
             const std::string& getActivationType(void); //!< Get the activation type of the pickup.
             const std::string& getDurationType(void); //!< Get the duration type of the pickup.
-            
+
             /**
             @brief Get whether the activation type is 'immediate'.
             @return Returns true if the activation type is 'immediate'.
@@ -122,16 +124,20 @@
             */
             inline bool isContinuous(void)
                 { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
-            
+
             virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
-                                    
+
             virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup.
-                
+
         protected:
             void initializeIdentifier(void);
-            
+
             virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
-            
+
+            bool startPickupTimer(float durationTime);
+
+            virtual void PickupTimerCallBack(void) {}
+
             /**
             @brief Set the activation type of the pickup.
             @param type The activation type of the pickup.
@@ -144,22 +150,24 @@
             */
             inline void setDurationTypeDirect(pickupDurationType::Value type)
                 { this->durationType_ = type; }
-                
+
             void setActivationType(const std::string& type); //!< Set the activation type of the pickup.
             void setDurationType(const std::string& type); //!< Set the duration type of the pickup
-                
+
         private:
             void initialize(void); //!< Initializes the member variables.
-            
+
             pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
             pickupDurationType::Value durationType_; //!< The duration type of the pickup.
-            
+
             static const std::string activationTypeImmediate_s;
             static const std::string activationTypeOnUse_s;
             static const std::string durationTypeOnce_s;
             static const std::string durationTypeContinuous_s;
-        
+
+            float durationTime_;
+            Timer durationTimer_;
     };
-    
+
 }
 #endif // _Pickup_H__

Modified: code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt
===================================================================
--- code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/modules/pickup/items/CMakeLists.txt	2010-03-29 14:33:22 UTC (rev 6641)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(PICKUP_SRC_FILES
   HealthPickup.cc
   MetaPickup.cc
+  InvisiblePickup.cc
 )

Modified: code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc
===================================================================
--- code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc	2010-03-29 14:33:22 UTC (rev 6641)
@@ -0,0 +1,209 @@
+/*
+ *   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:
+ *      Benedict Simlinger
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file InvisiblePickup.cc
+    @brief Implementation of the InvisiblePickup class.
+*/
+
+#include "InvisiblePickup.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "util/StringUtils.h"
+
+#include "worldentities/pawns/Pawn.h"
+#include "pickup/PickupIdentifier.h"
+
+#include <sstream>
+
+namespace orxonox
+{
+    
+    
+    CreateFactory(InvisiblePickup);
+    
+    /**
+    @brief
+        Constructor. Registers the object and initializes the member variables.
+    */
+    InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator)
+    {
+        RegisterObject(InvisiblePickup);
+	//! Defines who is allowed to pick up the pickup.
+	this->initialize(); 
+    }
+    
+    /**
+    @brief
+        Destructor.
+    */
+    InvisiblePickup::~InvisiblePickup()
+    {        
+    }
+    
+    
+    void InvisiblePickup::initializeIdentifier(void)
+    {
+	std::stringstream stream;
+	stream << this->getDuration();
+	std::string type1 = "duration";
+	std::string val1 = stream.str();
+	this->pickupIdentifier_->addParameter(type1, val1);
+    }
+    
+    /**
+    @brief
+    Initializes the member variables.
+    */
+    void InvisiblePickup::initialize(void)
+    {
+	this->duration_ = 0.0;
+	this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+    }
+ 
+   
+    
+
+    /**
+    @brief
+        Method for creating a HealthPickup object through XML.
+    */
+    void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
+    {
+        SUPER(InvisiblePickup, XMLPort, xmlelement, mode);    
+	XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode);
+	 
+	 this->initializeIdentifier();
+    }
+    
+    
+    /**
+    @brief
+        Is called when the pickup has transited from used to unused or the other way around.
+    */
+    void InvisiblePickup::changedUsed(void)
+    {
+        SUPER(InvisiblePickup, changedUsed);
+	
+        
+        //! If the pickup is not picked up nothing must be done.
+        if(!this->isPickedUp())
+            return;
+	if (this->isUsed())
+	{
+	    this->setInvisible(true);
+	    this->startPickupTimer(this->getDuration());
+	}
+	else
+	  this->setInvisible(false);
+	
+    }
+    
+    /**
+    @brief
+        Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+    @return
+        A pointer to the Pawn, or NULL if the conversion failed.
+    */
+    Pawn* InvisiblePickup::carrierToPawnHelper(void)
+    {
+        PickupCarrier* carrier = this->getCarrier();
+        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
+        
+        if(pawn == NULL)
+        {
+            COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;
+        }
+        return pawn;
+    }
+    
+    /**
+    @brief
+        Creates a duplicate of the input OrxonoxClass.
+    @param item
+        A pointer to the Orxonox class.
+    */
+    void InvisiblePickup::clone(OrxonoxClass*& item)
+    {
+        if(item == NULL)
+            item = new InvisiblePickup(this);
+        
+        SUPER(InvisiblePickup, clone, item);
+	
+	InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item);
+	pickup->setDuration(this->getDuration());
+	pickup->initializeIdentifier();
+    }
+    
+    
+    
+    
+     
+    /**
+    @brief
+        Sets the invisibility.
+    @param health
+        The invisibility.
+    */
+    bool InvisiblePickup::setInvisible(bool invisibility)
+    {
+      
+      Pawn* pawn = this->carrierToPawnHelper();
+      pawn->setVisible(!invisibility);
+      return 0;
+    }
+    
+   
+    
+    /**
+    @brief
+    Sets the duration.
+    @param duration
+    The duration
+    */
+    void InvisiblePickup::setDuration(float duration)
+    {
+	if(duration >= 0.0f)
+	{
+	    this->duration_ = duration;
+	}
+	else
+	{
+	    COUT(1) << "Invalid duration in InvisiblePickup." << std::endl;
+	    this->duration_ = 0;
+	}
+    }
+    
+    
+    
+    void InvisiblePickup::PickupTimerCallBack(void){
+	this->setInvisible(false);
+    }
+
+}

Modified: code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h
===================================================================
--- code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h	2010-03-29 14:33:22 UTC (rev 6641)
@@ -0,0 +1,89 @@
+/*
+ *   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:
+ *      Benedict Simlinger
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file InvisiblePickup.h
+    @brief Declaration of the InvisiblePickup class.
+*/
+
+#ifndef _InvisiblePickup_H__
+#define _InvisiblePickup_H__
+
+#include "pickup/PickupPrereqs.h"
+
+#include <string>
+#include <worldentities/pawns/Pawn.h>
+#include "worldentities/StaticEntity.h"
+
+#include "pickup/Pickup.h"
+
+namespace orxonox {
+        
+    /**
+    @brief
+        A pickup that makes the Pawn invisible.
+        There are 2 parameters that can be chosen:
+        1) The activation type: It can be chosen to be either 'immediate' or 'onUse'. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it.
+        2) The duration type: It can be chosen how long the Pawn will be invisibel.
+    @author
+        Benedict Simlinger
+    */
+    class _PickupExport InvisiblePickup : public Pickup
+    {
+        public:
+        
+            InvisiblePickup(BaseObject* creator); //!< Constructor.
+            virtual ~InvisiblePickup(); //!< Destructor.
+            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.
+            
+	     /**
+            @brief Checks wether the Pawn is invisible.
+            @return Returns if the Pawn is invisible.
+            */
+            inline bool getInvisibility(bool)
+                { return this->invisible_; }
+	    inline float getDuration()
+		{return this->duration_;}
+ 
+        protected:
+	    bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again.
+	    void setDuration(float duration);
+	    void initializeIdentifier(void);
+        
+        private:
+	   void initialize(void); //!< Initializes the member variables.
+            Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+            void PickupTimerCallBack(void); //!< Function that gets called when the timer ends.
+	    bool invisible_; //!< Helper to remember wether the Pawn is invisible.
+	    float duration_; //! Duration of invisibility.
+    };
+}
+
+#endif // _InvisiblePickup_H__

Modified: code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h	2010-03-29 14:23:08 UTC (rev 6640)
+++ code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h	2010-03-29 14:33:22 UTC (rev 6641)
@@ -47,10 +47,6 @@
 namespace orxonox
 {
 
-    //! Pre-declarations.
-    class Pickup;
-    class HealthPickup;
-    class MetaPickup;
 
     /**
     @brief
@@ -65,6 +61,7 @@
         friend class Pickup;
         friend class HealthPickup;
         friend class MetaPickup;
+	friend class InvisiblePickup;
         
         public:
             PickupCarrier(); //!< Constructor.




More information about the Orxonox-commit mailing list