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 | * Damian 'Mozork' Frick |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "core/CoreIncludes.h" |
---|
30 | |
---|
31 | #include "AddReward.h" |
---|
32 | #include "Rewardable.h" |
---|
33 | |
---|
34 | namespace orxonox { |
---|
35 | |
---|
36 | CreateFactory(AddReward); |
---|
37 | |
---|
38 | AddReward::AddReward(BaseObject* creator) : QuestEffect(creator) |
---|
39 | { |
---|
40 | RegisterObject(AddReward); |
---|
41 | |
---|
42 | this->initialize(); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | @brief |
---|
47 | Destructor. |
---|
48 | */ |
---|
49 | AddReward::~AddReward() |
---|
50 | { |
---|
51 | } |
---|
52 | |
---|
53 | void AddReward::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
54 | { |
---|
55 | SUPER(AddReward, XMLPort, xmlelement, mode); |
---|
56 | |
---|
57 | XMLPortObject(AddReward, Rewardable, "", addRewardable, getRewardables, xmlelement, mode); |
---|
58 | |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | @brief |
---|
63 | Initializes the object. Needs to be called first by every constructor of this class. |
---|
64 | */ |
---|
65 | void AddReward::initialize(void) |
---|
66 | { |
---|
67 | RegisterObject(AddReward); |
---|
68 | } |
---|
69 | |
---|
70 | const Rewardable* AddReward::getRewardables(unsigned int index) const |
---|
71 | { |
---|
72 | int i = index; |
---|
73 | for (std::list<Rewardable*>::const_iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward) |
---|
74 | { |
---|
75 | if(i == 0) |
---|
76 | { |
---|
77 | return *reward; |
---|
78 | } |
---|
79 | i--; |
---|
80 | } |
---|
81 | return NULL; |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | @brief |
---|
86 | Invokes the effect. |
---|
87 | @param player |
---|
88 | The player. |
---|
89 | @return |
---|
90 | Returns true if the effect was invoked successfully. |
---|
91 | */ |
---|
92 | bool AddReward::invoke(Player* player) |
---|
93 | { |
---|
94 | bool check = true; |
---|
95 | for ( std::list<Rewardable*>::iterator reward = this->rewards_.begin(); reward != this->rewards_.end(); ++reward ) |
---|
96 | { |
---|
97 | check = check && (*reward)->reward(player); |
---|
98 | } |
---|
99 | |
---|
100 | return check; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|