[Orxonox-commit 1703] r6421 - in code/branches/pickup3/src: modules/pickup modules/weapons/projectiles orxonox/interfaces
dafrick at orxonox.net
dafrick at orxonox.net
Sat Dec 26 10:06:55 CET 2009
Author: dafrick
Date: 2009-12-26 10:06:54 +0100 (Sat, 26 Dec 2009)
New Revision: 6421
Modified:
code/branches/pickup3/src/modules/pickup/DroppedItem.cc
code/branches/pickup3/src/modules/pickup/DroppedItem.h
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
code/branches/pickup3/src/modules/pickup/PickupCollection.h
code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
code/branches/pickup3/src/modules/pickup/PickupSpawner.h
code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc
code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
Log:
Some Documenting and bug fixes.
Modified: code/branches/pickup3/src/modules/pickup/DroppedItem.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.cc 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.cc 2009-12-26 09:06:54 UTC (rev 6421)
@@ -28,31 +28,33 @@
#include "DroppedItem.h"
-#include "util/Math.h"
#include "core/CoreIncludes.h"
-#include "core/Executor.h"
-#include "BaseItem.h"
-#include "graphics/Billboard.h"
+#include "interfaces/Pickupable.h"
#include "graphics/Model.h"
-#include "worldentities/pawns/Pawn.h"
namespace orxonox
{
- CreateFactory(DroppedItem); //TODO: This isn't needed, is it?
-
/**
@brief
Constructor. Registers object and sets default values.
*/
DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator)
{
- RegisterObject(DroppedItem);
+ this->initialize();
}
- DroppedItem::DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : PickupSpawner(creator, item, triggerDistance, respawnTime, maxSpawnedItems)
+ 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->item_ = item;
+
+ this->gotPickedUp_ = false;
}
/**
@@ -61,54 +63,59 @@
*/
DroppedItem::~DroppedItem()
{
-
+ if(this->gotPickedUp_ && this->pickup_ != NULL)
+ {
+ this->pickup_ = NULL;
+ }
}
- BaseItem* DroppedItem::getItem(void)
+ Pickupable* DroppedItem::getPickup(void)
{
- return this->item_;
+ return this->pickup_;
}
-
- /**
- @brief
-
- */
- //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)
+
+ void DroppedItem::createDrop(const Vector3& position)
{
- //TODO: triggerDistance?
- float triggerDistance = 20.0;
- DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1);
+ this->setPosition(position);
- //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: Make this work.
+ //const Model& model = PickupManager::getModel(item->getPickupIdentifier());
+ //this->attach(model);
}
- /**
- @brief
+//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);
- }
+// 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);
+// }
}
Modified: code/branches/pickup3/src/modules/pickup/DroppedItem.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/DroppedItem.h 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/DroppedItem.h 2009-12-26 09:06:54 UTC (rev 6421)
@@ -34,7 +34,7 @@
#ifndef _DroppedItem_H__
#define _DroppedItem_H__
-#include "OrxonoxPrereqs.h"
+#include "pickup/PickupPrereqs.h"
#include "PickupSpawner.h"
@@ -44,19 +44,18 @@
{
public:
DroppedItem(BaseObject* creator);
- DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems);
+ DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance);
virtual ~DroppedItem();
- static DroppedItem* createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
- static DroppedItem* createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);
-
protected:
- virtual BaseItem* getItem(void);
-
+ virtual Pickupable* getPickup(void);
+
private:
+ void initialize(void);
+ void createDrop(const Vector3& position);
+
+ bool gotPickedUp_;
- BaseItem* item_; //!< The dropped item.
-
};
}
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.cc 2009-12-26 09:06:54 UTC (rev 6421)
@@ -57,7 +57,7 @@
PickupCollection::~PickupCollection()
{
//! Destroy all Pickupables constructing this PickupCollection.
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
delete *it;
}
@@ -88,7 +88,7 @@
if(pickup == NULL)
return false;
- this->pickups_.insert(pickup);
+ this->pickups_.push_back(pickup);
return true;
}
@@ -100,7 +100,7 @@
@return
Returns a pointer to the Pickupable at the index given by index.
*/
- Pickupable* PickupCollection::getPickupable(unsigned int index)
+ const Pickupable* PickupCollection::getPickupable(unsigned int index)
{
return this->pickups_[index]; //TODO. Does this work?
}
@@ -111,7 +111,7 @@
SUPER(PickupCollection, changedUsed);
//! Change used for all Pickupables this PickupCollection consists of.
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
(*it)->changedUsed();
}
@@ -131,7 +131,7 @@
bool success = true;
//! Set all Pickupables to used.
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
if(!(*it)->use())
{
@@ -157,7 +157,7 @@
bool success = true;
//! Set all Pickupables to unused.
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
if(!(*it)->unuse())
{
@@ -186,7 +186,7 @@
COUT(2) << "Pickup wanted to get picked up by a new carrier, but it already has a carrier." << std::endl;
return false;
}
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
(*it)->setOwner(carrier);
}
@@ -218,7 +218,7 @@
BaseObject* newObject = collectionTemplate->getBaseclassIdentifier()->fabricate(this);
PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject);
- for(std::list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
+ for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
{
Pickupable* newPickup = (*it)->clone();
newCollection->pickups_.push_back(newPickup);
Modified: code/branches/pickup3/src/modules/pickup/PickupCollection.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupCollection.h 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/PickupCollection.h 2009-12-26 09:06:54 UTC (rev 6421)
@@ -68,11 +68,11 @@
virtual Pickupable* clone(void);
bool addPickupable(Pickupable* pickup);
- Pickupable* getPickupable(unsigned int index);
+ const Pickupable* getPickupable(unsigned int index);
private:
- std::list<Pickupable*> pickups_;
+ std::vector<Pickupable*> pickups_;
};
Modified: code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupPrereqs.h 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/PickupPrereqs.h 2009-12-26 09:06:54 UTC (rev 6421)
@@ -65,6 +65,7 @@
namespace orxonox
{
+ class DroppedItem;
class PickupCollection;
class PickupSpawner;
Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.cc 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.cc 2009-12-26 09:06:54 UTC (rev 6421)
@@ -52,7 +52,7 @@
/**
@brief
- Constructor. Registers the PickupSpawner.
+ Constructor. Creates a blank PickupSpawner.
@param creator
Pointer to the object which created this item.
*/
@@ -61,6 +61,20 @@
this->initialize();
}
+ /**
+ @brief
+ Constructor, Creates a fully functional PickupSpawner.
+ @param creator
+ The creator of this PickupSpawner.
+ @param pickup
+ The Pickupable to be spawned by this PickupSpawner.
+ @param triggerDistance
+ The distance at which the PickupSpawner will trigger.
+ @param respawnTime
+ The minimum time between two spawns.
+ @param maySpawnedItems
+ The maximum number of items spawned by this PickupSpawner.
+ */
PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)
{
this->initialize();
@@ -72,6 +86,10 @@
this->setMaxSpawnedItems(maxSpawnedItems);
}
+ /**
+ @brief
+ Registers the object and sets some default values.
+ */
void PickupSpawner::initialize(void)
{
RegisterObject(PickupSpawner);
@@ -91,7 +109,8 @@
*/
PickupSpawner::~PickupSpawner()
{
-
+ if(this->pickup_ != NULL)
+ delete this->pickup_;
}
/**
@@ -106,7 +125,7 @@
{
SUPER(PickupSpawner, XMLPort, xmlelement, mode);
- XMLPortObject(PickupSpawner, Pickupable, "pickup", addPickupable, getPickupable, xmlelement, mode);
+ XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode);
XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode);
XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode);
@@ -127,12 +146,18 @@
// & load the GUI itself too, along with some empty windows
// = even less delays
-// GUIManager::showGUI("PickupInventory");
-// GUIManager::hideGUI("PickupInventory");
+// GUIManager::getInstance().showGUI("PickupInventory");
+// GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
// PickupInventory::getSingleton();
}
- void PickupSpawner::addPickupable(Pickupable* pickup)
+ /**
+ @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)
{
@@ -148,7 +173,13 @@
this->pickup_ = pickup;
}
- Pickupable* PickupSpawner::getPickupable(void)
+ /**
+ @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_;
}
@@ -165,6 +196,12 @@
// (*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;
@@ -242,6 +279,13 @@
}
}
+ /**
+ @brief
+ 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)
{
if(this->spawnsRemaining_ != INF)
@@ -250,7 +294,7 @@
}
if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0)
{
- //TODO: Nicer?
+ //TODO: Nicer? Does this even work?
this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
this->setActive(false);
Modified: code/branches/pickup3/src/modules/pickup/PickupSpawner.h
===================================================================
--- code/branches/pickup3/src/modules/pickup/PickupSpawner.h 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/pickup/PickupSpawner.h 2009-12-26 09:06:54 UTC (rev 6421)
@@ -56,7 +56,7 @@
PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems);
virtual ~PickupSpawner();
- virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).
+ //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 tick(float dt);
@@ -86,7 +86,10 @@
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.
+ */
inline int getMaxSpawnedItems(void)
{ return this->maxSpawnedItems_; }
void setMaxSpawnedItems(int items);
@@ -94,10 +97,12 @@
protected:
virtual Pickupable* getPickup(void);
- void addPickupable(Pickupable* pickup);
- Pickupable* getPickupable(void);
+ void setPickupable(Pickupable* pickup);
+ const Pickupable* getPickupable(void);
void decrementSpawnsRemaining(void);
+
+ Pickupable* pickup_; //!< The pickup to be spawned.
private:
void initialize(void);
@@ -105,9 +110,6 @@
void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.
void respawnTimerCallback(); //!< Method called when the timer runs out.
-
- Pickupable* pickup_;
-
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.
Modified: code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc
===================================================================
--- code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc 2009-12-26 09:06:54 UTC (rev 6421)
@@ -200,8 +200,9 @@
}
float dmg = this->damage_;
- if (this->owner_)
- dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
+ //TODO: This souldn't be necessary here.
+ //if (this->owner_)
+ // dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
Pawn* victim = orxonox_cast<Pawn*>(otherObject);
if (victim)
Modified: code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
===================================================================
--- code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2009-12-25 22:08:24 UTC (rev 6420)
+++ code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h 2009-12-26 09:06:54 UTC (rev 6421)
@@ -47,7 +47,7 @@
public:
PickupCarrier();
- virtual ~PickupCarrier();
+ virtual ~PickupCarrier() {}
private:
More information about the Orxonox-commit
mailing list