[Orxonox-commit 243] r2900 - in branches/pickups: . src/orxonox/objects/controllers src/orxonox/objects/items src/orxonox/objects/pickup src/orxonox/objects/worldentities src/orxonox/objects/worldentities/pawns

danielh at orxonox.net danielh at orxonox.net
Mon Apr 6 15:53:50 CEST 2009


Author: danielh
Date: 2009-04-06 15:53:50 +0200 (Mon, 06 Apr 2009)
New Revision: 2900

Added:
   branches/pickups/src/orxonox/objects/pickup/DroppedItem.cc
   branches/pickups/src/orxonox/objects/pickup/DroppedItem.h
   branches/pickups/src/orxonox/objects/pickup/Jump.cc
   branches/pickups/src/orxonox/objects/pickup/Jump.h
Modified:
   branches/pickups/
   branches/pickups/src/orxonox/objects/controllers/HumanController.cc
   branches/pickups/src/orxonox/objects/controllers/HumanController.h
   branches/pickups/src/orxonox/objects/items/Engine.cc
   branches/pickups/src/orxonox/objects/pickup/BaseItem.cc
   branches/pickups/src/orxonox/objects/pickup/CMakeLists.txt
   branches/pickups/src/orxonox/objects/pickup/ModifierPickup.cc
   branches/pickups/src/orxonox/objects/pickup/ModifierPickup.h
   branches/pickups/src/orxonox/objects/pickup/ModifierType.h
   branches/pickups/src/orxonox/objects/pickup/PickupCollection.cc
   branches/pickups/src/orxonox/objects/pickup/PickupCollection.h
   branches/pickups/src/orxonox/objects/pickup/UsableItem.h
   branches/pickups/src/orxonox/objects/worldentities/ControllableEntity.h
   branches/pickups/src/orxonox/objects/worldentities/pawns/Pawn.h
Log:
- some changes to the base framework
- added DroppedItem
- implemented usable items and a test UsableItem (Jump), console command to use an item is "useItem"
- added ModifierType::Acceleration


Property changes on: branches/pickups
___________________________________________________________________
Added: svn:ignore
   + build
dependencies


Modified: branches/pickups/src/orxonox/objects/controllers/HumanController.cc
===================================================================
--- branches/pickups/src/orxonox/objects/controllers/HumanController.cc	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/controllers/HumanController.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -47,13 +47,13 @@
     SetConsoleCommand(HumanController, altFire,       true).keybindMode(KeybindMode::OnHold);
     SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
     SetConsoleCommand(HumanController, greet,         true);
-    SetConsoleCommand(HumanController, use,           true);
     SetConsoleCommand(HumanController, switchCamera,  true);
     SetConsoleCommand(HumanController, mouseLook,     true);
     SetConsoleCommand(HumanController, suicide,       true);
     SetConsoleCommand(HumanController, addBots,       true).defaultValues(1);
     SetConsoleCommand(HumanController, killBots,      true).defaultValues(0);
     SetConsoleCommand(HumanController, dropItems,     true);
+    SetConsoleCommand(HumanController, useItem,       true);
 
     CreateUnloadableFactory(HumanController);
 
@@ -131,12 +131,6 @@
             HumanController::localController_s->controllableEntity_->greet();
     }
 
-    void HumanController::use()
-    {
-        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
-            HumanController::localController_s->controllableEntity_->use();
-    }
-
     void HumanController::switchCamera()
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
@@ -159,6 +153,12 @@
         }
     }
 
+    void HumanController::useItem()
+    {
+        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+            HumanController::localController_s->controllableEntity_->useItem();
+    }
+
     void HumanController::addBots(unsigned int amount)
     {
         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())

Modified: branches/pickups/src/orxonox/objects/controllers/HumanController.h
===================================================================
--- branches/pickups/src/orxonox/objects/controllers/HumanController.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/controllers/HumanController.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -55,10 +55,10 @@
 
             static void boost();
             static void greet();
-            static void use();
             static void switchCamera();
             static void mouseLook();
             static void dropItems();
+            static void useItem();
 
             static void suicide();
 

Modified: branches/pickups/src/orxonox/objects/items/Engine.cc
===================================================================
--- branches/pickups/src/orxonox/objects/items/Engine.cc	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/items/Engine.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -191,7 +191,7 @@
                 acceleration.y = direction.y * this->accelerationUpDown_ * clamp((this->maxSpeedUpDown_ - velocity.y) / this->maxSpeedUpDown_, 0.0f, 1.0f);
         }
 
