Index: /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
===================================================================
--- /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc	(revision 2028)
+++ /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc	(revision 2029)
@@ -41,9 +41,18 @@
     RegisterObject(DistanceTrigger);
 
-    targetMask_.exclude(Class(BaseObject));
+    this->distance_ = 100;
+    this->targetMask_.exclude(Class(BaseObject));
   }
 
   DistanceTrigger::~DistanceTrigger()
   {
+  }
+
+  void DistanceTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+  {
+    SUPER(DistanceTrigger, XMLPort, xmlelement, mode);
+
+    XMLPortParam(DistanceTrigger, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(100.0f);
+    XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode);
   }
 
@@ -61,5 +70,5 @@
       COUT(4) << "Content of targetSet of trigger " << this << " :" << std::endl;
       std::set<Ogre::Node*>::iterator it;
-      for(it = this->targetSet_.begin(); it != this->targetSet_.end(); it++)
+      for (it = this->targetSet_.begin(); it != this->targetSet_.end(); ++it)
       {
         COUT(4) << *it << std::endl;
@@ -87,14 +96,12 @@
   {
     // Iterate through all WorldEntities
-    for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; it++)
+    for (Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it)
     {
       // check if WorldEntity is a target
-      if(targetMask_.isIncluded(it->getIdentifier()))
+      if (targetMask_.isIncluded(it->getIdentifier()))
       {
         Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition();
         if (distanceVec.length() < this->distance_)
-        {
           return true;
-        }
       }
     }
@@ -103,20 +110,7 @@
   }
 
-  void DistanceTrigger::setDistance(float dist)
-  {
-    this->distance_ = dist;
-  }
-
-  void DistanceTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-  {
-    Trigger::XMLPort(xmlelement, mode);
-
-    XMLPortParamLoadOnly(DistanceTrigger, "distance", setDistance, xmlelement, mode);
-    XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode);
-  }
-
   bool DistanceTrigger::isTriggered(TriggerMode mode)
   {
-    if(Trigger::isTriggered(mode))
+    if (Trigger::isTriggered(mode))
       return checkDistance();
     else
Index: /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h
===================================================================
--- /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h	(revision 2028)
+++ /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h	(revision 2029)
@@ -46,10 +46,17 @@
       DistanceTrigger(BaseObject* creator);
       ~DistanceTrigger();
+
+      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
       void addTarget(Ogre::Node* targetNode);
+      void addTargets(const std::string& targets);
       void removeTarget(Ogre::Node* targetNode);
-      void addTargets(const std::string& targets);
       void removeTargets(const std::string& targets);
-      void setDistance(float dist);
-      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+      inline void setDistance(float distance)
+        { this->distance_ = distance; }
+      inline float getDistance() const
+        { return this->distance_; }
+
       bool checkDistance();
 
Index: /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc
===================================================================
--- /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc	(revision 2028)
+++ /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc	(revision 2029)
@@ -48,21 +48,25 @@
     RegisterObject(Trigger);
 
-    mode_ = TM_EventTriggerAND;
-    bActive_ = false;
-    bInvertMode_ = false;
-    delay_ = 0.0;
-    bTriggered_ = false;
-    bUpdating_ = false;
-    remainingActivations_ = -1;
-    bStayOn_ = false;
-    latestState_ = 0x0;
+    this->mode_ = TM_EventTriggerAND;
+
+    this->bActive_ = false;
+    this->bTriggered_ = false;
+    this->latestState_ = 0x0;
+
+    this->bInvertMode_ = false;
+    this->bSwitch_ = false;
+    this->bStayActive_ = false;
+    this->delay_ = 0.0;
+    this->remainingActivations_ = -1;
+
+//    this->bUpdating_ = false;
 
     if (this->getScene() && this->getScene()->getSceneManager())
     {
-      debugBillboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
-      debugBillboard_.setVisible(false);
-    }
-
-    this->getNode()->attachObject(debugBillboard_.getBillboardSet());
+      this->debugBillboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
+      this->debugBillboard_.setVisible(false);
+    }
+
+    this->getNode()->attachObject(this->debugBillboard_.getBillboardSet());
   }
 
@@ -71,33 +75,16 @@
   }
 
