[Orxonox-commit 1757] r6475 - in code/branches/pickup3/src: modules/pickup modules/pickup/items orxonox/interfaces orxonox/pickup orxonox/worldentities/pawns
dafrick at orxonox.net
dafrick at orxonox.net
Fri Mar 5 18:26:54 CET 2010
Author: dafrick
Date: 2010-03-05 18:26:54 +0100 (Fri, 05 Mar 2010)
New Revision: 6475
Added:
code/branches/pickup3/src/modules/pickup/DroppedPickup.cc
code/branches/pickup3/src/modules/pickup/DroppedPickup.h
Removed:
code/branches/pickup3/src/modules/pickup/DroppedItem.cc
code/branches/pickup3/src/modules/pickup/DroppedItem.h
Modified:
code/branches/pickup3/src/modules/pickup/CMakeLists.txt
code/branches/pickup3/src/modules/pickup/Pickup.cc
code/branches/pickup3/src/modules/pickup/Pickup.h
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
code/branches/pickup3/src/modules/pickup/PickupCollection.h
code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.cc
code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.h
code/branches/pickup3/src/modules/pickup/PickupManager.cc
code/branches/pickup3/src/modules/pickup/PickupManager.h
code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc
code/branches/pickup3/src/modules/pickup/PickupRepresentation.h
code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
code/branches/pickup3/src/modules/pickup/PickupSpawner.h
code/branches/pickup3/src/modules/pickup/items/HealthPickup.cc
code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc
code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.h
code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h
Log:
Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.
Modified: code/branches/pickup3/src/modules/pickup/CMakeLists.txt
===================================================================
--- code/branches/pickup3/src/modules/pickup/CMakeLists.txt 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/CMakeLists.txt 2010-03-05 17:26:54 UTC (rev 6475)
@@ -1,5 +1,5 @@
SET_SOURCE_FILES(PICKUP_SRC_FILES
- DroppedItem.cc
+ DroppedPickup.cc
Pickup.cc
PickupCollection.cc
PickupCollectionIdentifier.cc
Deleted: code/branches/pickup3/src/modules/pickup/DroppedItem.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -1,122 +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:
- * ...
- *
- */
-
-#include "DroppedItem.h"
-
-#include "core/CoreIncludes.h"
-#include "interfaces/Pickupable.h"
-#include "graphics/Model.h"
-
-namespace orxonox
-{
- /**
- @brief
- Constructor. Registers object and sets default values.
- */
- DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator)
- {
- this->initialize();
- }
-
- DroppedItem::DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance) : PickupSpawner(creator, item, triggerDistance, 0, 1)
- {
- this->initialize();
-
- this->createDrop(position);
- }
-
- void DroppedItem::initialize(void)
- {
- RegisterObject(DroppedItem);
-
- this->gotPickedUp_ = false;
- }
-
- /**
- @brief
- Default destructor.
- */
- DroppedItem::~DroppedItem()
- {
- if(this->gotPickedUp_ && this->pickup_ != NULL)
- {
- this->pickup_ = NULL;
- }
- }
-
- Pickupable* DroppedItem::getPickup(void)
- {
- return this->pickup_;
- }
-
- //TODO; Doesn't seem to be needed anymore, just put setPosition in the constructor.
- void DroppedItem::createDrop(const Vector3& position)
- {
- this->setPosition(position);
-
- //TODO: Make this work.
- //const Model& model = PickupManager::getModel(item->getPickupIdentifier());
- //this->attach(model);
- }
-
-//TODO: Remove.
- //TODO: Comment.
- //Each pickup should have a XML template where the Model and Billboard, and so on, is specified.
-// /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
-// {
-// //TODO: triggerDistance?
-// float triggerDistance = 20.0;
-// DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1);
-//
-// //TODO: Do this somehwere else?
-// 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);
-//
-// droppedItem->setPosition(position);
-// droppedItem->attach(model);
-// droppedItem->attach(billboard);
-//
-// COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
-//
-// return droppedItem;
-// }
-
- //TODO: See one function above.
-// 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);
-// }
-}
Deleted: code/branches/pickup3/src/modules/pickup/DroppedItem.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -1,62 +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 DroppedItem
-*/
-
-#ifndef _DroppedItem_H__
-#define _DroppedItem_H__
-
-#include "PickupPrereqs.h"
-
-#include "PickupSpawner.h"
-
-namespace orxonox
-{
- class _OrxonoxExport DroppedItem : public PickupSpawner
- {
- public:
- DroppedItem(BaseObject* creator);
- DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance);
- virtual ~DroppedItem();
-
- protected:
- virtual Pickupable* getPickup(void);
-
- private:
- void initialize(void);
- void createDrop(const Vector3& position);
-
- bool gotPickedUp_;
-
- };
-}
-
-#endif /* _DroppedItem_H__ */
Copied: code/branches/pickup3/src/modules/pickup/DroppedPickup.cc (from rev 6466, code/branches/pickup3/src/modules/pickup/DroppedItem.cc)
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedPickup.cc (rev 0)
+++ code/branches/pickup3/src/modules/pickup/DroppedPickup.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -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:
+ * Damian 'Mozork' Frick
+ *
+ */
+
+/**
+ @file
+ @brief Implementation of the DroppedPickup class.
+*/
+
+#include "DroppedPickup.h"
+
+#include "core/CoreIncludes.h"
+#include "interfaces/Pickupable.h"
+#include "graphics/Model.h"
+
+namespace orxonox
+{
+ /**
+ @brief
+ Default constructor. Registers object and sets default values.
+ */
+ DroppedPickup::DroppedPickup(BaseObject* creator) : PickupSpawner(creator)
+ {
+ RegisterObject(DroppedPickup);
+
+ this->initialize();
+ }
+
+ /**
+ @brief
+ Constructor. Registers the object and sets values.
+ @param creator
+ The creator of the DroppedPickup.
+ @param pickup
+ The Pickupable that was dropped.
+ @param position
+ The position at which the DroppedPickup should be created.
+ @param triggerDistance
+ The distance at which the PickupSpawner triggers. Default is 10.
+ */
+ DroppedPickup::DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance) : PickupSpawner(creator, pickup, triggerDistance, 0, 1)
+ {
+ RegisterObject(DroppedPickup);
+
+ this->initialize();
+
+ this->setPosition(position);
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ DroppedPickup::~DroppedPickup()
+ {
+ if(this->gotPickedUp_ && this->pickup_ != NULL)
+ {
+ this->pickup_ = NULL;
+ }
+ }
+
+ /**
+ @brief
+ Initializes the member variables of the object.
+ */
+ void DroppedPickup::initialize(void)
+ {
+ this->gotPickedUp_ = false;
+ }
+
+ /**
+ @brief
+ Creates the Pickupable that is going to get picked up.
+ In the case of the DroppedItem it is the one and only Pickupable that was dropped. No additional Pickupables of the same type are created.
+ */
+ Pickupable* DroppedPickup::getPickup(void)
+ {
+ return this->pickup_;
+ }
+
+}
Copied: code/branches/pickup3/src/modules/pickup/DroppedPickup.h (from rev 6466, code/branches/pickup3/src/modules/pickup/DroppedItem.h)
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedPickup.h (rev 0)
+++ code/branches/pickup3/src/modules/pickup/DroppedPickup.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -0,0 +1,69 @@
+/*
+ * 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:
+ * Damian 'Mozork' Frick
+ *
+ */
+
+/**
+ @file
+ @brief Definition of the DroppedPickup class.
+*/
+
+#ifndef _DroppedPickup_H__
+#define _DroppedPickup_H__
+
+#include "PickupPrereqs.h"
+
+#include "PickupSpawner.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+ Special PickupSpawner that is created whe a Pickupable is dropped. It just spawns one pickup, the one that was dropped.
+ @author
+ Daniel 'Huty' Haggenmueller
+ Damian 'Mozork' Frick
+ */
+ class _OrxonoxExport DroppedPickup : public PickupSpawner
+ {
+ public:
+ DroppedPickup(BaseObject* creator); //!< Default constructor.
+ DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance = 10.0); //!< Constructor.
+ virtual ~DroppedPickup(); //!< Destructor.
+
+ protected:
+ virtual Pickupable* getPickup(void); //!< Creates the Pickupable that is going to get picked up.
+
+ private:
+ void initialize(void); //!< Initializes the member variables of the object.
+
+ bool gotPickedUp_; //!< Whether the pickup got picked up or not.
+
+ };
+}
+
+#endif /* _DroppedPickup_H__ */
Modified: code/branches/pickup3/src/modules/pickup/Pickup.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/Pickup.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/Pickup.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -29,6 +29,9 @@
#include "Pickup.h"
#include "core/CoreIncludes.h"
+#include "util/StringUtils.h"
+#include "pickup/PickupIdentifier.h"
+#include "DroppedPickup.h"
namespace orxonox
{
@@ -37,15 +40,15 @@
/*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
/*static*/ const std::string Pickup::durationTypeOnce_s = "once";
/*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
- /*static*/ const std::string Pickup::blankString_s = "";
- //TODO: Should this bee here? Does it work without?
+ //TODO: Should this be here? Does it work without?
CreateFactory(Pickup);
Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(Pickup);
+ this->initialize();
}
Pickup::~Pickup()
@@ -53,20 +56,39 @@
}
+ /**
+ @brief
+ Initializes the member variables.
+ */
+ void Pickup::initialize(void)
+ {
+ this->activationType_ = pickupActivationType::immediate;
+ this->durationType_ = pickupDurationType::once;
+ }
+
+ /**
+ @brief
+ Initializes the PickupIdentififer of this Pickup.
+ */
void Pickup::initializeIdentifier(void)
{
- this->pickupIdentifier_.addClass(this->getIdentifier());
+ //TODO: Check whether this could not be done in the Constructor if Pickupable. Would be much more convenient.
+ this->pickupIdentifier_->addClass(this->getIdentifier());
//TODO: Works?
std::string val1 = this->getActivationType();
std::string type1 = "activationType";
- this->pickupIdentifier_.addParameter(type1, val1);
+ this->pickupIdentifier_->addParameter(type1, val1);
std::string val2 = this->getDurationType();
std::string type2 = "durationType";
- this->pickupIdentifier_.addParameter(type2, val2);
+ this->pickupIdentifier_->addParameter(type2, val2);
}
+ /**
+ @brief
+ Method for creating a Pickup object through XML.
+ */
void Pickup::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(Pickup, XMLPort, xmlelement, mode);
@@ -80,8 +102,8 @@
/**
@brief
Get the activation type of the pickup.
- @param buffer
- The buffer to store the activation type as string in.
+ @return
+ Returns a string containing the activation type.
*/
const std::string& Pickup::getActivationType(void)
{
@@ -92,15 +114,15 @@
case pickupActivationType::onUse:
return activationTypeOnUse_s;
default:
- return blankString_s;
+ return BLANKSTRING;
}
}
/**
@brief
Get the duration type of the pickup.
- @param buffer
- The buffer to store the duration type as string in.
+ @return
+ Returns a string containing the duration type.
*/
const std::string& Pickup::getDurationType(void)
{
@@ -111,7 +133,7 @@
case pickupDurationType::continuous:
return durationTypeContinuous_s;
default:
- return blankString_s;
+ return BLANKSTRING;
}
}
@@ -161,7 +183,23 @@
/**
@brief
- Creates a duplicate of the pickup.
+ Should be called when the pickup has transited from picked up to dropped or the other way around.
+ Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
+ */
+ void Pickup::changedCarrier(void)
+ {
+ SUPER(Pickup, changedCarrier);
+
+ //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
+ if(this->isPickedUp() && this->isImmediate())
+ {
+ this->setUsed(true);
+ }
+ }
+
+ /**
+ @brief
+ Creates a duplicate of the Pickup.
@return
Returns the clone of this pickup as a pointer to a Pickupable.
*/
@@ -178,15 +216,21 @@
pickup->initializeIdentifier();
}
-
- void Pickup::changedCarrier(void)
+
+ /**
+ @brief
+ Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
+ This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
+ DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
+ @param position
+ The position at which the PickupSpawner should be placed.
+ @return
+ Returns true if a spawner was created, false if not.
+ */
+ bool Pickup::createSpawner(const Vector3& position)
{
- SUPER(Pickup, changedCarrier);
-
- if(this->isPickedUp() && this->isImmediate())
- {
- this->setUsed(true);
- }
+ DroppedPickup::DroppedPickup(this, this, position);
+ return true;
}
}
Modified: code/branches/pickup3/src/modules/pickup/Pickup.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/Pickup.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/Pickup.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -27,14 +27,15 @@
*/
#ifndef _Pickup_H__
-#define Pickup_H__
+#define _Pickup_H__
#include "pickup/PickupPrereqs.h"
-#include "interfaces/Pickupable.h"
#include "core/BaseObject.h"
#include "core/XMLPort.h"
+#include "interfaces/Pickupable.h"
+
namespace orxonox
{
@@ -58,14 +59,20 @@
};
}
+ /**
+ @brief
+ Pickup class. Offers base functionality for a wide range of pickups.
+ Pickups ingeriting from this class cann choose an activation type and a duration type.
+ @author
+ Damian 'Mozork' Frick
+ */
class _PickupExport Pickup : public Pickupable, public BaseObject
{
public:
+ Pickup(BaseObject* creator); //!< Constructor.
+ virtual ~Pickup(); //!< Destructor.
- Pickup(BaseObject* creator);
- virtual ~Pickup();
-
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
/**
@@ -84,22 +91,40 @@
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'.
+ */
inline bool isImmediate(void)
{ return this->getActivationTypeDirect() == pickupActivationType::immediate; }
+ /**
+ @brief Get whether the activation type is 'onUse'.
+ @return Returns true if the activation type is 'onUse'.
+ */
inline bool isOnUse(void)
{ return this->getActivationTypeDirect() == pickupActivationType::onUse; }
+ /**
+ @brief Get whether the duration type is 'once'.
+ @return Returns true if the duration type is 'once'.
+ */
inline bool isOnce(void)
{ return this->getDurationTypeDirect() == pickupDurationType::once; }
+ /**
+ @brief Get whether the duration type is 'continuous'.
+ @return Returns true if the duration type is 'continuous'.
+ */
inline bool isContinuous(void)
{ return this->getDurationTypeDirect() == pickupDurationType::continuous; }
-
- virtual void clone(OrxonoxClass* item);
- virtual void changedCarrier(void);
+ virtual void changedCarrier(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(const Vector3& position); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
+
/**
@brief Set the activation type of the pickup.
@param type The activation type of the pickup.
@@ -117,6 +142,8 @@
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.
@@ -124,7 +151,6 @@
static const std::string activationTypeOnUse_s;
static const std::string durationTypeOnce_s;
static const std::string durationTypeContinuous_s;
- static const std::string blankString_s; //TODO: Maybe already implemented somewhere?
};
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -37,7 +37,10 @@
#include "core/Template.h"
#include "core/XMLPort.h"
#include "interfaces/PickupCarrier.h"
+#include "DroppedPickup.h"
+#include "PickupCollectionIdentifier.h"
+
namespace orxonox
{
@@ -48,6 +51,8 @@
PickupCollection::PickupCollection(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(PickupCollection);
+
+ this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier();
}
/**
@@ -59,7 +64,7 @@
//! Destroy all Pickupables constructing this PickupCollection.
for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- delete *it;
+ (*it)->destroy();
}
}
@@ -79,16 +84,32 @@
void PickupCollection::initializeIdentifier(void)
{
- this->pickupCollectionIdentifier_.addClass(this->getIdentifier());
+ this->pickupCollectionIdentifier_->addClass(this->getIdentifier());
for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- this->pickupCollectionIdentifier_.addPickup((*it)->getPickupIdentifier());
+ this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
}
}
/**
@brief
+ Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
+ This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
+ DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position);
+ @param position
+ The position at which the PickupSpawner should be placed.
+ @return
+ Returns true if a spawner was created, false if not.
+ */
+ bool PickupCollection::createSpawner(const Vector3& position)
+ {
+ DroppedPickup::DroppedPickup(this, this, position);
+ return true;
+ }
+
+ /**
+ @brief
Add the input Pickupable to list of Pickupables combined by this PickupCollection.
@param pickup
The Pickupable to be added.
@@ -158,4 +179,9 @@
pickup->initializeIdentifier();
}
+ const PickupIdentifier* PickupCollection::getPickupIdentifier(void)
+ {
+ return this->pickupCollectionIdentifier_;
+ }
+
}
\ No newline at end of file
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -35,8 +35,6 @@
#include "core/BaseObject.h"
#include "core/XMLPort.h"
-#include "PickupCollectionIdentifier.h"
-
#include <list>
namespace orxonox
@@ -65,8 +63,7 @@
virtual void clone(OrxonoxClass* item);
- virtual const PickupIdentifier* getPickupIdentifier(void)
- { return &this->pickupCollectionIdentifier_; }
+ virtual const PickupIdentifier* getPickupIdentifier(void);
bool addPickupable(Pickupable* pickup);
const Pickupable* getPickupable(unsigned int index);
@@ -74,8 +71,10 @@
protected:
void initializeIdentifier(void);
- PickupCollectionIdentifier pickupCollectionIdentifier_;
+ virtual bool createSpawner(const Vector3& position); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
+ PickupCollectionIdentifier* pickupCollectionIdentifier_;
+
private:
std::vector<Pickupable*> pickups_;
Modified: code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -43,9 +43,9 @@
}
- int PickupCollectionIdentifier::compare(const PickupIdentifier& identifier) const
+ int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
{
- PickupIdentifier* temp = const_cast<PickupIdentifier*>(&identifier);
+ PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
if(collectionIdentifier == NULL)
{
@@ -59,9 +59,9 @@
for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
{
- if((*it)->compare(**it2) < 0)
+ if((*it)->compare(*it2) < 0)
return -1;
- if((*it2)->compare(**it) < 0)
+ if((*it2)->compare(*it) < 0)
return 1;
}
Modified: code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -44,12 +44,12 @@
PickupCollectionIdentifier(void);
~PickupCollectionIdentifier();
- virtual int compare(const PickupIdentifier& identifier) const;
+ virtual int compare(const PickupIdentifier* identifier) const;
void addPickup(const PickupIdentifier* identifier);
private:
- std::set<const PickupIdentifier*, PickupIdentifierPtrCompare> identifiers_;
+ std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_;
};
Modified: code/branches/pickup3/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupManager.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupManager.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -82,7 +82,7 @@
Returns true if successful and false if not.
*/
//TODO: Make sure that either the PickupRepresentation is destroyed upon destruction of the PickupManager if the representation wasn't created with XMLPort.
- bool PickupManager::registerRepresentation(const PickupIdentifier& identifier, PickupRepresentation* representation)
+ bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation)
{
if(this->representations_.find(identifier) == this->representations_.end()) //!< If the Pickupable already has a RepresentationRegistered.
return false;
@@ -103,7 +103,7 @@
*/
PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
{
- std::map<const PickupIdentifier, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(*identifier);
+ std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
if(it == this->representations_.end())
{
COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl;
Modified: code/branches/pickup3/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupManager.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupManager.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -70,7 +70,7 @@
static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); }
- bool registerRepresentation(const PickupIdentifier& identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
+ bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
//TODO: Delete or utilitze this.
@@ -80,7 +80,7 @@
static PickupManager* singletonPtr_s;
PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
- std::map<const PickupIdentifier, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
+ std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
//TODO: Delete or utilize this.
PickupCarrierNode* pickupCarrierStructure_;
Modified: code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupPrereqs.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupPrereqs.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -65,7 +65,7 @@
namespace orxonox
{
- class DroppedItem;
+ class DroppedPickup;
class Pickup;
class PickupCollection;
class PickupCollectionIdentifier;
Modified: code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -29,14 +29,20 @@
#include "PickupRepresentation.h"
#include "core/CoreIncludes.h"
+#include "graphics/Billboard.h"
+#include "util/StringUtils.h"
#include "PickupManager.h"
-#include "graphics/Billboard.h"
namespace orxonox
{
CreateFactory(PickupRepresentation);
+ /**
+ @brief
+ Constructor. Registers the object and initializes its member variables.
+ This is primarily for use of the PickupManager in creating a default PickupRepresentation.
+ */
PickupRepresentation::PickupRepresentation() : BaseObject(this)
{
RegisterObject(PickupRepresentation);
@@ -44,6 +50,10 @@
this->initialize();
}
+ /**
+ @brief
+ Default Constructor. Registers the object and initializes its member variables.
+ */
PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(PickupRepresentation);
@@ -51,11 +61,20 @@
this->initialize();
}
+ /**
+ @brief
+ Destructor.
+ */
PickupRepresentation::~PickupRepresentation()
{
-
+ if(this->spawnerRepresentation_ != NULL)
+ this->spawnerRepresentation_->destroy();
}
+ /**
+ @brief
+ Initializes the member variables of this PickupRepresentation.
+ */
void PickupRepresentation::initialize(void)
{
this->description_ = "This is a pickup.";
@@ -65,6 +84,10 @@
this->pickup_ = NULL;
}
+ /**
+ @brief
+ Method for creating a PickupRepresentation object through XML.
+ */
void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
@@ -75,21 +98,31 @@
XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
- PickupManager::getInstance().registerRepresentation(*this->pickup_->getPickupIdentifier(), this);
+ PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
}
+ /**
+ @brief
+ Get a spawnerRepresentation for a specific PickupSpawner.
+ @param spawner
+ A pointer to the PickupSpawner.
+ @return
+ Returns a pointer to the StaticEntity.
+ */
StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
{
if(this->spawnerRepresentation_ == NULL)
{
COUT(4) << "PickupRepresentation: No spawner representation found." << std::endl;
- if(this->spawnerTemplate_ == "")
+ if(this->spawnerTemplate_ == BLANKSTRING)
{
COUT(4) << "PickupRepresentation: Spawner template is empty." << std::endl;
+ //!< If neither spawnerRepresentation nor spawnerTemplate was specified
return this->getDefaultSpawnerRepresentation(spawner);
}
this->addTemplate(this->spawnerTemplate_);
}
+
StaticEntity* representation = this->spawnerRepresentation_;
this->addTemplate(this->spawnerTemplate_);
@@ -97,6 +130,16 @@
return representation;
}
+ /**
+ @brief
+ Get the default spawnerRepresentation for a specific PickupSpawner.
+ Helper method of internal use.
+ @param spawner
+ A pointer to the PickupSpawner.
+ @return
+ Returns a pointer to the StaticEntity.
+ */
+ //TODO: Think of more elegant solution.
StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
{
StaticEntity* representation = new StaticEntity(spawner);
Modified: code/branches/pickup3/src/modules/pickup/PickupRepresentation.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupRepresentation.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupRepresentation.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -31,63 +31,111 @@
#include "PickupPrereqs.h"
-#include "core/BaseObject.h"
-
#include "core/XMLPort.h"
+#include "interfaces/Pickupable.h"
#include "pickup/PickupIdentifier.h"
-#include "interfaces/Pickupable.h"
-#include "pickup/PickupSpawner.h"
#include "worldentities/StaticEntity.h"
+#include "PickupSpawner.h"
+#include "core/BaseObject.h"
+
namespace orxonox
{
+ /**
+ @brief
+ The PickupRepresentation class represents a specific pickup type (identified by its PickupIdentifier). It defines the information displayed in the GUI and how PickupSpawners that spawn the pickup type look like.
+ They are created through XML and are registered with the PickupManager.
+ */
class _PickupExport PickupRepresentation : public BaseObject
{
public:
- PickupRepresentation();
- PickupRepresentation(BaseObject* creator);
- virtual ~PickupRepresentation();
+ PickupRepresentation(); //!< Constructor
+ PickupRepresentation(BaseObject* creator); //!< Default constructor.
+ virtual ~PickupRepresentation(); //!< Destructor.
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ /**
+ @brief Set the name of the Pickupable represented by this PickupRepresentation.
+ @param name The name.
+ */
inline void setName(const std::string& name)
{ this->name_ = name; }
+ /**
+ @brief Set the description of the Pickupable represented by this PickupRepresentation.
+ @param description The Description.
+ */
inline void setDescription(const std::string& description)
{ this->description_ = description; }
+ /**
+ @brief Set the spawnerTemplate of the Pickupable represented by this PickupRepresentation.
+ The spawnerTemplate is a name of a template defined in XML that defines the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
+ @param spawnerTemplate The name of the template.
+ */
inline void setSpawnerTemplate(const std::string& spawnerTemplate)
{ this->spawnerTemplate_ = spawnerTemplate; }
+ /**
+ @brief Set the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
+ This will be set by the spawnerTemplate. Setting it when creating the PickupRepresentation without creating a template and specifying its name will be futile, because through the course of the game many PickupSpawners for one specific pickup type may have to be created, thus the StaticEntity that is the spawnerRepresentation has to be generated (with the template) for every new PickupSpawner spawning the Pickupable represented by this PickupRepresentation. The spawnerRepresentation that is set here, however can only be used once.
+ @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation.
+ */
inline void setSpawnerRepresentation(StaticEntity* representation)
{ this->spawnerRepresentation_ = representation; }
+ /**
+ @brief Set the Pickupable that is represented by this PickupRepresentation.
+ @param pickup A pointer to the Pickupable.
+ */
inline void setPickup(Pickupable* pickup)
{ this->pickup_ = pickup; }
+ /**
+ @brief Get the name of the Pickupable represented by this PickupRepresentation.
+ @return Returns the name.
+ */
inline const std::string& getName(void)
{ return this->name_; }
+ /**
+ @brief Get the description of the Pickupable represented by this PickupRepresentation.
+ @return Returns the description.
+ */
inline const std::string& getDescription(void)
{ return this->description_; }
+ /**
+ @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.
+ @return Returns the name of the spawnerTemplate.
+ */
inline const std::string& getSpawnerTemplate(void)
{ return this->spawnerTemplate_; }
+ /**
+ @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.
+ @param index The index.
+ @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL.
+ */
inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index)
{ if(index == 0) return this->spawnerRepresentation_; return NULL; }
+ /**
+ @brief Get the Pickupable represented by this PickupRepresentation.
+ @param index The index.
+ @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL.
+ */
inline const Pickupable* getPickup(unsigned int index)
{ if(index == 0) return this->pickup_; return NULL; }
- StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner);
+ StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.
private:
- void initialize(void);
- StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner);
+ void initialize(void); //!< Initializes the member variables of this PickupRepresentation.
+ StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner.
- std::string name_;
- std::string description_;
- std::string spawnerTemplate_;
- StaticEntity* spawnerRepresentation_;
+ std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation.
+ std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation.
+ std::string spawnerTemplate_; //!< The name of the template of this PickupRepresentation.
+ StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation.
- Pickupable* pickup_;
+ Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
-
};
}
Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -34,22 +34,15 @@
#include "PickupSpawner.h"
#include "core/CoreIncludes.h"
-//#include "core/GUIManager.h" // HACK; see below
#include "core/Template.h"
#include "core/XMLPort.h"
#include "worldentities/pawns/Pawn.h"
#include "PickupManager.h"
#include "PickupRepresentation.h"
-//#include "PickupInventory.h" // HACK; Only for hack, remove later
-
namespace orxonox
{
-// const float PickupSpawner::bounceSpeed_s = 6.0f;
-// const float PickupSpawner::rotationSpeed_s = 1.0f;
-// const float PickupSpawner::bounceDistance_s = 4.0f;
-
CreateFactory(PickupSpawner);
/**
@@ -63,9 +56,6 @@
RegisterObject(PickupSpawner);
this->initialize();
-
- PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(NULL);
- this->attach(representation->getSpawnerRepresentation(this));
}
/**
@@ -94,8 +84,16 @@
this->respawnTime_ = respawnTime;
this->setMaxSpawnedItems(maxSpawnedItems);
- PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
- this->attach(representation->getSpawnerRepresentation(this));
+ if(this->pickup_ == NULL)
+ {
+ COUT(2) << "A PickupSpawner was created without a valid Pickupable. This won't work." << std::endl;
+ this->setActive(false);
+ }
+ else
+ {
+ PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
+ this->attach(representation->getSpawnerRepresentation(this));
+ }
}
/**
@@ -108,7 +106,6 @@
this->triggerDistance_ = 20;
this->respawnTime_ = 0;
- this->tickSum_ = 0;
this->maxSpawnedItems_ = INF;
this->spawnsRemaining_ = INF;
}
@@ -140,84 +137,33 @@
XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode);
-
- //TODO: Kill hack.
- // 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 = orxonox_cast<BaseItem*>(newObject);
-// if (asItem)
-// {
-// asItem->addTemplate(this->itemTemplate_);
-// PickupInventory::getImageForItem(asItem);
-// newObject->destroy();
-// }
-
- // & load the GUI itself too, along with some empty windows
- // = even less delays
-// GUIManager::getInstance().showGUI("PickupInventory");
-// GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
-// PickupInventory::getSingleton();
- }
-
- /**
- @brief
- Sets a Pickupable for the PickupSpawner to spawn.
- @param pickup
- The Pickupable to be set.
- */
- void PickupSpawner::setPickupable(Pickupable* pickup)
- {
- if(this->pickup_ != NULL)
+
+ if(this->pickup_ == NULL)
{
- COUT(1) << "addPickupable called, with this->pickup_ already set." << std::endl;
- return;
+ COUT(2) << "A PickupSpawner was created without a valid Pickupable. This won't work." << std::endl;
+ this->setActive(false);
}
- if(pickup == NULL)
+ else
{
- COUT(1) << "Argument of addPickupable is NULL." << std::endl;
- return;
+ PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
+ this->attach(representation->getSpawnerRepresentation(this));
}
-
- this->pickup_ = pickup;
}
/**
@brief
- Get the Pickupable that is spawned by this PickupSpawner.
- @return
- Returns the Pickupable that is spawned by this PickupSpawner.
+ Invoked when the activity has changed. Sets visibility of attached objects.
*/
- const Pickupable* PickupSpawner::getPickupable(void)
+ void PickupSpawner::changedActivity()
{
- return this->pickup_;
- }
+ SUPER(PickupSpawner, changedActivity);
- /**
- @brief
- Invoked when the activity has changed. Sets visibility of attached objects.
- */
-// void PickupSpawner::changedActivity()
-// {
-// SUPER(PickupSpawner, changedActivity);
-//
-// for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
-// (*it)->setVisible(this->isActive());
-// }
-
- /**
- @brief
- Sets the maximum number of spawned items.
- @param items
- The maximum number of spawned items to be set.
- */
- void PickupSpawner::setMaxSpawnedItems(int items)
- {
- this->maxSpawnedItems_ = items;
- this->spawnsRemaining_ = items;
+ for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++)
+ {
+ (*it)->setVisible(this->isActive());
+ }
}
-
+
/**
@brief
Tick, checks if any Pawn is close enough to trigger.
@@ -240,54 +186,19 @@
this->trigger(*it);
}
}
-
- //! Animation.
-// this->yaw(Radian(rotationSpeed_s*dt));
-// this->tickSum_ += bounceSpeed_s*dt;
-// this->translate(Vector3(0,bounceDistance_s*dt*sin(this->tickSum_),0));
-// if (this->tickSum_ > 2*Ogre::Math::PI)
-// this->tickSum_ -= 2*Ogre::Math::PI;
}
}
-
+
/**
@brief
- Trigger the PickupSpawner.
-
- Adds the pickup to the Pawn that triggered,
- sets the timer to re-activate and deactives the PickupSpawner.
-
- @param pawn
- Pawn which triggered the PickupSpawner.
+ Sets the maximum number of spawned items.
+ @param items
+ The maximum number of spawned items to be set.
*/
- void PickupSpawner::trigger(Pawn* pawn)
+ void PickupSpawner::setMaxSpawnedItems(int items)
{
- //TODO: If private, isActive doesn't need to be tested anymore.
- if (this->isActive()) //!< Checks whether PickupItem is active.
- {
- Pickupable* pickup = this->getPickup();
- if (pickup != NULL) //!< If everything went ok, and pickup is not NULL.
- {
- //TODO: Not correct anymore.
- PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
- if(carrier == NULL)
- {
- COUT(1) << "This is bad. Pawn isn't PickupCarrier." << std::endl;
- return;
- }
-
- if(carrier->pickup(pickup))
- {
- COUT(3) << "Pickup got picked up." << std::endl;
-
- this->decrementSpawnsRemaining();
- }
- else
- {
- pickup->destroy();
- }
- }
- }
+ this->maxSpawnedItems_ = items;
+ this->spawnsRemaining_ = items;
}
/**
@@ -295,7 +206,6 @@
Decrements the number of remaining spawns.
Sets the PickupSpawner to inactive for the duration of the respawnTime.
Destroys the PickupSpawner if the number of remaining spawns has reached zero.
-
*/
void PickupSpawner::decrementSpawnsRemaining(void)
{
@@ -313,14 +223,104 @@
}
else
{
- COUT(3) << "PickupSpawner empty, selfdistruct initialized." << std::endl;
+ COUT(3) << "PickupSpawner empty, selfdestruct initialized." << std::endl;
this->setActive(false);
- this->destroy(); //TODO: Implement destroy().
+ this->destroy();
}
}
+
+ /**
+ @brief
+ Sets a Pickupable for the PickupSpawner to spawn.
+ @param pickup
+ The Pickupable to be set.
+ */
+ void PickupSpawner::setPickupable(Pickupable* pickup)
+ {
+ if(this->pickup_ != NULL)
+ {
+ COUT(1) << "In PickupSpawner: setPickupable called, with this->pickup_ already set." << std::endl;
+ return;
+ }
+ if(pickup == NULL)
+ {
+ COUT(1) << "In PickupSpawner: Argument of setPickupable is NULL." << std::endl;
+ return;
+ }
+
+ this->pickup_ = pickup;
+ }
+
+ /**
+ @brief
+ Get the Pickupable that is spawned by this PickupSpawner.
+ @return
+ Returns the Pickupable that is spawned by this PickupSpawner.
+ */
+ const Pickupable* PickupSpawner::getPickupable(void)
+ {
+ return this->pickup_;
+ }
/**
@brief
+ Trigger the PickupSpawner.
+ Adds the pickup to the Pawn that triggered, sets the timer to re-activate and deactives the PickupSpawner.
+ @param pawn
+ Pawn which triggered the PickupSpawner.
+ */
+ //TODO: Make more generic -> without pawn.
+ void PickupSpawner::trigger(Pawn* pawn)
+ {
+ if (this->isActive()) //!< Checks whether PickupItem is active.
+ {
+ PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
+ if(carrier == NULL)
+ {
+ COUT(1) << "This is bad. Pawn isn't PickupCarrier." << std::endl;
+ return;
+ }
+
+ if(!carrier->isTarget(this->pickup_))
+ {
+ COUT(4) << "PickupSpawner triggered but Pawn wasn't a target of the Pickupable." << std::endl;
+ return;
+ }
+
+ PickupCarrier* target = carrier->getTarget(this->pickup_);
+ Pickupable* pickup = this->getPickup();
+
+ if(target != NULL || pickup != NULL)
+ {
+ if(carrier->pickup(pickup))
+ {
+ this->decrementSpawnsRemaining();
+ }
+ else
+ {
+ pickup->destroy();
+ }
+ }
+ else
+ {
+ //TODO: Really that severe?
+ if(target == NULL)
+ COUT(1) << "PickupSpawner: Pickupable has no target." << std::endl;
+
+ if(pickup == NULL)
+ {
+ COUT(1) << "PickupSpawner: getPickup produced an error, no Pickupable created." << std::endl;
+ }
+ else
+ {
+ pickup->destroy();
+ }
+ }
+ }
+ }
+
+ /**
+ @brief
Creates a new Pickupable.
@return
The Pickupable created.
Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -22,7 +22,7 @@
* Author:
* Daniel 'Huty' Haggenmueller
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
@@ -37,94 +37,92 @@
#include "PickupPrereqs.h"
#include <string>
+#include "interfaces/Pickupable.h"
#include "tools/Timer.h"
+
#include "tools/interfaces/Tickable.h"
#include "worldentities/StaticEntity.h"
-#include "interfaces/Pickupable.h"
namespace orxonox
{
/**
- @brief PickupSpawner.
- @author Daniel 'Huty' Haggenmueller
+ @brief
+ The PickupSpawner class is responsible for spawning pickups of a specific type.
+ Forthermore it can be specified how long the time interval between spawning two items is and how many pickups are spawned at maximum, amongst other things.
+ @author
+ Daniel 'Huty' Haggenmueller
+ Damian 'Mozork' Frick
*/
class _OrxonoxExport PickupSpawner : public StaticEntity, public Tickable
{
public:
- //TODO: Add limit of items spawned here.
- PickupSpawner(BaseObject* creator);
- PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems);
- virtual ~PickupSpawner();
+ PickupSpawner(BaseObject* creator); //!< Default Constructor.
+ PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); //!< Constructor.
+ virtual ~PickupSpawner(); //!< Destructor.
- //virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML.
+ virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
virtual void tick(float dt);
/**
- @brief Get the distance in which to trigger.
- @return Returns the distance in which this gets triggered.
+ @brief Get the distance in which to trigger.
+ @return Returns the distance in which this gets triggered.
*/
inline float getTriggerDistance() const
{ return this->triggerDistance_; }
/**
- @brief Set the distance in which to trigger.
- @param value The new distance in which to trigger.
+ @brief Set the distance in which to trigger.
+ @param value The new distance in which to trigger.
*/
inline void setTriggerDistance(float value)
{ this->triggerDistance_ = value; }
/**
- @brief Get the time to respawn.
- @returns Returns the time after which this gets re-actived.
+ @brief Get the time to respawn.
+ @returns Returns the time after which this gets re-actived.
*/
inline float getRespawnTime() const
{ return this->respawnTime_; }
/**
- @brief Set the time to respawn.
- @param time New time after which this gets re-actived.
+ @brief Set the time to respawn.
+ @param time New time after which this gets re-actived.
*/
inline void setRespawnTime(float time)
{ this->respawnTime_ = time; }
/**
- @brief Get the maximum number of items that will be spawned by this PickupSpawner.
- @return Returns the maximum number of items spawned by this PickupSpawner.
+ @brief Get the maximum number of items that will be spawned by this PickupSpawner.
+ @return Returns the maximum number of items spawned by this PickupSpawner.
*/
inline int getMaxSpawnedItems(void)
{ return this->maxSpawnedItems_; }
- void setMaxSpawnedItems(int items);
+ void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items.
protected:
- virtual Pickupable* getPickup(void);
+ void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.
- void setPickupable(Pickupable* pickup);
- const Pickupable* getPickupable(void);
+ virtual Pickupable* getPickup(void); //!< Creates a new Pickupable.
- void decrementSpawnsRemaining(void);
+ void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn.
+ const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner.
Pickupable* pickup_; //!< The pickup to be spawned.
private:
void initialize(void);
- void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
- void respawnTimerCallback(); //!< Method called when the timer runs out.
+ void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
+ void respawnTimerCallback(); //!< Method called when the timer runs out.
- int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner.
- int spawnsRemaining_; //!< Number of items that can be spawned by this PickupSpawner until it selfdestructs.
+ int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner.
+ int spawnsRemaining_; //!< Number of items that can be spawned by this PickupSpawner until it selfdestructs.
- float triggerDistance_; //!< Distance in which this gets triggered.
+ float triggerDistance_; //!< Distance in which this gets triggered.
- /* Pickup animation */
- float tickSum_; //!< Adds up tick to use in sine movement
- static const float bounceSpeed_s; //!< Speed of pickup to bounce up and down
- static const float bounceDistance_s; //!< Distance the pickup bounces up and down
- static const float rotationSpeed_s; //!< Rotation speed of pickup
+ float respawnTime_; //!< Time after which this gets re-actived.
+ Timer respawnTimer_; //!< Timer used for re-activating.
- float respawnTime_; //!< Time after which this gets re-actived.
- Timer respawnTimer_; //!< Timer used for re-activating.
-
- static const int INF = -1; //!< Constant for infinity.
+ static const int INF = -1; //!< Constant for infinity.
};
}
Modified: code/branches/pickup3/src/modules/pickup/items/HealthPickup.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/items/HealthPickup.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/modules/pickup/items/HealthPickup.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -32,6 +32,7 @@
#include "core/XMLPort.h"
#include "worldentities/pawns/Pawn.h"
+#include "pickup/PickupIdentifier.h"
#include <sstream>
@@ -69,18 +70,18 @@
void HealthPickup::initializeIdentifier(void)
{
- this->pickupIdentifier_.addClass(this->getIdentifier());
+ this->pickupIdentifier_->addClass(this->getIdentifier());
std::stringstream stream;
stream << this->getHealth();
std::string type1 = "health";
std::string val1 = stream.str();
- this->pickupIdentifier_.addParameter(type1, val1);
+ this->pickupIdentifier_->addParameter(type1, val1);
//TODO: Does this work, is val valid outside the function scope?
std::string val2 = this->getHealthType();
std::string type2 = "healthType";
- this->pickupIdentifier_.addParameter(type2, val2);
+ this->pickupIdentifier_->addParameter(type2, val2);
}
void HealthPickup::HealthPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
Modified: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -64,7 +64,7 @@
@param pickup A pointer to the Pickupable.
@return Returns true if the Pickupable was picked up, false if not.
*/
- inline bool pickup(Pickupable* pickup)
+ bool pickup(Pickupable* pickup)
{
bool pickedUp = this->pickups_.insert(pickup).second;
if(pickedUp)
@@ -77,42 +77,93 @@
@param pickup A pointer to the Pickupable.
@return Returns true if the Pickupable has been dropped, false if not.
*/
- inline bool drop(Pickupable* pickup)
+ bool drop(Pickupable* pickup)
{
bool dropped = this->pickups_.erase(pickup) == 1;
if(dropped)
{
pickup->dropped();
- //TODO: Create Spawner.
}
return dropped;
}
- inline bool isTarget(Pickupable* pickup)
+ /**
+ @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
+ @param pickup A pointer to the Pickupable.
+ @return Returns true if the PickupCarrier or one of its children is a target, false if not.
+ */
+ //TODO: Use?
+ bool isTarget(const Pickupable* pickup)
{
- if(pickup->isTarget(this))
+ if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
return true;
- const std::list<PickupCarrier*>* children = this->getChildren();
+
+ //! Go recursively through all children to check whether they are a target.
+ std::list<PickupCarrier*>* children = this->getCarrierChildren();
for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
{
if((*it)->isTarget(pickup))
return true;
}
+ children->clear();
+ delete children;
+
return false;
}
+
+ /**
+ @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
+ @param pickup A pounter to the Pickupable.
+ @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable.
+ */
+ PickupCarrier* getTarget(const Pickupable* pickup)
+ {
+ if(!this->isTarget(pickup))
+ return NULL;
+
+ if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
+ return this;
+
+ //! Go recursively through all children to check whether they are the target.
+ std::list<PickupCarrier*>* children = this->getCarrierChildren();
+ for(std::list<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
+ {
+ if(pickup->isTarget(*it))
+ return *it;
+ }
+
+ children->clear();
+ delete children;
+
+ return NULL;
+ }
- protected:
- //TODO: Good return type?
- virtual const std::list<PickupCarrier*>* getChildren(void) = 0;
- virtual PickupCarrier* getParent(void) = 0;
+ protected:
+ /**
+ @brief Get all direct children of this PickupSpawner.
+ This method needs to be implemented by any direct derivative class of PickupCarrier.
+ @return Returns a pointer to a list of all direct children.
+ */
+ //TODO: Good return type? Maybe not const and destroyed in isTarget...
+ virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
+ /**
+ @brief Get the parent of this PickupSpawner
+ This method needs to be implemented by any direct derivative class of PickupCarrier.
+ @return Returns a pointer to the parent.
+ */
+ virtual PickupCarrier* getCarrierParent(void) = 0;
+ /**
+ @brief Get the (absolute) position of the PickupCarrier.
+ This method needs to be implemented by any direct derivative class of PickupCarrier.
+ @return Returns the position as a Vector3.
+ */
+ virtual const Vector3& getCarrierPosition(void) = 0;
private:
- std::set<Pickupable*> pickups_;
+ std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
-
};
-
}
#endif /* _PickupCarrier_H__ */
Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -35,6 +35,7 @@
#include "core/Identifier.h"
#include "core/CoreIncludes.h"
+#include "pickup/PickupIdentifier.h"
#include "PickupCarrier.h"
namespace orxonox
@@ -51,6 +52,8 @@
this->used_ = false;
this->pickedUp_ = false;
this->carrier_ = NULL;
+
+ this->pickupIdentifier_ = new PickupIdentifier();
}
/**
@@ -90,7 +93,7 @@
@return
Returns true if the given PickupCarrier is a target.
*/
- bool Pickupable::isTarget(PickupCarrier* carrier)
+ bool Pickupable::isTarget(const PickupCarrier* carrier) const
{
Identifier* identifier = carrier->getIdentifier();
//! Iterate through all targets of this Pickupable.
@@ -155,7 +158,13 @@
COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
this->setUsed(false);
this->setPickedUp(false);
+
+ bool created = this->createSpawner(this->getCarrier()->getCarrierPosition());
+
this->setCarrier(NULL);
+ if(!created)
+ this->destroy();
+
return true;
}
Modified: code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/Pickupable.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/interfaces/Pickupable.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -38,7 +38,6 @@
#include <list>
#include "core/Super.h"
-#include "pickup/PickupIdentifier.h"
#include "core/OrxonoxClass.h"
@@ -82,7 +81,7 @@
bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.
bool dropped(void); //!< Sets the Pickupable to not picked up or dropped.
- bool isTarget(PickupCarrier* carrier); //!< Get whether the given PickupCarrier is a target of this pickup.
+ bool isTarget(const PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
/**
@@ -107,7 +106,7 @@
@return Returns a pointer to the PickupIdentifier of this Pickupable.
*/
virtual const PickupIdentifier* getPickupIdentifier(void)
- { return &this->pickupIdentifier_; }
+ { return this->pickupIdentifier_; }
virtual void destroy(void)
{ delete this; }
@@ -119,8 +118,17 @@
//TODO: Really needed?
void initializeIdentifier(void) {}
+ /**
+ @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
+ This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.:
+ DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance);
+ @param position The position at which the PickupSpawner should be placed.
+ @return Returns true if a spawner was created, false if not.
+ */
+ virtual bool createSpawner(const Vector3& position) = 0;
+
//TODO: Move to private and create get method in protected.
- PickupIdentifier pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
+ PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.
private:
/**
Modified: code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc
===================================================================
--- code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.cc 2010-03-05 17:26:54 UTC (rev 6475)
@@ -33,11 +33,15 @@
namespace orxonox
{
+ /**
+ @brief
+ Constructor. Registers the object and initializes member variables.
+ */
PickupIdentifier::PickupIdentifier()
{
RegisterRootObject(PickupIdentifier);
-
+ this->classIdentifier_ = NULL;
}
PickupIdentifier::~PickupIdentifier()
@@ -51,38 +55,59 @@
@param identifier
Pointer to the second PickupIdentifier, b.
@return
- Returns an int.
+ Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b.
*/
- int PickupIdentifier::compare(const PickupIdentifier& identifier) const
+ int PickupIdentifier::compare(const PickupIdentifier* identifier) const
{
- if(!identifier.classIdentifier_->isExactlyA(this->classIdentifier_))
- return this->classIdentifier_->getName().compare(identifier.classIdentifier_->getName());
+ //! If the classIdentifiers are not the same (meaning the PickupIdentifiers identify different classes), the obviously the two Pickupables identified by the PickupIdentifiers cannot be the same. An ordering is established through the alphabetical ordering of the respective classnames.
+ if(!identifier->classIdentifier_->isExactlyA(this->classIdentifier_))
+ return this->classIdentifier_->getName().compare(identifier->classIdentifier_->getName());
- if(!(this->parameters_.size() == identifier.parameters_.size()))
+ //! If the class is the same for both PickupIdentifiers we go on to check the parameters of the class.
+ //! If the two have a different number of parameters then obviusly something is very wrong.
+ if(!(this->parameters_.size() == identifier->parameters_.size()))
{
COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl;
- return this->parameters_.size()-identifier.parameters_.size();
+ return this->parameters_.size()-identifier->parameters_.size();
}
+ //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.
for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++)
{
- if(identifier.parameters_.find(it->first) == identifier.parameters_.end())
+ //!< If a parameter present in one of the identifiers is not found in the other, once again, something is very wrong.
+ if(identifier->parameters_.find(it->first) == identifier->parameters_.end())
{
COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl;
return -1;
}
- if(identifier.parameters_.find(it->first)->second != it->second)
- return it->second.compare(identifier.parameters_.find(it->first)->second);
+ if(identifier->parameters_.find(it->first)->second != it->second)
+ return it->second.compare(identifier->parameters_.find(it->first)->second);
}
return false;
}
+ /**
+ @brief
+ Add the class of the Pickupable to its PickupIdentifier.
+ @param identifier
+ A pointer to the Identifier of the class.
+ */
void PickupIdentifier::addClass(Identifier* identifier)
{
this->classIdentifier_ = identifier;
}
+ /**
+ @brief
+ Add a parameter to the PickupIdentifier.
+ @param name
+ The name of the parameter.
+ @param value
+ The value of the parameter.
+ @return
+ Returns false if the parameter already existed, true if not.
+ */
bool PickupIdentifier::addParameter(std::string & name, std::string & value)
{
if(!(this->parameters_.find(name) == this->parameters_.end()))
Modified: code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.h
===================================================================
--- code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/pickup/PickupIdentifier.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -31,44 +31,50 @@
#include "OrxonoxPrereqs.h"
-#include "core/OrxonoxClass.h"
-#include "core/Identifier.h"
#include <map>
#include <string>
+#include "core/Identifier.h"
+#include "core/OrxonoxClass.h"
+
namespace orxonox
{
+ /**
+ @brief
+ The purpose of the PickupIdentifier class is to identify different types of pickups allthough they are of the same class.
+ This allows for more generic classes (or pickups in this case) that can be a number of different pickup types and can be identified as such without the need for a lot of different classes. An example is the HealthPickup class that encompasses a wide variety of different types of health pickups, e.g a HealthPickup that adds 10 health every second for 10 seconds or a HealthPickup that adds 100 health as soon as it is picked up, a.s.o.
+ To that purpose this class provides functionality to compare two PickupIdentifier (and since all Pickupables have an Identifier through that Pickupables can be compared). It als provides functionality to add parameters that distinguish between different types of pickups in the same pickup class.
+ Lastly a struct is provided that can be used in stl containers to establish a strictly lesser ordering between PickupIdentifiers (and thus Pickupables).
+ @author
+ Damian 'Mozork' Frick
+ */
class _OrxonoxExport PickupIdentifier : virtual public OrxonoxClass
{
public:
- PickupIdentifier(void);
- ~PickupIdentifier();
+ PickupIdentifier(void); //!< Constructor.
+ ~PickupIdentifier(); //!< Destructor.
- virtual int compare(const PickupIdentifier& identifier) const;
+ virtual int compare(const PickupIdentifier* identifier) const; //!< Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b).
- void addClass(Identifier* identifier);
- bool addParameter(std::string & name, std::string & value);
+ void addClass(Identifier* identifier); //!< Add the class of the Pickupable to its PickupIdentifier.
+ bool addParameter(std::string & name, std::string & value); //!< Add a parameter to the PickupIdentifier.
private:
- Identifier* classIdentifier_;
- std::map<std::string, std::string> parameters_;
+ Identifier* classIdentifier_; //!< The Identifier of the class.
+ std::map<std::string, std::string> parameters_; //!< The parameters identifying the type of the pickup beyond the class.
-
};
- //TODO: Needed?
+ /**
+ @brief
+ Struct that overloads the compare operation between two PickupIdentifier pointers.
+ */
struct PickupIdentifierCompare
{
- bool operator() (const PickupIdentifier& lhs, const PickupIdentifier& rhs) const
- { return lhs.compare(rhs) < 0; }
- };
-
- struct PickupIdentifierPtrCompare
- {
bool operator() (const PickupIdentifier* lhs, const PickupIdentifier* rhs) const
- { return lhs->compare(*rhs) < 0; }
+ { return lhs->compare(rhs) < 0; }
};
}
Modified: code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h 2010-03-05 08:49:56 UTC (rev 6474)
+++ code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h 2010-03-05 17:26:54 UTC (rev 6475)
@@ -137,10 +137,12 @@
//TODO: Remove.
//PickupCollection pickups_;
- virtual const std::list<PickupCarrier*>* getChildren(void)
+ virtual std::list<PickupCarrier*>* getCarrierChildren(void)
{ return new std::list<PickupCarrier*>(); }
- virtual PickupCarrier* getParent(void)
+ virtual PickupCarrier* getCarrierParent(void)
{ return NULL; }
+ virtual const Vector3& getCarrierPosition(void)
+ { return this->getWorldPosition(); };
float health_;
float maxHealth_;
More information about the Orxonox-commit
mailing list