-        this->ship_->setAcceleration(this->ship_->getOrientation() * acceleration);
+        this->ship_->setAcceleration(this->ship_->getPickups().processModifiers(ModifierType::Acceleration, this->ship_->getOrientation() * acceleration, false));
 
         if (!this->ship_->getPermanentBoost())
             this->ship_->setBoost(false);

Modified: branches/pickups/src/orxonox/objects/pickup/BaseItem.cc
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/BaseItem.cc	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/BaseItem.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -62,9 +62,12 @@
     {
         this->setOwner(pawn);
 
-        COUT(3) << "Adding '" << this->getPickupIdentifier() << "' item." << std::endl;
-
-        return pawn->getPickups().add(this);
+        if (pawn->getPickups().add(this))
+        {
+            COUT(3) << "Added '" << this->getPickupIdentifier() << "' item." << std::endl;
+            return true;
+        }
+        return false;
     }
     /**
         @brief Removes the item from a pawn.

Modified: branches/pickups/src/orxonox/objects/pickup/CMakeLists.txt
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/CMakeLists.txt	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/CMakeLists.txt	2009-04-06 13:53:50 UTC (rev 2900)
@@ -1,6 +1,8 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
   BaseItem.cc
+  DroppedItem.cc
   EquipmentItem.cc
+  Jump.cc
   ModifierPickup.cc
   PassiveItem.cc
   PickupCollection.cc

Added: branches/pickups/src/orxonox/objects/pickup/DroppedItem.cc
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/DroppedItem.cc	                        (rev 0)
+++ branches/pickups/src/orxonox/objects/pickup/DroppedItem.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -0,0 +1,93 @@
+#include "DroppedItem.h"
+
+#include "BaseItem.h"
+#include "objects/worldentities/pawns/Pawn.h"
+#include "objects/worldentities/Model.h"
+#include "objects/worldentities/Billboard.h"
+
+#include "core/CoreIncludes.h"
+#include "core/Core.h"
+
+namespace orxonox
+{
+    CreateFactory(DroppedItem);
+
+    DroppedItem::DroppedItem(BaseObject* creator) : StaticEntity(creator)
+    {
+        RegisterObject(DroppedItem);
+
+        this->triggerDistance_ = 20.0f;
+        this->timeToLive_ = 0;
+        this->item_ = 0;
+    }
+    DroppedItem::~DroppedItem()
+    {
+    }
+    void DroppedItem::tick(float dt)
+    {
+        if (this->item_)
+        {
+            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); it++)
+            {
+                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
+                if (distance.length() < this->triggerDistance_)
+                    this->trigger(*it);
+            }
+        }
+    }
+    void DroppedItem::trigger(Pawn* pawn)
+    {
+        if (this->item_->pickedUp(pawn))
+        {
+            COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl;
+            delete this;
+        }
+    }
+    void DroppedItem::createTimer()
+    {
+        if (this->timeToLive_ > 0)
+        {
+            ExecutorMember<DroppedItem>* exec = createExecutor(createFunctor(&DroppedItem::timerCallback));
+            this->timer_.setTimer(this->timeToLive_, false, this, exec, false);
+        }
+    }
+    void DroppedItem::timerCallback()
+    {
+        if (this->item_)
+            delete this->item_;
+
+        delete this;
+    }
+
+    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
+    {
+        DroppedItem* drop = new DroppedItem(item);
+        Model* model = new Model(item);
+        Billboard* billboard = new Billboard(item);
+        
+        model->setMeshSource("sphere.mesh");
+        model->setScale(3.0f);
+
+        billboard->setMaterial("Examples/Flare");
+        billboard->setColour(flareColour);
+        billboard->setScale(0.5f);
+
+        drop->setPosition(position);
+        drop->attach(model);
+        drop->attach(billboard);
+
+        drop->setItem(item);
+
+        drop->setTimeToLive(timeToLive);
+        drop->createTimer();
+
+        COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
+
+        return drop;
+    }
+    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
+    {
+        Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
+        return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
+    }
+}

Added: branches/pickups/src/orxonox/objects/pickup/DroppedItem.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/DroppedItem.h	                        (rev 0)
+++ branches/pickups/src/orxonox/objects/pickup/DroppedItem.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -0,0 +1,86 @@
+/*
+ *   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 BaseItem (base-class for items/pickups).
+*/
+
+#ifndef _DroppedItem_H__
+#define _DroppedItem_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "objects/Tickable.h"
+#include "objects/worldentities/StaticEntity.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+    class BaseItem;
+    class Pawn;
+
+    class _OrxonoxExport DroppedItem : public StaticEntity, public Tickable
+    {
+    public:
+        DroppedItem(BaseObject* creator);
+        virtual ~DroppedItem();
+
+        void tick(float dt);
+        void trigger(Pawn* pawn);
+
+        static DroppedItem* createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
+        static DroppedItem* createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
+
+        void createTimer();
+        void timerCallback();
+
+        inline float getTriggerDistance() const
+            { return this->triggerDistance_; }
+        inline void setTriggerDistance(float distance)
+            { this->triggerDistance_ = distance; }
+
+        inline BaseItem* getItem() const 
+            { return this->item_; }
+        inline void setItem(BaseItem* item)
+            { this->item_ = item; }
+
+        inline float getTimeToLive() const
+            { return this->timeToLive_; }
+        inline void setTimeToLive(float time)
+            { this->timeToLive_ = time; }
+    private:
+        float timeToLive_;
+        float triggerDistance_;
+        BaseItem* item_;
+
+        Timer<DroppedItem> timer_;
+    };
+}
+
+#endif /* _DroppedItem_H__ */

