Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/leveljoemeHS14/src/modules/objects/triggers/DistanceTrigger.h @ 10181

Last change on this file since 10181 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • 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 *      Benjamin Knecht
24 *   Co-authors:
25 *      Damian 'Mozork' Frick
26 *
27 */
28
29/**
30    @file DistanceTrigger.h
31    @brief Definition of the DistanceTrigger class.
32    @ingroup NormalTrigger
33*/
34
35#ifndef _DistanceTrigger_H__
36#define _DistanceTrigger_H__
37
38#include "objects/ObjectsPrereqs.h"
39
40#include <set>
41
42#include "core/ClassTreeMask.h"
43
44#include "interfaces/PlayerTrigger.h"
45
46#include "Trigger.h"
47
48namespace orxonox
49{
50   
51  /**
52  @brief
53      Enum for the beacon mode of the DistanceTrigger.
54     
55  @ingroup NormalTrigger
56  */
57  namespace distanceTriggerBeaconMode
58  {
59      enum Value {
60          off,
61          identify,
62          exclude
63      };
64  }
65
66    /**
67    @brief
68        The DistanceTrigger is a Trigger that triggers whenever an object (that is of the specified target type) is in a specified range of the DistanceTrigger. 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 Trigger):
70        - @b distance Which specifies the maximum distance at which the DistanceTrigger still triggers, i.e. its range. Default is <code>100</code>.
71        - @b target Which specifies the class of objects that can trigger the DistanceTrigger. Default is <code>"Pawn"</code>.
72        - @b beaconMode Which specifies, whether the DistanceTrigger operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the DistanceTrigger 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 DistanceTrigger 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>.
73        - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>).
74
75        A simple DistanceTrigger could look like this:
76        @code
77        <DistanceTrigger position="0,0,0" switch="true" target="Pawn" distance="20" />
78        @endcode
79
80        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
81        @code
82        <DistanceTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" />
83        @endcode
84        This particular DistanceTrigger would only react if an object was in range, that had a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the name <em>beacon1</em> attached.
85
86    @see Trigger
87        For more information on @ref orxonox::Trigger "Triggers".
88
89    @author
90        Benjamin Knecht
91    @author
92        Damian 'Mozork' Frick
93
94    @ingroup NormalTrigger
95    */
96    class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger
97    {
98        public:
99            DistanceTrigger(Context* context); // Constructor. Registers and initializes the object.
100            virtual ~DistanceTrigger();
101
102            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); // Method for creating a DistanceTrigger object through XML.
103
104            void addTarget(const std::string& targets); // Add some target to the DistanceTrigger.
105            void removeTarget(const std::string& targets); // Remove some target from the DistanceTrigger.
106
107            /**
108            @brief Set the range of the DistanceTrigger.
109            @param distance The range to be set.
110            */
111            inline void setDistance(float distance)
112                { this->distance_ = distance; }
113            /**
114            @brief Get the range of the DistanceTrigger.
115            @return Returns the range of the distance trigger.
116            */
117            inline float getDistance() const
118                { return this->distance_; }
119
120            void setBeaconModeDirect(distanceTriggerBeaconMode::Value mode); // Set the beacon mode.
121            /**
122            @brief Get the beacon mode.
123            @return Returns the mode as an enum.
124            */
125            inline distanceTriggerBeaconMode::Value getBeaconModeDirect(void) const
126            { return this->beaconMode_; }
127            void setBeaconMode(const std::string& mode); // Set the beacon mode.
128            const std::string& getBeaconMode(void) const; // Get the beacon mode.
129
130            /**
131            @brief Set the name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode.
132            @param targetname The name as a string.
133            */
134            inline void setTargetName(const std::string& targetname)
135                { this->targetName_ = targetname; }
136            /**
137            @brief Get the target name.
138            @return Returns the target name as a string.
139            */
140            inline const std::string& getTargetName(void)
141                { return this->targetName_; }
142
143            bool checkDistance(); // Check, whether there are entities that are targets of this DistanceTrigger in its range.
144
145        protected:
146            virtual bool isTriggered(TriggerMode::Value mode); // Check whether the DistanceTrigger is triggered.
147            /**
148            @brief Notifies interested parties about a change of the DistanceTrigger's target mask.
149            */
150            virtual void notifyMaskUpdate() {}
151
152            ClassTreeMask targetMask_; //!< The target mask, specifies by which types of objects the DistanceTrigger can be triggered.
153
154        private:
155            //! Strings for the beacon modes.
156            static const std::string beaconModeOff_s;
157            static const std::string beaconModeIdentify_s;
158            static const std::string beaconModeExlcude_s;
159
160            float distance_; //!< The range of the DistanceTrigger.
161           
162            distanceTriggerBeaconMode::Value beaconMode_; //!< The beacon mode.
163            std::string targetName_; //!< The name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode.
164            ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
165           
166            WeakPtr<WorldEntity> cache_; //!< Caches the entity that triggered the DistanceTrigger last.
167    };
168}
169
170#endif /* _DistanceTrigger_H__ */
Note: See TracBrowser for help on using the repository browser.