Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/DroppedItem.cc @ 2972

Last change on this file since 2972 was 2972, checked in by danielh, 15 years ago

Update

  • Minor changes in BaseItem
  • Updated to NotificationQueue from trunk (compile error with old)
  • Added PickupInventory for GUI handling
  • Added basic support for toLua++ methods
  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1#include "DroppedItem.h"
2
3#include "BaseItem.h"
4#include "objects/worldentities/pawns/Pawn.h"
5#include "objects/worldentities/Model.h"
6#include "objects/worldentities/Billboard.h"
7
8#include "core/CoreIncludes.h"
9#include "core/Core.h"
10
11namespace orxonox
12{
13    CreateFactory(DroppedItem);
14
15    DroppedItem::DroppedItem(BaseObject* creator) : StaticEntity(creator)
16    {
17        RegisterObject(DroppedItem);
18
19        this->triggerDistance_ = 20.0f;
20        this->timeToLive_ = 0;
21        this->item_ = 0;
22    }
23    DroppedItem::~DroppedItem()
24    {
25    }
26    void DroppedItem::tick(float dt)
27    {
28        if (this->item_)
29        {
30            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); it++)
31            {
32                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
33                if (distance.length() < this->triggerDistance_)
34                    this->trigger(*it);
35            }
36        }
37    }
38    void DroppedItem::trigger(Pawn* pawn)
39    {
40        if (this->item_->pickedUp(pawn))
41        {
42            COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl;
43            delete this;
44        }
45    }
46    void DroppedItem::createTimer()
47    {
48        if (this->timeToLive_ > 0)
49        {
50            ExecutorMember<DroppedItem>* exec = createExecutor(createFunctor(&DroppedItem::timerCallback));
51            this->timer_.setTimer(this->timeToLive_, false, this, exec, false);
52        }
53    }
54    void DroppedItem::timerCallback()
55    {
56        if (this->item_)
57        {
58            COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << "'" << std::endl;
59            delete this->item_;
60        }
61
62        delete this;
63    }
64
65    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
66    {
67        DroppedItem* drop = new DroppedItem(item);
68        Model* model = new Model(item);
69        Billboard* billboard = new Billboard(item);
70       
71        model->setMeshSource("sphere.mesh");
72        model->setScale(3.0f);
73
74        billboard->setMaterial("Examples/Flare");
75        billboard->setColour(flareColour);
76        billboard->setScale(0.5f);
77
78        drop->setPosition(position);
79        drop->attach(model);
80        drop->attach(billboard);
81
82        drop->setItem(item);
83
84        drop->setTimeToLive(timeToLive);
85        drop->createTimer();
86
87        COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl;
88
89        return drop;
90    }
91    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
92    {
93        Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
94        return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
95    }
96}
Note: See TracBrowser for help on using the repository browser.