Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6858 was 6857, checked in by dafrick, 15 years ago

Documented and simplified DistanceMultiTrigger.

File size: 4.2 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.
32*/
33
[6800]34#ifndef _DistanceMultiTrigger_H__
35#define _DistanceMultiTrigger_H__
36
37#include "objects/ObjectsPrereqs.h"
38
39#include "worldentities/WorldEntity.h"
40#include <set>
41
42#include "MultiTrigger.h"
43
44namespace orxonox
45{
46
[6857]47    /**
48    @brief
49        The DistanceMultiTrigger is a trigger that triggers whenever an object (that is of the specified target type) is in a specified range of the DistanceMultiTrigger.
50    @see MultiTrigger.h
51        For more information on MultiTriggers.
52    @author
53        Damian 'Mozork' Frick
54    */
[6800]55    class _ObjectsExport DistanceMultiTrigger : public MultiTrigger
56    {
57       
58        public:
[6857]59            DistanceMultiTrigger(BaseObject* creator); //!< Default Constructor. Registers the object and initializes default values.
60            ~DistanceMultiTrigger(); //!< Destructor.
[6800]61           
[6857]62            void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a DistanceMultiTrigger object through XML.
63
64            /**
65            @brief Set the distance at which the DistanceMultiTrigger triggers.
66            @param distance The distance.
67            */
[6800]68            inline void setDistance(float distance)
[6857]69                { if(distance >= 0) this->distance_ = distance; }
70            /**
71            @brief Get the distance at which the DistanceMultiTrigger triggers.
72            @return Returns the distance.
73            */
[6800]74            inline float getDistance() const
75                { return this->distance_; }
76               
77        protected:
[6857]78            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.
79
80            /**
81            @brief Check whether a given entity is currently (since the last update) in range of the DistanceMultiTrigger.
82            @param entity A pointer to the entity.
83            @return Returns true if the entity is in the range.
84            */
[6800]85            inline bool inRange(WorldEntity* entity)
86                { return this->range_.find(entity) != this->range_.end(); }
[6857]87            /**
88            @brief Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger.
89            @param entity A pointer to the entity.
90            @return Returns true if successful, false if not.
91            */
92            inline bool addToRange(WorldEntity* entity)
[6800]93                { std::pair<std::set<WorldEntity*>::iterator, bool> pair = this->range_.insert(entity); return pair.second; }
[6857]94            /**
95            @brief Remove a given entity from the set of entities, that currently are in range of the DistanceMultiTrigger.
96            @param entity A pointer ot the entity.
97            @return Returns true if successful.
98            */
99            inline bool removeFromRange(WorldEntity* entity)
[6800]100                { return this->range_.erase(entity) > 0; }
101               
102        private:
[6857]103            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
104            std::set<WorldEntity*> range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
[6800]105       
106    };
107   
108}
109
110#endif // _DistanceMultiTrigger_H__
Note: See TracBrowser for help on using the repository browser.