Added: branches/pickups/src/orxonox/objects/pickup/Jump.cc
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/Jump.cc	                        (rev 0)
+++ branches/pickups/src/orxonox/objects/pickup/Jump.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -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), 5.0f);
+        return this->removeFrom(pawn);
+    }
+}
\ No newline at end of file

Added: branches/pickups/src/orxonox/objects/pickup/Jump.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/Jump.h	                        (rev 0)
+++ branches/pickups/src/orxonox/objects/pickup/Jump.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -0,0 +1,92 @@
+/*
+ *   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 "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 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/pickups/src/orxonox/objects/pickup/ModifierPickup.cc
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/ModifierPickup.cc	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/ModifierPickup.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -73,6 +73,9 @@
 
         XMLPortParamTemplate(ModifierPickup, "damageAdd", setAdditiveDamage, getAdditiveDamage, element, mode, float);
         XMLPortParamTemplate(ModifierPickup, "damageMulti", setMultiplicativeDamage, getMultiplicativeDamage, element, mode, float);
+
+        XMLPortParamTemplate(ModifierPickup, "accelerationAdd", setAdditiveAcceleration, getAdditiveAcceleration, element, mode, float);
+        XMLPortParamTemplate(ModifierPickup, "accelerationMulti", setMultiplicativeAcceleration, getMultiplicativeAcceleration, element, mode, float);
     }
     /**
         @brief
@@ -140,6 +143,8 @@
             if (this->timer_.getRemainingTime() > 0.0f)
                 this->timer_.stopTimer();
 
+            delete this;
+
             return true;
         }
         return false;

Modified: branches/pickups/src/orxonox/objects/pickup/ModifierPickup.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/ModifierPickup.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/ModifierPickup.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -57,6 +57,8 @@
         virtual bool pickedUp(Pawn* pawn);                              //!< Override of the BaseItem::pickedUp() method.
         virtual bool dropped(Pawn* pawn);                               //!< Override of the BaseItem::dropped() method
 
+        virtual int getMaxCarryAmount(){ return INT_MAX; }              //!< Allow the player to carry infinite ModPickups
+
         /**
             @brief Get the duration of this pickup.
             @return Returns how long the effect holds on.
@@ -96,6 +98,32 @@
         inline void setMultiplicativeDamage(float value)
             { this->setMultiplicativeModifier(ModifierType::Damage, value); }
 
+        /**
+            @brief Get the amount of acceleration this pickup adds.
+            @return Returns how much acceleration this pickup adds.
+        */
+        inline float getAdditiveAcceleration() const
+            { return this->getAdditiveModifier(ModifierType::Acceleration); }
+        /**
+            @brief Get the factor by which this pickup multiplies the acceleration.
+            @return Returns the factor by which to multiply acceleration.
+        */
+        inline float getMultiplicativeAcceleration() const
+            { return this->getMultiplicativeModifier(ModifierType::Acceleration); }
+
+        /**
+            @brief Set the amount of acceleration this pickup adds.
+            @param value How much acceleration this pickup adds.
+        */
+        inline void setAdditiveAcceleration(float value)
+            { this->setAdditiveModifier(ModifierType::Acceleration, value); }
+        /**
+            @brief Set the factor by which this pickup multiplies the acceleration.
+            @param value Factor by which to multiply acceleration.
+        */
+        inline void setMultiplicativeAcceleration(float value)
+            { this->setMultiplicativeModifier(ModifierType::Acceleration, value); }
+
         void timerCallback(Pawn* pawn);     //!< Method called when the timer runs out.
     private:
         float getAdditiveModifier(ModifierType::Enum type) const;               //!< Get the additive modifier for a given ModifierType.

