Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Just changed some small stuff…

File size: 4.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 *      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#include "core/Event.h"
35
36#include "orxonox/objects/worldentities/ControllableEntity.h"
37#include "orxonox/objects/worldentities/triggers/Trigger.h"
38#include "QuestEffect.h"
39
40namespace orxonox {
41
42    CreateFactory(QuestEffectBeacon);
43
44    QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)
45    {
46        RegisterObject(QuestEffectBeacon);
47       
48        this->status_ = QuestEffectBeaconStatus::active;
49        this->times_ = -1;
50        this->trigger_ = NULL;
51    }
52
53    QuestEffectBeacon::~QuestEffectBeacon()
54    {
55    }
56   
57    void QuestEffectBeacon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(QuestEffectBeacon, XMLPort, xmlelement, mode);
60
61        XMLPortParam(QuestEffectBeacon, "times", setTimes, getTimes, xmlelement, mode);
62        XMLPortObject(QuestEffectBeacon, QuestEffect, "", addEffect, getEffect, xmlelement, mode);
63        XMLPortObject(QuestEffectBeacon, Trigger, "", addTrigger, getTrigger, xmlelement, mode);
64    }
65   
66    void processEvent(Event& event)
67    {
68        //TDO. Resolve pseudo code.
69        //if(isControllableEntity(event.originator_))
70        //{
71        //    SetEvent(BaseObject, "activity", execute, event);
72        //}
73    }
74   
75    bool QuestEffectBeacon::execute(ControllableEntity* player)
76    {
77        if(!(this->isActive()))
78        {
79            return false;
80        }
81        if(player == NULL)
82        {
83            return false;
84        }
85       
86        bool check = QuestEffect::invokeEffects(player, this->effects_);
87        if(check)
88        {
89            this->decrementTimes();
90            return true;
91        }
92       
93        return false;
94    }
95   
96    bool QuestEffectBeacon::isActive(void)
97    {
98        return this->status_ == QuestEffectBeaconStatus::active;
99    }
100   
101    bool QuestEffectBeacon::decrementTimes(void)
102    {
103        if(!(this->isActive()))
104        {
105            return false;
106        }
107        if(this->getTimes() == -1)
108        {
109            return true;
110        }
111       
112        this->times_ = this->times_ - 1;
113        if(this->getTimes() == 0)
114        {
115            this->status_ = QuestEffectBeaconStatus::inactive;
116        }
117       
118        return true;
119    }
120   
121   
122    bool QuestEffectBeacon::setTimes(const int & n)
123    {
124        if(n < -1)
125        {
126            return false;
127        }
128       
129        this->times_ = n;
130        return true;
131    }
132   
133   
134    /**
135    @brief
136
137    */
138    bool QuestEffectBeacon::addEffect(QuestEffect* effect)
139    {
140        if(effect == NULL)
141        {
142            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
143            return false;
144        }
145
146        this->effects_.push_back(effect);
147
148        COUT(3) << "A QuestEffect was added to a QuestEffectBeacon." << std::endl;
149        return true;
150    }
151   
152    bool QuestEffectBeacon::addTrigger(Trigger* trigger)
153    {
154        if(this->trigger_ != NULL)
155        {
156           COUT(2) << "A Trigger was trying to be added, where one was already set." << std::endl;
157           return false;
158        }
159        if(trigger == NULL)
160        {
161            COUT(2) << "A NULL-Trigger was trying to be added." << std::endl;
162            return false;
163        }
164       
165        COUT(3) << "A Trigger was added to a QuestEffectBeacon." << std::endl;
166        this->trigger_ = trigger;
167        return true;
168    }
169   
170     /**
171    @brief
172
173    */
174    const QuestEffect* QuestEffectBeacon::getEffect(unsigned int index) const
175    {
176        int i = index;
177        for (std::list<QuestEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect)
178        {
179            if(i == 0)
180            {
181               return *effect;
182            }
183            i--;
184        }
185        return NULL;
186    }
187
188    const Trigger* QuestEffectBeacon::getTrigger(unsigned int index) const
189    {
190        if(index == 0)
191        {
192            return this->trigger_;
193        }
194       
195        return NULL;
196    }
197
198}
Note: See TracBrowser for help on using the repository browser.