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 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | CreateFactory(DroppedItem); //TODO: This isn't needed, is it? |
---|
42 | |
---|
43 | /** |
---|
44 | @brief |
---|
45 | Constructor. Registers object and sets default values. |
---|
46 | */ |
---|
47 | DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator) |
---|
48 | { |
---|
49 | RegisterObject(DroppedItem); |
---|
50 | } |
---|
51 | |
---|
52 | DroppedItem::DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : PickupSpawner(creator, item, triggerDistance, respawnTime, maxSpawnedItems) |
---|
53 | { |
---|
54 | RegisterObject(DroppedItem); |
---|
55 | this->item_ = item; |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | @brief |
---|
60 | Default destructor. |
---|
61 | */ |
---|
62 | DroppedItem::~DroppedItem() |
---|
63 | { |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | BaseItem* DroppedItem::getItem(void) |
---|
68 | { |
---|
69 | return this->item_; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | @brief |
---|
74 | |
---|
75 | */ |
---|
76 | //TODO: Comment. |
---|
77 | //Each pickup should have a XML template where the Model and Billboard, and so on, is specified. |
---|
78 | /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive) |
---|
79 | { |
---|
80 | //TODO: triggerDistance? |
---|
81 | float triggerDistance = 20.0; |
---|
82 | DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1); |
---|
83 | |
---|
84 | //TODO: Do this somehwere else? |
---|
85 | Model* model = new Model(item); |
---|
86 | Billboard* billboard = new Billboard(item); |
---|
87 | |
---|
88 | model->setMeshSource("sphere.mesh"); |
---|
89 | model->setScale(3.0f); |
---|
90 | |
---|
91 | billboard->setMaterial("Examples/Flare"); |
---|
92 | billboard->setColour(flareColour); |
---|
93 | billboard->setScale(0.5f); |
---|
94 | |
---|
95 | droppedItem->setPosition(position); |
---|
96 | droppedItem->attach(model); |
---|
97 | droppedItem->attach(billboard); |
---|
98 | |
---|
99 | COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl; |
---|
100 | |
---|
101 | return droppedItem; |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | @brief |
---|
106 | |
---|
107 | */ |
---|
108 | //TODO: See one function above. |
---|
109 | DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive) |
---|
110 | { |
---|
111 | Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f); |
---|
112 | return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive); |
---|
113 | } |
---|
114 | } |
---|