[Orxonox-commit 1857] r6574 - in code/branches/ppspickups1: data/levels src/modules/pickup/items

ebeier at orxonox.net ebeier at orxonox.net
Sat Mar 20 18:36:01 CET 2010


Author: ebeier
Date: 2010-03-20 18:36:00 +0100 (Sat, 20 Mar 2010)
New Revision: 6574

Added:
   code/branches/ppspickups1/data/levels/pickup_ppstest1.oxw
Removed:
   code/branches/ppspickups1/data/levels/pickup_ppstest.oxw
   code/branches/ppspickups1/data/levels/pickuptest.oxw
Modified:
   code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc
   code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h
Log:
adapted SpeedPickup from HealthPickup

Deleted: code/branches/ppspickups1/data/levels/pickup_ppstest.oxw
===================================================================
--- code/branches/ppspickups1/data/levels/pickup_ppstest.oxw	2010-03-19 13:53:29 UTC (rev 6573)
+++ code/branches/ppspickups1/data/levels/pickup_ppstest.oxw	2010-03-20 17:36:00 UTC (rev 6574)
@@ -1,64 +0,0 @@
-<?lua
-  include("stats.oxo")
-  include("hudtemplates3.oxo")
-
-  include("templates/spaceship_assff.oxt")
-  include("templates/spaceship_pirate.oxt")
-  -- include("templates/pickup_representation_templates_speed.oxt")
-?>
-
-<Level
- name         = "SpeedPickupTest"
- description  = "Test for the new Speed Pickup"
->
-  <Scene
-    ambientlight = "0.8, 0.8, 0.8"
-    skybox       = "Orxonox/Starbox"
-  >
-
-<?lua
-  include("includes/pickups_speed.oxi")
-?>
-<!--
-    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
-        <pickup>
-            <SpeedPickup template="speedboostpickup" />
-        </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>
-<?lua
-  include("stats.oxo")
-  include("hudtemplates3.oxo")
-
-  include("templates/spaceship_assff.oxt")
-  include("templates/spaceship_pirate.oxt")
-  -- include("templates/pickup_representation_templates_speed.oxt")
-?>
-
-<Level
- name         = "SpeedPickupTest"
- description  = "Test for the new Speed Pickup"
->
-  <Scene
-    ambientlight = "0.8, 0.8, 0.8"
-    skybox       = "Orxonox/Starbox"
-  >
-
-<?lua
-  include("includes/pickups_speed.oxi")
-?>
-<!--
-    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
-        <pickup>
-            <SpeedPickup template="speedboostpickup" />
-        </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>

Copied: code/branches/ppspickups1/data/levels/pickup_ppstest1.oxw (from rev 6573, code/branches/ppspickups1/data/levels/pickup_ppstest.oxw)
===================================================================
--- code/branches/ppspickups1/data/levels/pickup_ppstest1.oxw	                        (rev 0)
+++ code/branches/ppspickups1/data/levels/pickup_ppstest1.oxw	2010-03-20 17:36:00 UTC (rev 6574)
@@ -0,0 +1,64 @@
+<?lua
+  include("stats.oxo")
+  include("hudtemplates3.oxo")
+
+  include("templates/spaceship_assff.oxt")
+  include("templates/spaceship_pirate.oxt")
+  -- include("templates/pickup_representation_templates_speed.oxt")
+?>
+
+<Level
+ name         = "SpeedPickupTest"
+ description  = "Test for the new Speed Pickup"
+>
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+<?lua
+  include("includes/pickups_speed.oxi")
+?>
+<!--
+    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <SpeedPickup template="speedboostpickup" />
+        </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>
+<?lua
+  include("stats.oxo")
+  include("hudtemplates3.oxo")
+
+  include("templates/spaceship_assff.oxt")
+  include("templates/spaceship_pirate.oxt")
+  -- include("templates/pickup_representation_templates_speed.oxt")
+?>
+
+<Level
+ name         = "SpeedPickupTest"
+ description  = "Test for the new Speed Pickup"
+>
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+<?lua
+  include("includes/pickups_speed.oxi")
+?>
+<!--
+    <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
+        <pickup>
+            <SpeedPickup template="speedboostpickup" />
+        </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>

