Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h @ 8029

Last change on this file since 8029 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
RevLine 
[6800]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
[6857]29/**
30    @file DistanceMultiTrigger.h
31    @brief Definition of the DistanceMultiTrigger class.
[7601]32    @ingroup MultiTrigger
[6857]33*/
34
[6800]35#ifndef _DistanceMultiTrigger_H__
36#define _DistanceMultiTrigger_H__
37
38#include "objects/ObjectsPrereqs.h"
39
[6860]40#include <map>
[6800]41
[7601]42#include "core/WeakPtr.h"
43
44#include "worldentities/WorldEntity.h"
45
[6800]46#include "MultiTrigger.h"
47
48namespace orxonox
49{
50
[6857]51    /**
52    @brief
[7601]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.
[7301]54        Parameters are (additional to the ones of MultiTrigger):
[7601]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.
[7301]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
[7601]63        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
[7301]64        @code
65        <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" />
66        @endcode
[7601]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
[6857]70        For more information on MultiTriggers.
[7601]71
[6857]72    @author
73        Damian 'Mozork' Frick
[7601]74
75    @ingroup MultiTrigger
[6857]76    */
[6800]77    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
78    {
[7163]79
[6800]80        public:
[6857]81            DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values.
[7301]82            virtual ~DistanceMultiTrigger(); //!< Destructor.
[7163]83
[6857]84            void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML.
85
[7301]86            void setTargetName(const std::string& targetname); //!< Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
[6857]87            /**
[6906]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_; }
[7163]93
[6906]94            /**
[6857]95            @brief Set the distance at which the DistanceMultiTrigger triggers.
96            @param distance The distance.
97            */
[6800]98            inline void setDistance(float distance)
[6857]99                { if(distance >= 0) this->distance_ = distance; }
100            /**
101            @brief Get the distance at which the DistanceMultiTrigger triggers.
102            @return Returns the distance.
103            */
[6800]104            inline float getDistance() const
105                { return this->distance_; }
[7163]106
[6800]107        protected:
[6857]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
[7301]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.
[7163]112
[6800]113        private:
[6857]114            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
[7601]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.
[7163]117
[6860]118            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
[7163]119
[6800]120    };
[7163]121
[6800]122}
123
124#endif // _DistanceMultiTrigger_H__
Note: See TracBrowser for help on using the repository browser.