[Orxonox-commit 510] r3063 - in branches/pickups2/src/orxonox/objects/pickup: . items

danielh at orxonox.net danielh at orxonox.net
Mon May 25 17:38:00 CEST 2009


Author: danielh
Date: 2009-05-25 17:38:00 +0200 (Mon, 25 May 2009)
New Revision: 3063

Added:
   branches/pickups2/src/orxonox/objects/pickup/items/
   branches/pickups2/src/orxonox/objects/pickup/items/CMakeLists.txt
   branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.cc
   branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.h
   branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.cc
   branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.h
   branches/pickups2/src/orxonox/objects/pickup/items/Jump.cc
   branches/pickups2/src/orxonox/objects/pickup/items/Jump.h
Removed:
   branches/pickups2/src/orxonox/objects/pickup/Jump.cc
   branches/pickups2/src/orxonox/objects/pickup/Jump.h
Modified:
   branches/pickups2/src/orxonox/objects/pickup/CMakeLists.txt
   branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc
Log:
- Moved pickups to a seperate directory
- Added two pickups: HealthImmediate, HealthUsable

Modified: branches/pickups2/src/orxonox/objects/pickup/CMakeLists.txt
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/CMakeLists.txt	2009-05-25 15:13:41 UTC (rev 3062)
+++ branches/pickups2/src/orxonox/objects/pickup/CMakeLists.txt	2009-05-25 15:38:00 UTC (rev 3063)
@@ -2,7 +2,6 @@
   BaseItem.cc
   DroppedItem.cc
   EquipmentItem.cc
-  Jump.cc
   ModifierPickup.cc
   PassiveItem.cc
   PickupCollection.cc
@@ -10,3 +9,5 @@
   PickupSpawner.cc
   UsableItem.cc
 )
+
+ADD_SUBDIRECTORY(items)

Deleted: branches/pickups2/src/orxonox/objects/pickup/Jump.cc
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/Jump.cc	2009-05-25 15:13:41 UTC (rev 3062)
+++ branches/pickups2/src/orxonox/objects/pickup/Jump.cc	2009-05-25 15:38:00 UTC (rev 3063)
@@ -1,108 +0,0 @@
-/*
- *   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:
- *      Daniel 'Huty' Haggenmueller
- *   Co-authors:
- *      ...
- *
- */
-
-/**
-    @file
-    @brief Implementation of Jump.
-*/
-
-#include "Jump.h"
-#include "DroppedItem.h"
-
-#include "objects/worldentities/pawns/Pawn.h"
-
-#include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
-#include "core/Core.h"
-
-namespace orxonox
-{
-    CreateFactory(Jump);
-
-    /**
-        @brief Constructor
-        @param creator Object that created this item.
-    */
-    Jump::Jump(BaseObject* creator) : UsableItem(creator)
-    {
-        RegisterObject(Jump);
-
-        this->velocity_ = Vector3(0.0f, 0.0f, 0.0f);
-        this->jumpsAvailable_ = 1;
-    }
-    //! Deconstructor
-    Jump::~Jump()
-    {
-    }
-    /**
-        @brief XMLPort for Jump.
-        @param xmlelement Element of the XML-file.
-        @param mode XMLPort mode to use.
-    */
-    void Jump::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(Jump, XMLPort, xmlelement, mode);
-
-        XMLPortParam(Jump, "velocity", setVelocity, getVelocity, xmlelement, mode);
-        XMLPortParam(Jump, "jumpsAvailable", setJumpsAvailable, getJumpsAvailable, xmlelement, mode);
-    }
-    /**
-        @brief Called when the item is used, makes the user "jump".
-        @param pawn Pawn which used te item.
-    */
-    void Jump::used(Pawn* pawn)
-    {
-        if (this->jumpsAvailable_ > 0){
-            pawn->setVelocity(pawn->getVelocity() + pawn->getOrientation() * this->velocity_);
-        }
-
-        this->jumpsAvailable_--;
-        if (this->jumpsAvailable_ <= 0)
-        {
-            this->removeFrom(pawn);
-            delete this;
-        }
-    }
-    /**
-        @brief Called when the item is picked up.
-        @param pawn Pawn which picked up the item.
-    */
-    bool Jump::pickedUp(Pawn* pawn)
-    {
-        return this->addTo(pawn);
-    }
-    /**
-        @brief Called when the item is dropped, creates a DroppedItem behind the pawn.
-        @param pawn Pawn which dropped the item.
-    */
-    bool Jump::dropped(Pawn* pawn)
-    {
-        DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 30.0f);
-        return this->removeFrom(pawn);
-    }
-}