Deleted: code/branches/ppspickups1/data/levels/pickuptest.oxw
===================================================================
--- code/branches/ppspickups1/data/levels/pickuptest.oxw	2010-03-19 13:53:29 UTC (rev 6573)
+++ code/branches/ppspickups1/data/levels/pickuptest.oxw	2010-03-20 17:36:00 UTC (rev 6574)
@@ -1,56 +0,0 @@
-<?lua
-  include("hudtemplates3.oxo")
-  include("stats.oxo")
-  include("templates/spaceship_assff.oxt")
-?>
-
-<Level
- name         = "Presentation"
- description  = "A simple testlevel"
->
-  <Scene
-   ambientlight = "0.5, 0.5, 0.5"
-   skybox       = "Orxonox/skypanoramagen1"
-  >
-
-    <Template name="jumpTest" baseclass="Jump">
-        <Jump velocity="0,0,500" jumpsAvailable="1" guiImage="decal.jpg" guiText="TEST" />
-    </Template>
-    <Template name="jumpTest2" baseclass="Jump">
-        <Jump velocity="0,0,-500" jumpsAvailable="1" guiImage="dish.jpg" guiText="J2" />
-    </Template>
-    <Template name="jumpTest3" baseclass="Jump">
-        <Jump velocity="0,0,-500" jumpsAvailable="1" guiImage="sl_organic03.jpg" guiText="J3" />
-    </Template>
-    <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" />
-
-    <PickupSpawner item="jumpTest" triggerDistance="20" respawnTime="2" position="100, 0, 0">
-        <attached>
-            <Model mesh="sphere.mesh" scale="3.0" />
-            <Billboard material="Examples/Flare" colour="0.5, 1.0, 0.3" scale="0.5" />
-        </attached>
-    </PickupSpawner>
-    <PickupSpawner item="jumpTest2" triggerDistance="20" respawnTime="5" position="140, 140, 140">
-        <attached>
-            <Model mesh="sphere.mesh" scale="3.0" />
-            <Billboard material="Examples/Flare" colour="1.0, 0.5, 0.3" scale="0.5" />
-        </attached>
-    </PickupSpawner>
-    <PickupSpawner item="jumpTest3" triggerDistance="20" respawnTime="5" position="180, 180, 180">
-        <attached>
-            <Model mesh="sphere.mesh" scale="3.0" />
-            <Billboard material="Examples/Flare" colour="0.5, 0.3, 1.0" scale="0.5" />
-        </attached>
-    </PickupSpawner>
-
-    <SpawnPoint position="200,200,200" lookat="100,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
-
-    <GlobalShader compositor="Bloom" visible=false>
-      <events>
-        <visibility>
-          <DistanceTrigger position="0,0,0" distance=30 target="Spectator" switch=true />
-        </visibility>
-      </events>
-    </GlobalShader>
-  </Scene>
-</Level>

Modified: code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc
===================================================================
--- code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc	2010-03-19 13:53:29 UTC (rev 6573)
+++ code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc	2010-03-20 17:36:00 UTC (rev 6574)
@@ -20,37 +20,262 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *   Author:
- *      Damian 'Mozork' Frick
+ *      Eric Beier
  *   Co-authors:
  *      ...
  *
- *   TODO: Implement...
  */
