Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/consolecommands2/src/orxonox/pickup/DroppedItem.cc @ 6989

Last change on this file since 6989 was 6417, checked in by rgrieder, 15 years ago

Merged presentation2 branch back to trunk.
Major new features:

  • Actual GUI with settings, etc.
  • Improved space ship steering (human interaction)
  • Rocket fire and more particle effects
  • Advanced sound framework
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Daniel 'Huty' Haggenmueller
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "DroppedItem.h"
30
31#include "util/Math.h"
32#include "core/CoreIncludes.h"
33#include "core/Executor.h"
34#include "BaseItem.h"
35#include "graphics/Billboard.h"
36#include "graphics/Model.h"
37#include "worldentities/pawns/Pawn.h"
38
39namespace orxonox
40{
41    CreateFactory(DroppedItem);
42
43    DroppedItem::DroppedItem(BaseObject* creator) : StaticEntity(creator)
44    {
45        RegisterObject(DroppedItem);
46
47        this->triggerDistance_ = 20.0f;
48        this->timeToLive_ = 0;
49        this->item_ = 0;
50    }
51    DroppedItem::~DroppedItem()
52    {
53    }
54    void DroppedItem::tick(float dt)
55    {
56        if (this->item_)
57        {
58            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
59            {
60                Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
61                if (distance.length() < this->triggerDistance_)
62                    this->trigger(*it);
63            }
64        }
65    }
66    void DroppedItem::trigger(Pawn* pawn)
67    {
68        if (this->item_->pickedUp(pawn))
69        {
70            COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl;
71            this->destroy();
72        }
73    }
74    void DroppedItem::createTimer()
75    {
76        if (this->timeToLive_ > 0)
77        {
78            this->timer_.setTimer(this->timeToLive_, false, createExecutor(createFunctor(&DroppedItem::timerCallback, this)), false);
79        }
80    }
81    void DroppedItem::timerCallback()
82    {
83        if (this->item_)
84        {
85            COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << '\'' << std::endl;
86            this->item_->destroy();
87        }
88
89        this->destroy();
90    }
91
92    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive)
93    {
94        DroppedItem* drop = new DroppedItem(item);
95        Model* model = new Model(item);
96        Billboard* billboard = new Billboard(item);
97
98        model->setMeshSource("sphere.mesh");
99        model->setScale(3.0f);
100
101        billboard->setMaterial("Examples/Flare");
102        billboard->setColour(flareColour);
103        billboard->setScale(0.5f);
104
105        drop->setPosition(position);
106        drop->attach(model);
107        drop->attach(billboard);
108
109        drop->setItem(item);
110
111        drop->setTimeToLive(timeToLive);
112        drop->createTimer();
113
114        COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << ',' << position.y << ',' << position.z << ")." << std::endl;
115
116        return drop;
117    }
118    DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)
119    {
120        Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);
121        return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);
122    }
123}
Note: See TracBrowser for help on using the repository browser.