Deleted: branches/pickups2/src/orxonox/objects/pickup/Jump.h
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/Jump.h	2009-05-25 15:13:41 UTC (rev 3062)
+++ branches/pickups2/src/orxonox/objects/pickup/Jump.h	2009-05-25 15:38:00 UTC (rev 3063)
@@ -1,97 +0,0 @@
-/*
- *   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:
- *      Daniel 'Huty' Haggenmueller
- *   Co-authors:
- *      ...
- *
- */
-
-/**
-    @file
-    @brief Definition of Jump.
-*/
-
-#ifndef _Jump_H__
-#define _Jump_H__
-
-#include <climits>
-
-#include "OrxonoxPrereqs.h"
-
-#include "UsableItem.h"
-#include "util/Math.h"
-
-namespace orxonox
-{
-    class Pawn;
-
-    /**
-        @brief Jump-item, enables player to "jump" into a direction.
-    */
-    class _OrxonoxExport Jump : public UsableItem
-    {
-    public:
-        Jump(BaseObject* creator);      //!< Constructor
-        virtual ~Jump();                //!< Deconstructor
-
-        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< XMLPort
-
-        virtual int getMaxCarryAmount() const
-            { return INT_MAX; }
-
-        virtual void used(Pawn* pawn);          //!< Called when the item is used.
-
-        virtual bool pickedUp(Pawn* pawn);      //!< Called when the item is picked up.
-        virtual bool dropped(Pawn* pawn);       //!< Called when the item is dropped.
-
-        /**
-            @brief Get the velocity added when the item is used.
-            @return Returns the added velocity (relative to the Pawn).
-        */
-        inline const Vector3& getVelocity() const
-            { return this->velocity_; }
-        /**
-            @brief Set the velocity added when the item is used.
-            @param velocity New added velocity (relative to Pawn).
-        */
-        inline void setVelocity(const Vector3& velocity)
-            { this->velocity_ = velocity; }
-        /**
-            @brief Get the amount of jumps available.
-            @return Returns how many times the item can be used.
-        */
-        inline int getJumpsAvailable() const
-            { return this->jumpsAvailable_; }
-        /**
-            @brief Set the amount of jumps available.
-            @param num New number of available jumps.
-        */
-        inline void setJumpsAvailable(int num)
-            { this->jumpsAvailable_ = num; }
-    private:
-        Vector3 velocity_;      //!< The velocity added when the item is used.
-        int jumpsAvailable_;    //!< Amount of jumps still available.
-    };
-}
-
-#endif /* _Jump_H__ */

Modified: branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc	2009-05-25 15:13:41 UTC (rev 3062)
+++ branches/pickups2/src/orxonox/objects/pickup/PickupSpawner.cc	2009-05-25 15:38:00 UTC (rev 3063)
@@ -33,6 +33,8 @@
 
 #include "PickupSpawner.h"
 #include "BaseItem.h"
+#include "PickupInventory.h"    // HACK; Only for hack, remove later
+#include "gui/GUIManager.h"     // HACK; see above
 
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
@@ -78,6 +80,24 @@
         XMLPortParam(PickupSpawner, "item", setItemTemplateName, getItemTemplateName, xmlelement, mode);
         XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
         XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