-/*
- *   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:
- *      ...
- *
- *   TODO: Implement...
- */
+
+/**
+    @file SpeedPickup.cc
+    @brief Implementation of the SpeedPickup class.
+*/
+
+#include "SpeedPickup.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(SpeedPickup);
+
+    /**
+    @brief
+        Constructor. Registers the object and initializes the member variables.
+    */
+    SpeedPickup::SpeedPickup(BaseObject* creator) : Pickup(creator)
+    {
+        RegisterObject(SpeedPickup);
+
+        this->initialize();
+    }
+
+    /**
+    @brief
+        Destructor.
+    */
+    SpeedPickup::~SpeedPickup()
+    {
+
+    }
+
+    /**
+    @brief
+        Initializes the member variables.
+    */
+    void SpeedPickup::initialize(void)
+    {
+        this->duration_ = 0;
+        this->speedAdd_ = 0;
+        this->speedMultiply_ = 0;
+
+        this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+    }
+
+    /**
+    @brief
+        Initializes the PickupIdentifier of this pickup.
+    */
+    void SpeedPickup::initializeIdentifier(void)
+    {
+        std::stringstream stream;
+        stream << this->getDuration();
+        std::string type1 = "duration";
+        std::string val1 = stream.str();
+        this->pickupIdentifier_->addParameter(type1, val1);
+
+        stream.clear();
+        stream << this->getSpeedAdd();
+        std::string type2 = "speedAdd";
+        std::string val2 = stream.str();
+        this->pickupIdentifier_->addParameter(type2, val2);
+
+        stream.clear();
+        stream << this->getSpeedMultiply();
+        std::string type3 = "speedMultiply";
+        std::string val3 = stream.str();
+        this->pickupIdentifier_->addParameter(type3, val3);
+    }
+
+    /**
+    @brief
+        Method for creating a SpeedPickup object through XML.
+    */
+    void SpeedPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
+    {
+        SUPER(SpeedPickup, XMLPort, xmlelement, mode);
+
+        XMLPortParam(SpeedPickup, "duration", setDuration, getDuration, xmlelement, mode);
+        XMLPortParam(SpeedPickup, "speedAdd", setSpeedAdd, getSpeedAdd, xmlelement, mode);
+        XMLPortParam(SpeedPickup, "speedMultiply", setSpeedMultiply, getSpeedMultiply, xmlelement, mode);
+
+        this->initializeIdentifier();
+    }
+
+    /**
+    @brief
+        Is called every tick.
+        Does count down the duration of the SpeedPickup.
+    @param dt
+        The duration of the last tick.
+    */
+    void SpeedPickup::tick(float dt)
+    {
+        if(this->isUsed())
+        {
+            Pawn* pawn = this->carrierToPawnHelper();
+            if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+                this->destroy();
+
+             //! Calculate the remaining duration of the Pickup
+            float duration=this->getDuration()-dt;
+            this->setDuration(duration);
+
+            //! If duration is over
+            if(this->getDuration() < 0)
+            {
+                this->setUsed(false);
+            }
+        }
+    }
+
+    /**
+    @brief
+        Is called when the pickup has transited from used to unused or the other way around.
+    */
+    void SpeedPickup::changedUsed(void)
+    {
+        SUPER(SpeedPickup, changedUsed);
+
+        //! If the pickup is not picked up nothing must be done.
+        if(!this->isPickedUp())
+            return;
+
+        //! If the pickup has transited to used.
+        if(this->isUsed())
+        {
+            if(this->isOnce())
+            {
+                Pawn* pawn = this->carrierToPawnHelper();
+                if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+                    this->destroy();
+
+                //! The pickup has been used up.
+                this->setUsed(false);
+            }
+        }
+        else
+        {
+            //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
+            if(this->isOnce() || (this->isContinuous() && this->getDuration() < 0))
+            {
+                this->destroy();
+            }
+        }
+    }
+
+    /**
+    @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* SpeedPickup::carrierToPawnHelper(void)
+    {
+        PickupCarrier* carrier = this->getCarrier();
+        Pawn* pawn = dynamic_cast<Pawn*>(carrier);
+
+        if(pawn == NULL)
+        {
+            COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl;
+        }
+
+        return pawn;
+    }
+
+    /**
+    @brief
+        Creates a duplicate of the input OrxonoxClass.
+    @param item
+        A pointer to the Orxonox class.
+    */
+    void SpeedPickup::clone(OrxonoxClass*& item)
+    {
+        if(item == NULL)
+            item = new SpeedPickup(this);
+
+        SUPER(SpeedPickup, clone, item);
+
+        SpeedPickup* pickup = dynamic_cast<SpeedPickup*>(item);
+        pickup->setDuration(this->getDuration());
+        pickup->setSpeedAdd(this->getSpeedAdd());
+        pickup->setSpeedMultiply(this->getSpeedMultiply());
+
+        pickup->initializeIdentifier();
+    }
+
+    /**
+    @brief
+        Sets the duration.
+    @param duration
+        The duration
+    */
+    void SpeedPickup::setDuration(float duration)
+    {
+        if(duration >= 0.0f)
+        {
+            this->duration_ = duration;
+        }
+        else
+        {
+            COUT(1) << "Invalid duration in SpeedPickup." << std::endl;
+            this->duration_ = 0.0;
+        }
+    }
+
+    /**
+    @brief
+        Sets the SpeedAdd
+    @param speedAdd
+        The added Speed
+    */
+    void SpeedPickup::setSpeedAdd(float speedAdd)
+    {
+        if(speedAdd > 0.0f)
+        {
+            this->speedAdd_ = speedAdd;
+        }
+        else
+        {
+            COUT(1) << "Invalid speedAdd in SpeedPickup." << std::endl;
+            this->speedAdd_ = 0.0;
+        }
+    }
+
+    /**
+    @brief
+        Sets the SpeedMultiply
+    @param speedAdd
+        The multiplied Speed
+    */
+    void SpeedPickup::setSpeedMultiply(float speedMultiply)
+    {
+        if(speedMultiply > 0.0f)
+        {
+            this->speedMultiply_ = speedMultiply;
+        }
+        else
+        {
+            COUT(1) << "Invalid speedMultiply in SpeedPickup." << std::endl;
+            this->speedMultiply_ = 0.0;
+        }
+    }
+}

