[Orxonox-commit 3596] r8281 - code/branches/spaceboundaries/src/orxonox/worldentities

kmaurus at orxonox.net kmaurus at orxonox.net
Thu Apr 21 16:16:30 CEST 2011


Author: kmaurus
Date: 2011-04-21 16:16:29 +0200 (Thu, 21 Apr 2011)
New Revision: 8281

Modified:
   code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
   code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
possibility to have several SpaceBoundaries instances in one level added

Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	2011-04-21 14:01:44 UTC (rev 8280)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	2011-04-21 14:16:29 UTC (rev 8281)
@@ -73,9 +73,25 @@
             delete this->boundary_;
         }
         
+        this->pawnsIn_.clear();
+        
 //        delete pColoredTextAreaOverlayElementFactory;
     }
     
+    void SpaceBoundaries::checkWhoIsIn()
+    {
+        pawnsIn_.clear();
+        for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
+        {
+            Pawn* currentPawn = *current;
+            float distance = this->computeDistance(currentPawn);
+            if(distance <= this->maxDistance_)
+            {
+                pawnsIn_.push_back(currentPawn);
+            }
+        }
+    }
+    
     void SpaceBoundaries::setMaxDistance(float r)
     {
         this->maxDistance_ = r;
@@ -123,46 +139,47 @@
     
     void SpaceBoundaries::tick(float dt)
     {
-        for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item)
+        
+        COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
+        
+        //for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
+        for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
         {
-            MobileEntity* myMobileEntity = *item;
-            Pawn* currentPawn = dynamic_cast<Pawn*>(myMobileEntity);
-            if(currentPawn != NULL)
+            Pawn* currentPawn = *current;
+            float distance = this->computeDistance(currentPawn);
+            bool humanItem = this->isHumanPlayer(currentPawn);
+            COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
+            if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
             {
-                float distance = this->computeDistance(currentPawn);
-                bool humanItem = this->isHumanPlayer(currentPawn);
-                COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
-                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
+                COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
+                if(humanItem)
                 {
-                    COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
-                    if(humanItem)
-                    {
-                        COUT(0) << "humanItem ist true" << std::endl;
-                        this->displayWarning("Attention! You are leaving the area!");
-                    } else {
-                        
-                    }
+                    COUT(0) << "humanItem ist true" << std::endl;
+                    this->displayWarning("Attention! You are leaving the area!");
+                } else {
+                    
                 }
-                if( (this->maxDistance_ - distance) < this->showDistance_)
+            }
+            if( (this->maxDistance_ - distance) < this->showDistance_)
+            {
+                // Zeige Grenze an!
+                this->displayBoundaries(currentPawn);
+            }
+            if(distance > this->maxDistance_)
+            {
+                if(humanItem)
                 {
-                    // Zeige Grenze an!
-                    this->displayBoundaries(currentPawn);
-                }
-                if(distance > this->maxDistance_)
-                {
-                    if(humanItem)
-                    {
-                        COUT(0) << "Health should be decreasing!" << std::endl;
-                        this->displayWarning("You are out of the area now!");
-                        currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
-                    } else {
-                        
-                    }
+                    COUT(0) << "Health should be decreasing!" << std::endl;
+                    this->displayWarning("You are out of the area now!");
+                    currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
+                } else {
                     
-                    this->bounceBack(currentPawn);
                 }
+                
+                this->bounceBack(currentPawn);
             }
         }
+        this->checkWhoIsIn();
     }
     
     float SpaceBoundaries::computeDistance(WorldEntity *item)
@@ -241,7 +258,7 @@
             //item->setOrientation(item->getOrientation().UnitInverse() );
             
             item->lookAt( velocity + this->getPosition() );
-
+            
             item->setAcceleration(acceleration * dampingFactor);
             item->setVelocity(velocity * dampingFactor);
         }

Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h	2011-04-21 14:01:44 UTC (rev 8280)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h	2011-04-21 14:16:29 UTC (rev 8281)
@@ -26,9 +26,20 @@
  *
  */
  
- /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
-          - Reflexion an Grenze mit Quaternionen machen (--> vgl. Funktion bounceBack() )
+ /* TODO:   - Mehrere SpaceBoundaries-Instanzen pro Level ermoeglichen
+            - Pro Pawn ein Billboard verwenden
  */
+ 
+ 
+ /* REALISIERUNGSIDEEN:
+   
+    Mehrere Instanzen:
+        Im Konstruktor schauen, wer innerhalb der eigenen Grenzen ist und diese in eine Liste geben, die in jeder tick-Funktion
+        durchgearbeitet wird.
+        Moeglichkeit bereitstellen, ein Pawn durch ein Portal einer anderen Instanz von SpaceBoundaries zuzuweisen.
+        Schauen, wie es zu handhaben ist, wenn ein neuer Spieler oder Bot nachtraeglich ins Spiel kommt.
+ 
+ */
 
 #ifndef _SpaceBoundaries_H__
 #define _SpaceBoundaries_H__
@@ -43,6 +54,7 @@
 //#include <ColoredTextAreaOverlayElementFactory.h>
 
 #include <string>
+#include <list>
 
 /**
 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
@@ -65,6 +77,8 @@
             SpaceBoundaries(BaseObject* creator);
             ~SpaceBoundaries();
             
+            void checkWhoIsIn();
+            
             void setMaxDistance(float r);
             float getMaxDistance();
             
@@ -82,6 +96,8 @@
             void tick(float dt);
 
         private:
+            std::list<Pawn*> pawnsIn_;
+        
             float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
             float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
             float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen.




More information about the Orxonox-commit mailing list