+
+        // HACKs
+        // Load the GUI image as soon as the PickupSpawner gets loaded
+        //  = less delays while running
+        BaseObject* newObject = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this);
+        BaseItem* asItem = dynamic_cast<BaseItem*>(newObject);
+        if (asItem)
+        {
+            asItem->addTemplate(this->itemTemplate_);
+            PickupInventory::getImageForItem(asItem);
+            delete newObject;
+        }
+
+        //  & load the GUI itself too, along with some empty windows
+        //   = even less delays
+        GUIManager::getInstancePtr()->showGUI("PickupInventory");
+        GUIManager::getInstancePtr()->executeCode("hideGUI(\"PickupInventory\")");
+        PickupInventory::getSingleton();
     }
     /**
         @brief Invoked when the activity has changed. Sets visibility of attached objects.

Added: branches/pickups2/src/orxonox/objects/pickup/items/CMakeLists.txt
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/CMakeLists.txt	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/CMakeLists.txt	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,5 @@
+ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+  HealthImmediate.cc
+  HealthUsable.cc
+  Jump.cc
+)

Added: branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.cc
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.cc	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.cc	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,76 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of HealthImmediate.
+*/
+
+#include "HealthImmediate.h"
+
+#include "objects/worldentities/pawns/Pawn.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/Core.h"
+
+namespace orxonox
+{
+    CreateFactory(HealthImmediate);
+
+    HealthImmediate::HealthImmediate(BaseObject* creator) : PassiveItem(creator)
+    {
+        RegisterObject(HealthImmediate);
+
+        this->recoveredHealth_ = 0;
+    }
+    HealthImmediate::~HealthImmediate()
+    {
+    }
+
+    void HealthImmediate::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(HealthImmediate, XMLPort, xmlelement, mode);
+
+        XMLPortParam(HealthImmediate, "recoveredHealth", setRecoveredHealth, getRecoveredHealth, xmlelement, mode);
+    }
+
+    bool HealthImmediate::pickedUp(Pawn* pawn)
+    {
+        float maxH = pawn->getMaxHealth();
+        float curH = pawn->getHealth();
+
+        if (curH < maxH)
+        {
+            pawn->addHealth(this->recoveredHealth_);
+            delete this;
+        }
+
+        return (curH < maxH);
+    }
+}
\ No newline at end of file

Added: branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.h
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.h	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/HealthImmediate.h	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,68 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Definition of HealthImmediate.
+*/
+
+#ifndef _HealthImmediate_H__
+#define _HealthImmediate_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "../PassiveItem.h"
+
+namespace orxonox
+{
+    class Pawn;
+
+    /**
+        @brief Health-item, immediatly recovers health when picked up.
+    */
+    class _OrxonoxExport HealthImmediate : public PassiveItem
+    {
+    public:
+        HealthImmediate(BaseObject* creator);
+        virtual ~HealthImmediate();
+
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+        virtual bool pickedUp(Pawn* pawn);
+
+        inline float getRecoveredHealth() const
+            { return this->recoveredHealth_; }
+        inline void setRecoveredHealth(float recovery)
+            { this->recoveredHealth_ = recovery; }
+
+    private:
+        float recoveredHealth_;
+    };
+}
+
+#endif /* _HealthImmediate_H__ */
\ No newline at end of file

