Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/triggers/DistanceTrigger.h @ 11985

Last change on this file since 11985 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

  • Property svn:eol-style set to native
File size: 7.3 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  enum class DistanceTriggerBeaconMode {
58      off,
59      identify,
60      exclude
61  };
62
63    /**
64    @brief
65        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.
66        Parameters are (additional to the ones of Trigger):
67        - @b distance Which specifies the maximum distance at which the DistanceTrigger still triggers, i.e. its range. Default is <code>100</code>.
68        - @b target Which specifies the class of objects that can trigger the DistanceTrigger. Default is <code>"Pawn"</code>.
69        - @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>.
70        - @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>).
71
72        A simple DistanceTrigger could look like this:
73        @code
74        <DistanceTrigger position="0,0,0" switch="true" target="Pawn" distance="20" />
75        @endcode
76
77        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
78        @code
79        <DistanceTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" />
80        @endcode
81        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.
82
83    @see Trigger
84        For more information on @ref orxonox::Trigger "Triggers".
85
86    @author
87        Benjamin Knecht
88    @author
89        Damian 'Mozork' Frick
90
91    @ingroup NormalTrigger
92    */
93    class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger
94    {
95        public:
96            DistanceTrigger(Context* context); // Constructor. Registers and initializes the object.
97            virtual ~DistanceTrigger();
98
99            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; // Method for creating a DistanceTrigger object through XML.
100
101            void addTarget(const std::string& targets); // Add some target to the DistanceTrigger.
102            void removeTarget(const std::string& targets); // Remove some target from the DistanceTrigger.
103
104            /**
105            @brief Set the range of the DistanceTrigger.
106            @param distance The range to be set.
107            */
108            inline void setDistance(float distance)
109                { this->distance_ = distance; }
110            /**
111            @brief Get the range of the DistanceTrigger.
112            @return Returns the range of the distance trigger.
113            */
114            inline float getDistance() const
115                { return this->distance_; }
116
117            void setBeaconModeDirect(DistanceTriggerBeaconMode mode); // Set the beacon mode.
118            /**
119            @brief Get the beacon mode.
120            @return Returns the mode as an enum.
121            */
122            inline DistanceTriggerBeaconMode getBeaconModeDirect(void) const
123            { return this->beaconMode_; }
124            void setBeaconMode(const std::string& mode); // Set the beacon mode.
125            const std::string& getBeaconMode(void) const; // Get the beacon mode.
126
127            /**
128            @brief Set the name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode.
129            @param targetname The name as a string.
130            */
131            inline void setTargetName(const std::string& targetname)
132                { this->targetName_ = targetname; }
133            /**
134            @brief Get the target name.
135            @return Returns the target name as a string.
136            */
137            inline const std::string& getTargetName(void)
138                { return this->targetName_; }
139
140            bool checkDistance(); // Check, whether there are entities that are targets of this DistanceTrigger in its range.
141
142        protected:
143            virtual bool isTriggered(TriggerMode mode) override; // Check whether the DistanceTrigger is triggered.
144            /**
145            @brief Notifies interested parties about a change of the DistanceTrigger's target mask.
146            */
147            virtual void notifyMaskUpdate() {}
148
149            ClassTreeMask targetMask_; //!< The target mask, specifies by which types of objects the DistanceTrigger can be triggered.
150
151        private:
152            //! Strings for the beacon modes.
153            static const std::string beaconModeOff_s;
154            static const std::string beaconModeIdentify_s;
155            static const std::string beaconModeExlcude_s;
156
157            float distance_; //!< The range of the DistanceTrigger.
158           
159            DistanceTriggerBeaconMode beaconMode_; //!< The beacon mode.
160            std::string targetName_; //!< The name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode.
161            ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
162           
163            WeakPtr<WorldEntity> cache_; //!< Caches the entity that triggered the DistanceTrigger last.
164    };
165}
166
167#endif /* _DistanceTrigger_H__ */
Note: See TracBrowser for help on using the repository browser.