-  void Trigger::init()
-  {
-    timeSinceLastEvent_ = delay_;
-  }
-
-  void Trigger::debugFlares(bool bVisible)
-  {
-    for (ObjectList<Trigger>::iterator it = ObjectList<Trigger>::begin(); it != ObjectList<Trigger>::end(); ++it)
-      it->setVisible(bVisible);
-  }
-
-  void Trigger::changedVisibility()
-  {
-    debugBillboard_.setVisible(this->isVisible());
-  }
-
-  const Trigger* Trigger::getTrigger(unsigned int index) const
-  {
-    if (children_.size() <= index)
-      return NULL;
-
-    std::set<Trigger*>::const_iterator it;
-    it = children_.begin();
-
-    for ( unsigned int i = 0; i != index; i++ )
-    {
-      it++;
-    }
-    return *it;
+  void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+  {
+    SUPER(Trigger, XMLPort, xmlelement, mode);
+
+    XMLPortParam(Trigger, "delay",       setDelay,       getDelay,       xmlelement, mode).defaultValues(0.0f);
+    XMLPortParam(Trigger, "switch",      setSwitch,      getSwitch,      xmlelement, mode).defaultValues(false);
+    XMLPortParam(Trigger, "stayactive",  setStayActive,  getStayActive,  xmlelement, mode).defaultValues(false);
+    XMLPortParam(Trigger, "activations", setActivations, getActivations, xmlelement, mode).defaultValues(-1);
+    XMLPortParam(Trigger, "invert",      setInvert,      getInvert,      xmlelement, mode).defaultValues(false);
+    XMLPortParamTemplate(Trigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&).defaultValues("or");
+
+    XMLPortObject(Trigger, Trigger, "", addTrigger, getTrigger, xmlelement, mode);
   }
 
@@ -105,20 +92,19 @@
   {
 
-    bool newTriggered;
-    newTriggered = this->isTriggered();
+    bool newTriggered = this->isTriggered();
 
     // check if new triggering event is really new
-    if((this->latestState_ & 0x1) != newTriggered)
+    if ((this->latestState_ & 0x1) != newTriggered)
     {
       // create new state
-      if(newTriggered)
+      if (newTriggered)
       {
-        latestState_ |= 1; // set trigger bit
+        this->latestState_ |= 1; // set trigger bit to 1
         this->switchState();
       }
       else
       {
-        latestState_ &= 0xFE; // set trigger bit
-        if (this->bStayOn_)
+        this->latestState_ &= 0xFE; // set trigger bit to 0
+        if (this->bSwitch_)
           this->storeState();
         else
@@ -127,64 +113,46 @@
     }
 
-    if(remainingTime_ > 0.0)
-    {
-      remainingTime_ -= dt;
+    if (this->remainingTime_ > 0.0)
+    {
+      this->remainingTime_ -= dt;
       // only increase when acctually waiting for a state in the queue
-      if(timeSinceLastEvent_ >= 0.0)
-        timeSinceLastEvent_ += dt;
-    }
-
-    while(remainingTime_ <= 0.0 && stateChanges_.size() > 0)
+      if (this->timeSinceLastEvent_ >= 0.0)
+        this->timeSinceLastEvent_ += dt;
+    }
+
+    while (this->remainingTime_ <= 0.0 && this->stateChanges_.size() > 0)
     {
       // time ran out, change state to new one
-      char newState = stateChanges_.front().second;
-      bTriggered_ = (newState & 0x1);
-      bActive_ = newState & 2;
+      char newState = this->stateChanges_.front().second;
+      this->bTriggered_ = (newState & 0x1);
+      this->bActive_ = newState & 2;
       this->stateChanges_.pop();
-      if(stateChanges_.size() != 0)
-        remainingTime_ = stateChanges_.front().first;
+      if (this->stateChanges_.size() != 0)
+        this->remainingTime_ = this->stateChanges_.front().first;
       else
-        timeSinceLastEvent_ = delay_;
-    }
-
-
-
-    if (bTriggered_ && bActive_)
+        this->timeSinceLastEvent_ = this->delay_;
+    }
+
+    if (this->bTriggered_ && this->bActive_)
       this->setBillboardColour(ColourValue(0.5, 1.0, 0.0));
-    else if (!bTriggered_ && bActive_)
+    else if (!this->bTriggered_ && this->bActive_)
       this->setBillboardColour(ColourValue(0.0, 1.0, 0.0));
-    else if (bTriggered_ && !bActive_)
+    else if (this->bTriggered_ && !this->bActive_)
       this->setBillboardColour(ColourValue(1.0, 0.5, 0.0));
     else
       this->setBillboardColour(ColourValue(1.0, 0.0, 0.0));
-    bUpdating_ = false;
-  }
-
-  void Trigger::setBillboardColour(ColourValue colour)
-  {
-    this->debugBillboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
-  }
-
-  void Trigger::storeState()
-  {
-    // put state change into queue
-    this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));
-    // reset time since last event
-    timeSinceLastEvent_ = 0.0;
-
-    if(this->stateChanges_.size() == 1)
-      remainingTime_ = stateChanges_.front().first;
   }
 
   bool Trigger::isTriggered(TriggerMode mode)
   {
-    if(bUpdating_)
-      return bTriggered_;
-
-    if( children_.size() != 0 )
-    {
-      bUpdating_ = true;
+//    if (this->bUpdating_)
+//      return this->bTriggered_;
+
+//    this->bUpdating_ = true;
+    if (this->children_.size() != 0)
+    {
       bool returnval = false;
-      switch(mode)
+
+      switch (mode)
       {
         case TM_EventTriggerAND:
@@ -201,5 +169,7 @@
           break;
       }
-      if(bInvertMode_)
+//      this->bUpdating_ = false;
+
+      if (this->bInvertMode_)
         return !returnval;
       else
@@ -209,61 +179,10 @@
   }
 
-  void Trigger::setDelay(float delay)
-  {
-    this->delay_ = delay;
-  }
-
-  void Trigger::setMode(const std::string& modeName)
-  {
-    if (modeName == "and")
-      setMode(TM_EventTriggerAND);
-    else if (modeName == "or")
-      setMode(TM_EventTriggerOR);
-    else if (modeName == "xor")
-      setMode(TM_EventTriggerXOR);
-  }
-
-  void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-  {
-    WorldEntity::XMLPort(xmlelement, mode);
-
-    XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode);
-    XMLPortParamLoadOnly(Trigger, "stayOn", setStayOn, xmlelement, mode);
-    XMLPortParamLoadOnly(Trigger, "activations", setActivations, xmlelement, mode);
-    XMLPortParamLoadOnly(Trigger, "invert", setInvert, xmlelement, mode);
-    XMLPortParamLoadOnlyTemplate(Trigger, "mode", setMode, xmlelement, mode, const std::string&);
-
-    XMLPortObject(Trigger, Trigger, "", addTrigger, getTrigger, xmlelement, mode);
-
-    this->init();
-  }
-
-  void Trigger::addTrigger(Trigger* trig)
-  {
-    if (this != trig)
-      this->children_.insert(trig);
-  }
-
-  bool Trigger::switchState()
-  {
-    if ( remainingActivations_ <= -1 || this->latestState_ & 2 || remainingActivations_ > 0)
-    {
-      this->latestState_ ^= 2; // toggle state bit
-      // increase activation count
-      if (this->latestState_ & 2) remainingActivations_--;
-      this->storeState();
-
-      return true;
-    }
-    return false;
-  }
-
-
   bool Trigger::checkAnd()
   {
     std::set<Trigger*>::iterator it;
-    for(it = this->children_.begin(); it != this->children_.end(); it++)
-    {
-      if(!((*it)->isActive()))
+    for(it = this->children_.begin(); it != this->children_.end(); ++it)
+    {
+      if (!(*it)->isActive())
         return false;
     }
@@ -274,7 +193,7 @@
   {
     std::set<Trigger*>::iterator it;
-    for(it = this->children_.begin(); it != this->children_.end(); it++)
-    {
-      if((*it)->isActive())
+    for(it = this->children_.begin(); it != this->children_.end(); ++it)
+    {
+      if ((*it)->isActive())
         return true;
     }
@@ -286,9 +205,9 @@
     std::set<Trigger*>::iterator it;
     bool test = false;
-    for(it = this->children_.begin(); it != this->children_.end(); it++)
-    {
-      if(test && (*it)->isActive())
+    for(it = this->children_.begin(); it != this->children_.end(); ++it)
+    {
+      if (test && (*it)->isActive())
         return false;
-      if((*it)->isActive())
+      if ((*it)->isActive())
         test = true;
     }
@@ -296,3 +215,98 @@
   }
 
+  bool Trigger::switchState()
+  {
+    if (( (this->latestState_ & 2) && this->bStayActive_ && (this->remainingActivations_ <= 0))
+     || (!(this->latestState_ & 2))                      && (this->remainingActivations_ == 0))
+      return false;
+    else
+    {
+      this->latestState_ ^= 2; // toggle state bit
+
+      // increase activation count
+      if (this->latestState_ & 2 && this->remainingActivations_ > 0)
+        this->remainingActivations_--;
+
+      this->storeState();
+
+      return true;
+    }
+  }
+
+  void Trigger::storeState()
+  {
+    // put state change into queue
+    this->stateChanges_.push(std::pair<float, char>(this->timeSinceLastEvent_, this->latestState_));
+    // reset time since last event
+    this->timeSinceLastEvent_ = 0.0;
+
+    if (this->stateChanges_.size() == 1)
+      this->remainingTime_ = this->stateChanges_.front().first;
+  }
+
+  void Trigger::setDelay(float delay)
+  {
+    this->delay_ = delay;
+    this->timeSinceLastEvent_ = delay;
+  }
+
+  void Trigger::setMode(const std::string& modeName)
+  {
+    if (modeName == "and")
+      this->setMode(TM_EventTriggerAND);
+    else if (modeName == "or")
+      this->setMode(TM_EventTriggerOR);
+    else if (modeName == "xor")
+      this->setMode(TM_EventTriggerXOR);
+  }
+
+  std::string Trigger::getModeString() const
+  {
+    if (this->mode_ == TM_EventTriggerAND)
+      return std::string("and");
+    else if (this->mode_ == TM_EventTriggerOR)
+      return std::string("or");
+    else if (this->mode_ == TM_EventTriggerXOR)
+      return std::string("xor");
+    else
+      return std::string("and");
+  }
+
+  void Trigger::addTrigger(Trigger* trigger)
+  {
+    if (this != trigger)
+      this->children_.insert(trigger);
+  }
+
+  const Trigger* Trigger::getTrigger(unsigned int index) const
+  {
+    if (this->children_.size() <= index)
+      return NULL;
+
+    std::set<Trigger*>::const_iterator it;
+    it = this->children_.begin();
+
+    for (unsigned int i = 0; i != index; ++i)
+      ++it;
+
+    return (*it);
+  }
+
+  void Trigger::debugFlares(bool bVisible)
+  {
+    for (ObjectList<Trigger>::iterator it = ObjectList<Trigger>::begin(); it != ObjectList<Trigger>::end(); ++it)
+      it->setVisible(bVisible);
+  }
+
+  void Trigger::setBillboardColour(const ColourValue& colour)
+  {
+    this->debugBillboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
+  }
+
+  void Trigger::changedVisibility()
+  {
+    SUPER(Trigger, changedVisibility);
+
+    this->debugBillboard_.setVisible(this->isVisible());
+  }
 }
Index: /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h
===================================================================
--- /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h	(revision 2028)
+++ /code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h	(revision 2029)
@@ -38,6 +38,6 @@
 #include "tools/BillboardSet.h"
 
-namespace orxonox {
-
+namespace orxonox
+{
   enum TriggerMode
   {
@@ -59,32 +59,41 @@
         { return bActive_; }
 
-      void addTrigger(Trigger* trig);
+      void addTrigger(Trigger* trigger);
       const Trigger* getTrigger(unsigned int index) const;
 
+      void setMode(const std::string& modeName);
+      inline void setMode(TriggerMode mode)
+        { this->mode_ = mode; }
       inline TriggerMode getMode() const
         { return mode_; }
-      inline void setMode(TriggerMode mode)
-        { this->mode_ = mode; }
-      void setMode(const std::string& modeName);
 
-      inline void setInvert(int invert)
-        { bInvertMode_ = invert; }
-      inline void setStayOn(int stayOn)
-        { this->bStayOn_ = (stayOn == 1) ? true : false; }
+      inline void setInvert(bool bInvert)
+        { this->bInvertMode_ = bInvert; }
+      inline bool getInvert() const
+        { return this->bInvertMode_; }
+
+      inline void setSwitch(bool bSwitch)
+        { this->bSwitch_ = bSwitch; }
+      inline bool getSwitch() const
+        { return this->bSwitch_; }
+
+      inline void setStayActive(bool bStayActive)
+        { this->bStayActive_ = bStayActive; }
+      inline bool getStayActive() const
+        { return this->bStayActive_; }
+
       inline void setActivations(int activations)
         { this->remainingActivations_ = activations; }
+      inline int getActivations() const
+        { return this->remainingActivations_; }
+
       void setDelay(float delay);
+      inline float getDelay() const
+        { return this->delay_; }
+
       bool switchState();
 
       static void debugFlares(bool bVisible);
       virtual void changedVisibility();
-
-    private:
-      void init();
-      bool checkAnd();
-      bool checkOr();
-      bool checkXor();
-      void setBillboardColour(ColourValue colour);
-      void storeState();
 
     protected:
@@ -93,18 +102,30 @@
 
     private:
-      std::set<Trigger*> children_;
-      std::queue<std::pair<float,char> > stateChanges_;
+      bool checkAnd();
+      bool checkOr();
+      bool checkXor();
+      void setBillboardColour(const ColourValue& colour);
+      void storeState();
+      std::string getModeString() const;
+
+      bool bActive_;
+      bool bTriggered_;
+
+      TriggerMode mode_;
+      bool bInvertMode_;
+      bool bSwitch_;
+      bool bStayActive_;
+      float delay_;
+      int remainingActivations_;
+
+      char latestState_;
       float remainingTime_;
       float timeSinceLastEvent_;
-      TriggerMode mode_;
-      bool bActive_;
-      bool bInvertMode_;
-      bool bTriggered_;
-      bool bUpdating_;
+
+//      bool bUpdating_;
       BillboardSet debugBillboard_;
-      float delay_;
-      int remainingActivations_;
-      bool bStayOn_;
-      char latestState_;
+
+      std::set<Trigger*> children_;
+      std::queue<std::pair<float, char> > stateChanges_;
   };
 