Added: branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.cc
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.cc	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.cc	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,105 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of HealthUsable.
+*/
+
+#include "HealthUsable.h"
+#include "../DroppedItem.h"
+
+#include "objects/worldentities/pawns/Pawn.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/Core.h"
+
+namespace orxonox
+{
+    CreateFactory(HealthUsable);
+
+    /**
+        @brief Constructor
+        @param creator Object that created this item.
+    */
+    HealthUsable::HealthUsable(BaseObject* creator) : UsableItem(creator)
+    {
+        RegisterObject(HealthUsable);
+
+        this->recoveredHealth_ = 0;
+    }
+    //! Deconstructor
+    HealthUsable::~HealthUsable()
+    {
+    }
+    /**
+        @brief XMLPort for Jump.
+        @param xmlelement Element of the XML-file.
+        @param mode XMLPort mode to use.
+    */
+    void HealthUsable::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(HealthUsable, XMLPort, xmlelement, mode);
+
+        XMLPortParam(HealthUsable, "recoveredHealth", setRecoveredHealth, getRecoveredHealth, xmlelement, mode);
+    }
+    /**
+        @brief Called when the item is used, makes the user "jump".
+        @param pawn Pawn which used te item.
+    */
+    void HealthUsable::used(Pawn* pawn)
+    {
+        float maxH = pawn->getMaxHealth();
+        float curH = pawn->getHealth();
+
+        if (curH < maxH) {
+            pawn->addHealth(this->recoveredHealth_);
+
+            this->removeFrom(pawn);
+            delete this;
+        }
+    }
+    /**
+        @brief Called when the item is picked up.
+        @param pawn Pawn which picked up the item.
+    */
+    bool HealthUsable::pickedUp(Pawn* pawn)
+    {
+        return this->addTo(pawn);
+    }
+    /**
+        @brief Called when the item is dropped, creates a DroppedItem behind the pawn.
+        @param pawn Pawn which dropped the item.
+    */
+    bool HealthUsable::dropped(Pawn* pawn)
+    {
+        DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 30.0f);
+        return this->removeFrom(pawn);
+    }
+}

Added: branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.h
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.h	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/HealthUsable.h	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,82 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Definition of HealthUsable.
+*/
+
+#ifndef _HealthUsable_H__
+#define _HealthUsable_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "../UsableItem.h"
+#include "util/Math.h"
+
+namespace orxonox
+{
+    class Pawn;
+
+    /**
+        @brief Health-item, enables player recover health when used.
+    */
+    class _OrxonoxExport HealthUsable : public UsableItem
+    {
+    public:
+        HealthUsable(BaseObject* creator);      //!< Constructor
+        virtual ~HealthUsable();                //!< Deconstructor
+
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< XMLPort
+
+        virtual int getMaxCarryAmount() const
+            { return INT_MAX; }
+
+        virtual void used(Pawn* pawn);          //!< Called when the item is used.
+
+        virtual bool pickedUp(Pawn* pawn);      //!< Called when the item is picked up.
+        virtual bool dropped(Pawn* pawn);       //!< Called when the item is dropped.
+
+        /**
+            @brief Get the amount of jumps available.
+            @return Returns how many times the item can be used.
+        */
+        inline float getRecoveredHealth() const
+            { return this->recoveredHealth_; }
+        /**
+            @brief Set the amount of jumps available.
+            @param num New number of available jumps.
+        */
+        inline void setRecoveredHealth(float recovery)
+            { this->recoveredHealth_ = recovery; }
+    private:
+        float recoveredHealth_;    //!< Amount of jumps still available.
+    };
+}
+
+#endif /* _HealthUsable_H__ */