Modified: code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h
===================================================================
--- code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h	2010-03-19 13:53:29 UTC (rev 6573)
+++ code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h	2010-03-20 17:36:00 UTC (rev 6574)
@@ -1,56 +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:
- *      Damian 'Mozork' Frick
- *   Co-authors:
- *      ...
- *
- *   TODO: Implement...
- */
-/*
- *   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:
- *      ...
- *
- *   TODO: Implement...
- */
+/*
+ *   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:
+ *      Eric Beier
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file SpeedPickup.h
+    @brief Declaration of the SpeedPickup class.
+*/
+
+#ifndef _SpeedPickup_H__
+#define _SpeedPickup_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 which can manipulate the Speed of a Pawn.
+
+        1) The speed multiplier:
+           The additional (forward) speed:
+        2) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.
+        4) The duration: the activation time of the pickup.
+
+    @author
+        Eric Beier
+    */
+    class _PickupExport SpeedPickup : public Pickup, public Tickable
+    {
+        public:
+
+            SpeedPickup(BaseObject* creator); //!< Constructor.
+            virtual ~SpeedPickup(); //!< Destructor.
+
+            virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML.
+            virtual void tick(float dt); //!< Is called every tick.
+
+            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 float getDuration(void)
+                { return this->duration_; }
+            inline float getSpeedAdd(void)
+                { return this->speedAdd_; }
+            inline float getSpeedMultiply(void)
+                { return this->speedMultiply_; }
+
+        protected:
+            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
+
+            void setDuration(float duration); //!< Sets the duration
+            void setSpeedAdd(float speedAdd);
+            void setSpeedMultiply(float speedMultiply);
+
+
+        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.
+
+            float duration_; //!< The health that is transferred to the Pawn.
+            float speedAdd_;
+            float speedMultiply_;
+    };
+}
+
+#endif // _HealthPickup_H__




More information about the Orxonox-commit mailing list