- Timestamp:
- Apr 9, 2011, 3:33:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/triggers/DistanceTrigger.h
r8079 r8213 39 39 40 40 #include <set> 41 41 42 #include "core/ClassTreeMask.h" 43 44 #include "interfaces/PlayerTrigger.h" 45 42 46 #include "Trigger.h" 43 #include "interfaces/PlayerTrigger.h"44 47 45 48 namespace orxonox 46 49 { 47 50 48 51 /** 49 52 @brief 50 51 @author 52 Benjamin Knecht 53 @author 54 Damian 'Mozork' Frick 55 53 Enum for the beacon mode of the DistanceTrigger. 54 56 55 @ingroup NormalTrigger 57 56 */ 58 class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger57 namespace distanceTriggerBeaconMode 59 58 { 60 public: 61 DistanceTrigger(BaseObject* creator); 62 virtual ~DistanceTrigger(); 59 enum Value { 60 off, 61 identify, 62 exclude 63 }; 64 } 63 65 64 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 66 /** 67 @brief 68 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. 69 Parameters are (additional to the ones of Trigger): 70 - @b distance Which specifies the maximum distance at which the DistanceTrigger still triggers, i.e. its range. Default is <code>100</code>. 71 - @b target Which specifies the class of objects that can trigger the DistanceTrigger. Default is <code>"Pawn"</code>. 72 - @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>. 73 - @b targetname Which specifies the name @ref oroxnox::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>). 65 74 66 void addTarget(Ogre::Node* targetNode);67 void addTargets(const std::string& targets);68 void removeTarget(Ogre::Node* targetNode);69 void removeTargets(const std::string& targets);75 A simple DistanceTrigger could look like this: 76 @code 77 <DistanceTrigger position="0,0,0" switch="true" target="Pawn" distance="20" /> 78 @endcode 70 79 71 inline void setTargetName(const std::string& targetname) 72 { if(targetname != "") this->singleTargetMode_ = true; else this->singleTargetMode_ = false; this->targetName_ = targetname; } 73 inline const std::string& getTargetName(void) 74 { return this->targetName_; } 80 An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this: 81 @code 82 <DistanceTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" /> 83 @endcode 84 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. 75 85 76 inline void setDistance(float distance) 77 { this->distance_ = distance; } 78 inline float getDistance() const 79 { return this->distance_; } 86 @see Trigger 87 For more information on @ref orxonox::Trigger "Triggers". 80 88 81 bool checkDistance(); 89 @author 90 Benjamin Knecht 91 @author 92 Damian 'Mozork' Frick 82 93 83 protected: 84 virtual bool isTriggered(TriggerMode::Value mode); 85 virtual void notifyMaskUpdate() {} 94 @ingroup NormalTrigger 95 */ 96 class _ObjectsExport DistanceTrigger : public Trigger, public PlayerTrigger 97 { 98 public: 99 DistanceTrigger(BaseObject* creator); // Constructor. Registers and initializes the object. 100 virtual ~DistanceTrigger(); 86 101 87 ClassTreeMask targetMask_;102 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); // Method for creating a DistanceTrigger object through XML. 88 103 89 private: 90 std::set<Ogre::Node*> targetSet_; 91 std::string targetName_; 92 float distance_; 93 bool singleTargetMode_; 104 void addTarget(const std::string& targets); // Add some target to the DistanceTrigger. 105 void removeTarget(const std::string& targets); // Remove some target from the DistanceTrigger. 94 106 95 }; 107 /** 108 @brief Set the range of the DistanceTrigger. 109 @param distance The range to be set. 110 */ 111 inline void setDistance(float distance) 112 { this->distance_ = distance; } 113 /** 114 @brief Get the range of the DistanceTrigger. 115 @return Returns the range of the distance trigger. 116 */ 117 inline float getDistance() const 118 { return this->distance_; } 119 120 void setBeaconModeDirect(distanceTriggerBeaconMode::Value mode); // Set the beacon mode. 121 /** 122 @brief Get the beacon mode. 123 @return Returns the mode as an enum. 124 */ 125 inline distanceTriggerBeaconMode::Value getBeaconModeDirect(void) const 126 { return this->beaconMode_; } 127 void setBeaconMode(const std::string& mode); // Set the beacon mode. 128 const std::string& getBeaconMode(void) const; // Get the beacon mode. 129 130 /** 131 @brief Set the name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode. 132 @param targetname The name as a string. 133 */ 134 inline void setTargetName(const std::string& targetname) 135 { this->targetName_ = targetname; } 136 /** 137 @brief Get the target name. 138 @return Returns the target name as a string. 139 */ 140 inline const std::string& getTargetName(void) 141 { return this->targetName_; } 142 143 bool checkDistance(); // Check, whether there are entities that are targets of this DistanceTrigger in its range. 144 145 protected: 146 virtual bool isTriggered(TriggerMode::Value mode); // Check whether the DistanceTrigger is triggered. 147 /** 148 @brief Notifies interested parties about a change of the DistanceTrigger's target mask. 149 */ 150 virtual void notifyMaskUpdate() {} 151 152 ClassTreeMask targetMask_; //!< The target mask, specifies by which types of objects the DistanceTrigger can be triggered. 153 154 private: 155 //! Strings for the beacon modes. 156 static const std::string beaconModeOff_s; 157 static const std::string beaconModeIdentify_s; 158 static const std::string beaconModeExlcude_s; 159 160 float distance_; //!< The range of the DistanceTrigger. 161 162 distanceTriggerBeaconMode::Value beaconMode_; //!< The beacon mode. 163 std::string targetName_; //!< The name a DistanceTriggerBeacon needs to have to make the DistanceTrigger react to it if in beacon-mode. 164 ClassTreeMask* beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons. 165 166 WeakPtr<WorldEntity> cache_; //!< Caches the entity that triggered the DistanceTrigger last. 167 }; 96 168 } 97 169
Note: See TracChangeset
for help on using the changeset viewer.