Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8206 for code


Ignore:
Timestamp:
Apr 7, 2011, 10:19:16 PM (14 years ago)
Author:
dafrick
Message:

Extending DistanceTrigger (both the normal and the MultiTrigger version). DistanceTriggerBeacons, can now also be used to exclude specific objects from triggering a DistanceTrigger.
Beware: The syntax for the DistanceTrigger, used with a DistanceTriggerBeacon has changed.
It was: <DistanceTrigger target="DistanceTriggerBeacon" targetname="someBeacon" />
And is now: <DistanceTrigger target="WhateverTargetYouWantYourTriggerToReactTo" beaconMode="identify" targetname="someBeacon" />
Consult the documentation in DistanceMultiTrigger for it's specific usage, the DistanceTrigger works analogously.

Location:
code/branches/dockingsystem2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/dockingsystem2/data/levels/docking.oxw

    r8197 r8206  
    5353            </events>
    5454            <attached>
    55                 <DistanceMultiTrigger position="0,0,0" distance="20" target="Pawn" name="dockMe" />
     55                <DistanceTrigger position="0,0,0" distance="20" target="Pawn" beaconMode="exclude" targetname="beacon1" name="dockMe" />
    5656                <Billboard material="Examples/Flare" colour="1.0, 0, 0" />
    5757            </attached>
    5858        </Dock>
     59        <DistanceTriggerBeacon name="beacon1" />
    5960     
    6061        <TeamSpawnPoint team=1 position="150,0,7" direction="-1,0,0" roll=90 yaw=0 spawnclass=SpaceShip pawndesign=spaceshipassff />
  • code/branches/dockingsystem2/data/levels/fightInOurBack.oxw

    r8079 r8206  
    135135            </events>
    136136            <attached>
    137                 <DistanceTrigger name="FightInOurBack_MainStart_FollowStart" position="0,0,0" distance="50" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" />
     137                <DistanceTrigger name="FightInOurBack_MainStart_FollowStart" position="0,0,0" distance="50" target="Pawn" beaconMode="identify" targetname="PlayerDistanceTrigger" />
    138138                <!--<Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Examples/Flare" />-->
    139139            </attached>
     
    153153            <attached>
    154154                <!--<Billboard position="0,0,0" colour="1,1,1" material="Examples/Flare" />-->
    155                 <DistanceTrigger name="FightInOurBack_FollowEnd_DTranspStart_AssisStart" position="0,0,0" distance="1000" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" stayactive=1 activations=1 />
     155                <DistanceTrigger name="FightInOurBack_FollowEnd_DTranspStart_AssisStart" position="0,0,0" distance="1000" target="Pawn" beaconMode="identify" targetname="PlayerDistanceTrigger" stayactive=1 activations=1 />
    156156            </attached>
    157157        </QuestEffectBeacon>
     
    316316<!---->
    317317<!--Trigger to activate this Team (TEAM NO 1)-->
    318     <DistanceTrigger name="activateTeam0No1" position="8000,0,3100" distance="1000" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" activations="1" stayactive="true" />
     318    <DistanceTrigger name="activateTeam0No1" position="8000,0,3100" distance="1000" target="Pawn" beaconMode="identify" targetname="PlayerDistanceTrigger" activations="1" stayactive="true" />
    319319
    320320<!--TEAM NO 1 (activationType : distance || killing a spaceship what belongs to TEAM 0 NO 0)-->
     
    476476
    477477<Trigger invert=true name="activateFirstSpawnpoint">
    478     <DistanceTrigger name="activateSecondSpawnpoint" position="10000,0,3000" distance="1000" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" activations="1" stayactive="true" />
     478    <DistanceTrigger name="activateSecondSpawnpoint" position="10000,0,3000" distance="1000" target="Pawn" beaconMode="identify" targetname="PlayerDistanceTrigger" activations="1" stayactive="true" />
    479479</Trigger>
    480480
  • code/branches/dockingsystem2/data/levels/pirateAttack.oxw

    r7679 r8206  
    142142            </events>
    143143            <attached>
    144                 <DistanceTrigger name=questbeacon1 position="0,0,0" distance=100 target=DistanceTriggerBeacon targetname=Me/>
     144                <DistanceTrigger name=questbeacon1 position="0,0,0" distance=100 target="Pawn" beaconMode="identify" targetname=Me/>
    145145            </attached>
    146146            </QuestEffectBeacon>
     
    156156                    <attached>
    157157                        <Billboard position="0,0,0" scale=3 colour="1.0,1.0,0" material="Examples/Flare" />
    158                         <DistanceTrigger name=questbeacon2 targetname=Me position="0,0,0" target=DistanceTriggerBeacon distance=400 />
     158                        <DistanceTrigger name=questbeacon2 targetname=Me position="0,0,0" target="Pawn" beaconMode="identify" distance=400 />
    159159                    </attached>
    160160                    <effects>
     
    171171        <QuestEffectBeacon position="0,0,0" times=1>
    172172                    <attached>
    173                         <DistanceTrigger name=questbeacon3  position="0,0,0" distance=300 target=DistanceTriggerBeacon targetname=Me delay="5" />
     173                        <DistanceTrigger name=questbeacon3  position="0,0,0" distance=300 target="Pawn" beaconMode="identify" targetname=Me delay="5" />
    174174                    </attached>
    175175                    <effects>
     
    188188                    <attached>
    189189                        <Billboard position="0,0,0" scale=3 colour="0,1.0,0" material="Examples/Flare" />
    190                         <DistanceTrigger name=questbeacon4  position="0,0,0" distance=200 target=DistanceTriggerBeacon targetname=Me />
     190                        <DistanceTrigger name=questbeacon4  position="0,0,0" distance=200 target="Pawn" beaconMode="identify" targetname=Me />
    191191                    </attached>
    192192   
     
    207207        <QuestEffectBeacon position="7600,300,-8000" times=1>
    208208                    <attached>
    209                         <DistanceTrigger name=questbeacon5  position="0,0,0" distance=300 target=DistanceTriggerBeacon targetname=Me />
     209                        <DistanceTrigger name=questbeacon5  position="0,0,0" distance=300 target="Pawn" beaconMode="identify" targetname=Me />
    210210                    </attached>
    211211                    <effects>
     
    222222        <QuestEffectBeacon position="1600,2300,-10000" times=1>
    223223                    <attached>
    224                         <DistanceTrigger name=questbeacon8  position="0,0,0" distance=300 target=DistanceTriggerBeacon targetname=Me />
     224                        <DistanceTrigger name=questbeacon8  position="0,0,0" distance=300 target="Pawn" beaconMode="identify" targetname=Me />
    225225                    </attached>
    226226                    <effects>
     
    237237        <QuestEffectBeacon position="4600,5300,-11000" times=1>
    238238                    <attached>
    239                         <DistanceTrigger name=questbeacon6  position="0,0,0" distance=600 target=DistanceTriggerBeacon targetname=Me />
     239                        <DistanceTrigger name=questbeacon6  position="0,0,0" distance=600 target="Pawn" beaconMode="identify" targetname=Me />
    240240                    </attached>
    241241                    <effects>
     
    255255        <QuestEffectBeacon position="4800,5785,-10725" times=1>
    256256                    <attached>
    257                         <DistanceTrigger name=questbeacon7  position="0,0,0" distance=30 target=DistanceTriggerBeacon targetname=Me />
     257                        <DistanceTrigger name=questbeacon7  position="0,0,0" distance=30 target="Pawn" beaconMode="identify" targetname=Me />
    258258                    </attached>
    259259                    <effects>
     
    274274                    <attached>
    275275                        <Billboard position="0,0,0" scale=3 colour="0,0,1.0" material="Examples/Flare" />
    276                         <DistanceTrigger name=questbeacon9 position="0,0,0" distance=500 target=DistanceTriggerBeacon targetname=Me />
     276                        <DistanceTrigger name=questbeacon9 position="0,0,0" distance=500 target="Pawn" beaconMode="identify" targetname=Me />
    277277                    </attached>
    278278                    <effects>
  • code/branches/dockingsystem2/data/levels/theTimeMachine.oxw

    r7845 r8206  
    9494   
    9595        <!--TRIGGERS IF THE PLAYERS REACHES THE "TIME MACHINE"-->
    96         <DistanceTrigger name="EnterTimeMachine" position="0,0,0" distance="100" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" >
     96        <DistanceTrigger name="EnterTimeMachine" position="0,0,0" distance="100" target="Pawn" beaconMode="identify" targetname="PlayerDistanceTrigger" >
    9797            <attached>
    9898                <Billboard position="0,0,0" material="Examples/Flare" colour="0, 0, 1" scale=1/>
  • code/branches/dockingsystem2/src/modules/objects/triggers/DistanceMultiTrigger.cc

    r8079 r8206  
    4343{
    4444
     45    /*static*/ const std::string DistanceMultiTrigger::beaconModeOff_s = "off";
     46    /*static*/ const std::string DistanceMultiTrigger::beaconModeIdentify_s = "identify";
     47    /*static*/ const std::string DistanceMultiTrigger::beaconModeExlcude_s = "exclude";
     48   
    4549    CreateFactory(DistanceMultiTrigger);
    4650
     
    4953        Default Constructor. Registers the object and initializes default values.
    5054    */
    51     DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator)
     55    DistanceMultiTrigger::DistanceMultiTrigger(BaseObject* creator) : MultiTrigger(creator), beaconMask_(NULL)
    5256    {
    5357        RegisterObject(DistanceMultiTrigger);
    5458
    5559        this->distance_ = 100.0f;
     60        this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::off);
    5661        this->targetName_ = "";
    57         this->singleTargetMode_ = false;
    5862    }
    5963
     
    6468    DistanceMultiTrigger::~DistanceMultiTrigger()
    6569    {
    66 
     70        if(this->beaconMask_ != NULL)
     71            delete this->beaconMask_;
    6772    }
    6873
     
    7681
    7782        XMLPortParam(DistanceMultiTrigger, "distance", setDistance, getDistance, xmlelement, mode);
     83        XMLPortParam(DistanceMultiTrigger, "beaconMode", setBeaconMode, getBeaconMode, xmlelement, mode);
    7884        XMLPortParam(DistanceMultiTrigger, "targetname", setTargetName, getTargetName, xmlelement, mode);
    7985    }
     
    126132
    127133        // Check for new objects that are in range
    128         for(ClassTreeMaskObjectIterator it = this->getTargetMask().begin(); it != this->getTargetMask().end(); ++it)
     134        ClassTreeMask targetMask = this->getTargetMask();
     135        if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)
     136            targetMask = *this->beaconMask_;
     137
     138        for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
    129139        {
    130140            WorldEntity* entity = static_cast<WorldEntity*>(*it);
    131141
    132             // If the DistanceMultiTrigger is in single-target mode.
    133             if(this->singleTargetMode_)
    134             {
    135                 // If the object that is a target is no DistanceTriggerBeacon, then the DistanceMultiTrigger can't be in single-target mode.
    136                 if(!entity->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
     142            // If the DistanceMultiTrigger is in identify mode and the DistanceTriggerBeacon attached to the object has the wrong name we ignore it.
     143            if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)
     144            {
     145                if(entity->getName() != this->targetName_)
     146                    continue;
     147                // If the object, the DistanceTriggerBeacon is attached to, is not a target of this DistanceMultiTrigger.
     148                else if(this->getTargetMask().isExcluded(entity->getParent()->getIdentifier()))
     149                    continue;
     150            }
     151           
     152            // If the DistanceMultiTrigger is in exclude mode and the DistanceTriggerBeacon attached to the object has the right name, we ignore it.
     153            if(this->beaconMode_ == distanceMultiTriggerBeaconMode::exclude)
     154            {
     155               
     156                const std::set<WorldEntity*> attached = entity->getAttachedObjects();
     157                bool found = false;
     158                for(std::set<WorldEntity*>::const_iterator it = attached.begin(); it != attached.end(); it++)
    137159                {
    138                     this->singleTargetMode_ = false;
    139                     COUT(2) << "DistanceMultiTrigger " << this->getName() << " (&" << this <<  ")" << "is in single-target mode but the target is '" << entity->getIdentifier()->getName() << "' instead of DistanceTriggerBeacon. Setting single-target mode to false." << std::endl;
     160                    if((*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(*it)->getName() == this->targetName_)
     161                    {
     162                        found = true;
     163                        break;
     164                    }
    140165                }
    141                 // If the target name and the name of the DistancTriggerBeacon don't match.
    142                 else if(entity->getName().compare(this->targetName_) != 0)
     166                if(found)
    143167                    continue;
    144168            }
     
    153177                    continue;
    154178
    155                 // Change the entity to the parent of the DistanceTriggerBeacon (if in single-target-mode), which is the entity to which the beacon is attached.
    156                 if(this->singleTargetMode_)
     179                // Change the entity to the parent of the DistanceTriggerBeacon (if in identify-mode), which is the entity to which the beacon is attached.
     180                if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify)
    157181                    entity = entity->getParent();
    158182
     
    171195        return queue;
    172196    }
    173 
    174     /**
    175     @brief
    176         Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
    177     @param targetname
    178         The name of the DistanceTriggerBeacon as a string.
    179     */
    180     void DistanceMultiTrigger::setTargetName(const std::string& targetname)
    181     {
    182         // If the targetname is no blank string single-target mode is enabled.
    183         if(targetname != "")
    184             this->singleTargetMode_ = true;
     197   
     198    /**
     199    @brief
     200        Set the beacon mode.
     201    @param mode
     202        The mode as an enum.
     203    */
     204    void DistanceMultiTrigger::setBeaconModeDirect(distanceMultiTriggerBeaconMode::Value mode)
     205    {
     206        this->beaconMode_ = mode;
     207        if(this->beaconMode_ == distanceMultiTriggerBeaconMode::identify && this->beaconMask_ == NULL)
     208        {
     209            this->beaconMask_ = new ClassTreeMask();
     210            this->beaconMask_->exclude(Class(BaseObject));
     211            this->beaconMask_->include(Class(DistanceTriggerBeacon));
     212        }
     213    }
     214   
     215    /**
     216    @brief
     217        Get the beacon mode.
     218    @return
     219        Returns the mode as a string.
     220    */
     221    const std::string& DistanceMultiTrigger::getBeaconMode(void) const
     222    {
     223        switch(this->getBeaconModeDirect())
     224        {
     225            case distanceMultiTriggerBeaconMode::off :
     226                return DistanceMultiTrigger::beaconModeOff_s;
     227            case distanceMultiTriggerBeaconMode::identify:
     228                return DistanceMultiTrigger::beaconModeIdentify_s;
     229            case distanceMultiTriggerBeaconMode::exclude:
     230                return DistanceMultiTrigger::beaconModeExlcude_s;
     231            default :
     232                assert(0); // This is impossible.
     233                return BLANKSTRING;
     234        }
     235    }
     236   
     237    /**
     238    @brief
     239        Set the beacon mode.
     240    @param mode
     241        The mode as a string.
     242    */
     243    void DistanceMultiTrigger::setBeaconMode(const std::string& mode)
     244    {
     245        if(mode == DistanceMultiTrigger::beaconModeOff_s)
     246            this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::off);
     247        else if(mode == DistanceMultiTrigger::beaconModeIdentify_s)
     248            this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::identify);
     249        else if(mode == DistanceMultiTrigger::beaconModeExlcude_s)
     250            this->setBeaconModeDirect(distanceMultiTriggerBeaconMode::exclude);
    185251        else
    186             this->singleTargetMode_ = false;
    187 
    188         this->targetName_ = targetname;
     252            COUT(1) << "Invalid beacon mode in DistanceMultiTrigger." << endl;
    189253    }
    190254
  • code/branches/dockingsystem2/src/modules/objects/triggers/DistanceMultiTrigger.h

    r7601 r8206  
    5151    /**
    5252    @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.
     53        Enum for the beacon mode of the DistanceMultiTrigger.
     54       
     55    @ingroup MultiTrigger
     56    */
     57    namespace distanceMultiTriggerBeaconMode
     58    {
     59        enum Value {
     60            off,
     61            identify,
     62            exclude
     63        };
     64    }
     65
     66    /**
     67    @brief
     68        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.
    5469        Parameters are (additional to the ones of MultiTrigger):
    5570        - @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.
     71        - @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>.
     72        - @b targetname Which, if not left blank, causes the DistanceMultiTrigger to be in <em>identify</em> beaconMode (unless otherwise specified), meaning, that it only reacts to objects that have a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" with the name specified by <em>targetname</em>, attached.
    5773
    5874        A simple DistanceMultiTrigger would look like this:
     
    6379        An implementation that only reacts to objects with a @ref orxonox::DistanceTriggerBeacon "DistanceTriggerBeacon" attached would look like this:
    6480        @code
    65         <DistanceMultiTrigger position="0,0,0" target="DistanceMultiTrigger" targetname="beacon1" distance="30" />
     81        <DistanceMultiTrigger position="0,0,0" target="Pawn" beaconMode="identify" targetname="beacon1" distance="30" />
    6682        @endcode
    6783        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.
     
    8399
    84100            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 
     101           
    94102            /**
    95103            @brief Set the distance at which the DistanceMultiTrigger triggers.
     
    104112            inline float getDistance() const
    105113                { return this->distance_; }
     114           
     115            void setBeaconModeDirect(distanceMultiTriggerBeaconMode::Value mode); //!< Set the beacon mode.
     116            /**
     117            @brief Get the beacon mode.
     118            @return Returns the mode as an enum.
     119            */
     120            inline distanceMultiTriggerBeaconMode::Value getBeaconModeDirect(void) const
     121                { return this->beaconMode_; }
     122            void setBeaconMode(const std::string& mode); //!< Set the beacon mode.
     123            const std::string& getBeaconMode(void) const; //!< Get the beacon mode.
     124
     125            /**
     126            @brief Set the target name of DistanceTriggerBeacons that triggers this DistanceMultiTrigger.
     127            @param targetname The name of the DistanceTriggerBeacon as a string.
     128            */
     129            inline void setTargetName(const std::string& targetname)
     130                { this->targetName_ = targetname; }
     131            /**
     132            @brief Get the target name of the DistanceTriggerbeacon, that triggers this DistanceMultiTrigger.
     133            @return Returns the target name as a string.
     134            */
     135            inline const std::string& getTargetName(void) const
     136                { return this->targetName_; }
    106137
    107138        protected:
     
    112143
    113144        private:
     145            //! Strings for the beacon modes.
     146            static const std::string beaconModeOff_s;
     147            static const std::string beaconModeIdentify_s;
     148            static const std::string beaconModeExlcude_s;
     149           
    114150            float distance_; //!< The distance at which the DistanceMultiTrigger triggers.
     151
     152            distanceMultiTriggerBeaconMode::Value beaconMode_; //!< The beacon mode, the DistanceMultiTrigger is in.
    115153            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.
     154            ClassTreeMask* beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
    117155
    118156            std::map<WorldEntity*, WeakPtr<WorldEntity>* > range_; //!< The set of entities that currently are in range of the DistanceMultiTrigger.
  • code/branches/dockingsystem2/src/modules/objects/triggers/DistanceTrigger.cc

    r8079 r8206  
    4242namespace orxonox
    4343{
     44   
     45  /*static*/ const std::string DistanceTrigger::beaconModeOff_s = "off";
     46  /*static*/ const std::string DistanceTrigger::beaconModeIdentify_s = "identify";
     47  /*static*/ const std::string DistanceTrigger::beaconModeExlcude_s = "exclude";
     48   
    4449  CreateFactory(DistanceTrigger);
    4550
    46   DistanceTrigger::DistanceTrigger(BaseObject* creator) : Trigger(creator)
     51  DistanceTrigger::DistanceTrigger(BaseObject* creator) : Trigger(creator), beaconMask_(NULL)
    4752  {
    4853    RegisterObject(DistanceTrigger);
     
    5156    this->targetMask_.exclude(Class(BaseObject));
    5257    this->targetName_ = "";
    53     this->singleTargetMode_ = false;
    5458  }
    5559
    5660  DistanceTrigger::~DistanceTrigger()
    5761  {
     62    if(this->beaconMask_ != NULL)
     63      delete this->beaconMask_;
    5864  }
    5965
     
    6470    XMLPortParam(DistanceTrigger, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(100.0f);
    6571    XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn");
     72    XMLPortParam(DistanceTrigger, "beaconMode", setBeaconMode, getBeaconMode, xmlelement, mode);
    6673    XMLPortParam(DistanceTrigger, "targetname", setTargetName, getTargetName, xmlelement, mode);
    6774  }
     
    127134  bool DistanceTrigger::checkDistance()
    128135  {
     136    // Check for new objects that are in range
     137    ClassTreeMask targetMask = this->targetMask_;
     138    if(this->beaconMode_ == distanceTriggerBeaconMode::identify)
     139     targetMask = *this->beaconMask_;
     140   
    129141    // Iterate through all objects
    130     for (ClassTreeMaskObjectIterator it = this->targetMask_.begin(); it != this->targetMask_.end(); ++it)
     142    for (ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
    131143    {
    132144      WorldEntity* entity = orxonox_cast<WorldEntity*>(*it);
    133145      if (!entity)
    134146        continue;
    135 
    136       // If the DistanceTrigger is in single-target mode.
    137       if(this->singleTargetMode_)
    138       {
    139         // If the object that is a target is no DistanceTriggerBeacon, then the DistanceTrigger can't be in single-target-mode.
    140         if(!(*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()))
     147     
     148       // If the DistanceTrigger is in identify mode and the DistanceTriggerBeacon attached to the object has the wrong name we ignore it.
     149      if(this->beaconMode_ == distanceTriggerBeaconMode::identify)
     150      {
     151        if(entity->getName() != this->targetName_)
     152            continue;
     153        // If the object, the DistanceTriggerBeacon is attached to, is not a target of this DistanceMultiTrigger.
     154        else if(this->targetMask_.isExcluded(entity->getParent()->getIdentifier()))
     155            continue;
     156      }
     157   
     158      // If the DistanceTrigger is in exclude mode and the DistanceTriggerBeacon attached to the object has the right name, we ignore it.
     159      if(this->beaconMode_ == distanceTriggerBeaconMode::exclude)
     160      {
     161       
     162        const std::set<WorldEntity*> attached = entity->getAttachedObjects();
     163        bool found = false;
     164        for(std::set<WorldEntity*>::const_iterator it = attached.begin(); it != attached.end(); it++)
    141165        {
    142           this->singleTargetMode_ = false;
    143           COUT(2) << "DistanceTrigger " << this->getName() << " (&" << this <<  ")" << "is in single-target mode but the target is '" << entity->getIdentifier()->getName() << "' instead of DistanceTriggerBeacon. Setting single-target mode to false." << std::endl;
     166          if((*it)->isA(ClassIdentifier<DistanceTriggerBeacon>::getIdentifier()) && static_cast<DistanceTriggerBeacon*>(*it)->getName() == this->targetName_)
     167          {
     168            found = true;
     169            break;
     170          }
    144171        }
    145         // If the target name and the name of the DistancTriggerBeacon don't match.
    146         else if(entity->getName().compare(this->targetName_) != 0)
     172        if(found)
    147173          continue;
    148174      }
     
    152178      {
    153179
    154         // If the target is a player (resp. is a, or is derived from a, ControllableEntity) the triggeringPlayer is set to the target entity.
     180        // If the target is a player (resp. is a, or is derived from a, Pawn) the triggeringPlayer is set to the target entity.
    155181        if(this->isForPlayer())
    156182        {
    157183
    158           // Change the entity to the parent of the DistanceTriggerBeacon (if in single-target-mode), which is the entity to which the beacon is attached.
    159           if(this->singleTargetMode_)
     184          // Change the entity to the parent of the DistanceTriggerBeacon (if in identify-mode), which is the entity to which the beacon is attached.
     185          if(this->beaconMode_ == distanceTriggerBeaconMode::identify)
    160186            entity = entity->getParent();
    161187
     
    170196    return false;
    171197  }
     198 
     199  /**
     200  @brief
     201    Set the beacon mode.
     202  @param mode
     203    The mode as an enum.
     204  */
     205  void DistanceTrigger::setBeaconModeDirect(distanceTriggerBeaconMode::Value mode)
     206  {
     207    this->beaconMode_ = mode;
     208    if(this->beaconMode_ == distanceTriggerBeaconMode::identify && this->beaconMask_ == NULL)
     209    {
     210      this->beaconMask_ = new ClassTreeMask();
     211      this->beaconMask_->exclude(Class(BaseObject));
     212      this->beaconMask_->include(Class(DistanceTriggerBeacon));
     213    }
     214  }
     215   
     216  /**
     217  @brief
     218    Get the beacon mode.
     219  @return
     220    Returns the mode as a string.
     221  */
     222  const std::string& DistanceTrigger::getBeaconMode(void) const
     223  {
     224    switch(this->getBeaconModeDirect())
     225    {
     226      case distanceTriggerBeaconMode::off :
     227        return DistanceTrigger::beaconModeOff_s;
     228      case distanceTriggerBeaconMode::identify:
     229        return DistanceTrigger::beaconModeIdentify_s;
     230      case distanceTriggerBeaconMode::exclude:
     231        return DistanceTrigger::beaconModeExlcude_s;
     232      default :
     233        assert(0); // This is impossible.
     234        return BLANKSTRING;
     235    }
     236  }
     237   
     238  /**
     239  @brief
     240    Set the beacon mode.
     241  @param mode
     242    The mode as a string.
     243  */
     244  void DistanceTrigger::setBeaconMode(const std::string& mode)
     245  {
     246    if(mode == DistanceTrigger::beaconModeOff_s)
     247      this->setBeaconModeDirect(distanceTriggerBeaconMode::off);
     248    else if(mode == DistanceTrigger::beaconModeIdentify_s)
     249      this->setBeaconModeDirect(distanceTriggerBeaconMode::identify);
     250    else if(mode == DistanceTrigger::beaconModeExlcude_s)
     251      this->setBeaconModeDirect(distanceTriggerBeaconMode::exclude);
     252    else
     253      COUT(1) << "Invalid beacon mode in DistanceTrigger." << endl;
     254  }
    172255
    173256  bool DistanceTrigger::isTriggered(TriggerMode::Value mode)
  • code/branches/dockingsystem2/src/modules/objects/triggers/DistanceTrigger.h

    r8079 r8206  
    4545namespace orxonox
    4646{
     47   
     48  /**
     49  @brief
     50      Enum for the beacon mode of the DistanceTrigger.
     51     
     52  @ingroup NormalTrigger
     53  */
     54  namespace distanceTriggerBeaconMode
     55  {
     56      enum Value {
     57          off,
     58          identify,
     59          exclude
     60      };
     61  }
    4762
    4863  /**
     
    6984      void removeTargets(const std::string& targets);
    7085
    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_; }
    75 
    7686      inline void setDistance(float distance)
    7787        { this->distance_ = distance; }
    7888      inline float getDistance() const
    7989        { return this->distance_; }
     90       
     91      void setBeaconModeDirect(distanceTriggerBeaconMode::Value mode); //!< Set the beacon mode.
     92      /**
     93      @brief Get the beacon mode.
     94      @return Returns the mode as an enum.
     95      */
     96      inline distanceTriggerBeaconMode::Value getBeaconModeDirect(void) const
     97        { return this->beaconMode_; }
     98      void setBeaconMode(const std::string& mode); //!< Set the beacon mode.
     99      const std::string& getBeaconMode(void) const; //!< Get the beacon mode.
     100           
     101      inline void setTargetName(const std::string& targetname)
     102        { this->targetName_ = targetname; }
     103      inline const std::string& getTargetName(void)
     104        { return this->targetName_; }
    80105
    81106      bool checkDistance();
     
    88113
    89114    private:
     115      //! Strings for the beacon modes.
     116      static const std::string beaconModeOff_s;
     117      static const std::string beaconModeIdentify_s;
     118      static const std::string beaconModeExlcude_s;
     119           
    90120      std::set<Ogre::Node*> targetSet_;
     121     
     122      distanceTriggerBeaconMode::Value beaconMode_;
    91123      std::string targetName_;
     124      ClassTreeMask* beaconMask_; //!< A mask, that only accepts DistanceTriggerBeacons.
     125     
    92126      float distance_;
    93       bool singleTargetMode_;
    94127
    95128  };
  • code/branches/dockingsystem2/src/modules/objects/triggers/MultiTrigger.cc

    r8193 r8206  
    312312
    313313        // We only want WorldEntities
    314         //TODO: Really?
    315314        ClassTreeMask WEMask;
    316315        WEMask.include(Class(WorldEntity));
Note: See TracChangeset for help on using the changeset viewer.