[Orxonox-commit 2455] r7162 - in code/branches/presentation3: data/gui/scripts data/levels src/modules/pickup src/modules/pickup/items src/orxonox src/orxonox/gametypes src/orxonox/interfaces src/orxonox/items src/orxonox/pickup src/orxonox/worldentities/pawns
dafrick at orxonox.net
dafrick at orxonox.net
Sun Aug 8 20:53:52 CEST 2010
Author: dafrick
Date: 2010-08-08 20:53:52 +0200 (Sun, 08 Aug 2010)
New Revision: 7162
Added:
code/branches/presentation3/src/modules/pickup/CollectiblePickup.cc
code/branches/presentation3/src/modules/pickup/CollectiblePickup.h
Modified:
code/branches/presentation3/data/gui/scripts/PickupInventory.lua
code/branches/presentation3/data/levels/pickups.oxw
code/branches/presentation3/src/modules/pickup/CMakeLists.txt
code/branches/presentation3/src/modules/pickup/Pickup.cc
code/branches/presentation3/src/modules/pickup/Pickup.h
code/branches/presentation3/src/modules/pickup/PickupCollection.cc
code/branches/presentation3/src/modules/pickup/PickupCollection.h
code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc
code/branches/presentation3/src/modules/pickup/PickupManager.cc
code/branches/presentation3/src/modules/pickup/PickupPrereqs.h
code/branches/presentation3/src/modules/pickup/PickupRepresentation.h
code/branches/presentation3/src/modules/pickup/PickupSpawner.cc
code/branches/presentation3/src/modules/pickup/PickupSpawner.h
code/branches/presentation3/src/modules/pickup/items/DronePickup.cc
code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc
code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc
code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc
code/branches/presentation3/src/modules/pickup/items/MetaPickup.h
code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc
code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc
code/branches/presentation3/src/orxonox/CameraManager.cc
code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc
code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc
code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc
code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
code/branches/presentation3/src/orxonox/items/Engine.cc
code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc
code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc
Log:
Significant structural changes to the pickup module. Lots of bugs found and fixed.
Introduced a new class CollectiblePickup (which is now the only kind a PickupCollection can consist of) to solve some issues cleanly.
MetaPickup received additional functionality. It can now also be set to either destroy all the pickups of a PickupCarrier or destroy the PickupCarrier itself. (This was done mainly for testing purposes)
I've done some extensive testing on the pickups, so they should really work now.
Modified: code/branches/presentation3/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/presentation3/data/gui/scripts/PickupInventory.lua 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/data/gui/scripts/PickupInventory.lua 2010-08-08 18:53:52 UTC (rev 7162)
@@ -53,9 +53,15 @@
if pickup:isUsed() == true then
useButton:setText("unuse")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
+ if pickup:isUsable() == false then
+ useButton:setEnabled(false)
+ end
else
useButton:setText("use")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
+ if pickup:isUnusable() == false then
+ useButton:setEnabled(false)
+ end
end
if pickup:isPickedUp() == false then
@@ -129,9 +135,15 @@
if pickup:isUsed() == false then
useButton:setText("use")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked")
+ if pickup:isUsable() == false then
+ useButton:setEnabled(false)
+ end
else
useButton:setText("unuse")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked")
+ if pickup:isUnusable() == false then
+ useButton:setEnabled(false)
+ end
end
item:addChildWindow(useButton)
@@ -228,9 +240,15 @@
if pickup:isUsed() == false then
useButton:setText("use")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked")
+ if pickup:isUsable() == false then
+ useButton:setEnabled(false)
+ end
else
useButton:setText("unuse")
orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked")
+ if pickup:isUnusable() == false then
+ useButton:setEnabled(false)
+ end
end
wrapper:addChildWindow(useButton)
Modified: code/branches/presentation3/data/levels/pickups.oxw
===================================================================
--- code/branches/presentation3/data/levels/pickups.oxw 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/data/levels/pickups.oxw 2010-08-08 18:53:52 UTC (rev 7162)
@@ -135,6 +135,18 @@
</pickup>
</PickupSpawner>
+ <PickupSpawner position="25,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
+ <pickup>
+ <MetaPickup metaType="destroy" />
+ </pickup>
+ </PickupSpawner>
+
+ <PickupSpawner position="50,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
+ <pickup>
+ <MetaPickup metaType="destroyCarrier" />
+ </pickup>
+ </PickupSpawner>
+
<!-- Pickup Collection pickups -->
<PickupSpawner position="-50,25,-125" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
@@ -161,13 +173,13 @@
inventoryRepresentation = "MediumHealth"
>
<pickup>
- <HealthPickup health=50 activationType="onUse" durationType="once" />
+ <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous />
</pickup>
</PickupRepresentation>
<PickupSpawner position="-50,0,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
<pickup>
- <HealthPickup health=50 activationType=onUse durationType=once />
+ <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous />
</pickup>
</PickupSpawner>
Modified: code/branches/presentation3/src/modules/pickup/CMakeLists.txt
===================================================================
--- code/branches/presentation3/src/modules/pickup/CMakeLists.txt 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/CMakeLists.txt 2010-08-08 18:53:52 UTC (rev 7162)
@@ -1,4 +1,5 @@
SET_SOURCE_FILES(PICKUP_SRC_FILES
+ CollectiblePickup.cc
DroppedPickup.cc
Pickup.cc
PickupCollection.cc
Added: code/branches/presentation3/src/modules/pickup/CollectiblePickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/CollectiblePickup.cc (rev 0)
+++ code/branches/presentation3/src/modules/pickup/CollectiblePickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -0,0 +1,164 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+/**
+ @file CollectiblePickup.cc
+ @brief Implementation of the CollectiblePickup class.
+*/
+
+#include "CollectiblePickup.h"
+
+#include "core/CoreIncludes.h"
+#include "PickupCollection.h"
+
+namespace orxonox {
+
+ /**
+ @brief
+ Constructor.
+ Registers the object and initializes variables.
+ */
+ CollectiblePickup::CollectiblePickup() : isInCollection_(false)
+ {
+ RegisterObject(CollectiblePickup);
+
+ this->collection_ = NULL;
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ CollectiblePickup::~CollectiblePickup()
+ {
+
+ }
+
+ /**
+ @brief
+ Is called by OrxonoxClass::destroy() before the object is actually destroyed.
+ */
+ void CollectiblePickup::preDestroy(void)
+ {
+ this->Pickupable::preDestroy();
+
+ // The PickupCollection has to be destroyed as well.
+ if(this->isInCollection())
+ this->collection_->Pickupable::destroy();
+ }
+
+ /**
+ @brief
+ Destroys a Pickupable.
+ */
+ void CollectiblePickup::destroyPickup(void)
+ {
+ if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called.
+ this->Pickupable::destroyPickup();
+ else // Else the ColectiblePickup is dropped and disabled,
+ {
+ this->drop(false);
+ if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped.
+ {
+ this->setDisabled();
+ this->collection_->pickupDisabled();
+ }
+ }
+ }
+
+ /**
+ @brief
+ Is called by the PickupCarrier when it is being destroyed.
+ */
+ void CollectiblePickup::carrierDestroyed(void)
+ {
+ if(!this->isInCollection())
+ this->Pickupable::destroy();
+ else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed.
+ this->drop(false);
+ }
+
+ /**
+ @brief
+ Is called when the pickup has transited from used to unused or the other way around.
+ */
+ void CollectiblePickup::changedUsed(void)
+ {
+ SUPER(CollectiblePickup, changedUsed);
+
+ if(this->isInCollection())
+ this->collection_->pickupChangedUsed(this->isUsed());
+ }
+
+ /**
+ @brief
+ Is called when the pickup has transited from picked up to dropped or the other way around.
+ */
+ void CollectiblePickup::changedPickedUp(void)
+ {
+ SUPER(CollectiblePickup, changedPickedUp);
+
+ if(this->isInCollection())
+ this->collection_->pickupChangedPickedUp(this->isPickedUp());
+ }
+
+ /**
+ @brief
+ Adds this CollectiblePickup to the input PickupCollection.
+ @param collection
+ A pointer to the PickupCollection to which the CollectiblePickup should be added.
+ @return
+ Returns true if the CollectiblePickup was successfully added to the PickupCollection.
+ */
+ bool CollectiblePickup::addToCollection(PickupCollection* collection)
+ {
+ if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL.
+ return false;
+
+ this->isInCollection_ = true;
+ this->collection_ = collection;
+ return true;
+ }
+
+ /**
+ @brief
+ Removes this CollectiblePickup from its PickupCollection.
+ @return
+ Returns true if the CollectiblePickup was succcessfully removed.
+ */
+ bool CollectiblePickup::removeFromCollection(void)
+ {
+ if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.
+ return false;
+
+ this->isInCollection_ = false;
+ this->collection_ = NULL;
+ return true;
+ }
+
+}
Added: code/branches/presentation3/src/modules/pickup/CollectiblePickup.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/CollectiblePickup.h (rev 0)
+++ code/branches/presentation3/src/modules/pickup/CollectiblePickup.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -0,0 +1,82 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Damian 'Mozork' Frick
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file CollectiblePickup.h
+ @brief Definition of the CollectiblePickup class.
+*/
+
+#ifndef _CollectiblePickup_H__
+#define _CollectiblePickup_H__
+
+#include "pickup/PickupPrereqs.h"
+
+#include "interfaces/Pickupable.h"
+
+namespace orxonox {
+
+ /**
+ @brief
+ Collectible Pickup class. Any pickup inheriting from this class can be added to a PickupCollection and thus be part uf such.
+ @author
+ Damian 'Mozork' Frick
+ */
+ class _PickupExport CollectiblePickup : public Pickupable
+ {
+
+ public:
+ CollectiblePickup(); //!< Constructor.
+ virtual ~CollectiblePickup(); //! Destructor.
+
+ virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
+ virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around.
+
+ /**
+ @brief Check whether the given CollectiblePickup is par of a PickupCollection.
+ @return Returns true if the ColelctiblePickup is part of a PickupCollection.
+ */
+ bool isInCollection(void)
+ { return this->isInCollection_; }
+
+ bool addToCollection(PickupCollection* collection); //!< Adds this CollectiblePickup to the input PickupCollection.
+ bool removeFromCollection(void); //!< Removes this CollectiblePickup from its PickupCollection.
+
+ void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
+
+ protected:
+ virtual void preDestroy(void); //!< Is called by OrxonoxClass::destroy() before the object is actually destroyed.
+ virtual void destroyPickup(void); //!< //!< Destroys a Pickupable.
+
+ private:
+ bool isInCollection_; //!< True if the CollectiblePickup is in a PickupCollection.
+ PickupCollection* collection_; //!< A pointer to the PickupCollection this CollectiblePickup is in.
+
+ };
+}
+
+#endif // _CollectiblePickup_H__
Modified: code/branches/presentation3/src/modules/pickup/Pickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/Pickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/Pickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -193,7 +193,7 @@
SUPER(Pickup, changedPickedUp);
//! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
- if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
+ if(this->isPickedUp() && this->isImmediate())
{
this->setUsed(true);
}
Modified: code/branches/presentation3/src/modules/pickup/Pickup.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/Pickup.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/Pickup.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -39,7 +39,7 @@
#include "core/BaseObject.h"
#include "core/XMLPort.h"
-#include "interfaces/Pickupable.h"
+#include "CollectiblePickup.h"
#include "tools/Timer.h"
@@ -73,7 +73,7 @@
@author
Damian 'Mozork' Frick
*/
- class _PickupExport Pickup : public Pickupable, public BaseObject
+ class _PickupExport Pickup : public CollectiblePickup, public BaseObject
{
public:
Modified: code/branches/presentation3/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupCollection.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupCollection.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -34,6 +34,7 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
#include "interfaces/PickupCarrier.h"
+#include "CollectiblePickup.h"
#include "DroppedPickup.h"
#include "PickupCollectionIdentifier.h"
@@ -53,6 +54,11 @@
RegisterObject(PickupCollection);
this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this);
+ this->usedCounter_ = 0;
+ this->pickedUpCounter_ = 0;
+ this->disabledCounter_ = 0;
+ this->processingUsed_ = false;
+ this->processingPickedUp_ = false;
}
/**
@@ -61,12 +67,13 @@
*/
PickupCollection::~PickupCollection()
{
- //! Destroy all Pickupables constructing this PickupCollection.
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ // Destroy all Pickupables constructing this PickupCollection.
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- if((*it).get() != NULL)
- (*it).get()->destroy();
+ (*it)->removeFromCollection();
+ (*it)->destroy();
}
+ this->pickups_.clear();
}
/**
@@ -77,7 +84,7 @@
{
SUPER(PickupCollection, XMLPort, xmlelement, mode);
- XMLPortObject(PickupCollection, Pickupable, "pickupables", addPickupable, getPickupable, xmlelement, mode);
+ XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode);
this->initializeIdentifier();
}
@@ -88,9 +95,9 @@
*/
void PickupCollection::initializeIdentifier(void)
{
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- this->pickupCollectionIdentifier_->addPickup((*it).get()->getPickupIdentifier());
+ this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());
}
}
@@ -103,15 +110,38 @@
{
SUPER(PickupCollection, changedUsed);
- //! Change used for all Pickupables this PickupCollection consists of.
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ this->processingUsed_ = true;
+ // Change used for all Pickupables this PickupCollection consists of.
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it).get()->setUsed(this->isUsed());
+ (*it)->setUsed(this->isUsed());
}
+ this->processingUsed_ = false;
+
+ this->changedUsedAction();
}
/**
@brief
+ Helper method.
+ Checks whether due to changes in the used status of the pickups of this PickupCollection the used status of this PickupCollection has to change as well.
+ */
+ void PickupCollection::changedUsedAction(void)
+ {
+ if(this->processingUsed_)
+ return;
+
+ // If all the pickups are not in use but the PickupCollection is.
+ if(this->usedCounter_ == 0 && this->isUsed())
+ this->setUsed(false);
+
+ // If all the enabled pickups are in use but the PickupCollection is not.
+ if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed())
+ this->setUsed(true);
+ }
+
+ /**
+ @brief
Is called when the pickup has changed its PickupCarrier.
Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
*/
@@ -119,10 +149,13 @@
{
SUPER(PickupCollection, changedCarrier);
- //! Change the PickupCarrier for all Pickupables this PickupCollection consists of.
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ // Change the PickupCarrier for all Pickupables this PickupCollection consists of.
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it).get()->setCarrier(this->getCarrier()->getTarget(*it), true);
+ if(this->getCarrier() == NULL)
+ (*it)->setCarrier(NULL);
+ else
+ (*it)->setCarrier(this->getCarrier()->getTarget(*it));
}
}
@@ -135,15 +168,38 @@
{
SUPER(PickupCollection, changedPickedUp);
- //! Change the pickedUp status for all Pickupables this PickupCollection consists of.
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ this->processingPickedUp_ = true;
+ // Change the pickedUp status for all Pickupables this PickupCollection consists of.
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- (*it).get()->setPickedUp(this->isPickedUp());
+ (*it)->setPickedUp(this->isPickedUp());
}
+ this->processingPickedUp_ = false;
+
+ this->changedPickedUpAction();
}
/**
@brief
+ Helper method.
+ Checks whether due to changes in the picked up status of the pickups of this PickupCollection the picked up status of this PickupCollection has to change as well.
+ */
+ void PickupCollection::changedPickedUpAction(void)
+ {
+ if(this->processingPickedUp_)
+ return;
+
+ // If at least all the enabled pickups of this PickupCollection are no longer picked up.
+ if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp())
+ this->Pickupable::destroy();
+
+ // If the PickupCollection is no longer picked up.
+ if(!this->isPickedUp())
+ this->pickedUpCounter_ = 0;
+ }
+
+ /**
+ @brief
Creates a duplicate of the input OrxonoxClass.
This method needs to be implemented by any Class inheriting from Pickupable.
@param item
@@ -157,11 +213,12 @@
SUPER(PickupCollection, clone, item);
PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
- //! Clone all Pickupables this PickupCollection consist of.
- for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ // Clone all Pickupables this PickupCollection consist of.
+ for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- Pickupable* newPickup = (*it).get()->clone();
- pickup->addPickupable(newPickup);
+ Pickupable* newPickup = (*it)->clone();
+ CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup);
+ pickup->addPickupable(collectible);
}
pickup->initializeIdentifier();
@@ -177,9 +234,9 @@
*/
bool PickupCollection::isTarget(PickupCarrier* carrier) const
{
- for(std::vector<WeakPtr<Pickupable> >::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
- if(!carrier->isTarget((*it).get()))
+ if(!carrier->isTarget(*it))
return false;
}
@@ -206,13 +263,13 @@
@return
Returns true if successful,
*/
- bool PickupCollection::addPickupable(Pickupable* pickup)
+ bool PickupCollection::addPickupable(CollectiblePickup* pickup)
{
if(pickup == NULL)
return false;
- WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid.
- this->pickups_.push_back(ptr);
+ pickup->addToCollection(this);
+ this->pickups_.push_back(pickup);
return true;
}
@@ -226,11 +283,55 @@
*/
const Pickupable* PickupCollection::getPickupable(unsigned int index)
{
- return this->pickups_[index].get();
+ return this->pickups_[index];
}
/**
@brief
+ Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
+ This is used internally by the CollectiblePickup class.
+ @param changed
+ The value the used status has changed to.
+ */
+ void PickupCollection::pickupChangedUsed(bool changed)
+ {
+ if(changed)
+ this->usedCounter_++;
+ else
+ this->usedCounter_--;
+
+ this->changedUsedAction();
+ }
+
+ /**
+ @brief
+ Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
+ This is used internally by the CollectiblePickup class.
+ @param changed
+ The value the picked up status has changed to.
+ */
+ void PickupCollection::pickupChangedPickedUp(bool changed)
+ {
+ if(changed)
+ this->pickedUpCounter_++;
+ else
+ this->pickedUpCounter_--;
+
+ this->changedPickedUpAction();
+ }
+
+ /**
+ @brief
+ Informs the PickupCollection, that one of its pickups has been disabled.
+ This is used internally by the CollectiblePickup class.
+ */
+ void PickupCollection::pickupDisabled(void)
+ {
+ this->disabledCounter_++;
+ }
+
+ /**
+ @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);
@@ -245,4 +346,4 @@
return true;
}
-}
\ No newline at end of file
+}
Modified: code/branches/presentation3/src/modules/pickup/PickupCollection.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupCollection.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupCollection.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -36,8 +36,8 @@
#include "PickupPrereqs.h"
-#include "interfaces/Pickupable.h"
#include "core/BaseObject.h"
+#include "CollectiblePickup.h"
#include <list>
@@ -46,15 +46,14 @@
/**
@brief
- The PickupCollection combines different Pickupables to a coherent, single pickup and makes the seem (from the outside looking in) just as if they were just one Pickupable.
+ The PickupCollection combines different Pickupables to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one Pickupable.
@author
Damian 'Mozork' Frick
*/
- class _PickupExport PickupCollection : public Pickupable, public BaseObject
+ class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject
{
public:
-
PickupCollection(BaseObject* creator); //!< Default Constructor.
virtual ~PickupCollection(); //!< Destructor.
@@ -70,9 +69,13 @@
virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection.
- bool addPickupable(Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
+ bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.
const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index.
+ void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value.
+ void pickupChangedPickedUp(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value.
+ void pickupDisabled(void); //!< Informs the PickupCollection, that one of its pickups has been disabled.
+
protected:
void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup.
@@ -81,9 +84,18 @@
PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves.
private:
+ void changedUsedAction(void); //!< Helper method.
+ void changedPickedUpAction(void); //!< Helper method.
+
+ std::vector<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
- std::vector<WeakPtr<Pickupable> > pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid.
+ unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use.
+ unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up.
+ unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled.
+ bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent.
+ bool processingPickedUp_; //!< Boolean to ensure, that the PickupCollection doesn't update its picked upp status while its internal state is inconsistent.
+
};
}
Modified: code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -66,21 +66,21 @@
*/
int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
{
- //! Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
+ // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
- //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
+ // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
if(collectionIdentifier == NULL)
{
return this->PickupIdentifier::compare(identifier);
}
- //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
+ // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
- //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
+ // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
{
Modified: code/branches/presentation3/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupManager.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupManager.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -42,6 +42,7 @@
#include "interfaces/PickupCarrier.h"
#include "infos/PlayerInfo.h"
#include "worldentities/pawns/Pawn.h"
+#include "CollectiblePickup.h"
#include "PickupRepresentation.h"
#include "ToluaBindPickup.h"
@@ -63,6 +64,7 @@
{
RegisterRootObject(PickupManager);
+ //TODO: This doesn't work, yet.
if( GameMode::showsGraphics() )
{
GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
@@ -171,7 +173,9 @@
std::set<Pickupable*> pickups = (*it)->getPickups();
for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
{
- this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
+ CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(*pickup);
+ if(collectible == NULL || !collectible->isInCollection())
+ this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup)));
}
}
delete carriers;
Modified: code/branches/presentation3/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupPrereqs.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupPrereqs.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -65,6 +65,7 @@
namespace orxonox
{
+ class CollectiblePickup;
class DroppedPickup;
class Pickup;
class PickupCollection;
Modified: code/branches/presentation3/src/modules/pickup/PickupRepresentation.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupRepresentation.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupRepresentation.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -148,7 +148,7 @@
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.
- std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?
+ std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory.
Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation.
Modified: code/branches/presentation3/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupSpawner.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupSpawner.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -106,6 +106,7 @@
this->respawnTime_ = 0;
this->maxSpawnedItems_ = INF;
this->spawnsRemaining_ = INF;
+ this->selfDestruct_ = false;
}
/**
@@ -114,7 +115,7 @@
*/
PickupSpawner::~PickupSpawner()
{
- if(this->pickup_ != NULL)
+ if(this->selfDestruct_ && this->pickup_ != NULL)
this->pickup_->destroy();
}
@@ -175,7 +176,7 @@
//! If the PickupSpawner is active.
if (this->isActive())
{
- SmartPtr<PickupSpawner> temp = this; // create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
+ SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)
//! Iterate trough all Pawns.
for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
@@ -304,11 +305,10 @@
if(target != NULL && pickup != NULL)
{
if(pickup->pickup(target))
- {
this->decrementSpawnsRemaining();
- }
else
{
+ this->selfDestruct_ = true;
pickup->destroy();
}
}
@@ -318,11 +318,10 @@
COUT(1) << "PickupSpawner (&" << this << "): Pickupable has no target." << std::endl;
if(pickup == NULL)
- {
COUT(1) << "PickupSpawner (&" << this << "): getPickup produced an error, no Pickupable created." << std::endl;
- }
else
{
+ this->selfDestruct_ = true;
pickup->destroy();
}
}
Modified: code/branches/presentation3/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/PickupSpawner.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/PickupSpawner.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -124,6 +124,8 @@
float respawnTime_; //!< Time after which this gets re-actived.
Timer respawnTimer_; //!< Timer used for re-activating.
+ bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing.
+
static const int INF = -1; //!< Constant for infinity.
};
}
Modified: code/branches/presentation3/src/modules/pickup/items/DronePickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/DronePickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/DronePickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -130,7 +130,7 @@
Pawn* pawn = this->carrierToPawnHelper();
if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
- this->destroy();
+ this->Pickupable::destroy();
//Attach to pawn
Drone* drone = new Drone(pawn->getCreator()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
@@ -154,7 +154,7 @@
//! 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->destroy();
+ this->Pickupable::destroy();
}
}
}
Modified: code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -142,7 +142,7 @@
{
Pawn* pawn = this->carrierToPawnHelper();
if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
- this->destroy();
+ this->Pickupable::destroy();
//! Calculate the health that is added this tick.
float health = dt*this->getHealthRate();
@@ -190,7 +190,7 @@
SUPER(HealthPickup, changedUsed);
//! If the pickup is not picked up nothing must be done.
- if(!this->isPickedUp())
+ if(!this->isPickedUp()) //TODO: Needed?
return;
//! If the pickup has transited to used.
@@ -200,7 +200,7 @@
{
Pawn* pawn = this->carrierToPawnHelper();
if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
- this->destroy();
+ this->Pickupable::destroy();
float health = 0;
switch(this->getHealthTypeDirect())
@@ -240,7 +240,7 @@
if(pawn == NULL)
{
COUT(1) << "Something went horribly wrong in Health Pickup. PickupCarrier is no Pawn." << std::endl;
- this->destroy();
+ this->Pickupable::destroy();
return;
}
@@ -255,7 +255,7 @@
//! 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->getHealth() == 0))
{
- this->destroy();
+ this->Pickupable::destroy();
}
}
}
Modified: code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -132,7 +132,7 @@
if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
{
- this->destroy();
+ this->Pickupable::destroy();
}
else
{
Modified: code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -33,6 +33,7 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
+#include "worldentities/pawns/Pawn.h"
#include "interfaces/PickupCarrier.h"
#include "pickup/PickupIdentifier.h"
@@ -46,6 +47,8 @@
/*static*/ const std::string MetaPickup::metaTypeNone_s = "none";
/*static*/ const std::string MetaPickup::metaTypeUse_s = "use";
/*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop";
+ /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy";
+ /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier";
/**
@brief
@@ -119,8 +122,14 @@
PickupCarrier* carrier = this->getCarrier();
if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL)
{
+ if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
+ {
+ Pawn* pawn = orxonox_cast<Pawn*>(carrier);
+ pawn->kill();
+ return;
+ }
std::set<Pickupable*> pickups = carrier->getPickups();
- //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type.
+ //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type.
for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++)
{
Pickup* pickup = dynamic_cast<Pickup*>(*it);
@@ -135,12 +144,19 @@
{
if(pickup != NULL && pickup != this)
{
- pickup->drop(carrier);
+ pickup->drop();
}
}
+ if(this->getMetaTypeDirect() == pickupMetaType::destroy)
+ {
+ if(pickup != NULL && pickup != this)
+ {
+ pickup->Pickupable::destroy();
+ }
+ }
}
}
- this->destroy();
+ this->Pickupable::destroy();
}
}
@@ -179,6 +195,10 @@
return MetaPickup::metaTypeUse_s;
case pickupMetaType::drop:
return MetaPickup::metaTypeDrop_s;
+ case pickupMetaType::destroy:
+ return MetaPickup::metaTypeDestroy_s;
+ case pickupMetaType::destroyCarrier:
+ return MetaPickup::metaTypeDestroyCarrier_s;
default:
return BLANKSTRING;
}
@@ -204,6 +224,16 @@
{
this->setMetaTypeDirect(pickupMetaType::drop);
}
+ else if(type == MetaPickup::metaTypeDestroy_s)
+ {
+ this->setMetaTypeDirect(pickupMetaType::destroy);
+ }
+ else if(type == MetaPickup::metaTypeDestroyCarrier_s)
+ {
+ this->setMetaTypeDirect(pickupMetaType::destroyCarrier);
+ }
+ else
+ COUT(2) << "Invalid metaType '" << type << "' in MetaPickup." << std::endl;
}
}
Modified: code/branches/presentation3/src/modules/pickup/items/MetaPickup.h
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/MetaPickup.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/MetaPickup.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -47,13 +47,19 @@
{
none,
use,
- drop
+ drop,
+ destroy,
+ destroyCarrier
};
}
/**
@brief
- The MetaPickup is a pickup that can, depending on the parameters, either drop all pickups of the PickupCarrier that picks it up, or use all the unused pickups of the PickupCarrier, that picks it up. The parameter to set for this is the metaType and it can be used with the values 'none', 'drop' and 'use'.
+ The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to
+ 1) 'use', all the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup.
+ 2) 'drop', all the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup.
+ 3) 'destroy', all the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup.
+ 4) 'destroyCarrier', the PickupCarrier is immediately destroyed upon pickup of the MetaPickup.
@author
Damian 'Mozork' Frick
*/
@@ -97,6 +103,8 @@
static const std::string metaTypeNone_s;
static const std::string metaTypeUse_s;
static const std::string metaTypeDrop_s;
+ static const std::string metaTypeDestroy_s;
+ static const std::string metaTypeDestroyCarrier_s;
};
Modified: code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -154,7 +154,7 @@
Pawn* pawn = this->carrierToPawnHelper();
if(pawn == NULL)
- this->destroy();
+ this->Pickupable::destroy();
//! If the pickup has transited to used.
if(this->isUsed())
@@ -180,7 +180,7 @@
{
if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
{
- this->destroy();
+ this->Pickupable::destroy();
}
else
{
Modified: code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc
===================================================================
--- code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -135,7 +135,7 @@
Engine* engine = this->carrierToEngineHelper();
if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.
- this->destroy();
+ this->Pickupable::destroy();
//! If the pickup has transited to used.
if(this->isUsed())
@@ -160,7 +160,7 @@
{
if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
{
- this->destroy();
+ this->Pickupable::destroy();
}
else
{
Modified: code/branches/presentation3/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/presentation3/src/orxonox/CameraManager.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/CameraManager.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -67,7 +67,6 @@
void CameraManager::requestFocus(Camera* camera)
{
- COUT(0) << "bliub" << endl;
// notify old camera (if it exists)
if (!this->cameraList_.empty())
this->cameraList_.front()->removeFocus();
Modified: code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -101,7 +101,8 @@
}
bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
- { //TODO: static and fading message for the "human" player's
+ {
+ //TODO: static and fading message for the "human" player's
if (!originator||!victim)
return false;
if (!originator->getPlayer()||!victim->getPlayer())
Modified: code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -58,17 +58,27 @@
PickupCarrier::PickupCarrier()
{
RegisterRootObject(PickupCarrier);
-
- this->setCarrierName("PickupCarrier");
}
PickupCarrier::~PickupCarrier()
{
+
+ }
+
+ void PickupCarrier::preDestroy(void)
+ {
std::set<Pickupable*>::iterator it = this->pickups_.begin();
+ std::set<Pickupable*>::iterator temp;
while(it != this->pickups_.end())
{
- (*it)->destroy();
+ (*it)->carrierDestroyed();
+ temp = it;
it = this->pickups_.begin();
+ if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure.
+ {
+ COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;;
+ it++;
+ }
}
this->pickups_.clear();
Modified: code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -78,6 +78,7 @@
public:
PickupCarrier(); //!< Constructor.
virtual ~PickupCarrier(); //!< Destructor.
+ void preDestroy(void);
/**
@brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
@@ -137,12 +138,6 @@
*/
virtual const Vector3& getCarrierPosition(void) = 0;
- /**
- @brief Get the name of this PickupCarrier.
- @return Returns the name as a string.
- */
- const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
-
protected:
/**
@brief Get all direct children of this PickupSpawner.
@@ -159,89 +154,37 @@
virtual PickupCarrier* getCarrierParent(void) = 0;
/**
- @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
- @param pickup A pointer to the pickup to be added.
- @return Returns true if successfull, false if the Pickupable was already present.
- */
- bool addPickup(Pickupable* pickup)
- { return this->pickups_.insert(pickup).second; }
-
- /**
- @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
- @param pickup A pointer to the pickup to be removed.
- @return Returns true if successfull, false if the Pickupable was not present in the list.
- */
- bool removePickup(Pickupable* pickup)
- { return this->pickups_.erase(pickup) == 1; }
-
- /**
@brief Get all Pickupables this PickupCarrier has.
@return Returns the set of all Pickupables this PickupCarrier has.
*/
std::set<Pickupable*>& getPickups(void)
{ return this->pickups_; }
- /**
- @brief Set the name of this PickupCarrier.
- The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
- @param name The name to be set.
- */
- void setCarrierName(const std::string& name)
- { this->carrierName_ = name; }
-
private:
std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
- std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
/**
- @brief Get the number of carrier children this PickupCarrier has.
- @return Returns the number of carrier children.
+ @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
+ @param pickup A pointer to the pickup to be added.
+ @return Returns true if successfull, false if the Pickupable was already present.
*/
- unsigned int getNumCarrierChildren(void)
+ bool addPickup(Pickupable* pickup)
{
- std::vector<PickupCarrier*>* list = this->getCarrierChildren();
- unsigned int size = list->size();
- delete list;
- return size;
+ COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
+ return this->pickups_.insert(pickup).second;
}
/**
- @brief Get the index-th child of this PickupCarrier.
- @param index The index of the child to return.
- @return Returns the index-th child.
+ @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
+ @param pickup A pointer to the pickup to be removed.
+ @return Returns true if successfull, false if the Pickupable was not present in the list.
*/
- PickupCarrier* getCarrierChild(unsigned int index)
+ bool removePickup(Pickupable* pickup)
{
- std::vector<PickupCarrier*>* list = this->getCarrierChildren();
- if(list->size() < index)
- return NULL;
- PickupCarrier* carrier = (*list)[index];
- delete list;
- return carrier;
+ COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
+ return this->pickups_.erase(pickup) == 1;
}
- /**
- @brief Get the number of Pickupables this PickupCarrier carries.
- @return returns the number of pickups.
- */
- unsigned int getNumPickups(void)
- { return this->pickups_.size(); }
-
- /**
- @brief Get the index-th Pickupable of this PickupCarrier.
- @param index The index of the Pickupable to return.
- @return Returns the index-th pickup.
- */
- Pickupable* getPickup(unsigned int index)
- {
- std::set<Pickupable*>::iterator it;
- for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
- index--;
- if(it == this->pickups_.end())
- return NULL;
- return *it;
- }
-
};
}
Modified: code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -57,6 +57,8 @@
this->carrier_ = NULL;
this->pickupIdentifier_ = new PickupIdentifier(this);
+ this->beingDestroyed_ = false;
+ this->enabled_ = true;
}
/**
@@ -65,20 +67,47 @@
*/
Pickupable::~Pickupable()
{
- if(this->isUsed())
- this->setUsed(false);
+ COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl;
+ if(this->pickupIdentifier_ != NULL)
+ this->pickupIdentifier_->destroy();
+ }
+ /**
+ @brief
+ A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
+ */
+ void Pickupable::preDestroy(void)
+ {
+ this->beingDestroyed_ = true;
+
if(this->isPickedUp())
- {
- this->drop(false);
- }
+ this->drop(false); // Drops the pickup without creating a PickupSpawner.
+ }
- if(this->pickupIdentifier_ != NULL)
- this->pickupIdentifier_->destroy();
+ /**
+ @brief
+ Is called internally within the pickup module to destroy pickups.
+ */
+ void Pickupable::destroy(void)
+ {
+ this->destroyPickup();
}
/**
@brief
+ Destroys a Pickupable.
+ If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped.
+ */
+ void Pickupable::destroyPickup(void)
+ {
+ if(!this->beingDestroyed_)
+ this->OrxonoxClass::destroy();
+ else
+ COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl;
+ }
+
+ /**
+ @brief
Sets the Pickupable to used or unused, depending on the input.
@param used
If used is true the Pickupable is set to used, it is set to unused, otherwise.
@@ -87,9 +116,12 @@
*/
bool Pickupable::setUsed(bool used)
{
- if(this->used_ == used)
+ if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up.
return false;
+ if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable.
+ return false;
+
COUT(4) << "Pickupable (&" << this << ") set to used " << used << "." << std::endl;
this->used_ = used;
@@ -111,6 +143,7 @@
{
if(carrier == NULL)
return false;
+
return this->isTarget(carrier->getIdentifier());
}
@@ -130,6 +163,7 @@
if(identifier->isA(*it))
return true;
}
+
return false;
}
@@ -177,15 +211,14 @@
if(carrier == NULL || this->isPickedUp()) //!< If carrier is NULL or the Pickupable is already picked up.
return false;
- if(!carrier->addPickup(this))
+ if(!this->setCarrier(carrier))
{
COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl;
return false;
}
-
+
+ this->setPickedUp(true);
COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
- this->setCarrier(carrier);
- this->setPickedUp(true);
return true;
}
@@ -193,19 +226,19 @@
@brief
Can be called to drop a Pickupable.
@param createSpawner
- If true a spawner is be created for the dropped Pickupable. True is default.
+ If true a spawner is to be created for the dropped Pickupable. True is default.
@return
Returns true if the Pickupable has been dropped, false if not.
*/
bool Pickupable::drop(bool createSpawner)
{
- if(!this->isPickedUp()) //!< If the Pickupable is not picked up.
+ if(!this->isPickedUp()) // If the Pickupable is not picked up.
return false;
- assert(this->getCarrier()); //!> The Carrier cannot be NULL at this point. //TODO: Too conservative?
+ assert(this->getCarrier()); // The Carrier cannot be NULL at this point.
if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later?
- COUT(2) << "Pickupable (&" << this << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
-
+ COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;
+
COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;
this->setUsed(false);
this->setPickedUp(false);
@@ -216,10 +249,8 @@
this->setCarrier(NULL);
- if(!created && createSpawner)
- {
+ if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't.
this->destroy();
- }
return true;
}
@@ -234,12 +265,14 @@
*/
bool Pickupable::setPickedUp(bool pickedUp)
{
- if(this->pickedUp_ == pickedUp)
+ if(this->pickedUp_ == pickedUp) // If the picked up status has not changed.
return false;
COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl;
this->pickedUp_ = pickedUp;
+ if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier.
+ this->getCarrier()->removePickup(this);
this->changedPickedUp();
GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()");
return true;
@@ -250,23 +283,40 @@
Sets the carrier of the Pickupable.
@param carrier
Sets the input PickupCarrier as the carrier of the pickup.
+ @param tell
+ If true (default) the pickup is added to the list of pickups in the PickupCarrier.
+ @return
+ Returns true if successful, false if not.
*/
- inline bool Pickupable::setCarrier(PickupCarrier* carrier, bool tell)
+ bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell)
{
- if(this->carrier_ == carrier)
+ if(this->carrier_ == carrier) // If the PickupCarrier doesn't change.
return false;
COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
+ if(carrier != NULL && tell)
+ {
+ if(!carrier->addPickup(this))
+ return false;
+ }
+
this->carrier_ = carrier;
this->changedCarrier();
- if(tell && carrier != NULL)
- this->carrier_->pickups_.insert(this);
return true;
}
/**
@brief
+ Is called by the PickupCarrier when it is being destroyed.
+ */
+ void Pickupable::carrierDestroyed(void)
+ {
+ this->destroy();
+ }
+
+ /**
+ @brief
Creates a duplicate of the Pickupable.
@return
Returns the clone of this pickup as a pointer to a Pickupable.
Modified: code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
===================================================================
--- code/branches/presentation3/src/orxonox/interfaces/Pickupable.h 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/interfaces/Pickupable.h 2010-08-08 18:53:52 UTC (rev 7162)
@@ -94,9 +94,29 @@
*/
virtual void changedPickedUp(void) {}
- bool pickup(PickupCarrier* carrier);
- bool drop(bool createSpawner = true);
+ /**
+ @brief Returns whether the Pickupable can be used.
+ @return Returns true if it can be used.
+ */
+ inline bool isUsable(void) { return this->enabled_; } // tolua_export
+
+ /**
+ @brief Returns whether the Pickupable can be unused.
+ @return Returns true if it can be unused.
+ */
+ inline bool isUnusable(void) { return this->enabled_; } // tolua_export
+ /**
+ @brief Returns whether the Pickupable is enabled.
+ Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused.
+ @return Returns true if the Pickupable is enabled.
+ */
+ inline bool isEnabled(void)
+ { return this->enabled_; }
+
+ bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable.
+ bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable.
+
virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
bool isTarget(const Identifier* identifier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this Pickupable.
bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
@@ -114,15 +134,30 @@
bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
- bool setCarrier(PickupCarrier* carrier, bool tell = false); //!< Sets the carrier of the pickup.
+ //TODO: private?
+ bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup.
+ //TODO: private?
+ virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed.
+
+ void destroy(void); //!< Is called internally within the pickup module to destroy pickups.
+
protected:
/**
@brief Helper method to initialize the PickupIdentifier.
*/
void initializeIdentifier(void) {}
+ virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed.
+ virtual void destroyPickup(void); //!< Destroys a Pickupable.
+
/**
+ @brief Sets the Pickuapble to disabled.
+ */
+ inline void setDisabled(void)
+ { this->enabled_ = false; }
+
+ /**
@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);
@@ -135,12 +170,16 @@
private:
- bool used_; //!< Whether the pickup is currently in use or not.
- bool pickedUp_; //!< Whether the pickup is currently picked up or not.
+ bool used_; //!< Whether the Pickupable is currently in use or not.
+ bool pickedUp_; //!< Whether the Pickupable is currently picked up or not.
- PickupCarrier* carrier_; //!< The carrier of the pickup.
- std::list<Identifier*> targets_; //!< The possible targets of this pickup.
+ bool enabled_; //!< Whether the Pickupable is enabled or not.
+ PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable.
+ std::list<Identifier*> targets_; //!< The possible targets of this Pickupable.
+
+ bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed.
+
// For implementing the Rewardable interface:
public:
virtual bool reward(PlayerInfo* player); //!< Method to transcribe a Pickupable as a Rewardable to the player.
Modified: code/branches/presentation3/src/orxonox/items/Engine.cc
===================================================================
--- code/branches/presentation3/src/orxonox/items/Engine.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/items/Engine.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -63,7 +63,6 @@
this->boostBlur_ = 0;
- this->setCarrierName("Engine");
this->speedAdd_ = 0.0;
this->speedMultiply_ = 1.0;
Modified: code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc
===================================================================
--- code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -104,7 +104,7 @@
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.
+ //! We iterate through all parameters and compare 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 a parameter present in one of the identifiers is not found in the other, once again, something is very wrong.
Modified: code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc 2010-07-28 18:29:32 UTC (rev 7161)
+++ code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc 2010-08-08 18:53:52 UTC (rev 7162)
@@ -82,8 +82,6 @@
else
this->weaponSystem_ = 0;
- this->setCarrierName("Pawn");
-
this->setRadarObjectColour(ColourValue::Red);
this->setRadarObjectShape(RadarViewable::Dot);
More information about the Orxonox-commit
mailing list