Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/release2012/src/modules/objects/triggers/DistanceMultiTrigger.h @ 11183

Last change on this file since 11183 was 9016, checked in by jo, 13 years ago

Merging presentation2011 branch to trunk. Please check for possible bugs.

  • Property svn:eol-style set to native
File size: 7.4 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 DistanceMultiTrigger.h
31    @brief Definition of the DistanceMultiTrigger class.
32    @ingroup MultiTrigger
33*/
34
35#ifndef _DistanceMultiTrigger_H__
36#define _DistanceMultiTrigger_H__
37
38#include "objects/ObjectsPrereqs.h"
39
40#include <map>
41
42#include "core/WeakPtr.h"
43
44#include "worldentities/WorldEntity.h"
45
46#include "MultiTrigger.h"
47
48namespace orxonox
49{
50
51    /**
52    @brief
53        Enum for the beacon mode of the DistanceMultiTrigger.
54       
55    @ingroup MultiTrigger
56    */
57    namespace distanceMultiTriggerBeaconMode
58    {
59        enum Value {
60            off, //!< The DistanceMultiTrigger is not in <em>beacon-mode</em>.
61            identify, //!< The DistanceTrigger is in <em>identify-mode</em>.
62            exclude //!< The DistanceTrigger is in <em>exclude-mode</em>.
63        };
64    }
65
66    /**
67    @brief
68        The DistanceMultiTrigger is a MultiTrigger that triggers whenever an object (that is of the specified target type) is in a specified range of the DistanceMultiTrigger. The object can be specified further by setting the <em>beaconMode</em> and attaching a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" to the object.
69        Parameters are (additional to the ones of MultiTrigger):
70        - @b distance Which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is <code>100</code>.
71        - @b beaconMode Which specifies, whether the DistanceMultiTrigger operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the DistanceMultiTrigger is only triggered by objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. If set to <em>exclude</em> the DistanceMultiTrigger is only triggered by objects that don't have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon", with the same name as specified in <em>targetname</em>, attached to them. Default is <em>off</em>.
72        - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceMultiTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).
73
74        A simple DistanceMultiTrigger could look like this:
75        @code
76        <DistanceMultiTrigger position="0,0,0" switch="true" target="Pawn" distance="20" />
77        @endcode
78
79        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
80        @code
81        <DistanceMultiTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" />
82        @endcode
83        This particular DistanceMultiTrigger would only react if an object was in range, that had a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the name <em>beacon1</em> attached.
84
85    @see MultiTrigger
86        For more information on @ref orxonox::MultiTrigger "MultiTriggers".
87
88    @author
89        Damian 'Mozork' Frick
90
91    @ingroup MultiTrigger
92    */
93    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
94    {
95
96        public:
97            DistanceMultiTrigger(BaseObject* creator); // Default Constructor. Registers the object and initializes default values.
98            virtual ~DistanceMultiTrigger(); // Destructor.
99
100            void XMLPort(Element& xmlelement, XMLPort::Mode mode); // Method for creating a DistanceMultiTrigger object through XML.
101           
102            /**
103            @brief Set the distance at which the DistanceMultiTrigger triggers.
104            @param distance The distance.
105            */
106            inline void setDistance(float distance)
107                { if(distance >= 0) this->distance_ = distance; }
108            /**
109            @brief Get the distance at which the DistanceMultiTrigger triggers.
110            @return Returns the distance.
111            */
112            inline float getDistance() const
113                { return this->distance_; }
114           
115            void setBeaconModeDirect(distanceMultiTriggerBeaconMode::Value mode); // Set the beacon mode.
116            /**
117            @brief Get the beacon mode.
118            @return Returns the mode as an enum.
119            */
120            inline distanceMultiTriggerBeaconMode::Value getBeaconModeDirect(void) const
121                { return this->beaconMode_; }
122            void setBeaconMode(const std::string& mode); // Set the beacon mode.
123            const std::string& getBeaconMode(void) const; // Get the beacon mode.
124
125            /**
126            @brief Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
127            @param targetname The name of the DistanceTriggerBeacon as a string.
128            */
129            inline void setTargetName(const std::string& targetname)
130                { this->targetName_ = targetname; }
131            /**
132            @brief Get the target name of the DistanceTriggerbeacon, that triggers this DistanceMultiTrigger.
133            @return Returns the target name as a string.
134            */
135            inline const std::string& getTargetName(void) const
136                { return this->targetName_; }
137
138        protected:
139            virtual std::queue<MultiTriggerState*>* letTrigger(void); // This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
140
141            bool addToRange(WorldEntity* entity); // Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
142            bool removeFromRange(WorldEntity* entity); // Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
143
144        private:
145            //! Strings for the beacon modes.
146            static const std::string beaconModeOff_s;
147            static const std::string beaconModeIdentify_s;
148            static const std::string beaconModeExlcude_s;
149           
150            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
151
152            distanceMultiTriggerBeaconMode::Value beaconMode_; //!< The beacon mode, the DistanceMultiTrigger is in.
153            std::string targetName_; //!< The target name, used in <em>single-target</em> mode.
154            ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
155
156            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
157
158    };
159
160}
161
162#endif // _DistanceMultiTrigger_H__
Note: See TracBrowser for help on using the repository browser.