Modified: branches/pickups/src/orxonox/objects/pickup/ModifierType.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/ModifierType.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/ModifierType.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -44,7 +44,8 @@
         enum Enum
         {
             Unknown = 0,
-            Damage
+            Damage,
+            Acceleration
         };
     }
 }

Modified: branches/pickups/src/orxonox/objects/pickup/PickupCollection.cc
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/PickupCollection.cc	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/PickupCollection.cc	2009-04-06 13:53:50 UTC (rev 2900)
@@ -93,9 +93,8 @@
         this->bBlockRemovals_ = true;
         for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
         {
-            (*it).second->dropped((*it).second->getOwner());
-
-            delete (*it).second;
+            if((*it).second && (*it).second->getOwner())
+                (*it).second->dropped((*it).second->getOwner());
         }
         this->items_.clear();
         this->bBlockRemovals_ = false;
@@ -125,7 +124,30 @@
             return false;
         }
     }
+    //! Uses the first usable item in the collection on the owner.
+    void PickupCollection::useItem()
+    {
+        Identifier* ident = Class(UsableItem);
+        for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++)
+        {
+            if ((*it).second->isA(ident))
+            {
+                UsableItem* asUsable = dynamic_cast<UsableItem*>((*it).second);
+                asUsable->used(this->owner_);
+                return;
+            }
+        }
+    }
     /**
+        @brief Uses a usable item on the owner of the collection.
+        @param item Item to use.
+    */
+    void PickupCollection::useItem(UsableItem* item)
+    {
+        if (item && this->owner_)
+            item->used(this->owner_);
+    }
+    /**
         @brief Remove an item/all of a type from the collection.
         @param item Item to remove.
         @param removeAllOfType Whether to remove all the items with the item's type (default: false).

Modified: branches/pickups/src/orxonox/objects/pickup/PickupCollection.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/PickupCollection.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/PickupCollection.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -47,6 +47,7 @@
 namespace orxonox
 {
     class BaseItem;
+    class UsableItem;
     class Pawn;
 
     /**
@@ -67,6 +68,9 @@
 
         void remove(BaseItem* item, bool removeAllOfType = false);                  //!< Remove an item from the collection.
 
+        void useItem();                                                             //!< Use the first usable item.
+        void useItem(UsableItem* item);                                             //!< Use a usable item.
+
         void addAdditiveModifier(ModifierType::Enum type, float value);             //!< Add an additive modifier.
         void addMultiplicativeModifier(ModifierType::Enum type, float value);       //!< Add a multiplicative modifier.
 

Modified: branches/pickups/src/orxonox/objects/pickup/UsableItem.h
===================================================================
--- branches/pickups/src/orxonox/objects/pickup/UsableItem.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/pickup/UsableItem.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -51,8 +51,8 @@
         virtual ~UsableItem();
 
         /**
-            @brief Method invoked if the item was used.
-            @param pawn Pawn which used the item.
+            @brief Method invoked when the item is being used.
+            @param pawn Pawn which is using the item.
         */
         virtual void used(Pawn* pawn) { }
     };

Modified: branches/pickups/src/orxonox/objects/worldentities/ControllableEntity.h
===================================================================
--- branches/pickups/src/orxonox/objects/worldentities/ControllableEntity.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/worldentities/ControllableEntity.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -86,7 +86,7 @@
 
             virtual void boost() {}
             virtual void greet() {}
-            virtual void use() {}
+            virtual void useItem() {}
             virtual void dropItems() {}
             virtual void switchCamera();
             virtual void mouseLook();

Modified: branches/pickups/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- branches/pickups/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-04-06 13:08:09 UTC (rev 2899)
+++ branches/pickups/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-04-06 13:53:50 UTC (rev 2900)
@@ -109,6 +109,8 @@
             virtual void dropItems();
             inline PickupCollection& getPickups()
                 { return this->pickups_; }
+            virtual void useItem()
+                { this->pickups_.useItem(); }
 
         protected:
             virtual void death();




More information about the Orxonox-commit mailing list