[Orxonox-commit 3694] r8375 - code/branches/pickup/src/modules/pickup/items
ssgier at orxonox.net
ssgier at orxonox.net
Mon May 2 13:22:16 CEST 2011
Author: ssgier
Date: 2011-05-02 13:22:15 +0200 (Mon, 02 May 2011)
New Revision: 8375
Added:
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
Log:
added source files for ShrinkPickup
Added: code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
===================================================================
--- code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc (rev 0)
+++ code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc 2011-05-02 11:22:15 UTC (rev 8375)
@@ -0,0 +1,91 @@
+#include "ShrinkPickup.h"
+
+#include <sstream>
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+#include "pickup/PickupIdentifier.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+ CreateFactory(ShrinkPickup);
+
+ ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator)
+ {
+ RegisterObject(ShrinkPickup);
+
+ this->initialize();
+ }
+
+ ShrinkPickup::~ShrinkPickup()
+ {
+
+ }
+
+ void ShrinkPickup::initialize(void)
+ {
+ this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+ }
+
+ void ShrinkPickup::changedUsed(void)
+ {
+ SUPER(ShrinkPickup, changedUsed);
+
+ if(this->isUsed())
+ {
+ this->pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ this->Pickupable::destroy();
+
+ COUT(0) << "shrinking..." << endl;
+ std::set<WorldEntity*> set = this->pawn->getAttachedObjects();
+ for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++)
+ {
+ (*it)->setScale((*it)->getScale() / 5.0);
+ }
+ durationTimer.setTimer(10, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));
+ }
+ else
+ {
+ this->Pickupable::destroy();
+ }
+ }
+
+ void ShrinkPickup::terminate(void)
+ {
+ std::set<WorldEntity*> set = this->pawn->getAttachedObjects();
+ for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++)
+ {
+ (*it)->setScale((*it)->getScale() * 5.0);
+ }
+ setUsed(false);
+ }
+
+ Pawn* ShrinkPickup::carrierToPawnHelper(void)
+ {
+ PickupCarrier* carrier = this->getCarrier();
+ Pawn* pawn = dynamic_cast<Pawn*>(carrier);
+
+ if(pawn == NULL)
+ {
+ COUT(1) << "Invalid PickupCarrier in ShrinkPickup." << std::endl;
+ }
+
+ return pawn;
+ }
+
+ /**
+ @brief
+ Creates a duplicate of the input OrxonoxClass.
+ @param item
+ A pointer to the Orxonox class.
+ */
+ void ShrinkPickup::clone(OrxonoxClass*& item)
+ {
+ if(item == NULL)
+ item = new ShrinkPickup(this);
+
+ SUPER(ShrinkPickup, clone, item);
+ }
+}
Added: code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
===================================================================
--- code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h (rev 0)
+++ code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h 2011-05-02 11:22:15 UTC (rev 8375)
@@ -0,0 +1,38 @@
+#ifndef _ShrinkPickup_H__
+#define _ShrinkPickup_H__
+
+#include "pickup/PickupPrereqs.h"
+
+#include <string>
+
+#include "pickup/Pickup.h"
+#include "tools/interfaces/Tickable.h"
+
+namespace orxonox {
+
+ /**
+ @author
+ Sandro Sgier
+
+ @ingroup PickupItems
+ */
+ class _PickupExport ShrinkPickup : public Pickup, public Tickable
+ {
+ public:
+ ShrinkPickup(BaseObject* creator); //!< Constructor.
+ virtual ~ShrinkPickup(); //!< Destructor.
+ virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
+ virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
+
+ private:
+ void initialize(void);
+ Pawn* carrierToPawnHelper(void);
+ Pawn* pawn;
+ Timer durationTimer;
+ void terminate(void);
+
+
+ };
+}
+
+#endif
More information about the Orxonox-commit
mailing list