Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem2/src/orxonox/objects/quest/QuestEffectBeacon.cc @ 2146

Last change on this file since 2146 was 2146, checked in by dafrick, 15 years ago

Started implementation of QuestEffectBeacon.
Done some documentation of QuestItem and subclasses.

File size: 3.7 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 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "QuestEffectBeacon.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34
35#include "orxonox/objects/worldentities/ControllableEntity.h"
36#include "QuestEffect.h"
37
38namespace orxonox {
39
40    CreateFactory(QuestEffectBeacon);
41
42    QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)
43    {
44        RegisterObject(QuestEffectBeacon);
45       
46        this->status_ = QuestEffectBeaconStatus::active;
47        this->times_ = -1;
48    }
49
50
51    QuestEffectBeacon::~QuestEffectBeacon()
52    {
53    }
54   
55    void QuestEffectBeacon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
56    {
57        SUPER(QuestEffectBeacon, XMLPort, xmlelement, mode);
58
59        XMLPortParam(QuestEffectBeacon, "times", setTimes, getTimes, xmlelement, mode);
60        XMLPortObject(QuestEffectBeacon, QuestEffect, "", addEffect, getEffects, xmlelement, mode);
61    }
62   
63    bool QuestEffectBeacon::execute(ControllableEntity* player)
64    {
65        if(!(this->isActive()))
66        {
67            return false;
68        }
69        if(player == NULL)
70        {
71            return false;
72        }
73       
74        bool check = QuestEffect::invokeEffects(player, this->effects_);
75        if(check)
76        {
77            this->decrementTimes();
78            return true;
79        }
80       
81        return false;
82    }
83   
84    bool QuestEffectBeacon::isActive(void)
85    {
86        return this->status_ == QuestEffectBeaconStatus::active;
87    }
88   
89    bool QuestEffectBeacon::decrementTimes(void)
90    {
91        if(!(this->isActive()))
92        {
93            return false;
94        }
95        if(this->times_ == -1)
96        {
97            return true;
98        }
99       
100        this->times_ = this->times_ - 1;
101        if(this->times_ == 0)
102        {
103            this->status_ = QuestEffectBeaconStatus::inactive;
104        }
105       
106        return true;
107    }
108   
109   
110    bool QuestEffectBeacon::setTimes(const int & n)
111    {
112        if(n < -1)
113        {
114            return false;
115        }
116       
117        this->times_ = n;
118        return true;
119    }
120   
121   
122    /**
123    @brief
124
125    */
126    bool QuestEffectBeacon::addEffect(QuestEffect* effect)
127    {
128        if(effect == NULL)
129        {
130            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
131            return false;
132        }
133
134        this->effects_.push_back(effect);
135
136        COUT(3) << "An effect was added to a QuestEffectBeacon." << std::endl;
137        return true;
138    }
139   
140     /**
141    @brief
142
143    */
144    const QuestEffect* QuestEffectBeacon::getEffects(unsigned int index) const
145    {
146        int i = index;
147        for (std::list<QuestEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect)
148        {
149            if(i == 0)
150            {
151               return *effect;
152            }
153            i--;
154        }
155        return NULL;
156    }
157
158
159}
Note: See TracBrowser for help on using the repository browser.