Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Playing with Triggers.

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/EventIncludes.h"
35
36#include "orxonox/objects/worldentities/ControllableEntity.h"
37#include "orxonox/objects/worldentities/triggers/PlayerTrigger.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 QuestEffectBeacon::processEvent(Event& event)
67    {
68        SetSubclassEvent(QuestEffectBeacon, "execute", execute, event, PlayerTrigger);
69    }
70   
71    bool QuestEffectBeacon::execute(ControllableEntity* player)
72    {
73        if(!(this->isActive()))
74        {
75            return false;
76        }
77        if(player == NULL)
78        {
79            return false;
80        }
81       
82        bool check = QuestEffect::invokeEffects(player, this->effects_);
83        if(check)
84        {
85            this->decrementTimes();
86            return true;
87        }
88       
89        return false;
90    }
91   
92    bool QuestEffectBeacon::isActive(void)
93    {
94        return this->status_ == QuestEffectBeaconStatus::active;
95    }
96   
97    bool QuestEffectBeacon::decrementTimes(void)
98    {
99        if(!(this->isActive()))
100        {
101            return false;
102        }
103        if(this->getTimes() == -1)
104        {
105            return true;
106        }
107       
108        this->times_ = this->times_ - 1;
109        if(this->getTimes() == 0)
110        {
111            this->status_ = QuestEffectBeaconStatus::inactive;
112        }
113       
114        return true;
115    }
116   
117   
118    bool QuestEffectBeacon::setTimes(const int & n)
119    {
120        if(n < -1)
121        {
122            return false;
123        }
124       
125        this->times_ = n;
126        return true;
127    }
128   
129   
130    /**
131    @brief
132
133    */
134    bool QuestEffectBeacon::addEffect(QuestEffect* effect)
135    {
136        if(effect == NULL)
137        {
138            COUT(2) << "A NULL-QuestEffect was trying to be added" << std::endl;
139            return false;
140        }
141
142        this->effects_.push_back(effect);
143
144        COUT(3) << "A QuestEffect was added to a QuestEffectBeacon." << std::endl;
145        return true;
146    }
147   
148    bool QuestEffectBeacon::addTrigger(PlayerTrigger* trigger)
149    {
150        if(this->trigger_ != NULL)
151        {
152           COUT(2) << "A Trigger was trying to be added, where one was already set." << std::endl;
153           return false;
154        }
155        if(trigger == NULL)
156        {
157            COUT(2) << "A NULL-Trigger was trying to be added." << std::endl;
158            return false;
159        }
160       
161        COUT(3) << "A Trigger was added to a QuestEffectBeacon." << std::endl;
162        this->trigger_ = trigger;
163        return true;
164    }
165   
166     /**
167    @brief
168
169    */
170    const QuestEffect* QuestEffectBeacon::getEffect(unsigned int index) const
171    {
172        int i = index;
173        for (std::list<QuestEffect*>::const_iterator effect = this->effects_.begin(); effect != this->effects_.end(); ++effect)
174        {
175            if(i == 0)
176            {
177               return *effect;
178            }
179            i--;
180        }
181        return NULL;
182    }
183
184    const Trigger* QuestEffectBeacon::getTrigger(unsigned int index) const
185    {
186        if(index == 0)
187        {
188            return this->trigger_;
189        }
190       
191        return NULL;
192    }
193
194}
Note: See TracBrowser for help on using the repository browser.