Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lastmanstanding3/src/modules/objects/triggers/DistanceMultiTrigger.h @ 8740

Last change on this file since 8740 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: 5.7 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        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 adding a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" (by just attaching it) to the objects that can trigger this DistanceMultiTrigger and specify the name of the @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the parameter <em>targetname</em> and only objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with that name will trigger the DistanceMultiTrigger.
54        Parameters are (additional to the ones of MultiTrigger):
55        - @b distance Which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is 100.
56        - @b targetname Which, if not left blank, causes the DistancMultiTrigger to be in <em>single-target</em> mode, meaning, that it only reacts to objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" (therefore the target has to be set to @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" for it to work), with the name specified by <em>targetname</em>, attached.
57
58        A simple DistanceMultiTrigger would look like this:
59        @code
60        <DistanceMultiTrigger position="0,0,0" switch="true" target="Pawn" distance="20" />
61        @endcode
62
63        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
64        @code
65        <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" />
66        @endcode
67        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.
68
69    @see MultiTrigger
70        For more information on MultiTriggers.
71
72    @author
73        Damian 'Mozork' Frick
74
75    @ingroup MultiTrigger
76    */
77    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
78    {
79
80        public:
81            DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values.
82            virtual ~DistanceMultiTrigger(); //!< Destructor.
83
84            void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML.
85
86            void setTargetName(const std::string& targetname); //!< Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
87            /**
88            @brief Get the target name of the DistanceTriggerbeacon, that triggers this DistanceMultiTrigger.
89            @return Returns the target name as a string.
90            */
91            inline const std::string& getTargetName(void)
92                { return this->targetName_; }
93
94            /**
95            @brief Set the distance at which the DistanceMultiTrigger triggers.
96            @param distance The distance.
97            */
98            inline void setDistance(float distance)
99                { if(distance >= 0) this->distance_ = distance; }
100            /**
101            @brief Get the distance at which the DistanceMultiTrigger triggers.
102            @return Returns the distance.
103            */
104            inline float getDistance() const
105                { return this->distance_; }
106
107        protected:
108            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.
109
110            bool addToRange(WorldEntity* entity); //!< Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
111            bool removeFromRange(WorldEntity* entity); //!< Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
112
113        private:
114            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
115            std::string targetName_; //!< The target name, used in <em>single-target</em> mode.
116            bool singleTargetMode_; //!< To indicate whe the MultiDistanceTrigger is in <em>single-target</em> mode.
117
118            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
119
120    };
121
122}
123
124#endif // _DistanceMultiTrigger_H__
Note: See TracBrowser for help on using the repository browser.