[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 | |
---|
[9667] | 42 | #include "core/object/WeakPtr.h" |
---|
[7601] | 43 | |
---|
| 44 | #include "worldentities/WorldEntity.h" |
---|
| 45 | |
---|
[6800] | 46 | #include "MultiTrigger.h" |
---|
| 47 | |
---|
| 48 | namespace orxonox |
---|
| 49 | { |
---|
| 50 | |
---|
[6857] | 51 | /** |
---|
| 52 | @brief |
---|
[8213] | 53 | Enum for the beacon mode of the DistanceMultiTrigger. |
---|
| 54 | |
---|
| 55 | @ingroup MultiTrigger |
---|
| 56 | */ |
---|
[11071] | 57 | enum class DistanceMultiTriggerBeaconMode { |
---|
| 58 | off, //!< The DistanceMultiTrigger is not in <em>beacon-mode</em>. |
---|
| 59 | identify, //!< The DistanceTrigger is in <em>identify-mode</em>. |
---|
| 60 | exclude //!< The DistanceTrigger is in <em>exclude-mode</em>. |
---|
| 61 | }; |
---|
[8213] | 62 | |
---|
| 63 | /** |
---|
| 64 | @brief |
---|
| 65 | 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 setting the <em>beaconMode</em> and attaching a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" to the object. |
---|
[7301] | 66 | Parameters are (additional to the ones of MultiTrigger): |
---|
[8213] | 67 | - @b distance Which specifies the maximum distance at which the DistanceMultiTrigger still triggers. Default is <code>100</code>. |
---|
| 68 | - @b beaconMode Which specifies, whether the DistanceMultiTrigger operates on @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" or not. If <em>off</em> the DistanceMultiTrigger works as usual. If set to <em>identify</em> the DistanceMultiTrigger 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 DistanceMultiTrigger 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>. |
---|
| 69 | - @b targetname Which specifies the name @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacons" need to have to make the DistanceMultiTrigger react to them if it is in <em>beacon-mode</em> (the beaconMode is not <em>off</em>). |
---|
[7301] | 70 | |
---|
[8213] | 71 | A simple DistanceMultiTrigger could look like this: |
---|
[7301] | 72 | @code |
---|
| 73 | <DistanceMultiTrigger position="0,0,0" switch="true" target="Pawn" distance="20" /> |
---|
| 74 | @endcode |
---|
| 75 | |
---|
[7601] | 76 | An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this: |
---|
[7301] | 77 | @code |
---|
[8213] | 78 | <DistanceMultiTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" /> |
---|
[7301] | 79 | @endcode |
---|
[7601] | 80 | 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. |
---|
| 81 | |
---|
| 82 | @see MultiTrigger |
---|
[8213] | 83 | For more information on @ref orxonox::MultiTrigger "MultiTriggers". |
---|
[7601] | 84 | |
---|
[6857] | 85 | @author |
---|
| 86 | Damian 'Mozork' Frick |
---|
[7601] | 87 | |
---|
| 88 | @ingroup MultiTrigger |
---|
[6857] | 89 | */ |
---|
[9016] | 90 | class _ObjectsExport DistanceMultiTrigger : public MultiTrigger |
---|
[6800] | 91 | { |
---|
[7163] | 92 | |
---|
[6800] | 93 | public: |
---|
[9667] | 94 | DistanceMultiTrigger(Context* context); // Default Constructor. Registers the object and initializes default values. |
---|
[8213] | 95 | virtual ~DistanceMultiTrigger(); // Destructor. |
---|
[7163] | 96 | |
---|
[8213] | 97 | void XMLPort(Element& xmlelement, XMLPort::Mode mode); // Method for creating a DistanceMultiTrigger object through XML. |
---|
| 98 | |
---|
[6857] | 99 | /** |
---|
| 100 | @brief Set the distance at which the DistanceMultiTrigger triggers. |
---|
| 101 | @param distance The distance. |
---|
| 102 | */ |
---|
[6800] | 103 | inline void setDistance(float distance) |
---|
[6857] | 104 | { if(distance >= 0) this->distance_ = distance; } |
---|
| 105 | /** |
---|
| 106 | @brief Get the distance at which the DistanceMultiTrigger triggers. |
---|
| 107 | @return Returns the distance. |
---|
| 108 | */ |
---|
[6800] | 109 | inline float getDistance() const |
---|
| 110 | { return this->distance_; } |
---|
[8213] | 111 | |
---|
[11071] | 112 | void setBeaconModeDirect(DistanceMultiTriggerBeaconMode mode); // Set the beacon mode. |
---|
[8213] | 113 | /** |
---|
| 114 | @brief Get the beacon mode. |
---|
| 115 | @return Returns the mode as an enum. |
---|
| 116 | */ |
---|
[11071] | 117 | inline DistanceMultiTriggerBeaconMode getBeaconModeDirect(void) const |
---|
[8213] | 118 | { return this->beaconMode_; } |
---|
| 119 | void setBeaconMode(const std::string& mode); // Set the beacon mode. |
---|
| 120 | const std::string& getBeaconMode(void) const; // Get the beacon mode. |
---|
[7163] | 121 | |
---|
[8213] | 122 | /** |
---|
| 123 | @brief Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger. |
---|
| 124 | @param targetname The name of the DistanceTriggerBeacon as a string. |
---|
| 125 | */ |
---|
| 126 | inline void setTargetName(const std::string& targetname) |
---|
| 127 | { this->targetName_ = targetname; } |
---|
| 128 | /** |
---|
| 129 | @brief Get the target name of the DistanceTriggerbeacon, that triggers this DistanceMultiTrigger. |
---|
| 130 | @return Returns the target name as a string. |
---|
| 131 | */ |
---|
| 132 | inline const std::string& getTargetName(void) const |
---|
| 133 | { return this->targetName_; } |
---|
| 134 | |
---|
[6800] | 135 | protected: |
---|
[8213] | 136 | 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. |
---|
[6857] | 137 | |
---|
[8213] | 138 | bool addToRange(WorldEntity* entity); // Add a given entity to the entities, that currently are in range of the DistanceMultiTrigger. |
---|
[7163] | 139 | |
---|
[6800] | 140 | private: |
---|
[8213] | 141 | //! Strings for the beacon modes. |
---|
| 142 | static const std::string beaconModeOff_s; |
---|
| 143 | static const std::string beaconModeIdentify_s; |
---|
| 144 | static const std::string beaconModeExlcude_s; |
---|
| 145 | |
---|
[6857] | 146 | float distance_; //!< The distance at which the DistanceMultiTrigger triggers. |
---|
[8213] | 147 | |
---|
[11071] | 148 | DistanceMultiTriggerBeaconMode beaconMode_; //!< The beacon mode, the DistanceMultiTrigger is in. |
---|
[7601] | 149 | std::string targetName_; //!< The target name, used in <em>single-target</em> mode. |
---|
[8706] | 150 | ClassTreeMask beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons. |
---|
[7163] | 151 | |
---|
[11071] | 152 | std::set<WeakPtr<WorldEntity>> range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger. |
---|
[7163] | 153 | |
---|
[6800] | 154 | }; |
---|
[7163] | 155 | |
---|
[6800] | 156 | } |
---|
| 157 | |
---|
| 158 | #endif // _DistanceMultiTrigger_H__ |
---|