Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutoriallevel/src/modules/objects/triggers/EventMultiTrigger.cc @ 8324

Last change on this file since 8324 was 7601, checked in by dafrick, 14 years ago

Adding all classes in modules/objects to Objects module (in doxygen).
Created TriggerBase which is the base class of Trigger and MultiTrigger and now provides the shared functionality and data.
Updated some of the documentation in MultiTrigger and Script.

  • Property svn:eol-style set to native
File size: 3.6 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/**
30    @file EventMultiTrigger.cc
31    @brief Implementation of the EventMultiTrigger class.
32    @ingroup MultiTrigger
33*/
34
35#include "EventMultiTrigger.h"
36
37#include "core/CoreIncludes.h"
38#include "core/EventIncludes.h"
39#include "core/XMLPort.h"
40#include "MultiTriggerContainer.h"
41
42namespace orxonox
43{
44
45    CreateFactory(EventMultiTrigger);
46
47    /**
48    @brief
49        Constructor. Registers the object.
50    */
51    EventMultiTrigger::EventMultiTrigger(BaseObject* creator) : MultiTrigger(creator)
52    {
53        RegisterObject(EventMultiTrigger);
54    }
55
56    /**
57    @brief
58        Destructor.
59    */
60    EventMultiTrigger::~EventMultiTrigger()
61    {
62
63    }
64
65    /**
66    @brief
67        Method for creating an EventMultiTrigger object through XML.
68    */
69    void EventMultiTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(EventMultiTrigger, XMLPort, xmlelement, mode);
72
73        this->setBroadcast(true);
74    }
75
76    /**
77    @brief
78        Creates an event port.
79    */
80    void EventMultiTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
81    {
82        SUPER(EventMultiTrigger, XMLEventPort, xmlelement, mode);
83
84        XMLPortEventState(EventMultiTrigger, BaseObject, "trigger", trigger, xmlelement, mode);
85    }
86
87    /**
88    @brief
89        Method that causes the EventMultiTrigger to trigger upon receiving an event.
90    @param bTriggered
91        Whether the event is a triggering or an un-triggering event.
92    @param originator
93        A pointer to the entity the event originates from.
94    */
95    void EventMultiTrigger::trigger(bool bTriggered, BaseObject* originator)
96    {
97        // If the originator is a MultiTriggerContainer, the event originates from a MultiTrigger and thus the event only triggers the EventMultiTrigger for the originator that caused the MultiTrigger to trigger.
98        if(originator != NULL && originator->isA(ClassIdentifier<MultiTriggerContainer>::getIdentifier()))
99        {
100            MultiTriggerContainer* container = static_cast<MultiTriggerContainer*>(originator);
101            // If the entity that triggered the MultiTrigger is no target of this EventMultiTrigger we process it as it weren't an event caused by a MultiTrigger.
102            // But if it is the EventMultiTrigger only triggers for the entity tha caused the MultiTrigger to trigger.
103            if(this->isTarget(container->getData()))
104            {
105                if(this->isTriggered(container->getData()) ^ bTriggered)
106                    this->changeTriggered(container->getData());
107
108                return;
109            }
110        }
111
112        // If we don't know who exactly caused the event we just send a broadcast.
113        if(this->isTriggered() ^ bTriggered)
114            this->changeTriggered();
115    }
116
117}
118
Note: See TracBrowser for help on using the repository browser.