Added: branches/pickups2/src/orxonox/objects/pickup/items/Jump.cc
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/Jump.cc	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/Jump.cc	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,108 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Implementation of Jump.
+*/
+
+#include "Jump.h"
+#include "DroppedItem.h"
+
+#include "objects/worldentities/pawns/Pawn.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/Core.h"
+
+namespace orxonox
+{
+    CreateFactory(Jump);
+
+    /**
+        @brief Constructor
+        @param creator Object that created this item.
+    */
+    Jump::Jump(BaseObject* creator) : UsableItem(creator)
+    {
+        RegisterObject(Jump);
+
+        this->velocity_ = Vector3(0.0f, 0.0f, 0.0f);
+        this->jumpsAvailable_ = 1;
+    }
+    //! Deconstructor
+    Jump::~Jump()
+    {
+    }
+    /**
+        @brief XMLPort for Jump.
+        @param xmlelement Element of the XML-file.
+        @param mode XMLPort mode to use.
+    */
+    void Jump::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(Jump, XMLPort, xmlelement, mode);
+
+        XMLPortParam(Jump, "velocity", setVelocity, getVelocity, xmlelement, mode);
+        XMLPortParam(Jump, "jumpsAvailable", setJumpsAvailable, getJumpsAvailable, xmlelement, mode);
+    }
+    /**
+        @brief Called when the item is used, makes the user "jump".
+        @param pawn Pawn which used te item.
+    */
+    void Jump::used(Pawn* pawn)
+    {
+        if (this->jumpsAvailable_ > 0){
+            pawn->setVelocity(pawn->getVelocity() + pawn->getOrientation() * this->velocity_);
+        }
+
+        this->jumpsAvailable_--;
+        if (this->jumpsAvailable_ <= 0)
+        {
+            this->removeFrom(pawn);
+            delete this;
+        }
+    }
+    /**
+        @brief Called when the item is picked up.
+        @param pawn Pawn which picked up the item.
+    */
+    bool Jump::pickedUp(Pawn* pawn)
+    {
+        return this->addTo(pawn);
+    }
+    /**
+        @brief Called when the item is dropped, creates a DroppedItem behind the pawn.
+        @param pawn Pawn which dropped the item.
+    */
+    bool Jump::dropped(Pawn* pawn)
+    {
+        DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 30.0f);
+        return this->removeFrom(pawn);
+    }
+}

Added: branches/pickups2/src/orxonox/objects/pickup/items/Jump.h
===================================================================
--- branches/pickups2/src/orxonox/objects/pickup/items/Jump.h	                        (rev 0)
+++ branches/pickups2/src/orxonox/objects/pickup/items/Jump.h	2009-05-25 15:38:00 UTC (rev 3063)
@@ -0,0 +1,97 @@
+/*
+ *   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:
+ *      Daniel 'Huty' Haggenmueller
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file
+    @brief Definition of Jump.
+*/
+
+#ifndef _Jump_H__
+#define _Jump_H__
+
+#include <climits>
+
+#include "OrxonoxPrereqs.h"
+
+#include "UsableItem.h"
+#include "util/Math.h"
+
+namespace orxonox
+{
+    class Pawn;
+
+    /**
+        @brief Jump-item, enables player to "jump" into a direction.
+    */
+    class _OrxonoxExport Jump : public UsableItem
+    {
+    public:
+        Jump(BaseObject* creator);      //!< Constructor
+        virtual ~Jump();                //!< Deconstructor
+
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);  //!< XMLPort
+
+        virtual int getMaxCarryAmount() const
+            { return INT_MAX; }
+
+        virtual void used(Pawn* pawn);          //!< Called when the item is used.
+
+        virtual bool pickedUp(Pawn* pawn);      //!< Called when the item is picked up.
+        virtual bool dropped(Pawn* pawn);       //!< Called when the item is dropped.
+
+        /**
+            @brief Get the velocity added when the item is used.
+            @return Returns the added velocity (relative to the Pawn).
+        */
+        inline const Vector3& getVelocity() const
+            { return this->velocity_; }
+        /**
+            @brief Set the velocity added when the item is used.
+            @param velocity New added velocity (relative to Pawn).
+        */
+        inline void setVelocity(const Vector3& velocity)
+            { this->velocity_ = velocity; }
+        /**
+            @brief Get the amount of jumps available.
+            @return Returns how many times the item can be used.
+        */
+        inline int getJumpsAvailable() const
+            { return this->jumpsAvailable_; }
+        /**
+            @brief Set the amount of jumps available.
+            @param num New number of available jumps.
+        */
+        inline void setJumpsAvailable(int num)
+            { this->jumpsAvailable_ = num; }
+    private:
+        Vector3 velocity_;      //!< The velocity added when the item is used.
+        int jumpsAvailable_;    //!< Amount of jumps still available.
+    };
+}
+
+#endif /* _Jump_H__ */




More information about the Orxonox-commit mailing list