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 | /** |
---|
30 | @file |
---|
31 | @brief Implementation of HealthUsable. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "HealthUsable.h" |
---|
35 | |
---|
36 | #include "util/Math.h" |
---|
37 | #include "core/CoreIncludes.h" |
---|
38 | #include "core/XMLPort.h" |
---|
39 | #include "pickup/DroppedItem.h" |
---|
40 | #include "worldentities/pawns/Pawn.h" |
---|
41 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | CreateFactory(HealthUsable); |
---|
45 | |
---|
46 | /** |
---|
47 | @brief Constructor |
---|
48 | @param creator Object that created this item. |
---|
49 | */ |
---|
50 | HealthUsable::HealthUsable(BaseObject* creator) : UsableItem(creator) |
---|
51 | { |
---|
52 | RegisterObject(HealthUsable); |
---|
53 | |
---|
54 | this->recoveredHealth_ = 0; |
---|
55 | } |
---|
56 | |
---|
57 | //! Deconstructor |
---|
58 | HealthUsable::~HealthUsable() |
---|
59 | { |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | @brief XMLPort for Jump. |
---|
64 | @param xmlelement Element of the XML-file. |
---|
65 | @param mode XMLPort mode to use. |
---|
66 | */ |
---|
67 | void HealthUsable::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
68 | { |
---|
69 | SUPER(HealthUsable, XMLPort, xmlelement, mode); |
---|
70 | |
---|
71 | XMLPortParam(HealthUsable, "recoveredHealth", setRecoveredHealth, getRecoveredHealth, xmlelement, mode); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | @brief Called when the item is used, makes the user "jump". |
---|
76 | @param pawn Pawn which used te item. |
---|
77 | */ |
---|
78 | //TODO: Jump? Nope! => Comment. |
---|
79 | //Should be destroyed anyways. |
---|
80 | void HealthUsable::used(Pawn* pawn) |
---|
81 | { |
---|
82 | float maxH = pawn->getMaxHealth(); |
---|
83 | float curH = pawn->getHealth(); |
---|
84 | |
---|
85 | if (curH < maxH) { |
---|
86 | pawn->addHealth(this->recoveredHealth_); |
---|
87 | |
---|
88 | this->removeFrom(pawn); |
---|
89 | delete this; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | @brief Called when the item is picked up. |
---|
95 | @param pawn Pawn which picked up the item. |
---|
96 | */ |
---|
97 | bool HealthUsable::pickedUp(Pawn* pawn) |
---|
98 | { |
---|
99 | return this->addTo(pawn); |
---|
100 | } |
---|
101 | |
---|
102 | /** |
---|
103 | @brief Called when the item is dropped, creates a DroppedItem behind the pawn. |
---|
104 | @param pawn Pawn which dropped the item. |
---|
105 | */ |
---|
106 | bool HealthUsable::dropped(Pawn* pawn) |
---|
107 | { |
---|
108 | DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 30.0f); |
---|
109 | return this->removeFrom(pawn); |
---|
110 | } |
---|
111 | } |
---|